summaryrefslogtreecommitdiff
path: root/tests/hlsl-intrinsic
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-08-31 13:49:40 -0700
committerGitHub <noreply@github.com>2023-08-31 13:49:40 -0700
commitcc412af89e54b04ead508ca84825a18d001b92d0 (patch)
treeda7bb020c494cc4dc62a9c641fb88d7b0b9f89f2 /tests/hlsl-intrinsic
parent1996785e1c5d76254a102c1ec0df5dd7e2e4d68a (diff)
Add SPIRV atomics intrinsics and fix buffer layout lowering. (#3170)
* Fix atomics intrinsics and buffer layout lowering. * Fix. * Add more test. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests/hlsl-intrinsic')
-rw-r--r--tests/hlsl-intrinsic/byte-address-buffer-atomics.slang64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/hlsl-intrinsic/byte-address-buffer-atomics.slang b/tests/hlsl-intrinsic/byte-address-buffer-atomics.slang
new file mode 100644
index 000000000..f133bb372
--- /dev/null
+++ b/tests/hlsl-intrinsic/byte-address-buffer-atomics.slang
@@ -0,0 +1,64 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -dx12 -use-dxil -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+//TEST_INPUT:set bbuffer = ubuffer(data=[0 0 0 0])
+RWByteAddressBuffer bbuffer;
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint originalValue;
+ bbuffer.InterlockedAdd(0, 1);
+
+ bbuffer.InterlockedAdd(0, 1, originalValue);
+ outputBuffer[4] = originalValue;
+
+ bbuffer.InterlockedMax(0, 3);
+ bbuffer.InterlockedMax(0, 4, originalValue);
+ outputBuffer[5] = originalValue;
+
+ bbuffer.InterlockedMin(0, 2);
+ bbuffer.InterlockedMin(0, 2, originalValue);
+ outputBuffer[6] = originalValue;
+
+ bbuffer.InterlockedOr(0, 1);
+ bbuffer.InterlockedOr(0, 1, originalValue);
+ outputBuffer[7] = originalValue;
+
+ bbuffer.InterlockedXor(0, 4);
+ bbuffer.InterlockedXor(0, 4, originalValue);
+ outputBuffer[8] = originalValue;
+
+ bbuffer.InterlockedAnd(0, 7);
+ bbuffer.InterlockedAnd(0, 7, originalValue);
+ outputBuffer[9] = originalValue;
+
+ bbuffer.InterlockedCompareExchange(4, 0, 1, originalValue);
+ outputBuffer[10] = originalValue;
+
+ bbuffer.InterlockedExchange(8, 3, originalValue);
+ outputBuffer[11] = originalValue;
+
+ bbuffer.InterlockedCompareStore(12, 0, 3);
+
+ // CHECK: 3
+ // CHECK: 1
+ // CHECK: 3
+ // CHECK: 3
+ outputBuffer[0] = bbuffer.Load(0);
+ outputBuffer[1] = bbuffer.Load(4);
+ outputBuffer[2] = bbuffer.Load(8);
+ outputBuffer[3] = bbuffer.Load(12);
+ // CHECK: 1
+ // CHECK: 3
+ // CHECK: 2
+ // CHECK: 3
+ // CHECK: 7
+ // CHECK: 3
+ // CHECK: 0
+ // CHECK: 0
+} \ No newline at end of file