yum-mirror/slang

Making it easier to work with shaders

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

Darren WihandiFix HLSL ByteAddressBuffer Load* parameter integer type (#7117)8683b85c0

master
1.3 KiB48 linesraw
1// byte-address-buffer.slang
2
3//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj
4//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
5//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
6//TEST(compute):COMPARE_COMPUTE_EX:-d3d12 -compute -shaderobj
7
8//TEST:SIMPLE(filecheck=SPV):-target spirv -entry computeMain -stage compute -emit-spirv-directly
9
10// Confirm cross-compilation of `(RW)ByteAddressBuffer`
11//
12// TODO: I'm only using `RWByteAddressBuffer` for now because I don't
13// know if `render-test` supports the non-UAV case.
14
15//TEST_INPUT:ubuffer(data=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]):name=inputBuffer
16RWByteAddressBuffer inputBuffer;
17
18//TEST_INPUT:ubuffer(data=[0 0 0 0]):out,name=outputBuffer
19RWByteAddressBuffer outputBuffer;
20
21// Make sure arithmetic ops are properly performed on unsigned types.
22// SPV-NOT: OpSDiv
23// SPV: OpUDiv
24
25void test(uint val)
26{
27	uint tmp = val;
28
29	tmp = inputBuffer.Load(uint(tmp * 4));
30
31	uint2 pair = inputBuffer.Load2(uint(tmp * 4));
32	tmp = (pair.x + pair.y) & 0xF;
33
34	uint4 quad = inputBuffer.Load4(uint(tmp * 4));
35	tmp = (quad.x + quad.y + quad.z + quad.w) & 0xF;
36
37	outputBuffer.Store(val*4, tmp);
38}
39
40[numthreads(4, 1, 1)]
41[shader("compute")]
42void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
43{
44    uint tid = dispatchThreadID.x;
45
46    uint val = uint(tid);
47    test(val);
48}