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
919 B49 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 infer a generic type parameter from the base type of a dependent generic argument.
5
6interface IFoo : IDefaultInitializable
7{
8    int get();
9}
10
11struct Foo : IFoo
12{
13    int get()
14    {
15        return 1;
16    }
17}
18
19interface IBar<T : IFoo>
20{
21    int getVal();
22}
23
24struct Bar<T : IFoo> : IBar<T>
25{
26    int getVal()
27    {
28        T t = T();
29        return t.get();
30    }
31}
32
33int test<T:IFoo, B : IBar<T>>(B b)
34{
35    return b.getVal();
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    Bar<Foo> obj2;
45    let result = test(obj2);
46
47    // CHECK: 1
48    outputBuffer[0] = result;
49}