Skip to content

Commit 65d391f

Browse files
committed
[SPIR-V] Add Fragment execution model
This commits allows the fragment execution model to be set using the hlsl.shader attribute. Fixes llvm#136962
1 parent c3057de commit 65d391f

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ getExecutionModel(const SPIRVSubtarget &STI, const Function &F) {
306306
return SPIRV::ExecutionModel::GLCompute;
307307
if (value == "vertex")
308308
return SPIRV::ExecutionModel::Vertex;
309+
if (value == "pixel")
310+
return SPIRV::ExecutionModel::Fragment;
309311

310312
report_fatal_error("This HLSL entry point is not supported by this backend.");
311313
}
@@ -471,10 +473,21 @@ bool SPIRVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
471473
// environment if we need to.
472474
const SPIRVSubtarget *ST =
473475
static_cast<const SPIRVSubtarget *>(&MIRBuilder.getMF().getSubtarget());
476+
SPIRV::ExecutionModel::ExecutionModel ExecutionModel =
477+
getExecutionModel(*ST, F);
474478
auto MIB = MIRBuilder.buildInstr(SPIRV::OpEntryPoint)
475-
.addImm(static_cast<uint32_t>(getExecutionModel(*ST, F)))
479+
.addImm(static_cast<uint32_t>(ExecutionModel))
476480
.addUse(FuncVReg);
477481
addStringImm(F.getName(), MIB);
482+
483+
if (ExecutionModel == SPIRV::ExecutionModel::Fragment) {
484+
// SPIR-V common validation: Fragment requires OriginUpperLeft or
485+
// OriginLowerLeft VUID-StandaloneSpirv-OriginLowerLeft-04653: Fragment
486+
// must declare OriginUpperLeft.
487+
MIRBuilder.buildInstr(SPIRV::OpExecutionMode)
488+
.addUse(FuncVReg)
489+
.addImm(static_cast<uint32_t>(SPIRV::ExecutionMode::OriginUpperLeft));
490+
}
478491
} else if (F.getLinkage() != GlobalValue::InternalLinkage &&
479492
F.getLinkage() != GlobalValue::PrivateLinkage) {
480493
SPIRV::LinkageType::LinkageType LnkTy =

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@ void SPIRVModuleAnalysis::processOtherInstrs(const Module &M) {
595595
collectOtherInstr(MI, MAI, SPIRV::MB_DebugNames, IS);
596596
} else if (OpCode == SPIRV::OpEntryPoint) {
597597
collectOtherInstr(MI, MAI, SPIRV::MB_EntryPoints, IS);
598+
} else if (OpCode == SPIRV::OpExecutionMode) {
599+
collectOtherInstr(MI, MAI, SPIRV::MB_EntryPoints, IS);
598600
} else if (TII->isAliasingInstr(MI)) {
599601
collectOtherInstr(MI, MAI, SPIRV::MB_AliasingInsts, IS);
600602
} else if (TII->isDecorationInstr(MI)) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-vulkan1.3-pixel %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan1.3-pixel %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK-DAG: OpEntryPoint Fragment %[[#entry:]] "main"
5+
; CHECK-DAG: OpExecutionMode %[[#entry]] OriginUpperLeft
6+
7+
define void @main() #1 {
8+
entry:
9+
ret void
10+
}
11+
12+
attributes #1 = { "hlsl.shader"="pixel" }

0 commit comments

Comments
 (0)