yum-mirror/slang

Making it easier to work with shaders

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

Yong HeSupport extension on generic type. (#4968)24df5515d

master
926 B49 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj
2interface IFoo
3{
4    int getVal();
5}
6
7interface IBar
8{
9    int getValPlusOne();
10}
11
12interface IBaz
13{
14    int getValPlusTwo();
15}
16
17struct MyInt { int v; }
18
19extension MyInt : IFoo
20{
21    int getVal() { return v; }
22}
23
24// Since MyInt:IFoo, the following extension will make MyInt:IBar.
25extension<T: IFoo> T : IBar
26{
27    int getValPlusOne() { return this.getVal() + 1; }
28}
29
30// Since MyInt:IBar, the following extension will make MyInt:IBaz.
31extension<T: IBar> T : IBaz
32{
33    int getValPlusTwo() { return this.getValPlusOne() + 1; }
34}
35
36//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
37RWStructuredBuffer<int> outputBuffer;
38
39[numthreads(1,1,1)]
40void computeMain()
41{
42    MyInt v = {1};
43
44    // Check that the extensions applied to MyInt correctly, i.e.
45    // MyInt.getValPlusTwo() eixsts.
46
47    // CHECK: 3
48    outputBuffer[0] = v.getValPlusTwo();
49}