Skip to content

Commit 99f2d49

Browse files
[SPIR-V] Implement Shader Model 6.8 Extended Command Information (microsoft#6843)
Compile `SV_StartVertexLocation` as `BaseVertex` and `SV_StartInstanceLocation` as `BaseInstance`.
1 parent 1e78247 commit 99f2d49

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

docs/SPIR-V.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,10 @@ some system-value (SV) semantic strings will be translated into SPIR-V
15191519
| | | with | | |
15201520
| | | ``-fvk-support-nonzero-base-instance`` | | |
15211521
+---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
1522+
| SV_StartVertexLocation | VSIn | ``BaseVertex`` | N/A | ``Shader`` |
1523+
+---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
1524+
| SV_StartInstanceLocation | VSIn | ``BaseInstance`` | N/A | ``Shader`` |
1525+
+---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
15221526
| SV_Depth | PSOut | ``FragDepth`` | N/A | ``Shader`` |
15231527
+---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
15241528
| SV_DepthGreaterEqual | PSOut | ``FragDepth`` | ``DepthGreater`` | ``Shader`` |

tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4218,6 +4218,22 @@ SpirvVariable *DeclResultIdMapper::createSpirvStageVar(
42184218
llvm_unreachable("invalid usage of SV_InstanceID sneaked in");
42194219
}
42204220
}
4221+
// According to DXIL spec, the StartVertexLocation SV can only be used by
4222+
// VSIn. According to Vulkan spec, the BaseVertex BuiltIn can only be used by
4223+
// VSIn.
4224+
case hlsl::Semantic::Kind::StartVertexLocation: {
4225+
stageVar->setIsSpirvBuiltin();
4226+
return spvBuilder.addStageBuiltinVar(type, sc, BuiltIn::BaseVertex,
4227+
isPrecise, srcLoc);
4228+
}
4229+
// According to DXIL spec, the StartInstanceLocation SV can only be used by
4230+
// VSIn. According to Vulkan spec, the BaseInstance BuiltIn can only be used
4231+
// by VSIn.
4232+
case hlsl::Semantic::Kind::StartInstanceLocation: {
4233+
stageVar->setIsSpirvBuiltin();
4234+
return spvBuilder.addStageBuiltinVar(type, sc, BuiltIn::BaseInstance,
4235+
isPrecise, srcLoc);
4236+
}
42214237
// According to DXIL spec, the Depth{|GreaterEqual|LessEqual} SV can only be
42224238
// used by PSOut.
42234239
// According to Vulkan spec, the FragDepth BuiltIn can only be used by PSOut.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %dxc -T vs_6_8 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
// CHECK: OpEntryPoint Vertex %main "main"
4+
// CHECK-SAME: %gl_BaseInstance
5+
6+
// CHECK: OpDecorate %gl_BaseInstance BuiltIn BaseInstance
7+
8+
// CHECK: %gl_BaseInstance = OpVariable %_ptr_Input_int Input
9+
10+
int main(int input: SV_StartInstanceLocation) : A {
11+
return input;
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %dxc -T vs_6_8 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
// CHECK: OpEntryPoint Vertex %main "main" [[baseVertex:%[0-9]+]]
4+
5+
// CHECK: OpDecorate [[baseVertex]] BuiltIn BaseVertex
6+
7+
// CHECK: [[baseVertex]] = OpVariable %_ptr_Input_int Input
8+
9+
int main(int input: SV_StartVertexLocation) : A {
10+
return input;
11+
}

0 commit comments

Comments
 (0)