summaryrefslogtreecommitdiffstats
path: root/tests/compute
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-07-10 16:25:51 -0400
committerGitHub <noreply@github.com>2024-07-10 13:25:51 -0700
commitff9437e6c926c1e7c6a0ebe66592b46dbb3fb36b (patch)
tree973c2f2cad40e87591c0af9a97f376b7602e1c64 /tests/compute
parenta08ccfa50a06797dab60918b788570a520c45454 (diff)
Implement non member function atomic texture support (#4544)
* Implement non member function atomic texture support texture_buffer and texture1d Fixes: #4538 Related to: #4291, fixes `tests/compute/atomics-buffer.slang` Texture objects cannot use `__getMetalAtomicRef` to cast objects into atomic value type. [Texture objects mandate use of member functions](https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf#Texture%20Functions). The implementation is as follows: * We can detect texture object usage through checking for an `IRImageSubscript` Operation. `__isTextureAccess()` was added to evaluate if we have an `IRImageSubscript` operation at compile time (before `static_assert`). `__isTextureAccess()` only checks if we are targeting Metal. * We have all parameter data needed to call a texture atomic function embedded inside `IRImageSubscript`. `__extractTextureFromTextureAccess()` and `__extractCoordFromTextureAccess()` was added to extract this data for use with Metal atomics. Note: * Metal documentation has various incorrect details (function names) * Since we currently hardcode metal versions for compiling, the Metal compiler version was changed to target `Metal 3.1` (`slang-gcc-compiler-util.cpp`) * textures do not permit atomic float operations * add fallthrough attribute + fix bug with 'exchange instead of xor' + fix warning bug * incorrect function name fix * missing filecheck * disable atomics-buffer.slang compute test since GFX issue causing it to fail * Array support for metal interlockedAtomic and proper verification of texture with interlockedAtomic functions * Array support for metal interlockedAtomic * proper verification of texture with interlockedAtomic functions note: had to seperate many functions to allow forceInlining to run * missing getOperand(0) * push atomic fix for metal * fix atomic syntax for metal and hlsl emitting extra brackets (breaks tests) * test changes and meta changes 1. max is 8 rw textures with metal because Metal has this limit. Split up tests to not hit this limit 2. added back `[0]`...,`T` to test since this legalizes metal atomic intrinsic * macro'ify some of the atomic code 1. addresses review 2. makes code easier to modify in the future (rather than sifting through 1000 lines we can just look at ~10-30 * fix test 'check' * missing float support due to macro * add functions macro generates, `InternalAtomicOperationInfo` --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests/compute')
-rw-r--r--tests/compute/atomics-buffer.slang4
-rw-r--r--tests/compute/atomics-invalid-dest-type.slang24
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/compute/atomics-buffer.slang b/tests/compute/atomics-buffer.slang
index 72b86368d..6745d6b58 100644
--- a/tests/compute/atomics-buffer.slang
+++ b/tests/compute/atomics-buffer.slang
@@ -9,7 +9,11 @@
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cuda -shaderobj
// Atomics not available on CPU currently
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu -shaderobj
+// RWBuffer does not work with the GFX backend as expected with Metal
//DISABLE_TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -mtl
+//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage compute -entry computeMain
+
+//METALLIB: @computeMain
//TEST_INPUT:ubuffer(format=R_UInt32, data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]):out,name outputBuffer
diff --git a/tests/compute/atomics-invalid-dest-type.slang b/tests/compute/atomics-invalid-dest-type.slang
new file mode 100644
index 000000000..864debaee
--- /dev/null
+++ b/tests/compute/atomics-invalid-dest-type.slang
@@ -0,0 +1,24 @@
+// atomics-buffer.slang
+
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry computeMain
+//TEST:SIMPLE(filecheck=CHECK): -target hlsl -stage compute -entry computeMain
+//TEST:SIMPLE(filecheck=CHECK): -target glsl -stage compute -entry computeMain
+//TEST:SIMPLE(filecheck=CHECK): -target metal -stage compute -entry computeMain
+
+//CHECK: Atomic must be applied to a scalar texture or non-texture
+
+RWBuffer<uint2> outputBuffer;
+
+void test(uint val)
+{
+ uint originalValue;
+
+ InterlockedAdd(outputBuffer[val][0], val, originalValue);
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ test(tid);
+}