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

// Test that we can defer buffer loads by ruling out potential aliasing writes.

struct Bottom
{
    float bigArray[1024];

    float bottomGetValue(int index)
    {
        // RWStructuredBuffer is considered to not alias with anything else.
        // this write should not prevent deferring loading bigArray.
        gOther[0] = 100;
        // this write should not prevent deferring loading bigArray.
        gSharedVar = 1;
        // this write should not prevent deferring loading bigArray.
        gStaticVar = 2;

        // 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 RWStructuredBuffer<int> gOther;
static int gStaticVar;
groupshared int gSharedVar;


RWStructuredBuffer<float> outputBuffer;

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