summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/defer/generics.slang
blob: 7ecd7de3174213fb7d34eca8cae9768abb5df3e8 (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
//TEST(compute):COMPARE_COMPUTE: -shaderobj
//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj
//TEST(compute):COMPARE_COMPUTE:-cpu -shaderobj

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

interface IDroppable
{
    void drop(inout int i);
};

interface IDiscombobulatable
{
    void discombobulate(inout int i, int param);
}

void genericFunc<T>(int param)
    where T : IDroppable, IDiscombobulatable
{
    T t;
    int i = 0;
    defer t.drop(i);

    int p = param;
    defer t.discombobulate(i, p);
    t.discombobulate(i, p);
    p += 1;
}

struct TestType : IDroppable, IDiscombobulatable
{
    void drop(inout int i)
    {
        outputBuffer[i++] = 0xFF;
    }

    void discombobulate(inout int i, int param)
    {
        outputBuffer[i++] = param;
    }
}

[numthreads(1, 1, 1)]
void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
{
    genericFunc<TestType>(2);
}