Skip to content

[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 3 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ getExecutionModel(const SPIRVSubtarget &STI, const Function &F) {
return SPIRV::ExecutionModel::GLCompute;
if (value == "vertex")
return SPIRV::ExecutionModel::Vertex;
if (value == "pixel")
return SPIRV::ExecutionModel::Fragment;

report_fatal_error(
"This HLSL entry point is not supported by this backend.");
Expand All @@ -306,6 +308,8 @@ getExecutionModel(const SPIRVSubtarget &STI, const Function &F) {
return SPIRV::ExecutionModel::GLCompute;
if (value == "vertex")
return SPIRV::ExecutionModel::Vertex;
if (value == "pixel")
return SPIRV::ExecutionModel::Fragment;

report_fatal_error("This HLSL entry point is not supported by this backend.");
}
Expand Down Expand Up @@ -471,10 +475,21 @@ bool SPIRVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
// environment if we need to.
const SPIRVSubtarget *ST =
static_cast<const SPIRVSubtarget *>(&MIRBuilder.getMF().getSubtarget());
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 =
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/CodeGen/SPIRV/ExecutionMode_Fragment.ll
Original file line number Diff line number Diff line change
@@ -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 --target-env vulkan1.3 %}

; CHECK-DAG: OpEntryPoint Fragment %[[#entry:]] "main"
; CHECK-DAG: OpExecutionMode %[[#entry]] OriginUpperLeft

define void @main() #1 {
entry:
ret void
}

attributes #1 = { "hlsl.shader"="pixel" }
Loading