diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2025-09-04 04:05:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-03 20:05:26 +0000 |
| commit | a766d27447aa0fcf69334c0467d9b1124892e180 (patch) | |
| tree | 67ca5615e4a8c94d7454ee43375eeffc8c8a7d4c /tests/diagnostics | |
| parent | bf607e2f3fa183e9a2b18c7a98438a05247d6ed3 (diff) | |
Diagnose on structured buffers containing resources (#8222)
closes https://github.com/shader-slang/slang/issues/3313
Diffstat (limited to 'tests/diagnostics')
7 files changed, 214 insertions, 3 deletions
diff --git a/tests/diagnostics/recursive-type.slang b/tests/diagnostics/recursive-type.slang index 90f49aa86..ccf7da1f8 100644 --- a/tests/diagnostics/recursive-type.slang +++ b/tests/diagnostics/recursive-type.slang @@ -6,9 +6,11 @@ struct Outer { Outer next; // non-pointer int y; }; -RWStructuredBuffer<Outer> Buf; +RWStructuredBuffer<int> Buf; [numthreads(1,1,1)] void csmain() { - Buf[0].y = 0; -}
\ No newline at end of file + Outer outer; + outer.y = 0; + Buf[0] = outer.y; +} diff --git a/tests/diagnostics/structuredbuffer-resource-static.slang b/tests/diagnostics/structuredbuffer-resource-static.slang new file mode 100644 index 000000000..12cbe492e --- /dev/null +++ b/tests/diagnostics/structuredbuffer-resource-static.slang @@ -0,0 +1,53 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -spirv + +struct WithStaticTexture +{ + float4 color; + static Texture2D tex; + float scale; +} + +struct WithStaticSampler +{ + static SamplerState sampler; + float2 uv; +} + +struct NestedWithStatic +{ + WithStaticTexture data; + float value; +} + +// These should NOT produce error 38204 because resources are static +//CHECK-NOT: error 38204 +StructuredBuffer<WithStaticTexture> bufferWithStaticTexture; + +//CHECK-NOT: error 38204 +StructuredBuffer<WithStaticSampler> bufferWithStaticSampler; + +//CHECK-NOT: error 38204 +StructuredBuffer<NestedWithStatic> bufferNestedStatic; + +RWStructuredBuffer<float4> output; + +Texture2D tex; +SamplerState sampler; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint i = dispatchThreadID.x; + + WithStaticTexture.tex = tex; + WithStaticSampler.sampler = sampler; + + // Use all non-static members and static resources + float4 result = bufferWithStaticTexture[i].color * bufferWithStaticTexture[i].scale + + WithStaticTexture.tex.Sample(WithStaticSampler.sampler, bufferWithStaticSampler[i].uv) + + bufferNestedStatic[i].data.color * bufferNestedStatic[i].data.scale + + float4(bufferNestedStatic[i].value, 0, 0, 0); + + output[i] = result; +} + diff --git a/tests/diagnostics/structuredbuffer-resource-struct-array.slang b/tests/diagnostics/structuredbuffer-resource-struct-array.slang new file mode 100644 index 000000000..891a63b07 --- /dev/null +++ b/tests/diagnostics/structuredbuffer-resource-struct-array.slang @@ -0,0 +1,27 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -target spirv + +struct HasResource +{ + Texture2D tex; +} + +//CHECK-DAG: ([[# @LINE+1]]): error 38204 +StructuredBuffer<HasResource> bufferArray[4]; + +//CHECK-DAG: ([[# @LINE+1]]): error 38204 +RWStructuredBuffer<Texture2D> rwBufferArray[2]; + +SamplerState sampler; +RWStructuredBuffer<float> output; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint i = dispatchThreadID.x; + + // Force usage of all array elements and struct members + float result = bufferArray[i % 4][i].tex.Sample(sampler, float2(0, 0)).x; + rwBufferArray[i % 2][i] = bufferArray[0][i].tex; + output[i] = result; +} + diff --git a/tests/diagnostics/structuredbuffer-resource-struct-recursive-mutual.slang b/tests/diagnostics/structuredbuffer-resource-struct-recursive-mutual.slang new file mode 100644 index 000000000..ac9449965 --- /dev/null +++ b/tests/diagnostics/structuredbuffer-resource-struct-recursive-mutual.slang @@ -0,0 +1,34 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -target spirv + +struct MutualB +{ + //CHECK-DAG: ([[# @LINE+1]]): error 38205 + StructuredBuffer<MutualA> aBuffer; +} + +struct MutualA +{ + //CHECK-DAG: ([[# @LINE+1]]): error 38205 + StructuredBuffer<MutualB> bBuffer; +} + +StructuredBuffer<MutualA> mutualRoot; +RWStructuredBuffer<float> output; + +// External function to force consumption of recursive types +float consumeMutual(MutualA a, MutualB b); + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint i = dispatchThreadID.x; + + float result = 0; + // Force usage of mutual recursion + MutualA a = mutualRoot[i]; + MutualB b = a.bBuffer[0]; + result += consumeMutual(a, b); + + output[i] = result; +} + diff --git a/tests/diagnostics/structuredbuffer-resource-struct-recursive.slang b/tests/diagnostics/structuredbuffer-resource-struct-recursive.slang new file mode 100644 index 000000000..ae8f916dd --- /dev/null +++ b/tests/diagnostics/structuredbuffer-resource-struct-recursive.slang @@ -0,0 +1,21 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -target spirv + +struct RecursiveFoo +{ + float value; + //CHECK-DAG: ([[# @LINE+1]]): error 38205 + StructuredBuffer<RecursiveFoo> children; +} + +StructuredBuffer<RecursiveFoo> recursiveRoot; +RWStructuredBuffer<float> output; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint i = dispatchThreadID.x; + RecursiveFoo foo = recursiveRoot[i]; + float result = foo.value + foo.children[0].value + foo.children[0].children[0].value; + output[i] = result; +} + diff --git a/tests/diagnostics/structuredbuffer-resource-struct.slang b/tests/diagnostics/structuredbuffer-resource-struct.slang new file mode 100644 index 000000000..8654b0ad6 --- /dev/null +++ b/tests/diagnostics/structuredbuffer-resource-struct.slang @@ -0,0 +1,46 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -target spirv + +struct WithTexture +{ + float4 color; + Texture2D tex; + float scale; +} + +struct WithSampler +{ + SamplerState sampler; + float2 uv; +} + +struct Nested +{ + WithTexture data; + float value; +} + +//CHECK-DAG: ([[# @LINE+1]]): error 38204 +StructuredBuffer<WithTexture> bufferWithTexture; + +//CHECK-DAG: ([[# @LINE+1]]): error 38204 +StructuredBuffer<WithSampler> bufferWithSampler; + +//CHECK-DAG: ([[# @LINE+1]]): error 38204 +StructuredBuffer<Nested> bufferNested; + +RWStructuredBuffer<float4> output; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint i = dispatchThreadID.x; + + // Use all struct members from all buffers + float4 result = bufferWithTexture[i].color * bufferWithTexture[i].scale + + bufferWithTexture[i].tex.Sample(bufferWithSampler[i].sampler, bufferWithSampler[i].uv) + + bufferNested[i].data.tex.Sample(bufferWithSampler[0].sampler, float2(0, 0)) * bufferNested[i].data.scale + + float4(bufferNested[i].value, 0, 0, 0); + + output[i] = result; +} + diff --git a/tests/diagnostics/structuredbuffer-resource.slang b/tests/diagnostics/structuredbuffer-resource.slang new file mode 100644 index 000000000..3f30f0102 --- /dev/null +++ b/tests/diagnostics/structuredbuffer-resource.slang @@ -0,0 +1,28 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -target spirv + +// Direct resource types as StructuredBuffer elements + +//CHECK-DAG: ([[# @LINE+1]]): error 38204 +StructuredBuffer<Texture2D<float>> textureBuffer; + +//CHECK-DAG: ([[# @LINE+1]]): error 38204 +StructuredBuffer<SamplerState> samplerBuffer; + +//CHECK-DAG: ([[# @LINE+1]]): error 38204 +StructuredBuffer<StructuredBuffer<float>> nestedBuffer; + +//CHECK-DAG: ([[# @LINE+1]]): error 38204 +RWStructuredBuffer<Texture2D<float>> rwTextureBuffer; + +RWStructuredBuffer<float> output; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint i = dispatchThreadID.x; + float result = textureBuffer[i].Sample(samplerBuffer[i], float2(0, 0)).x + + nestedBuffer[i][0]; + + rwTextureBuffer[i] = textureBuffer[i]; + output[i] = result; +} |
