Author: Cassandra Beckley
Date: 2025-03-21T14:52:47-04:00
New Revision: 3757ecf5f16c0d9b8cbfc1c9d41965df537d43e6

URL: 
https://github.com/llvm/llvm-project/commit/3757ecf5f16c0d9b8cbfc1c9d41965df537d43e6
DIFF: 
https://github.com/llvm/llvm-project/commit/3757ecf5f16c0d9b8cbfc1c9d41965df537d43e6.diff

LOG: [HLSL] Add support for SV_GroupIndex in SPIR-V (#130672)

Lower the `SV_GroupIndex` semantic as the
`llvm.spv.flattened.thread.id.in.group` intrinsic.

Depends on #130670.

---------

Co-authored-by: Steven Perron <stevenper...@google.com>

Added: 
    

Modified: 
    clang/lib/CodeGen/CGHLSLRuntime.cpp
    clang/lib/CodeGen/CGHLSLRuntime.h
    clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index e3e3102fe8d5c..0e859dd4a0b1d 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -338,9 +338,9 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> 
&B,
                                               llvm::Type *Ty) {
   assert(D.hasAttrs() && "Entry parameter missing annotation attribute!");
   if (D.hasAttr<HLSLSV_GroupIndexAttr>()) {
-    llvm::Function *DxGroupIndex =
-        CGM.getIntrinsic(Intrinsic::dx_flattened_thread_id_in_group);
-    return B.CreateCall(FunctionCallee(DxGroupIndex));
+    llvm::Function *GroupIndex =
+        CGM.getIntrinsic(getFlattenedThreadIdInGroupIntrinsic());
+    return B.CreateCall(FunctionCallee(GroupIndex));
   }
   if (D.hasAttr<HLSLSV_DispatchThreadIDAttr>()) {
     llvm::Function *ThreadIDIntrinsic =

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 23f187b24284f..68151c0f0ea24 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -86,6 +86,8 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Degrees, degrees)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(FlattenedThreadIdInGroup,
+                                   flattened_thread_id_in_group)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Normalize, normalize)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)

diff  --git a/clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl 
b/clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl
index ea358c411997d..be9a96cc3c9d3 100644
--- a/clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl
+++ b/clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm 
-disable-llvm-passes -o - -hlsl-entry main %s | FileCheck %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm 
-disable-llvm-passes -o - -hlsl-entry main %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-DXIL -DTARGET=dx
+// RUN: %clang_cc1 -triple spirv-unknown-vulkan-compute -x hlsl -emit-llvm 
-disable-llvm-passes -o - -hlsl-entry main %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-SPIRV -DTARGET=spv
 
 [numthreads(1,1,1)]
 void main(unsigned GI : SV_GroupIndex) {
@@ -10,13 +11,14 @@ void main(unsigned GI : SV_GroupIndex) {
 // semantic parameters and provides the expected void(void) signature that
 // drivers expect for entry points.
 
-//CHECK: define void @main() #[[#ENTRY_ATTR:]] {
-//CHECK-NEXT: entry:
-//CHECK-NEXT:   %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
-//CHECK-NEXT:   call void @_Z4mainj(i32 %0)
-//CHECK-NEXT:   ret void
-//CHECK-NEXT: }
+// CHECK: define void @main() #[[#ENTRY_ATTR:]] {
+// CHECK: entry:
+// CHECK:   %[[#ID_X:]] = call i32 
@llvm.[[TARGET]].flattened.thread.id.in.group()
+// CHECK-DXIL:   call void @_Z4mainj(i32 %[[#ID_X]])
+// CHECK-SPIRV:   call spir_func void @_Z4mainj(i32 %[[#ID_X]])
+// CHECK:   ret void
+// CHECK: }
 
 // Verify that the entry had the expected dx.shader attribute
 
-//CHECK: attributes #[[#ENTRY_ATTR]] = { {{.*}}"hlsl.shader"="compute"{{.*}} }
+// CHECK: attributes #[[#ENTRY_ATTR]] = { {{.*}}"hlsl.shader"="compute"{{.*}} }


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to