forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpack-any-value-8bit.slang
68 lines (56 loc) · 1.68 KB
/
pack-any-value-8bit.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
// Test anyvalue packing of 8bit types.
//TEST_DISABLED(compute):COMPARE_COMPUTE_EX:-slang -compute -cuda -output-using-type
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -render-feature int16
//TEST_DISABLED(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_2 -use-dxil -output-using-type
[anyValueSize(20)]
interface IInterface
{
float run();
}
struct Val : IInterface
{
int8_t v0;
uint8_t v1;
float f0;
uint16_t v2;
uint8_t v3;
uint32_t v4;
uint8_t v5;
float run()
{
return v0 + v1 + f0 + v2 + v3 + v4 + v5;
}
};
struct UserDefinedPackedType
{
uint values[5];
};
//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=gOutputBuffer
RWStructuredBuffer<float> gOutputBuffer;
//TEST_INPUT: type_conformance Val:IInterface = 11
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
UserDefinedPackedType objStorage;
objStorage.values[0] = 0xA5A50201;
objStorage.values[1] = asuint(3.0f);
objStorage.values[2] = 4u|(0xA505u<<16u);
objStorage.values[3] = 6;
objStorage.values[4] = 7;
IInterface dynamicObj = createDynamicObject<IInterface, UserDefinedPackedType>(11, objStorage);
float result = dynamicObj.run();
gOutputBuffer[0] = result;
Val v;
v.v0 = 1;
v.v1 = 2;
v.f0 = 3;
v.v2 = 4;
v.v3 = 5;
v.v4 = 6;
v.v5 = 7;
IInterface dynamicObj1 = createDynamicObject<IInterface, Val>(11, v);;
gOutputBuffer[1] = dynamicObj1.run();
var packed = reinterpret<UserDefinedPackedType, Val>(v);
var unpacked = reinterpret<Val, UserDefinedPackedType>(packed);
gOutputBuffer[2] = unpacked.run();
}