-
Notifications
You must be signed in to change notification settings - Fork 826
Implement GetGroupWaveIndex and GetGroupWaveCount #7959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b56103b
Implement GetGroupWaveIndex and GetGroupWaveCount
JoeCitizen 6677fb6
Formatting
JoeCitizen bc69bac
Implement lowering to SPIR-V SubgroupId and NumSubgroups
JoeCitizen 54ff3f7
formatting
JoeCitizen bd5aea7
Update release notes
JoeCitizen dedc2a5
Add new lines to EOF and add checks to SPIR-V lowering test
JoeCitizen 2388db2
rebase after experimental opcode change
JoeCitizen f541f0b
clang format
JoeCitizen 4645896
Merge changes
JoeCitizen deeac02
Add requires dxil-1-10
JoeCitizen 82e01d4
Disallow usage in libraries
JoeCitizen 1618c1b
retrigger checks
JoeCitizen 6505b7b
Add tests to verify that validation catches invalid usage
JoeCitizen 2d981a2
dxil validation
JoeCitizen 9e669c7
move tests to lit framework
JoeCitizen 60f8a58
Add REQUIRES: dxil-1-10 to dxil tests
JoeCitizen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
tools/clang/test/CodeGenSPIRV/sm6_10.group-wave-count.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // RUN: %dxc -T cs_6_10 -E main -fspv-target-env=vulkan1.1 -fcgl %s -spirv | FileCheck %s | ||
|
|
||
| // CHECK: ; Version: 1.3 | ||
|
|
||
| RWStructuredBuffer<uint> output: register(u0); | ||
|
|
||
| // CHECK: OpCapability GroupNonUniform | ||
|
|
||
| // CHECK: OpEntryPoint GLCompute | ||
| // CHECK-SAME: %NumSubgroups | ||
|
|
||
| // CHECK: OpDecorate %NumSubgroups BuiltIn NumSubgroups | ||
|
|
||
| // CHECK: %NumSubgroups = OpVariable %_ptr_Input_uint Input | ||
|
|
||
| [numthreads(64, 1, 1)] | ||
| void main(uint3 id: SV_DispatchThreadID) { | ||
| // CHECK: OpLoad %uint %NumSubgroups | ||
| output[id.x] = GetGroupWaveCount(); | ||
| } |
20 changes: 20 additions & 0 deletions
20
tools/clang/test/CodeGenSPIRV/sm6_10.group-wave-index.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // RUN: %dxc -T cs_6_10 -E main -fspv-target-env=vulkan1.1 -fcgl %s -spirv | FileCheck %s | ||
|
|
||
| // CHECK: ; Version: 1.3 | ||
|
|
||
| RWStructuredBuffer<uint> output: register(u0); | ||
|
|
||
| // CHECK: OpCapability GroupNonUniform | ||
|
|
||
| // CHECK: OpEntryPoint GLCompute | ||
| // CHECK-SAME: %SubgroupId | ||
|
|
||
| // CHECK: OpDecorate %SubgroupId BuiltIn SubgroupId | ||
|
|
||
| // CHECK: %SubgroupId = OpVariable %_ptr_Input_uint Input | ||
|
|
||
| [numthreads(64, 1, 1)] | ||
| void main(uint3 id: SV_DispatchThreadID) { | ||
| // CHECK: OpLoad %uint %SubgroupId | ||
| output[id.x] = GetGroupWaveIndex(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| ; RUN: %dxopt %s -hlsl-passes-resume -dxilgen -S | FileCheck %s | ||
|
|
||
| ; CHECK: call i32 @dx.op.getGroupWaveIndex(i32 -2147483647) | ||
| ; CHECK: call i32 @dx.op.getGroupWaveCount(i32 -2147483646) | ||
|
|
||
| ; Generated from: | ||
| ; utils/hct/ExtractIRForPassTest.py -p dxilgen -o tools/clang/test/DXC/Passes/DxilGen/group-wave-index.ll tools/clang/test/HLSLFileCheckLit/hlsl/intrinsics/wave/group-wave-index.hlsl -- -T cs_6_10 -E main | ||
| ; Debug info manually stripped. | ||
|
|
||
| target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64" | ||
| target triple = "dxil-ms-dx" | ||
|
|
||
| %"class.RWStructuredBuffer<unsigned int>" = type { i32 } | ||
| %dx.types.Handle = type { i8* } | ||
| %dx.types.ResourceProperties = type { i32, i32 } | ||
|
|
||
| @"\01?output0@@3V?$RWStructuredBuffer@I@@A" = external global %"class.RWStructuredBuffer<unsigned int>", align 4 | ||
|
|
||
| ; Function Attrs: nounwind | ||
| define void @main(<3 x i32> %id) #0 { | ||
| entry: | ||
| %0 = call i32 @"dx.hl.op.rn.i32 (i32)"(i32 396) | ||
| %1 = call i32 @"dx.hl.op.rn.i32 (i32)"(i32 395) | ||
| %2 = load %"class.RWStructuredBuffer<unsigned int>", %"class.RWStructuredBuffer<unsigned int>"* @"\01?output0@@3V?$RWStructuredBuffer@I@@A" | ||
| %3 = call %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %\22class.RWStructuredBuffer<unsigned int>\22)"(i32 0, %"class.RWStructuredBuffer<unsigned int>" %2) | ||
| %4 = call %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %\22class.RWStructuredBuffer<unsigned int>\22)"(i32 14, %dx.types.Handle %3, %dx.types.ResourceProperties { i32 4108, i32 4 }, %"class.RWStructuredBuffer<unsigned int>" zeroinitializer) | ||
| %5 = call i32* @"dx.hl.subscript.[].rn.i32* (i32, %dx.types.Handle, i32)"(i32 0, %dx.types.Handle %4, i32 0) | ||
| store i32 %0, i32* %5 | ||
| %6 = load %"class.RWStructuredBuffer<unsigned int>", %"class.RWStructuredBuffer<unsigned int>"* @"\01?output0@@3V?$RWStructuredBuffer@I@@A" | ||
| %7 = call %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %\22class.RWStructuredBuffer<unsigned int>\22)"(i32 0, %"class.RWStructuredBuffer<unsigned int>" %6) | ||
| %8 = call %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %\22class.RWStructuredBuffer<unsigned int>\22)"(i32 14, %dx.types.Handle %7, %dx.types.ResourceProperties { i32 4108, i32 4 }, %"class.RWStructuredBuffer<unsigned int>" zeroinitializer) | ||
| %9 = call i32* @"dx.hl.subscript.[].rn.i32* (i32, %dx.types.Handle, i32)"(i32 0, %dx.types.Handle %8, i32 16) | ||
| store i32 %1, i32* %9 | ||
| ret void | ||
| } | ||
|
|
||
| ; Function Attrs: nounwind | ||
| declare void @llvm.lifetime.start(i64, i8* nocapture) #0 | ||
|
|
||
| ; Function Attrs: nounwind | ||
| declare void @llvm.lifetime.end(i64, i8* nocapture) #0 | ||
|
|
||
| ; Function Attrs: nounwind readnone | ||
| declare i32 @"dx.hl.op.rn.i32 (i32)"(i32) #1 | ||
|
|
||
| ; Function Attrs: nounwind readnone | ||
| declare i32* @"dx.hl.subscript.[].rn.i32* (i32, %dx.types.Handle, i32)"(i32, %dx.types.Handle, i32) #1 | ||
|
|
||
| ; Function Attrs: nounwind readnone | ||
| declare %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %\22class.RWStructuredBuffer<unsigned int>\22)"(i32, %"class.RWStructuredBuffer<unsigned int>") #1 | ||
|
|
||
| ; Function Attrs: nounwind readnone | ||
| declare %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %\22class.RWStructuredBuffer<unsigned int>\22)"(i32, %dx.types.Handle, %dx.types.ResourceProperties, %"class.RWStructuredBuffer<unsigned int>") #1 | ||
|
|
||
| attributes #0 = { nounwind } | ||
| attributes #1 = { nounwind readnone } | ||
|
|
||
| !pauseresume = !{!1} | ||
| !llvm.ident = !{!2} | ||
| !dx.version = !{!3} | ||
| !dx.valver = !{!3} | ||
| !dx.shaderModel = !{!4} | ||
| !dx.typeAnnotations = !{!5, !11} | ||
| !dx.entryPoints = !{!18} | ||
| !dx.fnprops = !{!23} | ||
| !dx.options = !{!24, !25} | ||
|
|
||
| !1 = !{!"hlsl-hlemit", !"hlsl-hlensure"} | ||
| !2 = !{!"dxc(private) 1.8.0.5134 (Group-Wave-Intrinsics, 84e7262d3)"} | ||
| !3 = !{i32 1, i32 10} | ||
| !4 = !{!"cs", i32 6, i32 10} | ||
| !5 = !{i32 0, %"class.RWStructuredBuffer<unsigned int>" undef, !6} | ||
| !6 = !{i32 4, !7, !8} | ||
| !7 = !{i32 6, !"h", i32 3, i32 0, i32 7, i32 5} | ||
| !8 = !{i32 0, !9} | ||
| !9 = !{!10} | ||
| !10 = !{i32 0, i32 undef} | ||
| !11 = !{i32 1, void (<3 x i32>)* @main, !12} | ||
| !12 = !{!13, !15} | ||
| !13 = !{i32 1, !14, !14} | ||
| !14 = !{} | ||
| !15 = !{i32 0, !16, !17} | ||
| !16 = !{i32 4, !"SV_DispatchThreadID", i32 7, i32 5, i32 13, i32 3} | ||
| !17 = !{i32 0} | ||
| !18 = !{void (<3 x i32>)* @main, !"main", null, !19, null} | ||
| !19 = !{null, !20, null, null} | ||
| !20 = !{!21} | ||
| !21 = !{i32 0, %"class.RWStructuredBuffer<unsigned int>"* @"\01?output0@@3V?$RWStructuredBuffer@I@@A", !"output0", i32 0, i32 0, i32 1, i32 12, i1 false, i1 false, i1 false, !22} | ||
| !22 = !{i32 1, i32 4} | ||
| !23 = !{void (<3 x i32>)* @main, i32 5, i32 1, i32 1, i32 1} | ||
| !24 = !{i32 64} | ||
| !25 = !{i32 -1} |
23 changes: 23 additions & 0 deletions
23
tools/clang/test/HLSLFileCheckLit/hlsl/intrinsics/wave/group-wave-index.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // REQUIRES: dxil-1-10 | ||
|
|
||
| // RUN: %dxc -T cs_6_10 -E main -fcgl %s | FileCheck %s --check-prefix=FCGL | ||
JoeCitizen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // RUN: %dxc -T cs_6_10 -E main %s | FileCheck %s | ||
|
|
||
| // FCGL: call i32 @"dx.hl.op.rn.i32 (i32)"(i32 396) | ||
| // FCGL: call i32 @"dx.hl.op.rn.i32 (i32)"(i32 395) | ||
|
|
||
| // CHECK: %[[Index:[^ ]+]] = call i32 @dx.op.getGroupWaveIndex(i32 -2147483647) ; GetGroupWaveIndex() | ||
| // CHECK: %[[Count:[^ ]+]] = call i32 @dx.op.getGroupWaveCount(i32 -2147483646) ; GetGroupWaveCount() | ||
| // CHECK: call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %{{[^,]+}}, i32 0, i32 0, i32 %[[Index]], i32 undef, i32 undef, i32 undef, i8 1, i32 4) | ||
| // CHECK: call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %{{[^,]+}}, i32 16, i32 0, i32 %[[Count]], i32 undef, i32 undef, i32 undef, i8 1, i32 4) | ||
|
|
||
| RWStructuredBuffer<uint> output0 : register(u0); | ||
|
|
||
| [numthreads(1, 1, 1)] | ||
| void main(uint3 id: SV_DispatchThreadID) { | ||
| uint waveIdx = GetGroupWaveIndex(); | ||
| uint waveCount = GetGroupWaveCount(); | ||
|
|
||
| output0[0] = waveIdx; | ||
| output0[16] = waveCount; | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
tools/clang/test/HLSLFileCheckLit/hlsl/intrinsics/wave/group-wave-invalid-nodes.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // REQUIRES: dxil-1-10 | ||
|
|
||
| // RUN: not %dxc -T lib_6_10 %s 2>&1 | FileCheck %s | ||
|
|
||
| // CHECK-DAG: error: Function requires a visible group, but is called from a shader without one. | ||
|
|
||
| struct InputRecord { | ||
| uint value; | ||
| }; | ||
|
|
||
| struct OutputRecord { | ||
| uint value; | ||
| }; | ||
|
|
||
| RWStructuredBuffer<uint> output : register(u0); | ||
|
|
||
| // Thread launch - no thread group, should FAIL | ||
| [Shader("node")] | ||
| [NodeLaunch("thread")] | ||
| void ThreadNode( | ||
| RWThreadNodeInputRecord<InputRecord> inputData, | ||
| [MaxRecords(1)] NodeOutput<OutputRecord> outputData) { | ||
| uint waveIdx = GetGroupWaveIndex(); | ||
| uint waveCount = GetGroupWaveCount(); | ||
| ThreadNodeOutputRecords<OutputRecord> outRec = outputData.GetThreadNodeOutputRecords(1); | ||
| outRec.Get().value = waveIdx + waveCount; | ||
| outRec.OutputComplete(); | ||
| } |
67 changes: 67 additions & 0 deletions
67
tools/clang/test/HLSLFileCheckLit/hlsl/intrinsics/wave/group-wave-invalid-raytracing.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // REQUIRES: dxil-1-10 | ||
|
|
||
| // RUN: not %dxc -T lib_6_10 %s 2>&1 | FileCheck %s | ||
|
|
||
| // CHECK-DAG: error: Opcode GetGroupWaveCount not valid in shader model lib_6_10(callable). | ||
| // CHECK-DAG: error: Opcode GetGroupWaveCount not valid in shader model lib_6_10(intersection). | ||
| // CHECK-DAG: error: Opcode GetGroupWaveCount not valid in shader model lib_6_10(anyhit). | ||
| // CHECK-DAG: error: Opcode GetGroupWaveCount not valid in shader model lib_6_10(miss). | ||
| // CHECK-DAG: error: Opcode GetGroupWaveCount not valid in shader model lib_6_10(closesthit). | ||
| // CHECK-DAG: error: Opcode GetGroupWaveCount not valid in shader model lib_6_10(raygeneration). | ||
| // CHECK-DAG: error: Opcode GetGroupWaveIndex not valid in shader model lib_6_10(callable). | ||
| // CHECK-DAG: error: Opcode GetGroupWaveIndex not valid in shader model lib_6_10(intersection). | ||
| // CHECK-DAG: error: Opcode GetGroupWaveIndex not valid in shader model lib_6_10(anyhit). | ||
| // CHECK-DAG: error: Opcode GetGroupWaveIndex not valid in shader model lib_6_10(miss). | ||
| // CHECK-DAG: error: Opcode GetGroupWaveIndex not valid in shader model lib_6_10(closesthit). | ||
| // CHECK-DAG: error: Opcode GetGroupWaveIndex not valid in shader model lib_6_10(raygeneration). | ||
|
|
||
| struct [raypayload] Payload { | ||
| float value : write(closesthit, miss, anyhit, caller) : read(caller); | ||
| }; | ||
| struct Attributes { | ||
| float2 barycentrics; | ||
| }; | ||
|
|
||
| RWStructuredBuffer<uint> output : register(u0); | ||
|
|
||
| [shader("raygeneration")] | ||
| void RayGenMain() { | ||
| uint waveIdx = GetGroupWaveIndex(); | ||
| uint waveCount = GetGroupWaveCount(); | ||
| output[0] = waveIdx + waveCount; | ||
| } | ||
|
|
||
| [shader("closesthit")] | ||
| void ClosestHitMain(inout Payload payload, in Attributes attribs) { | ||
| uint waveIdx = GetGroupWaveIndex(); | ||
| uint waveCount = GetGroupWaveCount(); | ||
| payload.value = waveIdx + waveCount; | ||
| } | ||
|
|
||
| [shader("miss")] | ||
| void MissMain(inout Payload payload) { | ||
| uint waveIdx = GetGroupWaveIndex(); | ||
| uint waveCount = GetGroupWaveCount(); | ||
| payload.value = waveIdx + waveCount; | ||
| } | ||
|
|
||
| [shader("anyhit")] | ||
| void AnyHitMain(inout Payload payload, in Attributes attribs) { | ||
| uint waveIdx = GetGroupWaveIndex(); | ||
| uint waveCount = GetGroupWaveCount(); | ||
| payload.value = waveIdx + waveCount; | ||
| } | ||
|
|
||
| [shader("intersection")] | ||
| void IntersectionMain() { | ||
| uint waveIdx = GetGroupWaveIndex(); | ||
| uint waveCount = GetGroupWaveCount(); | ||
| output[0] = waveIdx + waveCount; | ||
| } | ||
|
|
||
| [shader("callable")] | ||
| void CallableMain(inout Payload payload) { | ||
| uint waveIdx = GetGroupWaveIndex(); | ||
| uint waveCount = GetGroupWaveCount(); | ||
| payload.value = waveIdx + waveCount; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.