From a766d27447aa0fcf69334c0467d9b1124892e180 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Thu, 4 Sep 2025 04:05:26 +0800 Subject: Diagnose on structured buffers containing resources (#8222) closes https://github.com/shader-slang/slang/issues/3313 --- .../structuredbuffer-resource-static.slang | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/diagnostics/structuredbuffer-resource-static.slang (limited to 'tests/diagnostics/structuredbuffer-resource-static.slang') 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 bufferWithStaticTexture; + +//CHECK-NOT: error 38204 +StructuredBuffer bufferWithStaticSampler; + +//CHECK-NOT: error 38204 +StructuredBuffer bufferNestedStatic; + +RWStructuredBuffer 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; +} + -- cgit v1.2.3