Game: guarantee 8-byte alignment for pipeline stream subobjects and input elements #2531

Open
reeledMarek wants to merge 1 commit from upstream-pr/2533 into main
reeledMarek commented 2026-11-25 15:23:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T15:23:44Z.


Problem

victory_game::pipelines::Stream backed its D3D12 pipeline state subobject stream with Vec<u8> and its D3D12_INPUT_ELEMENT_DESC array with Vec<[u8; 32]>. Both types have alignment 1, whereas D3D12 requires 8-byte alignment for subobject streams and input element descriptors, and victory-gpu/src/pipeline.rs casts stream offsets directly to &Bytecode (alignment 8).

Fix

  • Introduce #[repr(C, align(8))] struct AlignedBytes<const N: usize>([u8; N]) and store bytes: Box<AlignedBytes<0x2b0>> and _elements: Vec<AlignedBytes<32>> in Stream.

Testing

  • Added alignment assertions in a_record_becomes_the_engines_creation_stream (crates/victory-game/src/pipelines.rs).
  • Verified cargo test -p victory-game --locked and Windows cross-clippy (-D warnings).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6607870001 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2533). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T15:23:44Z. --- ### Problem `victory_game::pipelines::Stream` backed its D3D12 pipeline state subobject stream with `Vec<u8>` and its `D3D12_INPUT_ELEMENT_DESC` array with `Vec<[u8; 32]>`. Both types have alignment 1, whereas D3D12 requires 8-byte alignment for subobject streams and input element descriptors, and `victory-gpu/src/pipeline.rs` casts stream offsets directly to `&Bytecode` (alignment 8). ### Fix - Introduce `#[repr(C, align(8))] struct AlignedBytes<const N: usize>([u8; N])` and store `bytes: Box<AlignedBytes<0x2b0>>` and `_elements: Vec<AlignedBytes<32>>` in `Stream`. ### Testing - Added alignment assertions in `a_record_becomes_the_engines_creation_stream` (`crates/victory-game/src/pipelines.rs`). - Verified `cargo test -p victory-game --locked` and Windows cross-clippy (`-D warnings`).
Marvisak commented 2026-11-25 16:09:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:53:56Z.


Automated triage for the maintainers.

Recommended for a look. pipelines::stream (crates/victory-game/src/pipelines.rs) now stores the 0x2b0-byte creation stream and the input element array in an 8-byte-aligned wrapper instead of Vec<u8> / Vec<[u8; 32]>. I checked the consumer: apps/victory/src/prebuild.rs hands stream.bytes() to victory-gpu, whose pipeline.rs takes &*ptr.cast::<Bytecode>() at stream offsets, so the alignment was only guaranteed by the allocator in practice, not by the types; the change is mechanical otherwise. CI (clippy + tests on Windows): passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167410743 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2533#issuecomment-7167410743). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:53:56Z. --- <!-- victory-triage v1 head=41ab323a049915a92557517b3aba6228820c3070 verdict=merge-candidate at=2026-11-25T15:53:48Z --> Automated triage for the maintainers. Recommended for a look. `pipelines::stream` (crates/victory-game/src/pipelines.rs) now stores the 0x2b0-byte creation stream and the input element array in an 8-byte-aligned wrapper instead of `Vec<u8>` / `Vec<[u8; 32]>`. I checked the consumer: apps/victory/src/prebuild.rs hands `stream.bytes()` to victory-gpu, whose pipeline.rs takes `&*ptr.cast::<Bytecode>()` at stream offsets, so the alignment was only guaranteed by the allocator in practice, not by the types; the change is mechanical otherwise. CI (clippy + tests on Windows): passing. --- _Generated by [Claude Code](https://claude.ai/code)_
futurepro62 commented 2026-11-26 02:07:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T01:37:34Z.


Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 41ab323 (on its base 940d32f).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 696 passed, 0 failed, 10 ignored.
  • No new #[test] functions in the diff.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7179961266 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2533#issuecomment-7179961266). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T01:37:34Z. --- Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `41ab323` (on its base `940d32f`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **696 passed, 0 failed, 10 ignored**. - No new `#[test]` functions in the diff. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
fuzeofficlal commented 2026-11-26 03:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:26:53Z.

Review: COMMENTED


Reviewed and verified against main (63bcca43) on Windows 11 — real alignment-UB fix and ready to merge:

  • Downstream crates/victory-gpu/src/pipeline/host.rs:191-194 calls slice::from_raw_parts::<D3D12_INPUT_ELEMENT_DESC>(...) (requires 8-byte alignment) on pointers backed by Stream._elements (Vec<[u8; 32]>, align 1) and Stream.bytes (Vec<u8>, align 1). #[repr(C, align(8))] struct AlignedBytes<const N: usize> guarantees 8-byte alignment for both without changing Stream::bytes().

Local verification:

  • cargo test --locked -p victory-game: 15/15 passed
  • cargo clippy --locked -p victory-game --tests -- -D warnings (default & --all-features) + cargo xtask policy (191 files ok): 0 warnings
<!-- greyfinch-sync:Marvisak/VIctory:review:6067747720 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2533#pullrequestreview-6067747720). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T02:26:53Z. **Review:** COMMENTED --- Reviewed and verified against `main` (`63bcca43`) on Windows 11 — real alignment-UB fix and ready to merge: - Downstream `crates/victory-gpu/src/pipeline/host.rs:191-194` calls `slice::from_raw_parts::<D3D12_INPUT_ELEMENT_DESC>(...)` (requires 8-byte alignment) on pointers backed by `Stream._elements` (`Vec<[u8; 32]>`, align 1) and `Stream.bytes` (`Vec<u8>`, align 1). `#[repr(C, align(8))] struct AlignedBytes<const N: usize>` guarantees 8-byte alignment for both without changing `Stream::bytes()`. **Local verification**: - `cargo test --locked -p victory-game`: **15/15 passed** - `cargo clippy --locked -p victory-game --tests -- -D warnings` (default & `--all-features`) + `cargo xtask policy` (`191 files ok`): 0 warnings
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2533:upstream-pr/2533'
git switch 'upstream-pr/2533'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2533'
git switch 'upstream-pr/2533'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2533'
git switch 'upstream-pr/2533'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2533'
git switch 'main'
git merge --squash 'upstream-pr/2533'
git switch 'main'
git merge --ff-only 'upstream-pr/2533'
git switch 'main'
git merge 'upstream-pr/2533'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2531
No description provided.