yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
1.7 KiB51 linesraw
1// byte-address-struct-load.slang
2
3// Test that load of a `struct` type from a byte-address
4// buffer can be translated into per-field loads on
5// all targets that support loads of the field types.
6
7//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu -shaderobj
8//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
9//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj
10//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-slang -vk -compute -shaderobj
11//TEST(compute):COMPARE_COMPUTE_EX:-slang -cuda -compute -shaderobj
12
13// Note: This input should really be just a `ByteAddressBuffer`,
14// so that we can confirm that the functionality works in the
15// read-only case as well. The reason we are using a `RWByteAddressBuffer`
16// is because of limitations in the `render-test` app, and if
17// those limitations get fixed, we should switch this code.
18//
19//TEST_INPUT:ubuffer(data=[0x5 0x3f800000 0x6 0x40000000 0x7 0x40400000 0x8 0x40800000]):name=inputBuffer
20RWByteAddressBuffer inputBuffer;
21
22//TEST_INPUT:ubuffer(data=[0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef]):name=tmpBuffer
23RWByteAddressBuffer tmpBuffer;
24
25//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
26RWStructuredBuffer<int> outputBuffer;
27
28struct Data
29{
30	int a;
31	float b;
32}
33
34int test(int val)
35{
36	int offsetX = val*8;
37	int offsetY = offsetX & 0xFF;
38
39	Data x = inputBuffer.Load<Data>(offsetX);
40	tmpBuffer.Store<Data>(offsetY, x);
41
42	Data y = tmpBuffer.Load<Data>(offsetX);
43	return y.a*256*16 + int(y.b);
44}
45
46[numthreads(4, 1, 1)]
47void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
48{
49	int tid = dispatchThreadID.x;
50	outputBuffer[tid] = test(tid);
51}