forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic-dispatch-14.slang
76 lines (63 loc) · 1.73 KB
/
dynamic-dispatch-14.slang
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
76
// Test using interface typed shader parameters with associated types.
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0 -use-dxil
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx11 -profile sm_5_0
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -vk -profile glsl_440
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu
[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: set gCb = new StructuredBuffer<IInterface>{new MyImpl{1}};
RWStructuredBuffer<IInterface> gCb;
//TEST_INPUT: set gCb1 = new StructuredBuffer<IInterface>{new MyImpl{1}}
RWStructuredBuffer<IInterface> gCb1;
[numthreads(4, 1, 1)]
void computeMain(int3 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;
}
// Type must be marked `public` to ensure it is visible in the generated DLL.
export struct MyImpl : IInterface
{
int val;
export struct TAssoc : IAssoc
{
int val;
int eval() { return val; }
}
TAssoc run(int input)
{
TAssoc rs;
rs.val = input + val;
return rs;
}
};
export struct MyImpl2 : IInterface
{
int val;
export struct TAssoc : IAssoc
{
int val;
int eval() { return val; }
}
TAssoc run(int input)
{
TAssoc rs;
rs.val = input - val;
return rs;
}
};