-
Notifications
You must be signed in to change notification settings - Fork 14k
[SPIR-V] Add Fragment execution model #141787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-backend-spir-v Author: Nathan Gauër (Keenuts) ChangesThis 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:
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" }
|
s-perron
approved these changes
May 29, 2025
s-perron
reviewed
Jun 2, 2025
s-perron
approved these changes
Jun 2, 2025
This commits allows the fragment execution model to be set using the hlsl.shader attribute. Fixes llvm#136962
rebased for merging |
Tests are passing, merging this |
rorth
pushed a commit
to rorth/llvm-project
that referenced
this pull request
Jun 11, 2025
This commits allows the fragment execution model to be set using the hlsl.shader attribute. Fixes llvm#136962
Keenuts
added a commit
to Keenuts/llvm-project
that referenced
this pull request
Jun 12, 2025
PR llvm#141787 added code to emit the Fragment execution model. This required emitting the OriginUpperLeft ExecutionMode. But this was done by using the same codepath used for OpEntrypoint. This has 2 issues: - the interface variables were added to both OpEntryPoint and OpExecutionMode. - the existing OpExecutionMode logic was not used. This commit fixes this, regrouping OpExecutionMode handling in one place, and fixing bad codegen issue when interface variiables are added.
Keenuts
added a commit
that referenced
this pull request
Jun 12, 2025
PR #141787 added code to emit the Fragment execution model. This required emitting the OriginUpperLeft ExecutionMode. But this was done by using the same codepath used for OpEntrypoint. This has 2 issues: - the interface variables were added to both OpEntryPoint and OpExecutionMode. - the existing OpExecutionMode logic was not used. This commit fixes this, regrouping OpExecutionMode handling in one place, and fixing bad codegen issue when interface variiables are added.
tomtor
pushed a commit
to tomtor/llvm-project
that referenced
this pull request
Jun 14, 2025
This commits allows the fragment execution model to be set using the hlsl.shader attribute. Fixes llvm#136962
tomtor
pushed a commit
to tomtor/llvm-project
that referenced
this pull request
Jun 14, 2025
PR llvm#141787 added code to emit the Fragment execution model. This required emitting the OriginUpperLeft ExecutionMode. But this was done by using the same codepath used for OpEntrypoint. This has 2 issues: - the interface variables were added to both OpEntryPoint and OpExecutionMode. - the existing OpExecutionMode logic was not used. This commit fixes this, regrouping OpExecutionMode handling in one place, and fixing bad codegen issue when interface variiables are added.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commits allows the fragment execution model to be set using the hlsl.shader attribute.
Fixes #136962