Skip to content

Commit 3757ecf

Browse files
[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 <[email protected]>
1 parent 0f400cb commit 3757ecf

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B,
338338
llvm::Type *Ty) {
339339
assert(D.hasAttrs() && "Entry parameter missing annotation attribute!");
340340
if (D.hasAttr<HLSLSV_GroupIndexAttr>()) {
341-
llvm::Function *DxGroupIndex =
342-
CGM.getIntrinsic(Intrinsic::dx_flattened_thread_id_in_group);
343-
return B.CreateCall(FunctionCallee(DxGroupIndex));
341+
llvm::Function *GroupIndex =
342+
CGM.getIntrinsic(getFlattenedThreadIdInGroupIntrinsic());
343+
return B.CreateCall(FunctionCallee(GroupIndex));
344344
}
345345
if (D.hasAttr<HLSLSV_DispatchThreadIDAttr>()) {
346346
llvm::Function *ThreadIDIntrinsic =

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class CGHLSLRuntime {
8686
GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
8787
GENERATE_HLSL_INTRINSIC_FUNCTION(Degrees, degrees)
8888
GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
89+
GENERATE_HLSL_INTRINSIC_FUNCTION(FlattenedThreadIdInGroup,
90+
flattened_thread_id_in_group)
8991
GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
9092
GENERATE_HLSL_INTRINSIC_FUNCTION(Normalize, normalize)
9193
GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm -disable-llvm-passes -o - -hlsl-entry main %s | FileCheck %s
1+
// 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
2+
// 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
23

34
[numthreads(1,1,1)]
45
void main(unsigned GI : SV_GroupIndex) {
@@ -10,13 +11,14 @@ void main(unsigned GI : SV_GroupIndex) {
1011
// semantic parameters and provides the expected void(void) signature that
1112
// drivers expect for entry points.
1213

13-
//CHECK: define void @main() #[[#ENTRY_ATTR:]] {
14-
//CHECK-NEXT: entry:
15-
//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
16-
//CHECK-NEXT: call void @_Z4mainj(i32 %0)
17-
//CHECK-NEXT: ret void
18-
//CHECK-NEXT: }
14+
// CHECK: define void @main() #[[#ENTRY_ATTR:]] {
15+
// CHECK: entry:
16+
// CHECK: %[[#ID_X:]] = call i32 @llvm.[[TARGET]].flattened.thread.id.in.group()
17+
// CHECK-DXIL: call void @_Z4mainj(i32 %[[#ID_X]])
18+
// CHECK-SPIRV: call spir_func void @_Z4mainj(i32 %[[#ID_X]])
19+
// CHECK: ret void
20+
// CHECK: }
1921

2022
// Verify that the entry had the expected dx.shader attribute
2123

22-
//CHECK: attributes #[[#ENTRY_ATTR]] = { {{.*}}"hlsl.shader"="compute"{{.*}} }
24+
// CHECK: attributes #[[#ENTRY_ATTR]] = { {{.*}}"hlsl.shader"="compute"{{.*}} }

0 commit comments

Comments
 (0)