diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-05-29 11:39:55 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-29 11:39:55 -0700 |
| commit | e7a83323bfc4dd698ef491375a37c65c83915951 (patch) | |
| tree | 4dc8d7ac5c192817a6d3fa680b731723ff9eba27 /tests | |
| parent | ace9a8dc7e4353b1cf8e846abe2b8dc53ecdbc59 (diff) | |
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<T>` and then using it appropriately when lowering `__ref` parameters/arguments to the IR.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compute/atomics-groupshared.slang | 35 | ||||
| -rw-r--r-- | tests/compute/atomics-groupshared.slang.expected.txt | 4 | ||||
| -rw-r--r-- | tests/compute/atomics.slang | 24 | ||||
| -rw-r--r-- | tests/compute/atomics.slang.expected.txt | 4 |
4 files changed, 67 insertions, 0 deletions
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<uint> 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<uint> 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 |
