From 296bff695adde81db7160e668553491f6d2b11a1 Mon Sep 17 00:00:00 2001 From: luciechoi Date: Fri, 17 Oct 2025 00:34:47 +0000 Subject: [PATCH 1/3] Add unit test for maximal reconvergence --- .../MaximalReconvergence/loop_peeling.test | 44 ++++++++++++++++ .../subgroup_uniform_control_flow.test | 52 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 test/Feature/MaximalReconvergence/loop_peeling.test create mode 100644 test/Feature/MaximalReconvergence/subgroup_uniform_control_flow.test diff --git a/test/Feature/MaximalReconvergence/loop_peeling.test b/test/Feature/MaximalReconvergence/loop_peeling.test new file mode 100644 index 00000000..1143f628 --- /dev/null +++ b/test/Feature/MaximalReconvergence/loop_peeling.test @@ -0,0 +1,44 @@ +#--- source.hlsl +RWStructuredBuffer Out : register(u0); + +[numthreads(8,1,1)] +void main(uint3 TID : SV_GroupThreadID) { + for (uint i = 0; i < 8; i++) { + if (i == TID.x) { + Out[TID.x] = WaveActiveMax(TID.x); + break; + } + } +} + +//--- pipeline.yaml + +--- +Shaders: + - Stage: Compute + Entry: main + DispatchSize: [1, 1, 1] +Buffers: + - Name: Out + Format: UInt32 + Data: [ 0, 0, 0, 0, 0, 0, 0, 0 ] +DescriptorSets: + - Resources: + - Name: Out + Kind: RWStructuredBuffer + DirectXBinding: + Register: 0 + Space: 0 + VulkanBinding: + Binding: 0 +... + +#--- end + +# RUN: split-file %s %t +# RUN: %dxc_target -T cs_6_5 -fspv-enable-maximal-reconvergence -Fo %t.o %t/source.hlsl +# RUN: %offloader %t/pipeline.yaml %t.o | FileCheck %s + +# CHECK: Name: Out +# CHECK: Format: UInt32 +# CHECK: Data: [ 0, 1, 2, 3, 4, 5, 6, 7 ] diff --git a/test/Feature/MaximalReconvergence/subgroup_uniform_control_flow.test b/test/Feature/MaximalReconvergence/subgroup_uniform_control_flow.test new file mode 100644 index 00000000..ccfe1dbf --- /dev/null +++ b/test/Feature/MaximalReconvergence/subgroup_uniform_control_flow.test @@ -0,0 +1,52 @@ +#--- source.hlsl +RWStructuredBuffer Out : register(u0); + +[numthreads(8,1,1)] +void main(uint3 TID : SV_GroupThreadID) { + // First non-uniform branch + if (TID.x < 4) { + // Second non-uniform branch + if (TID.x % 2 == 0) { + Out[TID.x] = WaveActiveSum(TID.x); + } else { + Out[TID.x] = WaveActiveMax(TID.x); + } + // Must reconverge here with maximal reconvergence + Out[TID.x] += WaveActiveMax(TID.x); + } else { + Out[4] = WaveActiveMax(TID.x); + } + Out[TID.x] += WaveActiveMax(TID.x); +} + +//--- pipeline.yaml + +--- +Shaders: + - Stage: Compute + Entry: main + DispatchSize: [1, 1, 1] +Buffers: + - Name: Out + Format: UInt32 + Data: [ 0, 0, 0, 0, 0, 0, 0, 0 ] +DescriptorSets: + - Resources: + - Name: Out + Kind: RWStructuredBuffer + DirectXBinding: + Register: 0 + Space: 0 + VulkanBinding: + Binding: 0 +... + +#--- end + +# RUN: split-file %s %t +# RUN: %dxc_target -T cs_6_0 -fspv-enable-maximal-reconvergence -Fo %t.o %t/source.hlsl +# RUN: %offloader %t/pipeline.yaml %t.o | FileCheck %s + +# CHECK: Name: Out +# CHECK: Format: UInt32 +# CHECK: Data: [ 12, 13, 12, 13, 14, 7, 7, 7 ] From 7b90ab1ba51d92a715580172fc9396f255b4291e Mon Sep 17 00:00:00 2001 From: luciechoi Date: Tue, 21 Oct 2025 20:42:18 +0000 Subject: [PATCH 2/3] Trigger pipeline with SPIR-V Tools update From 557f48fcbbf36af02715995088eb7768a0c1e7c5 Mon Sep 17 00:00:00 2001 From: luciechoi Date: Tue, 21 Oct 2025 21:15:57 +0000 Subject: [PATCH 3/3] Add extension requirement --- test/Feature/MaximalReconvergence/loop_peeling.test | 4 ++++ .../MaximalReconvergence/subgroup_uniform_control_flow.test | 1 + 2 files changed, 5 insertions(+) diff --git a/test/Feature/MaximalReconvergence/loop_peeling.test b/test/Feature/MaximalReconvergence/loop_peeling.test index 1143f628..12f1d272 100644 --- a/test/Feature/MaximalReconvergence/loop_peeling.test +++ b/test/Feature/MaximalReconvergence/loop_peeling.test @@ -34,6 +34,10 @@ DescriptorSets: ... #--- end +# UNSUPPORTED: !VK_KHR_shader_maximal_reconvergence + +# BUG: https://github.com/llvm/llvm-project/issues/164496 +# XFAIL: Clang # RUN: split-file %s %t # RUN: %dxc_target -T cs_6_5 -fspv-enable-maximal-reconvergence -Fo %t.o %t/source.hlsl diff --git a/test/Feature/MaximalReconvergence/subgroup_uniform_control_flow.test b/test/Feature/MaximalReconvergence/subgroup_uniform_control_flow.test index ccfe1dbf..841fd8a4 100644 --- a/test/Feature/MaximalReconvergence/subgroup_uniform_control_flow.test +++ b/test/Feature/MaximalReconvergence/subgroup_uniform_control_flow.test @@ -42,6 +42,7 @@ DescriptorSets: ... #--- end +# UNSUPPORTED: !VK_KHR_shader_maximal_reconvergence # RUN: split-file %s %t # RUN: %dxc_target -T cs_6_0 -fspv-enable-maximal-reconvergence -Fo %t.o %t/source.hlsl