summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/generics/where-optional-2.slang
blob: 67679bd8db02a22656942b535f7cc02085fb5b18 (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
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -shaderobj

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

interface IThing
{
    [mutating]
    int thing(int index);
}

struct MyThing: IThing
{
    int val;

    [mutating]
    int thing(int index)
    {
        val++;
        outputBuffer[index] = val;
        return val;
    }
}

struct NotMyThing
{
    int val;
}

void f<T>(inout T t, int index) where optional T: IThing
{
    if (T is IThing)
    {
        outputBuffer[index+1] = 2 * t.thing(index);
    }
    else
    {
        outputBuffer[index] = 0;
        outputBuffer[index+1] = 0;
    }
}

[numthreads(1, 1, 1)]
void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
{
    MyThing mt = MyThing(0);
    NotMyThing nt = NotMyThing(1);

    // CHECK: 1
    // CHECK-NEXT: 2
    f<MyThing>(mt, 0);
    // CHECK-NEXT: 0
    // CHECK-NEXT: 0
    f<NotMyThing>(nt, 2);
    // CHECK: 2
    // CHECK-NEXT: 4
    f(mt, 4);
    // CHECK-NEXT: 0
    // CHECK-NEXT: 0
    f(nt, 6);
}