yum-mirror/slang

Making it easier to work with shaders

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

kaizhangNVImplement if(let ...) syntax (#3673) (#3958)d3fd7470e

master
1.1 KiB53 linesraw
1//TEST:SIMPLE(filecheck=CHECK): -target glsl -stage compute -entry computeMain
2//TEST:SIMPLE(filecheck=CHECK): -target hlsl -stage compute -entry computeMain
3//TEST:SIMPLE(filecheck=CHECK): -target cuda -stage compute -entry computeMain
4//TEST:SIMPLE(filecheck=CHECK): -target cpp -stage compute -entry computeMain
5
6//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
7RWStructuredBuffer<int> outputBuffer;
8
9
10interface IFoo
11{
12    int foo(int a);
13}
14
15struct MyImpl : IFoo
16{
17    int foo(int a) { return a; }
18}
19
20struct MyImpl1 : IFoo
21{
22    int foo(int a) { return a; }
23}
24
25int test(IFoo foo, int idx)
26{
27    int val = 0;
28    if (let a = foo as MyImpl)
29    {
30        val = a.foo(idx);
31    }
32    // CHECK: error 30015: undefined identifier 'a'.
33    else if(a == none)
34    {
35        val = -1;
36    }
37    else
38    {
39        // CHECK: error 30015: undefined identifier 'a'.
40        if (a == none)
41        {
42            val = -1;
43        }
44    }
45    return (val);
46}
47
48[numthreads(4, 1, 1)]
49void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
50{
51    MyImpl1 impl;
52    outputBuffer[dispatchThreadID.x] = test(impl, dispatchThreadID.x);
53}