summaryrefslogtreecommitdiff
path: root/tests/metal
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-10-17 20:14:22 -0700
committerGitHub <noreply@github.com>2024-10-17 20:14:22 -0700
commita618b8c5e249b0f20e6c0c95f9da1b5cbfdbf08b (patch)
treed583c373d574a265fefe7f288a96c4b382e259b8 /tests/metal
parent11e1ecafa09396a3559fe245d729b40ce4f25d52 (diff)
Cleanup atomic intrinsics. (#5324)
* Cleanup atomic intrinsics. * Fix. * Fix glsl. * Remove hacky intrinsic expansion logic for glsl image atomics. * Fix all tests. * Fix. * Add `InterlockedAddF16Emulated`. * Fix glsl intrinsic. * Fix.
Diffstat (limited to 'tests/metal')
-rw-r--r--tests/metal/atomic-byteaddressbuffer.slang57
-rw-r--r--tests/metal/atomic-intrinsics.slang11
-rw-r--r--tests/metal/atomic-texture-buffer.slang2
3 files changed, 63 insertions, 7 deletions
diff --git a/tests/metal/atomic-byteaddressbuffer.slang b/tests/metal/atomic-byteaddressbuffer.slang
new file mode 100644
index 000000000..677f80dbf
--- /dev/null
+++ b/tests/metal/atomic-byteaddressbuffer.slang
@@ -0,0 +1,57 @@
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -dx12 -profile cs_6_0 -use-dxil -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-vk -compute -shaderobj -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-cuda -compute -shaderobj -output-using-type
+//TEST:SIMPLE(filecheck=LIB):-target metallib -entry computeMain -stage compute -DMETAL
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0]):name=uintBuffer
+RWByteAddressBuffer uintBuffer;
+
+//TEST_INPUT: ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ], stride=4):out,name outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+[numthreads(1,1,1)]
+void computeMain()
+{
+ uintBuffer.InterlockedAdd(0, 1);
+ int oldValue;
+ //LIB: call {{.*}}.atomic.global.add.u.i32
+ uintBuffer.InterlockedAdd(0, 1, oldValue);
+ // CHK: 1
+ outputBuffer[0] = oldValue;
+
+ uintBuffer.InterlockedAdd(0, 1, oldValue);
+ // CHK: 2
+ outputBuffer[1] = (int)oldValue;
+
+ uintBuffer.InterlockedCompareExchange(0, 3, 4, oldValue);
+ // CHK: 3
+ outputBuffer[2] = (int)oldValue;
+
+ uintBuffer.InterlockedOr(0, 3, oldValue);
+ // CHK: 4
+ outputBuffer[3] = oldValue; // 4
+
+ uintBuffer.InterlockedExchange(0, 4, oldValue);
+ // CHK: 7
+ outputBuffer[4] = oldValue; // 7
+
+ uintBuffer.InterlockedMin(0, 3, oldValue);
+ // CHK: 4
+ outputBuffer[5] = oldValue; // 4
+
+ uintBuffer.InterlockedMax(0, 4, oldValue);
+ // CHK: 3
+ outputBuffer[6] = oldValue; // 3
+
+ uintBuffer.InterlockedAnd(0, 7, oldValue);
+ // CHK: 4
+ outputBuffer[7] = oldValue; // 4
+
+ uintBuffer.InterlockedXor(0, 7, oldValue);
+ // CHK: 4
+ outputBuffer[8] = oldValue; // 4
+
+ // CHK: 3
+ outputBuffer[9] = uintBuffer.Load(0);
+
+} \ No newline at end of file
diff --git a/tests/metal/atomic-intrinsics.slang b/tests/metal/atomic-intrinsics.slang
index 5d47db913..afa0e5365 100644
--- a/tests/metal/atomic-intrinsics.slang
+++ b/tests/metal/atomic-intrinsics.slang
@@ -1,8 +1,7 @@
//TEST:SIMPLE(filecheck=MTL):-target metal -entry computeMain -stage compute -DMETAL
//TEST:SIMPLE(filecheck=LIB):-target metallib -entry computeMain -stage compute -DMETAL
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -dx12 -profile cs_6_0 -use-dxil -shaderobj -output-using-type
-//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-vk -emit-spirv-directly -compute -shaderobj -output-using-type
-//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-vk -emit-spirv-via-glsl -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-vk -compute -shaderobj -output-using-type
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj -output-using-type
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
@@ -36,22 +35,22 @@ void computeMain(uint groupIndex : SV_GroupIndex)
float val = 0.0f;
// InterlockedAdd
- //MTL: atomic_uint threadgroup* {{.*}}shareMemUI
+ //MTL: atomic_uint threadgroup*{{.*}}shareMemUI
//LIB: call {{.*}}.atomic.local.add.u.i32
InterlockedAdd(shareMemUI[idx], uint(1));
val += shareMemUI[idx];
- //MTL: atomic_int threadgroup* {{.*}}shareMemI
+ //MTL: atomic_int threadgroup*{{.*}}shareMemI
//LIB: call {{.*}}.atomic.local.add.s.i32
InterlockedAdd(shareMemI[idx], 2);
val += shareMemI[idx];
- //MTL: atomic_uint device* {{.*}}uintBuffer
+ //MTL: atomic_uint device*{{.*}}uintBuffer
//LIB: call {{.*}}.atomic.global.add.u.i32
InterlockedAdd(uintBuffer[idx], 1);
val += uintBuffer[idx];
- //MTL: atomic_int device* {{.*}}intBuffer
+ //MTL: atomic_int device*{{.*}}intBuffer
//LIB: call {{.*}}.atomic.global.add.s.i32
InterlockedAdd(intBuffer[idx], 2);
val += intBuffer[idx];
diff --git a/tests/metal/atomic-texture-buffer.slang b/tests/metal/atomic-texture-buffer.slang
index 3e4eda94b..1db156364 100644
--- a/tests/metal/atomic-texture-buffer.slang
+++ b/tests/metal/atomic-texture-buffer.slang
@@ -2,7 +2,7 @@
//TEST:SIMPLE(filecheck=METAL_FLOAT): -target metal -stage compute -entry computeMain -DFLOAT
//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage compute -entry computeMain
-// METAL_FLOAT: 'float' atomic texture operations are disallowed with Metal target's
+// METAL_FLOAT: floating point atomic operation
//METALLIB: @computeMain