Prechádzať zdrojové kódy

[spirv] Translation of SV_DispatchThreadID. (#582)

Ehsan 8 rokov pred
rodič
commit
f17bbb3c39

+ 7 - 0
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

@@ -676,6 +676,13 @@ uint32_t DeclResultIdMapper::createSpirvStageVar(StageVar *stageVar,
     return theBuilder.addStageIOVar(type, sc, name.str());
     // TODO: patch constant function in hull shader
   }
+  case hlsl::Semantic::Kind::DispatchThreadID: {
+    // DispatchThreadID semantic is only valid for compute shaders, and it is
+    // always an input.
+    stageVar->setIsSpirvBuiltin();
+    return theBuilder.addStageBuiltinVar(type, spv::StorageClass::Input,
+                                         BuiltIn::GlobalInvocationId);
+  }
   default:
     emitError("semantic %0 unimplemented yet")
         << stageVar->getSemantic()->GetName();

+ 7 - 0
tools/clang/test/CodeGenSPIRV/semantic.dispatch-thread-id.cs.hlsl

@@ -0,0 +1,7 @@
+// Run: %dxc -T cs_6_0 -E main
+
+// CHECK: OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
+// CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
+// CHECK: %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
+
+void main(uint3 tid : SV_DispatchThreadId) {}

+ 3 - 0
tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp

@@ -298,6 +298,9 @@ TEST_F(FileTest, SemanticArbitraryAlphaLocation) {
 TEST_F(FileTest, SemanticDuplication) {
   runFileTest("semantic.duplication.hlsl", /*expectSuccess*/ false);
 }
+TEST_F(FileTest, SemanticDispatchThreadId) {
+  runFileTest("semantic.dispatch-thread-id.cs.hlsl");
+}
 
 // For texture methods
 TEST_F(FileTest, TextureSample) { runFileTest("texture.sample.hlsl"); }