summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/interfaces/default-method.slang
blob: 98bebc1e3c62c77c9fe2c16d7b5869e65a02c0e8 (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
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type

// Test that interface method can have a body providing default implementation.

interface IFoo
{
    int getVal();
    int getGreaterVal()
    {
        return getVal() + 1;
    }
    static int getStaticVal()
    {
        return 100;
    }
}

struct Impl : IFoo
{
    int getVal()
    {
        return 42;
    }
    
    // Using the default implementation for getGreaterVal.
}

int test<T:IFoo>(T v) { return v.getGreaterVal(); }

int test2<T:IFoo>() { return T.getStaticVal();}

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

[numthreads(1,1,1)]
void computeMain()
{
    Impl impl = {};
    int result = test(impl);
    resultBuffer[0] = result;
    // CHECK: 43

    resultBuffer[1] = test2<Impl>();
    // CHECK: 100
}