HLE: write decoded Opus samples through unaligned output buffers #1214

Merged
divyeshganta merged 1 commit from upstream-pr/1214 into main 2026-11-25 00:17:24 +00:00
divyeshganta commented 2026-11-24 16:26:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by divyeshganta on 2026-11-24T16:26:31Z.


Fixes #839.

XApuEnqueueCommand receives a packed process command whose output is a byte pointer with no 4-byte alignment guarantee. The decoder now writes sample bytes through a u8 slice, preserving interleaved and deinterleaved layouts without constructing a potentially misaligned &mut [f32]. Zero-frame requests skip slice construction.

Also reject invalid channel counts before constructing the Opus decoder, and free the connection allocation if optional result-event creation fails.

Patch by AndyLatimer, carried from commit 13df0dad39c78af7c6479116cc185ab22ce44f05.

The branch adds synthetic tests for unaligned output, both stereo layouts, zero frames, invalid channels, and bit-for-bit parity. Independent Windows 10/11 reports on the source branch say the focused tests and cargo test -p victory-hle passed; Clippy with -D warnings was clean. I attempted cargo test -p victory-hle --locked locally on this PR head after installing Rust 1.98.1, but compilation stopped before tests ran because link.exe (the MSVC linker) is unavailable in this environment. GitHub shows the workflow awaiting maintainer approval, so this PR has no check result yet. No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6586480447 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1214). Originally posted by [divyeshganta](https://github.com/divyeshganta) on 2026-11-24T16:26:31Z. --- Fixes #839. `XApuEnqueueCommand` receives a packed process command whose output is a byte pointer with no 4-byte alignment guarantee. The decoder now writes sample bytes through a `u8` slice, preserving interleaved and deinterleaved layouts without constructing a potentially misaligned `&mut [f32]`. Zero-frame requests skip slice construction. Also reject invalid channel counts before constructing the Opus decoder, and free the connection allocation if optional result-event creation fails. Patch by AndyLatimer, carried from commit `13df0dad39c78af7c6479116cc185ab22ce44f05`. The branch adds synthetic tests for unaligned output, both stereo layouts, zero frames, invalid channels, and bit-for-bit parity. Independent Windows 10/11 reports on the source branch say the focused tests and `cargo test -p victory-hle` passed; Clippy with `-D warnings` was clean. I attempted `cargo test -p victory-hle --locked` locally on this PR head after installing Rust 1.98.1, but compilation stopped before tests ran because `link.exe` (the MSVC linker) is unavailable in this environment. GitHub shows the workflow awaiting maintainer approval, so this PR has no check result yet. No game data used.
mercuryVM commented 2026-11-24 18:04:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T17:54:31Z.

Review: APPROVED


Tested 643fc6df on Windows 11, RTX 5070, MSVC:

  • cargo test -p victory-hle passes on the head (95 passed), including the unaligned interleaved and deinterleaved decode test.
  • Merged into our fork: workspace tests, shader tests and clippy -D warnings (default and all features) are all clean.

The changes are right:

  • Writing to_le_bytes chunks through a u8 slice removes the misaligned &mut [f32].
  • bytes > 0 skips building a slice from a possibly dangling pointer.
  • The channel check now runs before decoding.
  • Freeing memory when CreateEventW fails closes a leak.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6044555990 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1214#pullrequestreview-6044555990). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T17:54:31Z. **Review:** APPROVED --- Tested 643fc6df on Windows 11, RTX 5070, MSVC: - `cargo test -p victory-hle` passes on the head (95 passed), including the unaligned interleaved and deinterleaved decode test. - Merged into our fork: workspace tests, shader tests and `clippy -D warnings` (default and all features) are all clean. The changes are right: - Writing `to_le_bytes` chunks through a `u8` slice removes the misaligned `&mut [f32]`. - `bytes > 0` skips building a slice from a possibly dangling pointer. - The channel check now runs before decoding. - Freeing `memory` when `CreateEventW` fails closes a leak. AI-assisted (Claude Code).
Zipettte commented 2026-11-24 18:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T17:59:56Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 643fc6d: 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:7140009099 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1214#issuecomment-7140009099). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T17:59:56Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 643fc6d: `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)._
upstream-sync closed this pull request 2026-11-25 01:05:57 +00:00
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!1214
No description provided.