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-struct.slang | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/diagnostics/structuredbuffer-resource-struct.slang (limited to 'tests/diagnostics/structuredbuffer-resource-struct.slang') 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 bufferWithTexture; + +//CHECK-DAG: ([[# @LINE+1]]): error 38204 +StructuredBuffer bufferWithSampler; + +//CHECK-DAG: ([[# @LINE+1]]): error 38204 +StructuredBuffer bufferNested; + +RWStructuredBuffer 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; +} + -- cgit v1.2.3