summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/interfaces/interface-conjunction.slang
blob: dbb57343132be03b57046cb32ca632ddc0fccb8d (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
// interface-conjunction.slang

// Test that we can compose interfaces with `&`

//TEST(compute):COMPARE_COMPUTE: -shaderobj

interface IFirst
{
    int getFirst();
}

interface ISecond
{
    int getSecond();
}

struct Pair : IFirst, ISecond
{
    int first;
    int second;

    int getFirst() { return first; }
    int getSecond() { return second; }
}

typealias IBoth = IFirst & ISecond;

int add<T : IBoth>(T input)
{
    return 2*input.getFirst() + input.getSecond();
}

int test(int value)
{
    Pair p = { value, (value+1) * 256 };
    return add(p);
}

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

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