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
837 B36 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -compile-arg -msvc-style-bitfield-packing
2
3// MSVC style packs from MSB to LSB
4// struct S { uint a:4; uint b:8; uint c:4; uint d:16; }
5// Memory layout (32-bit):
6// bits 28-31: a (0x5)
7// bits 20-27: b (0xAB) 
8// bits 16-19: c (0xC)
9// bits 0-15:  d (0xDEF0)
10// Expected: 0x5ABCDEF0
11
12// CHECK: 5ABCDEF0
13
14//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
15RWStructuredBuffer<uint> outputBuffer;
16
17struct S {
18    uint a : 4;   // bits 28-31 (MSB side)
19    uint b : 8;   // bits 20-27
20    uint c : 4;   // bits 16-19
21    uint d : 16;  // bits 0-15
22};
23
24[numthreads(1, 1, 1)]
25void computeMain()
26{
27    S s;
28    s.a = 0x5;
29    s.b = 0xAB;
30    s.c = 0xC;
31    s.d = 0xDEF0;
32
33    // Write the struct to memory and read it back as uint
34    outputBuffer[0] = *((uint*)&s);
35}
36