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

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

interface IFoo
{
    int getVal();
    int getGreaterVal<int x>()
    {
        return getVal() + x;
    }
}

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

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

//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
}