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
847 B30 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -output-using-type -compile-arg -msvc-style-bitfield-packing
2
3// MSVC packing with zero-width bitfields
4// CHECK:      123
5// CHECK-NEXT: 4567
6// CHECK-NEXT: 1
7// CHECK-NEXT: 0
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;      // First backing field
14    int breaker : 0;  // Forces new backing field
15    int bar : 24;     // Second backing field
16};
17
18[numthreads(1, 1, 1)]
19void computeMain()
20{
21    S s;
22    s.foo = 123;
23    s.bar = 4567;
24    s.breaker = 9999; // Zero-width field, assignment has no effect
25    outputBuffer[0] = s.foo;
26    outputBuffer[1] = s.bar;
27    outputBuffer[2] = sizeof(S) == sizeof(int) * 2; // Two backing fields
28    outputBuffer[3] = s.breaker; // Always returns 0
29}
30