summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/pointer/const-ref.slang
blob: f62fda6971343a3a116f4382de3ac941bf3e2d45 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// pointer-self-reference.slang

//TEST:SIMPLE(filecheck=CHECK): -target cuda -entry computeMain -stage compute
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER): -slang -compute -output-using-type -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER): -vk -compute -output-using-type -shaderobj


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

struct Thing
{
    int value;
    int bigArray[128];

    // Check that we are not inserting local variables that are copies of `this` parameter.
    
    // CHECK: __device__ int Thing_getSum{{.*}}(Thing{{.*}} * this{{.*}})
    // CHECK-NOT: Thing{{[a-zA-Z0-9_]*}} {{[a-zA-Z0-9_]+}}
    // CHECK: }
    [constref]
    int getSum()
    {
        int result = 0;
        for (int i = 0; i < 128; i++)
        {
            result += bigArray[i];
        }
        return result;
    }
};

// Check that we are not inserting local variables that are copies of `thing` parameter.

// CHECK: __device__ int test{{.*}}(Thing{{.*}} * thing{{.*}})
// CHECK-NOT: Thing{{[a-zA-Z0-9_]*}} {{[a-zA-Z0-9_]+}}
// CHECK: }

int test(__constref Thing thing)
{
    int sum0 = thing.getSum();
    AllMemoryBarrier();
    int sum1 = thing.getSum();
    return sum0 + sum1;
}

int caller(Thing thing)
{
    return test(thing);
}

[numthreads(1, 1, 1)]
void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
{
    int idx = dispatchThreadID.x;

    Thing thing = {};

    thing.bigArray[0] = 100;
    thing.bigArray[99] = 1;

    // BUFFER: 202
    outputBuffer[idx] = caller(thing);
}