yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeAllow interface methods to have default implementations. (#7439)6a23949f0

master
876 B45 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type
2
3// Test that interface method can have a body providing default implementation.
4
5interface IFoo
6{
7    int getVal();
8    int getGreaterVal()
9    {
10        return getVal() + 1;
11    }
12    static int getStaticVal()
13    {
14        return 100;
15    }
16}
17
18struct Impl : IFoo
19{
20    int getVal()
21    {
22        return 42;
23    }
24    
25    // Using the default implementation for getGreaterVal.
26}
27
28int test<T:IFoo>(T v) { return v.getGreaterVal(); }
29
30int test2<T:IFoo>() { return T.getStaticVal();}
31
32//TEST_INPUT: set resultBuffer = out ubuffer(data=[0 0 0 0], stride=4)
33RWStructuredBuffer<int> resultBuffer;
34
35[numthreads(1,1,1)]
36void computeMain()
37{
38    Impl impl = {};
39    int result = test(impl);
40    resultBuffer[0] = result;
41    // CHECK: 43
42
43    resultBuffer[1] = test2<Impl>();
44    // CHECK: 100
45}