Skip to content

Commit 0044d3a

Browse files
Keenutstomtor
authored andcommitted
[SPIR-V] Add Fragment execution model (llvm#141787)
This commits allows the fragment execution model to be set using the hlsl.shader attribute. Fixes llvm#136962
1 parent d0f72b8 commit 0044d3a

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ getExecutionModel(const SPIRVSubtarget &STI, const Function &F) {
282282
return SPIRV::ExecutionModel::GLCompute;
283283
if (value == "vertex")
284284
return SPIRV::ExecutionModel::Vertex;
285+
if (value == "pixel")
286+
return SPIRV::ExecutionModel::Fragment;
285287

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

310314
report_fatal_error("This HLSL entry point is not supported by this backend.");
311315
}
@@ -471,10 +475,21 @@ bool SPIRVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
471475
// environment if we need to.
472476
const SPIRVSubtarget *ST =
473477
static_cast<const SPIRVSubtarget *>(&MIRBuilder.getMF().getSubtarget());
478+
SPIRV::ExecutionModel::ExecutionModel ExecutionModel =
479+
getExecutionModel(*ST, F);
474480
auto MIB = MIRBuilder.buildInstr(SPIRV::OpEntryPoint)
475-
.addImm(static_cast<uint32_t>(getExecutionModel(*ST, F)))
481+
.addImm(static_cast<uint32_t>(ExecutionModel))
476482
.addUse(FuncVReg);
477483
addStringImm(F.getName(), MIB);
484+
485+
if (ExecutionModel == SPIRV::ExecutionModel::Fragment) {
486+
// SPIR-V common validation: Fragment requires OriginUpperLeft or
487+
// OriginLowerLeft VUID-StandaloneSpirv-OriginLowerLeft-04653: Fragment
488+
// must declare OriginUpperLeft.
489+
MIRBuilder.buildInstr(SPIRV::OpExecutionMode)
490+
.addUse(FuncVReg)
491+
.addImm(static_cast<uint32_t>(SPIRV::ExecutionMode::OriginUpperLeft));
492+
}
478493
} else if (F.getLinkage() != GlobalValue::InternalLinkage &&
479494
F.getLinkage() != GlobalValue::PrivateLinkage) {
480495
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 --target-env vulkan1.3 %}
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)