forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic-dispatch-18.slang
53 lines (43 loc) · 1.31 KB
/
dynamic-dispatch-18.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
// Test using generic interface methods with dynamic dispatch.
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0 -use-dxil -output-using-type
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx11 -profile sm_5_0 -output-using-type
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type
[anyValueSize(12)]
interface IReturnsZero
{
float get();
}
[anyValueSize(16)]
interface IInterface
{
associatedtype Getter : IReturnsZero;
Getter createGetter();
}
struct Impl : IInterface
{
int data;
struct Getter : IReturnsZero
{
bool data;
float get() { if (data) return 0.0; else return 1.0;}
}
Getter createGetter() { Getter g; g.data = true; return g; }
};
float test(IReturnsZero r)
{
return r.get();
}
//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer
RWStructuredBuffer<float> gOutputBuffer;
//TEST_INPUT: set gObj = new StructuredBuffer<IInterface>[new Impl{1}];
RWStructuredBuffer<IInterface> gObj;
//TEST_INPUT: type_conformance Impl:IInterface = 3
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
float result = 0.0;
let i = createDynamicObject<IInterface, int>(3, 0);
IReturnsZero iobj = i.createGetter();
result = test(iobj);
gOutputBuffer[0] = result;
}