From e7a83323bfc4dd698ef491375a37c65c83915951 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 29 May 2018 11:39:55 -0700 Subject: Fix global atomic functions (#582) Fixes #581 This change adds a new parameter passing mode `__ref` to exist alongisde `in`, `out`, and `inout`. The `__ref` modifier indicates true by-reference parameter passing (whereas `inout` is copy-in-copy-out). This is not intended to be something that users interact with directly, but rather a low-level feature that lets us provide a correct signature for the `Interlocked*()` operations in the standard library. Most of the support for passing what are logically addresses around already exists in the IR, so the majority of the work here is just in introducing the new type `Ref` and then using it appropriately when lowering `__ref` parameters/arguments to the IR. --- tests/compute/atomics-groupshared.slang | 35 ++++++++++++++++++++++ .../compute/atomics-groupshared.slang.expected.txt | 4 +++ tests/compute/atomics.slang | 24 +++++++++++++++ tests/compute/atomics.slang.expected.txt | 4 +++ 4 files changed, 67 insertions(+) create mode 100644 tests/compute/atomics-groupshared.slang create mode 100644 tests/compute/atomics-groupshared.slang.expected.txt create mode 100644 tests/compute/atomics.slang create mode 100644 tests/compute/atomics.slang.expected.txt (limited to 'tests') diff --git a/tests/compute/atomics-groupshared.slang b/tests/compute/atomics-groupshared.slang new file mode 100644 index 000000000..7ac6809eb --- /dev/null +++ b/tests/compute/atomics-groupshared.slang @@ -0,0 +1,35 @@ +// atomics-groupshared.slang + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out + +RWStructuredBuffer outputBuffer; + +groupshared uint shared[4]; + +uint test(uint val) +{ + uint originalValue; + + outputBuffer[val] = 0; + + GroupMemoryBarrierWithGroupSync(); + + InterlockedAdd(outputBuffer[val], val, originalValue); + InterlockedAdd(outputBuffer[val ^ 1], val*16, originalValue); + InterlockedAdd(outputBuffer[val ^ 2], val*16*16, originalValue); + + GroupMemoryBarrierWithGroupSync(); + + return outputBuffer[val]; +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + uint val = test(tid); + outputBuffer[tid] = val; +} \ No newline at end of file diff --git a/tests/compute/atomics-groupshared.slang.expected.txt b/tests/compute/atomics-groupshared.slang.expected.txt new file mode 100644 index 000000000..30966f0df --- /dev/null +++ b/tests/compute/atomics-groupshared.slang.expected.txt @@ -0,0 +1,4 @@ +210 +301 + 32 +123 diff --git a/tests/compute/atomics.slang b/tests/compute/atomics.slang new file mode 100644 index 000000000..b769be5d7 --- /dev/null +++ b/tests/compute/atomics.slang @@ -0,0 +1,24 @@ +// atomics.slang + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out + +RWStructuredBuffer outputBuffer; + +void test(uint val) +{ + uint originalValue; + + InterlockedAdd(outputBuffer[val], val, originalValue); + InterlockedAdd(outputBuffer[val ^ 1], val*16, originalValue); + InterlockedAdd(outputBuffer[val ^ 2], val*16*16, originalValue); +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + test(tid); +} \ No newline at end of file diff --git a/tests/compute/atomics.slang.expected.txt b/tests/compute/atomics.slang.expected.txt new file mode 100644 index 000000000..30966f0df --- /dev/null +++ b/tests/compute/atomics.slang.expected.txt @@ -0,0 +1,4 @@ +210 +301 + 32 +123 -- cgit v1.2.3