yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskamsvc style bitfield packing (#7963)66301ab90

master
1.1 KiB43 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -output-using-type -compile-arg -msvc-style-bitfield-packing
2
3// MSVC starts new backing fields when type sizes change
4// CHECK:      4
5// CHECK-NEXT: 12
6// CHECK-NEXT: 8
7// CHECK-NEXT: 16
8
9//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
10RWStructuredBuffer<uint> outputBuffer;
11
12struct S {
13    int foo : 8;
14    int bar : 24;
15};
16
17// MSVC will use separate backing fields for different sized types
18struct T {
19    int64_t foo : 33;  // Uses int64_t backing
20    int bar : 24;      // Uses separate int backing due to type size change
21};
22
23// This still takes two ints to store all the bits
24struct P {
25    int foo : 24;
26    int bar : 24;
27};
28
29// MSVC will use separate backing fields due to type size difference
30struct Q {
31    int8_t foo : 1;    // Uses int8_t backing
32    int64_t bar : 63;  // Uses separate int64_t backing
33};
34
35[numthreads(1, 1, 1)]
36void computeMain()
37{
38    outputBuffer[0] = sizeof(S);
39    outputBuffer[1] = sizeof(T);
40    outputBuffer[2] = sizeof(P);
41    outputBuffer[3] = sizeof(Q);
42}
43