summaryrefslogtreecommitdiffstats
path: root/tests/optimization/buffer-load-defer-aliasing.slang
blob: a0240cc40d9be9181ea74977ff27a76388b33d86 (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
//TEST:SIMPLE(filecheck=SPV): -target spirv -O0

// Test that we are not deferring buffer loads due to potential aliasing writes.

struct Bottom
{
    float bigArray[1024];

    float bottomGetValue(int index)
    {
        // this write may cause data stored at gRoot to be modified,
        // thus bigArray[index] may be different from what it was before the call to
        // bottomGetValue. So we should not defer loading bigArray until after this write.
        *gOther = 100; 

        // We should return the value from bigArray from a previously loaded value of `this`.
        return bigArray[index];
    }
}

struct Root
{
    Bottom bottom1;
    Bottom bottom2;
}

uniform Root* gRoot;
uniform int* gOther;

RWStructuredBuffer<float> outputBuffer;

[shader("compute")]
[numthreads(1, 1, 1)]
void compute_main(uint3 tid: SV_DispatchThreadID)
{
    // SPV: OpLoad %Bottom_natural
    outputBuffer[0] = gRoot.bottom1.bottomGetValue(0);
}