diff options
Diffstat (limited to 'tests')
4 files changed, 110 insertions, 0 deletions
diff --git a/tests/hlsl-intrinsic/byte-address-buffer/byte-address-16bit.slang b/tests/hlsl-intrinsic/byte-address-buffer/byte-address-16bit.slang new file mode 100644 index 000000000..840c72676 --- /dev/null +++ b/tests/hlsl-intrinsic/byte-address-buffer/byte-address-16bit.slang @@ -0,0 +1,51 @@ +// byte-address-16bit-load.slang + +// Test that loading values using 16-bit types from +// byte-address buffers works as expected, on targets +// that support it. + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -profile cs_6_2 -render-features half +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-slang -vk -compute -profile cs_6_2 -render-features half +//TEST(compute):COMPARE_COMPUTE_EX:-slang -cuda -compute + +// Unavailable on D3D and fxc-based targets, because fxc doesn't +// support loading anything besides `uint` from a byte-address +// buffer. +// +//TEST_DISABLED(compute):COMPARE_COMPUTE_EX:-slang -compute + + +//TEST_INPUT:ubuffer(data=[0x00010002 0x00030004 0x00050006 0x00070008]):name=inputBuffer +RWByteAddressBuffer inputBuffer; + +//TEST_INPUT:ubuffer(data=[0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef]):name=tmpBuffer +RWByteAddressBuffer tmpBuffer; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +struct Data +{ + int16_t a; + int16_t b; +} + +int test(int val) +{ + int offsetX = val*4; + int offsetY = offsetX & 0xFF; + + Data x = inputBuffer.Load<Data>(offsetX); + tmpBuffer.Store<Data>(offsetY, x); + + Data y = tmpBuffer.Load<Data>(offsetX); + return int(y.a)*256*16 + int(y.b); +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + outputBuffer[tid] = test(tid); +}
\ No newline at end of file diff --git a/tests/hlsl-intrinsic/byte-address-buffer/byte-address-16bit.slang.expected.txt b/tests/hlsl-intrinsic/byte-address-buffer/byte-address-16bit.slang.expected.txt new file mode 100644 index 000000000..eefd23c0a --- /dev/null +++ b/tests/hlsl-intrinsic/byte-address-buffer/byte-address-16bit.slang.expected.txt @@ -0,0 +1,4 @@ +2001 +4003 +6005 +8007 diff --git a/tests/hlsl-intrinsic/byte-address-buffer/byte-address-struct.slang b/tests/hlsl-intrinsic/byte-address-buffer/byte-address-struct.slang new file mode 100644 index 000000000..520dce88a --- /dev/null +++ b/tests/hlsl-intrinsic/byte-address-buffer/byte-address-struct.slang @@ -0,0 +1,51 @@ +// byte-address-struct-load.slang + +// Test that load of a `struct` type from a byte-address +// buffer can be translated into per-field loads on +// all targets that support loads of the field types. + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-slang -vk -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -cuda -compute + +// Note: This input should really be just a `ByteAddressBuffer`, +// so that we can confirm that the functionality works in the +// read-only case as well. The reason we are using a `RWByteAddressBuffer` +// is because of limitations in the `render-test` app, and if +// those limitations get fixed, we should switch this code. +// +//TEST_INPUT:ubuffer(data=[0x5 0x3f800000 0x6 0x40000000 0x7 0x40400000 0x8 0x40800000]):name=inputBuffer +RWByteAddressBuffer inputBuffer; + +//TEST_INPUT:ubuffer(data=[0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef]):name=tmpBuffer +RWByteAddressBuffer tmpBuffer; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +struct Data +{ + int a; + float b; +} + +int test(int val) +{ + int offsetX = val*8; + int offsetY = offsetX & 0xFF; + + Data x = inputBuffer.Load<Data>(offsetX); + tmpBuffer.Store<Data>(offsetY, x); + + Data y = tmpBuffer.Load<Data>(offsetX); + return y.a*256*16 + int(y.b); +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + outputBuffer[tid] = test(tid); +}
\ No newline at end of file diff --git a/tests/hlsl-intrinsic/byte-address-buffer/byte-address-struct.slang.expected.txt b/tests/hlsl-intrinsic/byte-address-buffer/byte-address-struct.slang.expected.txt new file mode 100644 index 000000000..af04f5b0e --- /dev/null +++ b/tests/hlsl-intrinsic/byte-address-buffer/byte-address-struct.slang.expected.txt @@ -0,0 +1,4 @@ +5001 +6002 +7003 +8004 |
