yum-mirror/slang

Making it easier to work with shaders

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

Yong HeFix extension override behavior, and disallow extension on interface types. (#4977)ddd29057e

master
1.5 KiB65 linesraw
1// Test that the override behavior around extensions and generic extensions works as expected.
2
3// When there are multiple ways for a type to conform to an interface, then the expected behavior
4// is that:
5// 1. If the type directly implements an interface, use that conformance.
6// 2. Otherwise, if there is a direct extension on the type that makes it conform to the interface, use that
7//    extension.
8// 3. Otherwise, if there is a generic extension that makes the type conform to the interface, use that.
9
10//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj
11interface IFoo
12{
13    int getVal();
14}
15
16interface IBar
17{
18    int getValPlusOne();
19}
20
21interface IBaz
22{
23    int getValPlusTwo();
24}
25
26struct MyInt
27{
28    int v;
29}
30
31extension MyInt : IFoo
32{
33    int getVal() { return v; }
34}
35
36extension MyInt : IBar
37{
38    int getValPlusOne() { return this.getVal() + 2; }
39}
40
41extension<T: IFoo> T : IBar
42{
43    int getValPlusOne() { return this.getVal() + 1; }
44}
45
46int helper1<T:IBar>(T v){ return v.getValPlusOne();}
47int helper2<T:IFoo>(T v){ return v.getValPlusOne();}
48
49//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
50RWStructuredBuffer<int> outputBuffer;
51
52[numthreads(1,1,1)]
53void computeMain()
54{
55    MyInt v = {1};
56
57    // CHECK: 3
58    outputBuffer[0] = v.getValPlusOne(); // should call MyInt::ext::getValPlusOne();
59
60    // CHECK: 3
61    outputBuffer[1] = helper1(v); // should call MyInt::ext::getValPlusOne();
62
63    // CHECK: 2
64    outputBuffer[2] = helper2(v); // should call T::ext::getValPlusOne();
65}