yum-mirror/slang

Making it easier to work with shaders

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

RonanFixed generic interface specialization crashes (#6601): (#6688)6b44630af

master
1.4 KiB81 linesraw
1
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type
3//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type
4
5//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8interface IGetter
9{
10    float get(uint id);
11}
12
13struct GetterImpl : IGetter
14{
15    float[8] data;
16
17    __init(float[8] data)
18    { this.data = data; }
19
20    float get(uint id)
21    {
22        return data[id];
23    }
24}
25interface IFoo<int N>
26{
27    associatedtype Params : IGetter;
28
29    Params bar();
30}
31
32struct FooImpl1: IFoo<8>
33{   
34    typealias Params = GetterImpl;
35
36    __init()
37    { }
38
39    Params bar()
40    {
41        float x = outputBuffer[0];
42        return GetterImpl({x, x+1, x+2, x+3, x+4, x+5, x+6, x+7});
43    }
44}
45
46struct FooImpl2: IFoo<8>
47{
48    typealias Params = GetterImpl;
49
50    __init()
51    { }
52
53    Params bar()
54    {
55        float x = 2 * outputBuffer[0];
56        return GetterImpl({x+3, x+5, x+7, x+9, x+11, x+13, x+15, x+17});
57    }
58}
59
60IFoo<8> getFoo(uint id)
61{
62    if (id == 0)
63        return FooImpl1();
64    else
65        return FooImpl2();
66}
67
68float doThing(uint id)
69{
70    IFoo<8> foo = getFoo(id);
71    return foo.bar().get(0);
72}
73
74[shader("compute")]
75void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
76{
77    // CHECK: 0
78    outputBuffer[0] = doThing(0);
79	// CHECK: 3
80    outputBuffer[1] = doThing(1);
81}