yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
66301ab90
master
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -output-using-type -compile-arg -msvc-style-bitfield-packing 2 3// MSVC packing with mixed type sizes 4// CHECK: 15 5// CHECK-NEXT: 255 6// CHECK-NEXT: 4095 7// CHECK-NEXT: 8 8 9//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 10RWStructuredBuffer<uint> outputBuffer; 11 12struct MixedTypes { 13 uint8_t a : 4; // Uses uint8_t backing, bits 7-4 14 uint8_t b : 4; // Same backing, bits 3-0 15 uint16_t c : 8; // New uint16_t backing due to type change, bits 15-8 16 uint16_t d : 8; // Same backing, bits 7-0 17 uint32_t e : 12; // New uint32_t backing due to type change, bits 31-20 18 uint32_t f : 12; // Same backing, bits 19-8 19 uint32_t g : 8; // Same backing, bits 7-0 20}; 21 22[numthreads(1, 1, 1)] 23void computeMain() 24{ 25 MixedTypes m; 26 m.a = 15; // 0xF 27 m.b = 15; // 0xF 28 m.c = 255; // 0xFF 29 m.d = 255; // 0xFF 30 m.e = 4095; // 0xFFF 31 m.f = 4095; // 0xFFF 32 m.g = 255; // 0xFF 33 34 outputBuffer[0] = m.a; 35 outputBuffer[1] = m.c; 36 outputBuffer[2] = m.e; 37 // Verify struct size includes all three backing fields 38 outputBuffer[3] = sizeof(MixedTypes); 39} 40