yum-mirror/slang

Making it easier to work with shaders

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

Yong HeInitial support for immutable lambda expressions. (#6914)7f1df9d0b

master
947 B47 linesraw
1
2//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type
3//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -output-using-type
4
5//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride=4)
6RWStructuredBuffer<float> outputBuffer;
7
8struct Matrix
9{
10    float data[16];
11
12    [mutating]
13    void map(IFunc<float, float> f)
14    {
15        for (int i = 0; i < 16; ++i)
16        {
17            data[i] = f(data[i]);
18        }
19    }
20}
21
22struct Applier
23{
24    float c;
25    void apply(inout Matrix m)
26    {
27        m.map((float x) =>
28        {
29            if (x > 2.5)
30                return x * c;
31            else
32                return x + c;
33        });
34    }
35}
36
37[numthreads(1,1,1)]
38void computeMain()
39{
40    Matrix m = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
41    Applier applier = { 1.5 };
42    applier.apply(m);
43    outputBuffer[0] = m.data[1];
44    // CHECK: 3.5
45    outputBuffer[1] = m.data[3];
46    // CHECK: 6.0
47}