summaryrefslogtreecommitdiffstats
path: root/tests/compute/byte-address-buffer.slang
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-11-19 09:07:34 -0800
committerGitHub <noreply@github.com>2018-11-19 09:07:34 -0800
commit7e0c5ad677e04be4ecd2ce087d856ba26f1667a4 (patch)
treefd4168b307fff97e3811defe4813029b660ec697 /tests/compute/byte-address-buffer.slang
parent0f67d92df9ca1f528b7a7fc8a8712aaea56f7115 (diff)
Add Vulkan cross-compilation for byte-address buffers (#721)
* Add Vulkan cross-compilation for byte-address buffers This covers `ByteAddressBuffer`, `RWByteAddressBuffer`, and `RasterizerOrderedByteAddressBuffer`. A declaration of any of these types translates to a GLSL `buffer` declaration with a single `uint` array of data. Most of the methods on these types then have straightforward translations to operations on the array. The overall translation is similar to what was already being done for structured buffers. While implementing GLSL translation for the various atomic (`Interlocked*`) methods, I discovered that some of these included declarations that aren't actually included in HLSL. I cleaned these up, including in the declarations of the global `Interlocked*` functions. The test case that is included here covers only the most basic functionality: `Load`, `Load2`, `Load4` and `Store`. We should try to back-fill tests for the remaining methods when we have time. Two large caveats with this work: 1. We don't handle arrays of byte-address buffers, just as we don't handle arrays of structured buffers. That will take additional work. 2. We don't handle byte-address (or structured) buffers being passed as function parameters, since the parameter would need to be declared as a bare `uint[]` array. * Fixup: don't lump raytracing acceleration structures in with buffers Raytracing acceleration structures share a common base class with byte-address buffers (they are both buffer resources without a specific element type), and I was mistakently matching on this base class in an attempt to have a catch-all that applied to all byte-address buffers. The fix here was to add a distinct base class for all byte-address buffers and catch that instead. * Fixup: typos
Diffstat (limited to 'tests/compute/byte-address-buffer.slang')
-rw-r--r--tests/compute/byte-address-buffer.slang40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/compute/byte-address-buffer.slang b/tests/compute/byte-address-buffer.slang
new file mode 100644
index 000000000..2efbeb630
--- /dev/null
+++ b/tests/compute/byte-address-buffer.slang
@@ -0,0 +1,40 @@
+// byte-address-buffer.slang
+
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-d3d12 -compute
+
+// Confirm cross-compilation of `(RW)ByteAddressBuffer`
+//
+// TODO: I'm only using `RWByteAddressBuffer` for now because I don't
+// know if `render-test` supports the non-UAV case.
+
+//TEST_INPUT:ubuffer(data=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]):dxbinding(0),glbinding(0)
+RWByteAddressBuffer inputBuffer;
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0]):dxbinding(1),glbinding(1),out
+RWByteAddressBuffer outputBuffer;
+
+void test(int val)
+{
+ uint tmp = val;
+
+ tmp = inputBuffer.Load(tmp * 4);
+
+ uint2 pair = inputBuffer.Load2(tmp * 4);
+ tmp = (pair.x + pair.y) & 0xF;
+
+ uint4 quad = inputBuffer.Load4(tmp * 4);
+ tmp = (quad.x + quad.y + quad.z + quad.w) & 0xF;
+
+ outputBuffer.Store(val * 4, tmp);
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+
+ int val = int(tid);
+ test(val);
+} \ No newline at end of file