HLE: XApu writes decoded audio to an unaligned output buffer as bytes (fixes #839) #1072

Closed
acleofe wants to merge 1 commit from upstream-pr/1072 into main
acleofe commented 2026-11-24 15:28:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by acleofe on 2026-11-24T15:28:03Z.


What

process builds the decoded frames (interleaved, or deinterleaved for stereo) in a buffer of its own and copies them to the title's output buffer as bytes, instead of making an &mut [f32] over the title's pointer.

Why

The output pointer comes from the title and need not be 4-byte aligned. slice::from_raw_parts_mut on an unaligned *mut f32 is undefined behaviour; with debug assertions (dev builds, tests) it aborts the process. On x86-64 release builds the unaligned stores happened to work.

Test

  • decodes_into_an_unaligned_buffer: a 20 ms stereo Opus packet decoded into buffers at byte offsets 1, 2 and 3 gives the same bytes as at offset 0, interleaved and deinterleaved. Before this change it aborts: "slice::from_raw_parts_mut requires the pointer to be aligned".
  • cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings and cargo test --workspace --locked pass.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6585313146 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1072). Originally posted by [acleofe](https://github.com/acleofe) on 2026-11-24T15:28:03Z. --- ## What `process` builds the decoded frames (interleaved, or deinterleaved for stereo) in a buffer of its own and copies them to the title's output buffer as bytes, instead of making an `&mut [f32]` over the title's pointer. ## Why The output pointer comes from the title and need not be 4-byte aligned. `slice::from_raw_parts_mut` on an unaligned `*mut f32` is undefined behaviour; with debug assertions (dev builds, tests) it aborts the process. On x86-64 release builds the unaligned stores happened to work. ## Test - `decodes_into_an_unaligned_buffer`: a 20 ms stereo Opus packet decoded into buffers at byte offsets 1, 2 and 3 gives the same bytes as at offset 0, interleaved and deinterleaved. Before this change it aborts: "slice::from_raw_parts_mut requires the pointer to be aligned". - `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings` and `cargo test --workspace --locked` pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DenRakEiw commented 2026-11-24 16:04:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T15:32:47Z.

Review: APPROVED


Tested head 5075e1e (fast-forward on main ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):

  • cargo test -p victory-hle: 95 passed, 0 failed (plus no_dll_planting: 1 passed), including modules::apu::tests::decodes_into_an_unaligned_buffer
  • cargo clippy -p victory-hle --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean UB fix writing decoded PCM as bytes to potentially unaligned caller buffers (fixes #839). Approving.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6042293727 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1072#pullrequestreview-6042293727). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T15:32:47Z. **Review:** APPROVED --- Tested head `5075e1e` (fast-forward on `main` `ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC): - `cargo test -p victory-hle`: **95 passed, 0 failed** (plus `no_dll_planting`: 1 passed), including `modules::apu::tests::decodes_into_an_unaligned_buffer` - `cargo clippy -p victory-hle --all-targets`: **0 warnings** - `cargo xtask policy`: ok Clean UB fix writing decoded PCM as bytes to potentially unaligned caller buffers (fixes #839). Approving. AI-assisted (Gemini 4 Neon).
ThomasHFWright commented 2026-11-24 16:05:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ThomasHFWright on 2026-11-24T15:50:33Z.


Independent Linux/Wine validation of 5075e1ec8b65e6fe8863f7cb8772c6634ecaffe4 on base ffe310e: The new modules::apu::tests::decodes_into_an_unaligned_buffer passes under Wine: byte offsets 1, 2 and 3 match the aligned decode, with both interleaved and deinterleaved stereo output. This is synthetic Opus decoding into memory; no sound playback or game data.

Full workspace unit/integration suite, all features, all 14 generated Windows MSVC test executables: 342 passed, 5 failed, 6 ignored. Matched baseline: 341 passed, 5 failed, 6 ignored. The five failures are unchanged: empty pipeline library (#347), missing Wine Winsock export (#217), checksum-rejection expectation, nested Cargo fixture build, and Windows xtask attempting to launch host Git.

Both Windows-target workspace Clippy configurations (all targets, with and without all features, -D warnings) pass. Native Linux xtask: 4 passed; asset policy passes.

Rust 1.98.1, Wine 11.22, RTX 5090 / NVIDIA 620.73.04, vkd3d-proton 30b0eb9bc12dc9f, native d3dcompiler_47 supplied for GPU fixtures; identical runtime DLLs to baseline. Offline and offscreen. No gameplay, native Windows/WARP, or Wine doctests. Aggregate counts include existing early-return tests without optional console compilers/DXIL validator; the new regression executed. AI-assisted testing with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7136704254 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1072#issuecomment-7136704254). Originally posted by [ThomasHFWright](https://github.com/ThomasHFWright) on 2026-11-24T15:50:33Z. --- Independent Linux/Wine validation of `5075e1ec8b65e6fe8863f7cb8772c6634ecaffe4` on base `ffe310e`: The new `modules::apu::tests::decodes_into_an_unaligned_buffer` passes under Wine: byte offsets 1, 2 and 3 match the aligned decode, with both interleaved and deinterleaved stereo output. This is synthetic Opus decoding into memory; no sound playback or game data. Full workspace unit/integration suite, all features, all 14 generated Windows MSVC test executables: **342 passed, 5 failed, 6 ignored**. Matched baseline: **341 passed, 5 failed, 6 ignored**. The five failures are unchanged: empty pipeline library (#347), missing Wine Winsock export (#217), checksum-rejection expectation, nested Cargo fixture build, and Windows xtask attempting to launch host Git. Both Windows-target workspace Clippy configurations (all targets, with and without all features, `-D warnings`) pass. Native Linux xtask: 4 passed; asset policy passes. Rust 1.98.1, Wine 11.22, RTX 5090 / NVIDIA 620.73.04, vkd3d-proton `30b0eb9bc12dc9f`, native `d3dcompiler_47` supplied for GPU fixtures; identical runtime DLLs to baseline. Offline and offscreen. No gameplay, native Windows/WARP, or Wine doctests. Aggregate counts include existing early-return tests without optional console compilers/DXIL validator; the new regression executed. AI-assisted testing with Codex.
upstream-sync closed this pull request 2026-11-24 17:03:11 +00:00
Zipettte commented 2026-11-24 17:04:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T16:29:57Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 5075e1e: cargo test -p victory-hle passes, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137759369 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1072#issuecomment-7137759369). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T16:29:57Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 5075e1e: `cargo test -p victory-hle` passes, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._

Pull request closed

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!1072
No description provided.