summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLujin Wang <143145775+lujinwangnv@users.noreply.github.com>2025-10-08 16:18:50 -0700
committerGitHub <noreply@github.com>2025-10-08 23:18:50 +0000
commit4e4aad5a0493defde1e0ef29f27e5d663c1182cd (patch)
tree8d5a5bbe78d297ce31cfce7c0b18d2ca91b417c2
parent1e4265edd4ec4c44e3d8f209fca802727076aa46 (diff)
Fix DerivativeGroupQuadsKHR workgroup size validation for texture sampling (#8647)
Fixes #8545 where Slang generates SPIR-V with DerivativeGroupQuadsKHR execution mode but doesn't validate workgroup sizes when texture sampling triggers automatic derivative computation. **Root Cause**: Validation code was looking for IRNumThreadsDecoration on the wrong IR node **Fix**: One-line change in slang-emit-spirv.cpp to search decoration on entryPoint instead of entryPointDecor **Tests**: Added regression tests for both quad and linear derivative group validation Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Lujin Wang <lujinwangnv@users.noreply.github.com> Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
-rw-r--r--source/slang/slang-emit-spirv.cpp3
-rw-r--r--tests/compute/derivative-group-linear-validation.slang27
-rw-r--r--tests/compute/derivative-group-quad-validation.slang26
3 files changed, 54 insertions, 2 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 36368c3ee..73a83f9c0 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -4285,8 +4285,7 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
ensureExtensionDeclaration(
UnownedStringSlice("SPV_KHR_compute_shader_derivatives"));
- auto numThreadsDecor =
- entryPointDecor->findDecoration<IRNumThreadsDecoration>();
+ auto numThreadsDecor = entryPoint->findDecoration<IRNumThreadsDecoration>();
if (isQuad)
{
verifyComputeDerivativeGroupModifiers(
diff --git a/tests/compute/derivative-group-linear-validation.slang b/tests/compute/derivative-group-linear-validation.slang
new file mode 100644
index 000000000..02f440cc1
--- /dev/null
+++ b/tests/compute/derivative-group-linear-validation.slang
@@ -0,0 +1,27 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv-asm
+//TEST_INPUT:ubuffer(data=[0], stride=4):out
+
+// Test that DerivativeGroupLinearKHR execution mode validates workgroup size
+// This test should produce an error because numthreads(3,1,1) violates the requirement
+// that the product of dimensions must be a multiple of 4
+
+[[vk::binding(0, 0)]]
+RWStructuredBuffer<float4> g_ssbo;
+
+[[vk::binding(0, 1)]]
+Texture2D g_textures[];
+[[vk::binding(0, 2)]]
+SamplerState g_samplers[];
+
+[shader("compute")]
+[DerivativeGroupLinear]
+[numthreads(3, 1, 1)] // Invalid: 3*1*1 = 3, not multiple of 4
+void main() {
+ float4 texture_color = g_textures[0].Sample(
+ g_samplers[0],
+ float2(0.0f, 0.0f)
+ );
+ g_ssbo[0] = texture_color;
+}
+
+// CHECK: error 31211: compute derivative group linear requires total thread dispatch count to be at a multiple of 4 \ No newline at end of file
diff --git a/tests/compute/derivative-group-quad-validation.slang b/tests/compute/derivative-group-quad-validation.slang
new file mode 100644
index 000000000..bbf09b809
--- /dev/null
+++ b/tests/compute/derivative-group-quad-validation.slang
@@ -0,0 +1,26 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv-asm
+//TEST_INPUT:ubuffer(data=[0], stride=4):out
+
+// Test that DerivativeGroupQuadsKHR execution mode validates workgroup size
+// This test should produce an error because numthreads(1,1,1) violates the requirement
+// that X and Y dimensions must be multiples of 2
+
+[[vk::binding(0, 0)]]
+RWStructuredBuffer<float4> g_ssbo;
+
+[[vk::binding(0, 1)]]
+Texture2D g_textures[];
+[[vk::binding(0, 2)]]
+SamplerState g_samplers[];
+
+[shader("compute")]
+[numthreads(1, 1, 1)] // Invalid: should be multiples of 2 for derivative group quads
+void main() {
+ float4 texture_color = g_textures[0].Sample(
+ g_samplers[0],
+ float2(0.0f, 0.0f)
+ );
+ g_ssbo[0] = texture_color;
+}
+
+// CHECK: error 31210: compute derivative group quad requires thread dispatch count of X and Y to each be at a multiple of 2 \ No newline at end of file