formats,hle(audio): optimize XMA VLC decoding, chain XMA overlap buffers, and add XApu rate conversion #91

Merged
Androtim merged 1 commit from upstream-pr/91 into main 2026-11-29 09:06:24 +00:00
Androtim commented 2026-11-29 08:47:07 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T08:47:07Z.


Summary

Adapted from upstream VIctory-NVIDIA commits 0a0ff43 and 462cd10 (GPL-3.0), extracted cleanly off origin/main (7fe6886) with zero overlap against open PRs:

  • Fast XMA VLC decoding & frame copying (crates/victory-formats/src/xma.rs): Table-drives VLC decoding, bulk-copies decoded frames, and caches quantization powers.
  • XMA overlap-buffer context chaining (crates/victory-formats/src/xma.rs, crates/victory-hle/src/modules/{apu.rs,audio.rs}): Adds xma::Decoder::carry() / resume() and persists/restores overlap state in context overlap buffers inside the APU heap block so chained XMA contexts avoid seam clicks.
  • XApu sample-rate & pitch conversion (crates/victory-hle/src/modules/{apu.rs,audio.rs}): Implements DecodeConvertOpus and ConvertPCM with clamped pitch (1/8 to 8), rate-limited ramping, 256/480/512/960/1024 output framing, Flush draining, and decoder-only reset.

Verification

  • cargo xtask policy: asset policy: 303 files ok
  • cargo test -p victory-formats --lib --locked -- xma::: 15 passed; 0 failed; 4 ignored (pre-existing benchmarks/external-data tests), including vlc_tables_match_prefix_binary_search and a_carried_stream_goes_on_in_another_decoder
  • cargo test -p victory-hle --lib --locked -- apu:: audio:: xaudio2::: 15 passed; 0 failed, including pcm_converts_in_whole_outputs, decoded_opus_converts_at_its_pitch, consecutive_contexts_go_on_through_the_overlap_buffer, and decodes_opus_as_the_title_drives_it
  • cargo clippy --workspace --all-targets -- -D warnings & --features diagnostics: 0 warnings
  • Plain --release + objdump -p: standard Windows system DLLs only
  • Live 75s Series S GPU verification (pr92-xma-xapu-audio): 11/11 gates PASS
    • Median FPS: 12.6 fps (79.4 ms, vs 8.9 fps baseline, +3.70 fps)
    • Max VRAM: 5762 MB / 6956 MB budget (over=0 MB, -102 MB vs baseline)
    • Waiting textures: 1712 (vs 7121 baseline) | mapped() stall rate: 7.16 ms/s
    • Shader translation: untranslated=1 | Crashes / host texture errors: 0 / 0
    • Visually inspected 24 captured frames (frame-8679.png, frame-8719.png, median luma 103.7, edge energy 7.12, 0.0% near-black/magenta).
<!-- greyfinch-sync:Androtim/MiniVI:issue:5549135870 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/91). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-29T08:47:07Z. --- ## Summary Adapted from upstream `VIctory-NVIDIA` commits `0a0ff43` and `462cd10` (GPL-3.0), extracted cleanly off `origin/main` (`7fe6886`) with zero overlap against open PRs: - **Fast XMA VLC decoding & frame copying (`crates/victory-formats/src/xma.rs`):** Table-drives VLC decoding, bulk-copies decoded frames, and caches quantization powers. - **XMA overlap-buffer context chaining (`crates/victory-formats/src/xma.rs`, `crates/victory-hle/src/modules/{apu.rs,audio.rs}`):** Adds `xma::Decoder::carry()` / `resume()` and persists/restores overlap state in context overlap buffers inside the APU heap block so chained XMA contexts avoid seam clicks. - **XApu sample-rate & pitch conversion (`crates/victory-hle/src/modules/{apu.rs,audio.rs}`):** Implements `DecodeConvertOpus` and `ConvertPCM` with clamped pitch (`1/8` to `8`), rate-limited ramping, `256`/`480`/`512`/`960`/`1024` output framing, `Flush` draining, and decoder-only reset. ## Verification - `cargo xtask policy`: `asset policy: 303 files ok` - `cargo test -p victory-formats --lib --locked -- xma::`: **15 passed; 0 failed; 4 ignored** (pre-existing benchmarks/external-data tests), including `vlc_tables_match_prefix_binary_search` and `a_carried_stream_goes_on_in_another_decoder` - `cargo test -p victory-hle --lib --locked -- apu:: audio:: xaudio2::`: **15 passed; 0 failed**, including `pcm_converts_in_whole_outputs`, `decoded_opus_converts_at_its_pitch`, `consecutive_contexts_go_on_through_the_overlap_buffer`, and `decodes_opus_as_the_title_drives_it` - `cargo clippy --workspace --all-targets -- -D warnings` & `--features diagnostics`: **0 warnings** - Plain `--release` + `objdump -p`: standard Windows system DLLs only - Live 75s Series S GPU verification (`pr92-xma-xapu-audio`): **11/11 gates PASS** - Median FPS: `12.6 fps` (`79.4 ms`, vs `8.9 fps` baseline, `+3.70 fps`) - Max VRAM: `5762 MB` / `6956 MB` budget (`over=0 MB`, `-102 MB` vs baseline) - Waiting textures: `1712` (vs `7121` baseline) | `mapped()` stall rate: `7.16 ms/s` - Shader translation: `untranslated=1` | Crashes / host texture errors: `0` / `0` - Visually inspected 24 captured frames (`frame-8679.png`, `frame-8719.png`, median luma `103.7`, edge energy `7.12`, `0.0%` near-black/magenta).
Androtim commented 2026-11-29 09:04:23 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T09:04:23Z.


Automated triage for the maintainers (not an approval).

Verdict: merge-candidate · CI (check): passing

Summary

Clean, well-scoped audio optimization and feature PR across victory-formats and victory-hle with passing CI and thorough unit tests.

Code Review

  • crates/victory-formats/src/xma.rs
    • read_frame: bulk byte-copy path preserves packet-boundary and unaligned bit-shift behavior (avail_bytes == 0 falls back to cursor.bits(8), and at..at + n + 1 stays within the current packet when shift != 0).
    • Bits::peek32 / peek32_tail and two-level Vlc (VLC_PRIMARY_BITS = 11): bit-exact with the previous prefix binary search; vlc_tables_match_prefix_binary_search verifies every code boundary across all 7 tables.
    • quant_table(): out-of-range exponents (including < QUANT_MIN, which wrap to a large usize) safely fall back to 10f32.powf(...).
    • Decoder::carry() / Decoder::resume(): validates sample count and power-of-two block_len in MIN_SUBFRAME..=FRAME_SAMPLES. (Minor nit: resume calls self.reset() before validating block_len on all channels, which is harmless for the audio.rs caller since it discards the fresh decoder on false.)
  • crates/victory-hle/src/modules/audio.rs
    • save_carry / resume_carry: bounds-checked via heap_bytes(address, carry_bytes(channels)), tagged with VXO1 + channel count, and cleared on first resume so overlap state is consumed once.
  • crates/victory-hle/src/modules/apu.rs
    • XApuConnect / XApuEnqueueCommand / Stream::convert / Converter: properly validates frames_per_output (256 | 480 | 512 | 960 | 1024), clamps pitch to 0.125..=8.0 (handling non-finite start_pitch, target_pitch, and pitch_ramp safely), and bounds-checks both interleaved and deinterleaved unaligned writes against output_length.
    • (Minor note: for DECODE_CONVERT_OPUS, a FLUSH command with input_length == 0 still passes an empty slice to OpusDecoder::decode before draining buffered output; fine if titles only flush with valid packets or opus_pure accepts empty packets.)

Verdict

merge-candidate — CPU-only audio decoding and HLE changes with passing CI, solid bounds/edge-case handling, and good unit test coverage; no local GPU test required.


Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7253517496 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/91#issuecomment-7253517496). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-29T09:04:23Z. --- <!-- minivi-triage v1 head=59badc9a46ee00c21cda9463eeb4ed42ba6fd2ca verdict=merge-candidate ci=passing at=2026-11-29T09:04:55Z --> Automated triage for the maintainers (not an approval). **Verdict:** `merge-candidate` · **CI (`check`):** `passing` ### Summary Clean, well-scoped audio optimization and feature PR across `victory-formats` and `victory-hle` with passing CI and thorough unit tests. ### Code Review - **`crates/victory-formats/src/xma.rs`** - `read_frame`: bulk byte-copy path preserves packet-boundary and unaligned bit-shift behavior (`avail_bytes == 0` falls back to `cursor.bits(8)`, and `at..at + n + 1` stays within the current packet when `shift != 0`). - `Bits::peek32` / `peek32_tail` and two-level `Vlc` (`VLC_PRIMARY_BITS = 11`): bit-exact with the previous prefix binary search; `vlc_tables_match_prefix_binary_search` verifies every code boundary across all 7 tables. - `quant_table()`: out-of-range exponents (including `< QUANT_MIN`, which wrap to a large `usize`) safely fall back to `10f32.powf(...)`. - `Decoder::carry()` / `Decoder::resume()`: validates sample count and power-of-two `block_len` in `MIN_SUBFRAME..=FRAME_SAMPLES`. (Minor nit: `resume` calls `self.reset()` before validating `block_len` on all channels, which is harmless for the `audio.rs` caller since it discards the fresh decoder on `false`.) - **`crates/victory-hle/src/modules/audio.rs`** - `save_carry` / `resume_carry`: bounds-checked via `heap_bytes(address, carry_bytes(channels))`, tagged with `VXO1` + channel count, and cleared on first resume so overlap state is consumed once. - **`crates/victory-hle/src/modules/apu.rs`** - `XApuConnect` / `XApuEnqueueCommand` / `Stream::convert` / `Converter`: properly validates `frames_per_output` (`256 | 480 | 512 | 960 | 1024`), clamps pitch to `0.125..=8.0` (handling non-finite `start_pitch`, `target_pitch`, and `pitch_ramp` safely), and bounds-checks both interleaved and deinterleaved unaligned writes against `output_length`. - (Minor note: for `DECODE_CONVERT_OPUS`, a `FLUSH` command with `input_length == 0` still passes an empty slice to `OpusDecoder::decode` before draining buffered output; fine if titles only flush with valid packets or `opus_pure` accepts empty packets.) ### Verdict `merge-candidate` — CPU-only audio decoding and HLE changes with passing CI, solid bounds/edge-case handling, and good unit test coverage; no local GPU test required. --- _Generated with Antigravity CLI (`agy`)._
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
Androtim/MiniVI!91
No description provided.