yum-mirror/slang

Making it easier to work with shaders

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

Julius IkkalaInline global constants for shader style CPU targets (#8686)537697d3a

master
1.3 KiB51 linesraw
1// type-legalize-global-with-init.slang
2//
3// Confirm that type legalization can handle a global constant
4// with a resource type or a type that recursively contains
5// resources.
6//
7//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj
8//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -vk
9//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -cpu
10//
11//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
12RWStructuredBuffer<uint> outputBuffer;
13
14//TEST_INPUT:ubuffer(data=[1 2 3 4 5 6 7 8], stride=4):name=inputBuffer
15RWStructuredBuffer<uint> inputBuffer;
16
17static const RWStructuredBuffer<uint> gBuffer = inputBuffer;
18
19struct Stuff
20{
21    __init(RWStructuredBuffer<uint> a1, RWStructuredBuffer<uint> b2)
22    {
23        a = a1;
24        b = b2;
25    }
26
27    RWStructuredBuffer<uint> a;
28    RWStructuredBuffer<uint> b;
29}
30
31static const Stuff gStuff = Stuff( inputBuffer, inputBuffer );
32
33uint test(uint x)
34{
35    return gBuffer[x]
36        + gStuff.a[x + 1] * 16
37        + gStuff.b[x + 2] * 256;
38}
39
40[numthreads(4, 1, 1)]
41void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
42{
43    let tid = dispatchThreadID.x;
44    let inVal = tid;
45    let outVal = test(inVal);
46    outputBuffer[tid] = outVal;
47    // CHECK: 321
48    // CHECK: 432
49    // CHECK: 543
50    // CHECK: 654
51}