diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2025-07-31 15:23:13 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-31 07:23:13 +0000 |
| commit | 66301ab9068c5705e5a2bcbf2eaadfb28e8bb084 (patch) | |
| tree | 3682e0224df6706bcf70f58e37873c1d078c785c /tests/language-feature/bitfield/msvc-zero-width.slang | |
| parent | db59c22cfb774e984a207a074f13870b78ec0071 (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/msvc-zero-width.slang')
| -rw-r--r-- | tests/language-feature/bitfield/msvc-zero-width.slang | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/language-feature/bitfield/msvc-zero-width.slang b/tests/language-feature/bitfield/msvc-zero-width.slang new file mode 100644 index 000000000..3363ef066 --- /dev/null +++ b/tests/language-feature/bitfield/msvc-zero-width.slang @@ -0,0 +1,30 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -output-using-type -compile-arg -msvc-style-bitfield-packing + +// MSVC packing with zero-width bitfields +// CHECK: 123 +// CHECK-NEXT: 4567 +// CHECK-NEXT: 1 +// CHECK-NEXT: 0 + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<uint> outputBuffer; + +struct S { + int foo : 8; // First backing field + int breaker : 0; // Forces new backing field + int bar : 24; // Second backing field +}; + +[numthreads(1, 1, 1)] +void computeMain() +{ + S s; + s.foo = 123; + s.bar = 4567; + s.breaker = 9999; // Zero-width field, assignment has no effect + outputBuffer[0] = s.foo; + outputBuffer[1] = s.bar; + outputBuffer[2] = sizeof(S) == sizeof(int) * 2; // Two backing fields + outputBuffer[3] = s.breaker; // Always returns 0 +} + |
