[llvm] [SPIR-V] Add Fragment execution model (PR #141787)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 28 08:07:20 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-spir-v
Author: Nathan Gauër (Keenuts)
<details>
<summary>Changes</summary>
This commits allows the fragment execution model to be set using the hlsl.shader attribute.
Fixes #<!-- -->136962
---
Full diff: https://github.com/llvm/llvm-project/pull/141787.diff
3 Files Affected:
- (modified) llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp (+14-1)
- (modified) llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp (+2)
- (added) llvm/test/CodeGen/SPIRV/ExecutionMode_Fragment.ll (+12)
``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
index 5991a9af6364d..3a02f2764ad40 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
@@ -279,6 +279,8 @@ getExecutionModel(const SPIRVSubtarget &STI, const Function &F) {
const auto value = attribute.getValueAsString();
if (value == "compute")
return SPIRV::ExecutionModel::GLCompute;
+ if (value == "pixel")
+ return SPIRV::ExecutionModel::Fragment;
report_fatal_error("This HLSL entry point is not supported by this backend.");
}
@@ -439,10 +441,21 @@ bool SPIRVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
// Handle entry points and function linkage.
if (isEntryPoint(F)) {
+ SPIRV::ExecutionModel::ExecutionModel ExecutionModel =
+ getExecutionModel(*ST, F);
auto MIB = MIRBuilder.buildInstr(SPIRV::OpEntryPoint)
- .addImm(static_cast<uint32_t>(getExecutionModel(*ST, F)))
+ .addImm(static_cast<uint32_t>(ExecutionModel))
.addUse(FuncVReg);
addStringImm(F.getName(), MIB);
+
+ if (ExecutionModel == SPIRV::ExecutionModel::Fragment) {
+ // SPIR-V common validation: Fragment requires OriginUpperLeft or
+ // OriginLowerLeft VUID-StandaloneSpirv-OriginLowerLeft-04653: Fragment
+ // must declare OriginUpperLeft.
+ MIRBuilder.buildInstr(SPIRV::OpExecutionMode)
+ .addUse(FuncVReg)
+ .addImm(static_cast<uint32_t>(SPIRV::ExecutionMode::OriginUpperLeft));
+ }
} else if (F.getLinkage() != GlobalValue::InternalLinkage &&
F.getLinkage() != GlobalValue::PrivateLinkage) {
SPIRV::LinkageType::LinkageType LnkTy =
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index 2fdd54fdfc390..1de0784e16255 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -595,6 +595,8 @@ void SPIRVModuleAnalysis::processOtherInstrs(const Module &M) {
collectOtherInstr(MI, MAI, SPIRV::MB_DebugNames, IS);
} else if (OpCode == SPIRV::OpEntryPoint) {
collectOtherInstr(MI, MAI, SPIRV::MB_EntryPoints, IS);
+ } else if (OpCode == SPIRV::OpExecutionMode) {
+ collectOtherInstr(MI, MAI, SPIRV::MB_EntryPoints, IS);
} else if (TII->isAliasingInstr(MI)) {
collectOtherInstr(MI, MAI, SPIRV::MB_AliasingInsts, IS);
} else if (TII->isDecorationInstr(MI)) {
diff --git a/llvm/test/CodeGen/SPIRV/ExecutionMode_Fragment.ll b/llvm/test/CodeGen/SPIRV/ExecutionMode_Fragment.ll
new file mode 100644
index 0000000000000..3374274bb3445
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/ExecutionMode_Fragment.ll
@@ -0,0 +1,12 @@
+; RUN: llc -O0 -mtriple=spirv-unknown-vulkan1.3-pixel %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan1.3-pixel %s -o - -filetype=obj | spirv-val %}
+
+; CHECK-DAG: OpEntryPoint Fragment %[[#entry:]] "main"
+; CHECK-DAG: OpExecutionMode %[[#entry]] OriginUpperLeft
+
+define void @main() #1 {
+entry:
+ ret void
+}
+
+attributes #1 = { "hlsl.shader"="pixel" }
``````````
</details>
https://github.com/llvm/llvm-project/pull/141787
More information about the llvm-commits
mailing list