summaryrefslogtreecommitdiff
path: root/tests/compute/dynamic-dispatch-14.slang
blob: 5d84a3ee69e47a010a45c2b06f51a8486cd7139a (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Test using interface typed shader parameters with associated types.

//TEST(compute):COMPARE_COMPUTE:-cpu
//TEST(compute):COMPARE_COMPUTE:-cuda

[anyValueSize(8)]
interface IAssoc
{
    int eval();
}

[anyValueSize(8)]
interface IInterface
{
    associatedtype TAssoc : IAssoc;
    TAssoc run(int input);
}

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer
RWStructuredBuffer<int> gOutputBuffer;

//TEST_INPUT:ubuffer(data=[rtti(MyImpl) witness(MyImpl, IInterface) 1 0], stride=4):name=gCb
StructuredBuffer<IInterface> gCb;

//TEST_INPUT:ubuffer(data=[rtti(MyImpl) witness(MyImpl, IInterface) 1 0], stride=4):name=gCb1
StructuredBuffer<IInterface> gCb1;

[numthreads(4, 1, 1)]
void computeMain(uint3       dispatchThreadID : SV_DispatchThreadID)
{
    let tid = dispatchThreadID.x;

    let inputVal : int = tid;
    IInterface v0 = gCb.Load(0);
    IInterface v1 = gCb1[0];
    let outputVal = v0.run(inputVal).eval() + v1.run(inputVal).eval();

    gOutputBuffer[tid] = outputVal;
}

// Specialize gCb1, but not gCb2
//TEST_INPUT: globalExistentialType MyImpl
//TEST_INPUT: globalExistentialType __Dynamic
// Type must be marked `public` to ensure it is visible in the generated DLL.
public struct MyImpl : IInterface
{
    int val;
    public struct TAssoc : IAssoc
    {
        int val;
        int eval() { return val; }
    }
    TAssoc run(int input)
    {
        TAssoc rs;
        rs.val = input + val;
        return rs;
    }
};

public struct MyImpl2 : IInterface
{
    int val;
    public struct TAssoc : IAssoc
    {
        int val;
        int eval() { return val; }
    }
    TAssoc run(int input)
    {
        TAssoc rs;
        rs.val = input - val;
        return rs;
    }
};