summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/interfaces/is-as.slang
blob: 2712d9810db31b8f5b330daa03de5a8cf057e162 (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
// is-as.slang

// Test that `is` and `as` operators works as intended.

//TEST(compute):COMPARE_COMPUTE: -shaderobj

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

interface IFoo
{
    int method();
}

struct Impl1 : IFoo
{
    int data;
    int method() { return data; }
}

struct Impl2 : IFoo
{
    int data1;
    int data2;
    int method() { return data1 + data2; }
}

int getData(IFoo foo)
{
    let castResult = foo as Impl2;
    if (castResult.hasValue)
    {
        return castResult.value.method();
    }
    return 0;
}

[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
    Impl2 obj;
    obj.data1 = 1;
    obj.data2 = 2;
    int outVal = getData(obj);
    outputBuffer[0] = outVal;
}