summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/extensions/generic-extension-1.slang
blob: 47940e31a79879baada5998875bcca89b4670f1b (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
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj
interface IFoo
{
    int getVal();
}

interface IBar
{
    int getValPlusOne();
}

interface IBaz
{
    int getValPlusTwo();
}

struct MyInt { int v; }

extension MyInt : IFoo
{
    int getVal() { return v; }
}

// Since MyInt:IFoo, the following extension will make MyInt:IBar.
extension<T: IFoo> T : IBar
{
    int getValPlusOne() { return this.getVal() + 1; }
}

// Since MyInt:IBar, the following extension will make MyInt:IBaz.
extension<T: IBar> T : IBaz
{
    int getValPlusTwo() { return this.getValPlusOne() + 1; }
}

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

[numthreads(1,1,1)]
void computeMain()
{
    MyInt v = {1};

    // Check that the extensions applied to MyInt correctly, i.e.
    // MyInt.getValPlusTwo() eixsts.

    // CHECK: 3
    outputBuffer[0] = v.getValPlusTwo();
}