summaryrefslogtreecommitdiffstats
path: root/tests/bugs/mutating/mutating-call-in-loop-dce.slang
blob: 231ddbaeee6a741c732e6990603d886c9b1ba377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type

// Confirm that a SideEffectFree mutable method does not get DCE'd when
// it is called from within a loop.

struct C
{
    int a;
    [mutating]
    int add()
    {
        a++;
        return a;
    }
    [mutating]
    void init()
    {
        a = 0;
    }
}
int doSomething(C d_in)
{
    C d = d_in;
    int rs = 0;
    for (int i = 0; i < 10; i++)
        rs = d.add();
    return rs;
}

//TEST_INPUT:ubuffer(data=[0], stride=4):out, name outputBuffer
RWStructuredBuffer<int> outputBuffer;

[numthreads(1, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
    int tid = dispatchThreadID.x;
    C c;
    c.init();
    outputBuffer[tid] = doSomething(c);
}