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