yum-mirror/slang

Making it easier to work with shaders

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

Yong HeSupport dependent generic constraints. (#4870)f9f6a28df

master
951 B50 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type
3
4// Test that we can define a generic where one of the type parameter conforms to an generic interface parameterized on another
5// type parameter.
6
7interface IFoo
8{
9    int get();
10}
11
12struct Foo : IFoo
13{
14    int get()
15    {
16        return 1;
17    }
18}
19
20interface IBar<T : IFoo>
21{
22    int getVal(T t);
23}
24
25struct Bar<T : IFoo> : IBar<T>
26{
27    int getVal(T t)
28    {
29        return t.get();
30    }
31}
32
33int test<T:IFoo, B : IBar<T>>(B b, T t)
34{
35    return b.getVal(t);
36}
37
38//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
39RWStructuredBuffer<int> outputBuffer;
40
41[numthreads(1, 1, 1)]
42void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
43{
44    Foo obj1;
45    Bar<Foo> obj2;
46    let result = test(obj2, obj1);
47
48    // CHECK: 1
49    outputBuffer[0] = result;
50}