summaryrefslogtreecommitdiff
path: root/tests/language-feature/types/opaque/inout-param-opaque-type-in-struct.slang
blob: 37e2585cdf3c05447dba4db13fb67f92105e8b1d (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
// inout-param-opaque-type-in-struct.slang

// Test that a function/method can have an `out` parameter of
// aggregate type that includes an opaque type

//TEST(compute):COMPARE_COMPUTE:
//TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -mtl

struct Things
{
    int first;
    RWStructuredBuffer<int> rest;
}

//TEST_INPUT:set C = new { {1, ubuffer(data=[2 3 4 5], stride=4)}, {6, ubuffer(data=[7 8 9 10], stride=4)} }
cbuffer C
{
    Things gX;
    Things gY;
}

void swap(
    inout Things a,
    inout Things b)
{
    Things t = a;
    a = b;
    b = t;
}

int eval(Things t, int val)
{
    return t.first*256 + t.rest[val];
}

int test(int val)
{
    Things f = gX;
    Things g = gY;

    swap(f, g);

    return (eval(f,val) << 16) + eval(g,val);
}

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

[numthreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
    int tid = dispatchThreadID.x;
    int inVal = tid;
    int outVal = test(inVal);
    gOutput[tid] = outVal;
}