[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 4 10:05:22 PST 2024


================
@@ -342,8 +343,19 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B,
     return B.CreateCall(FunctionCallee(DxGroupIndex));
   }
   if (D.hasAttr<HLSLSV_DispatchThreadIDAttr>()) {
-    llvm::Function *DxThreadID = CGM.getIntrinsic(Intrinsic::dx_thread_id);
-    return buildVectorInput(B, DxThreadID, Ty);
+    llvm::Function *ThreadIDIntrinsic;
+    switch (CGM.getTarget().getTriple().getArch()) {
+    case llvm::Triple::dxil:
+      ThreadIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_thread_id);
+      break;
+    case llvm::Triple::spirv:
+      ThreadIDIntrinsic = CGM.getIntrinsic(Intrinsic::spv_thread_id);
+      break;
+    default:
+      llvm_unreachable("Input semantic not supported by target");
+      break;
+    }
+    return buildVectorInput(B, ThreadIDIntrinsic, Ty);
----------------
bogner wrote:

Sure, that's one implementation approach. I was thinking of keeping it as simple as a bag of functions, along these lines:
```
struct HLSLTargetIntrinsic {
  IntrinsicID getThreadID(llvm::Triple::ArchType Arch) {
    switch (Arch) {
    case llvm::Triple::dxil:
      return Intrinsic::dx_thread_id;
    case llvm::Triple::spirv:
      return Intrinsic::spa_thread_id;
    }
  }
}
```
(whether the Arch is passed in as a function arg, a member of the type, or a template arg is an implementation detail...)

https://github.com/llvm/llvm-project/pull/82536


More information about the cfe-commits mailing list