yum-mirror/slang

Making it easier to work with shaders

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

Yong HeRegister allocation during phi elimination. (#2613)4a66e9729

master
1.4 KiB68 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
2//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
3
4//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
5RWStructuredBuffer<uint> outputBuffer;
6
7int test1(uint p)
8{
9    int a, b;
10    if (p > 1)
11    {
12        a = 1;
13        b = 2;
14    }
15    else
16    {
17        a = 2;
18        b = 3;
19    }
20    // b is not used and should not interfere the result of a.
21    return a;
22}
23
24int test2(uint p)
25{
26    int a, b;
27    if (p > 1)
28    {
29        a = 1;
30        b = 2;
31    }
32    else
33    {
34        a = 2;
35        b = 3;
36    }
37    // a is not used and should not interfere the result of b.
38    return b;
39}
40
41int test3(uint p)
42{
43    int a = 1;
44    int b = 5;
45    
46    if (p > 0) a = 2;
47    if (p > 0) b = 3;
48
49    // a and b are now register allocated.
50    // The first block of the loop will have IRParams in the form of (a, b)
51    for (int i = 0; i <= p + 2; i++)
52    {
53        let tmp = a;
54        a = b;
55        b = tmp;
56        // The branch back to the loop header will have phi args: (b, a)
57        // Phi-elmination must handle this case of concurrent assignment correctly.
58    }
59    return a - b; // should be 4 when p == 0.
60}
61
62[numthreads(1, 1, 1)]
63void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
64{
65    let rs1 = test1(dispatchThreadID.x) + test2(dispatchThreadID.x);
66    outputBuffer[0] = rs1;
67    outputBuffer[1] = test3(0);
68}