summaryrefslogtreecommitdiff
path: root/tests/language-feature/bitfield/repr.slang
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2025-07-31 15:23:13 +0800
committerGitHub <noreply@github.com>2025-07-31 07:23:13 +0000
commit66301ab9068c5705e5a2bcbf2eaadfb28e8bb084 (patch)
tree3682e0224df6706bcf70f58e37873c1d078c785c /tests/language-feature/bitfield/repr.slang
parentdb59c22cfb774e984a207a074f13870b78ec0071 (diff)
msvc style bitfield packing (#7963)
Closes https://github.com/shader-slang/slang/issues/3646 New tests rather than just adding another TEST line to existing tests so that we get the msvc- prefix in the output of slang-test
Diffstat (limited to 'tests/language-feature/bitfield/repr.slang')
-rw-r--r--tests/language-feature/bitfield/repr.slang36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/language-feature/bitfield/repr.slang b/tests/language-feature/bitfield/repr.slang
new file mode 100644
index 000000000..a199b23ff
--- /dev/null
+++ b/tests/language-feature/bitfield/repr.slang
@@ -0,0 +1,36 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu
+
+// Default GCC/Clang style packs from LSB to MSB
+// struct S { uint a:4; uint b:8; uint c:4; uint d:16; }
+// Memory layout (32-bit):
+// bits 0-3: a (0x5)
+// bits 4-11: b (0xAB)
+// bits 12-15: c (0xC)
+// bits 16-31: d (0xDEF0)
+// Expected: 0xDEF0CAB5
+
+// CHECK: DEF0CAB5
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<uint> outputBuffer;
+
+struct S {
+ uint a : 4; // bits 0-3
+ uint b : 8; // bits 4-11
+ uint c : 4; // bits 12-15
+ uint d : 16; // bits 16-31
+};
+
+[numthreads(1, 1, 1)]
+void computeMain()
+{
+ S s;
+ s.a = 0x5;
+ s.b = 0xAB;
+ s.c = 0xC;
+ s.d = 0xDEF0;
+
+ // Write the struct to memory and read it back as uint
+ outputBuffer[0] = *((uint*)&s);
+}
+