forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface-param.slang
45 lines (36 loc) · 1 KB
/
interface-param.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
// interface-param.slang
// Test basic use of an interface as an existential type
// for a value parameter, instead of just as a constraint
// on a generic type parameter.
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj
interface IHelper
{
int getVal();
}
int doTheThing(IHelper helper)
{
return helper.getVal();
}
struct HelperImpl : IHelper
{
int storedVal;
int getVal() { return storedVal; }
}
int test(int val)
{
HelperImpl helperImpl = { val };
return doTheThing(helperImpl);
}
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer
RWStructuredBuffer<int> gOutputBuffer;
[numthreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
int tid = dispatchThreadID.x;
int inputVal = tid;
int outputVal = test(inputVal);
gOutputBuffer[tid] = outputVal;
}