From 93948b564d04eda555bf96025e89853be86cff8a Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 5 Jul 2023 14:24:05 -0400 Subject: Disable l-value coercion for ref types (#2960) * Make lvalue coercion not work for ref, to stop problem with atomics (for GLSL output). * Improve some comments. --- tests/bugs/atomic-coerce.slang | 27 +++++++++++++++++++++++++++ tests/bugs/atomic-coerce.slang.expected.txt | 4 ++++ 2 files changed, 31 insertions(+) create mode 100644 tests/bugs/atomic-coerce.slang create mode 100644 tests/bugs/atomic-coerce.slang.expected.txt (limited to 'tests/bugs') diff --git a/tests/bugs/atomic-coerce.slang b/tests/bugs/atomic-coerce.slang new file mode 100644 index 000000000..1e56a8d25 --- /dev/null +++ b/tests/bugs/atomic-coerce.slang @@ -0,0 +1,27 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj +//TEST(compute,vulkan):COMPARE_COMPUTE_EX:-vk -slang -compute -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0 ], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +groupshared uint gs_values[2]; + +[shader("compute")] +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int index = (int)dispatchThreadID.x; + + // Initialize first + if (index < 2) + { + gs_values[index] = 2; + } + + GroupMemoryBarrierWithGroupSync(); + + // NOTE! We have to cast to uint, to make atomic work + InterlockedAdd(gs_values[index & 1], uint(index * index)); + + outputBuffer[index] = gs_values[index & 1]; +} diff --git a/tests/bugs/atomic-coerce.slang.expected.txt b/tests/bugs/atomic-coerce.slang.expected.txt new file mode 100644 index 000000000..9f774a3a1 --- /dev/null +++ b/tests/bugs/atomic-coerce.slang.expected.txt @@ -0,0 +1,4 @@ +6 +C +6 +C -- cgit v1.2.3