forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic-dispatch-16.slang
58 lines (50 loc) · 1.56 KB
/
dynamic-dispatch-16.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
// Test packing a user provided value and typeID into an existential value.
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -vk -output-using-type
//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
[anyValueSize(16)]
interface IInterface
{
float run();
}
struct UserDefinedPackedType
{
float3 val;
uint flags;
};
//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer
RWStructuredBuffer<float> gOutputBuffer;
//TEST_INPUT: set gObj = new StructuredBuffer<UserDefinedPackedType>[new UserDefinedPackedType{[1.0, 2.0, 3.0], 3}, new UserDefinedPackedType{[2.0, 3.0, 4.0], 4}];
RWStructuredBuffer<UserDefinedPackedType> gObj;
//TEST_INPUT: type_conformance FloatVal:IInterface = 3
//TEST_INPUT: type_conformance Float4Val:IInterface = 4
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
float result = 0.0;
for (int i = 0; i < 2; i++)
{
var rawObj = gObj.Load(i);
IInterface dynamicObj = createDynamicObject<IInterface, UserDefinedPackedType>(rawObj.flags, rawObj);
result += dynamicObj.run();
}
gOutputBuffer[0] = result;
}
struct FloatVal : IInterface
{
float val;
float run()
{
return val;
}
};
interface ISomething{void g();}
struct Float4Struct : ISomething { float4 val; void g() {} }
struct Float4Val : IInterface
{
Float4Struct val;
float run()
{
return val.val.x + val.val.y;
}
};