summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/ifunc/ifunc.slang
blob: 7571ca06dd0d239b3cd9db19b2a0541c3b76f16d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-dx12 -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -output-using-type

struct Functor : IFunc<int, int, bool>
{
    int operator()(int p, bool t)
    {
        return p + 1;
    }
}

struct MutatingFunctor : IMutatingFunc<int, int, bool>
{
    int data = 0;
    [mutating]
    int operator()(int p, bool t)
    {
        data++;
        return p + 1;
    }
}

int apply(IMutatingFunc<int, int, bool> f, int p)
{
    return f(p, true);
}

//TEST_INPUT:ubuffer(data=[0 3 2 2], stride=4):out,name=outputBuffer
RWStructuredBuffer<uint> outputBuffer;

[numthreads(1, 1, 1)]
void computeMain(uint tid: SV_DispatchThreadID)
{
    // CHECK: 2
    outputBuffer[0] = apply(MutatingFunctor(), 1);
    // CHECK: 3
    outputBuffer[1] = apply(Functor(), 2);
}