Keep XMA input valid when looping back to the start of a buffer #2712

Open
VlREX wants to merge 1 commit from upstream-pr/2714 into main
VlREX commented 2026-11-25 18:39:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by VlREX on 2026-11-25T18:39:07Z.


A zero read position selects the first frame in the input buffer. When a loop requested that position, the decoder previously cleared the valid-input bit as though there were no next frame. Preserve the optional next position until the context update so a real offset of zero survives. The synthetic two-packet regression failed before the change and verifies the first frame is decoded again, with the requested subframe skip, and normal playback continues when the loop count runs out. All nine audio module tests passed in an isolated Windows GNU run. No in-game verification.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5497058243 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2714). Originally posted by [VlREX](https://github.com/VlREX) on 2026-11-25T18:39:07Z. --- A zero read position selects the first frame in the input buffer. When a loop requested that position, the decoder previously cleared the valid-input bit as though there were no next frame. Preserve the optional next position until the context update so a real offset of zero survives. The synthetic two-packet regression failed before the change and verifies the first frame is decoded again, with the requested subframe skip, and normal playback continues when the loop count runs out. All nine audio module tests passed in an isolated Windows GNU run. No in-game verification.
kotekompotek commented 2026-11-25 19:06:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T18:51:02Z.


Elegant fix - Option is exactly the right type for 'no next frame' vs 'next at bit 0'. The loop path assigning Some(field) preserves a genuine zero loop start, and the regression verifies both halves: input stays valid through the wrap and invalidates normally when loops run out.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171488678 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2714#issuecomment-7171488678). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T18:51:02Z. --- Elegant fix - Option<usize> is exactly the right type for 'no next frame' vs 'next at bit 0'. The loop path assigning Some(field) preserves a genuine zero loop start, and the regression verifies both halves: input stays valid through the wrap and invalidates normally when loops run out.
fuzeofficlal commented 2026-11-25 20:06:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T19:38:50Z.


Independent Windows 11 verification and review of 69d5708 (on 13f91ca):

Verification (rustc 1.98.1 MSVC)

  • cargo xtask policy: 184 files ok.
  • cargo clippy --locked -p victory-formats -p victory-hle --all-targets -- -D warnings: 0 warnings.
  • cargo test --locked -p victory-formats: 38 passed, 0 failed, 5 ignored.
  • cargo test --locked -p victory-hle: 147 passed, 0 failed (lib, including a_loop_to_the_start_of_the_buffer_keeps_the_input_valid), plus fidelityfx (1) and no_dll_planting (1) clean.
  • 5-way XMA merge compatibility: verified clean zero-conflict sequential git merge-tree across the entire 5-PR stack #2694 + #2708 + #2709 + #2710 + #2714.

Review Notes

  • Switching next from a 0 sentinel to Option<usize> keeps valid == 1 when loop_start == 0 while still clearing the valid bit on true end-of-stream (frame.next == None), and pairs directly with #2708 when the next decode() sees at < 32. Clean and ready to merge.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7172581897 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2714#issuecomment-7172581897). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T19:38:50Z. --- Independent Windows 11 verification and review of `69d5708` (on `13f91ca`): ### Verification (`rustc 1.98.1` MSVC) - `cargo xtask policy`: **184 files ok**. - `cargo clippy --locked -p victory-formats -p victory-hle --all-targets -- -D warnings`: **0 warnings**. - `cargo test --locked -p victory-formats`: **38 passed, 0 failed, 5 ignored**. - `cargo test --locked -p victory-hle`: **147 passed, 0 failed** (`lib`, including `a_loop_to_the_start_of_the_buffer_keeps_the_input_valid`), plus `fidelityfx` (1) and `no_dll_planting` (1) clean. - **5-way XMA merge compatibility:** verified clean zero-conflict sequential `git merge-tree` across the entire 5-PR stack **#2694 + #2708 + #2709 + #2710 + #2714**. ### Review Notes - Switching `next` from a `0` sentinel to `Option<usize>` keeps `valid == 1` when `loop_start == 0` while still clearing the valid bit on true end-of-stream (`frame.next == None`), and pairs directly with #2708 when the next `decode()` sees `at < 32`. Clean and ready to merge.
oni-swr commented 2026-11-25 20:06:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T19:41:09Z.


Independent WARP/CPU verification

Head: 69d5708107565d3740bcdb408d8e41d397042544
Base: origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca
Status: open, non-draft; clean merge tree; no oni-swr comment on this head.

Environment: Windows x64, WARP selected (VICTORY_WARP=1, VICTORY_D3D12_WARP=1), dxil.dll 1.8.2502.11 from Windows SDK 10.0.26100.0; rustc 1.98.1.

Commands (each with CARGO_TARGET_DIR=D:\victory-warp-2690-target and the WARP variables above):

  • Baseline and PR: cargo test --locked -p victory-hle
  • PR targeted: cargo test --locked -p victory-hle a_loop_to_the_start_of_the_buffer_keeps_the_input_valid
  • PR lint: cargo clippy --locked -p victory-hle --all-targets -- -D warnings

Results: baseline 148 passed, 0 failed (146 unit + 2 integration); PR 149 passed, 0 failed (147 unit + 2 integration). Targeted regression 1/1 passed. Clippy passed.

Negative control: restored the old 0 == no next frame invalidation; the new loop-to-zero test failed (exit 101), as expected. No implementation bug found.

Not tested: physical GPU, retail title, release build. AI-assisted: Codex (gpt-6-luna).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7172632313 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2714#issuecomment-7172632313). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T19:41:09Z. --- Independent WARP/CPU verification Head: `69d5708107565d3740bcdb408d8e41d397042544` Base: `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca` Status: open, non-draft; clean merge tree; no `oni-swr` comment on this head. Environment: Windows x64, WARP selected (`VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`), `dxil.dll` 1.8.2502.11 from Windows SDK 10.0.26100.0; rustc 1.98.1. Commands (each with `CARGO_TARGET_DIR=D:\victory-warp-2690-target` and the WARP variables above): - Baseline and PR: `cargo test --locked -p victory-hle` - PR targeted: `cargo test --locked -p victory-hle a_loop_to_the_start_of_the_buffer_keeps_the_input_valid` - PR lint: `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` Results: baseline 148 passed, 0 failed (146 unit + 2 integration); PR 149 passed, 0 failed (147 unit + 2 integration). Targeted regression 1/1 passed. Clippy passed. Negative control: restored the old `0 == no next frame` invalidation; the new loop-to-zero test failed (exit 101), as expected. No implementation bug found. Not tested: physical GPU, retail title, release build. AI-assisted: Codex (gpt-6-luna).
Marvisak commented 2026-11-26 00:03:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:17:41Z.


Automated triage for the maintainers.

In crates/victory-hle/src/modules/audio.rs decode, the next read position becomes an Option<usize>, so a loop whose start field (context dword 3) is 0 no longer clears the input's valid bit as if the stream had ended. I checked this against main: decode already treats a read position below 32 as "the first frame of the buffer", so 0 is a real position there and the old 0 == no next frame sentinel conflicted with that. The test is now parameterised over loop starts 32 and 0, and the 0 case asserts that the valid bit stays set. CI (check) passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177370716 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2714#issuecomment-7177370716). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:17:41Z. --- <!-- victory-triage v1 head=69d5708107565d3740bcdb408d8e41d397042544 verdict=merge-candidate at=2026-11-25T23:17:33Z --> Automated triage for the maintainers. In `crates/victory-hle/src/modules/audio.rs` `decode`, the next read position becomes an `Option<usize>`, so a loop whose start field (context dword 3) is 0 no longer clears the input's valid bit as if the stream had ended. I checked this against `main`: `decode` already treats a read position below 32 as "the first frame of the buffer", so 0 is a real position there and the old `0 == no next frame` sentinel conflicted with that. The test is now parameterised over loop starts 32 and 0, and the 0 case asserts that the valid bit stays set. CI (`check`) passes. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
DenRakEiw commented 2026-11-26 00:49:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-26T00:49:51Z.

Review: APPROVED


Verified against origin/main (63bcca4):

  • Keeping XMA input valid when looping back to the start of a buffer passes all audio tests cleanly.
  • cargo test -p victory-hle audio::: 9/9 passed (including a_loop_to_the_start_of_the_buffer_keeps_the_input_valid).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 192 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6067059533 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2714#pullrequestreview-6067059533). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-26T00:49:51Z. **Review:** APPROVED --- Verified against `origin/main` (`63bcca4`): - Keeping XMA input valid when looping back to the start of a buffer passes all audio tests cleanly. - `cargo test -p victory-hle audio::`: 9/9 passed (including `a_loop_to_the_start_of_the_buffer_keeps_the_input_valid`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
futurepro62 commented 2026-11-26 13:04:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T12:17:12Z.


NVIDIA full-suite run, to go with the reports above by DenRakEiw, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head 69d5708 (on its base 13f91ca).

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: 774 passed, 0 failed, 9 ignored.
  • The new tests ran and passed: a_loop_to_the_start_of_the_buffer_keeps_the_input_valid.
  • --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:7191806627 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2714#issuecomment-7191806627). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T12:17:12Z. --- NVIDIA full-suite run, to go with the reports above by DenRakEiw, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head `69d5708` (on its base `13f91ca`). **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`: **774 passed, 0 failed, 9 ignored**. - The new tests ran and passed: `a_loop_to_the_start_of_the_buffer_keeps_the_input_valid`. - `--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-27 02:23:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:23:25Z.

Review: APPROVED


Looks good to me — clean fix for the next == 0 sentinel collision when an XMA stream loops back to bit offset 0.

Review & Verification Notes

  • crates/victory-hle/src/modules/audio.rs: keeping next as Option<usize> cleanly separates end-of-input (None, which clears the valid bit) from a loop-start offset of 0 (Some(0), which keeps the input valid so the next decode() resolves bit < 32 to packet 0's first_frame_bit). Finite loop counts decrement as before and malformed packets still clear the valid bit on xma::read_frame(...) == None.
  • Verified locally merged cleanly onto origin/main (63bcca43):
    • cargo xtask policy passes (191 files ok).
    • cargo clippy -p victory-hle (--lib, --tests, and --features diagnostics --lib/--tests, -D warnings) is clean.
    • victory-hle modules::audio passes (9/9, including a_loop_to_the_start_of_the_buffer_keeps_the_input_valid) under both default and --features diagnostics builds.
<!-- greyfinch-sync:Marvisak/VIctory:review:6082663717 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2714#pullrequestreview-6082663717). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T02:23:25Z. **Review:** APPROVED --- Looks good to me — clean fix for the `next == 0` sentinel collision when an XMA stream loops back to bit offset `0`. ### Review & Verification Notes - `crates/victory-hle/src/modules/audio.rs`: keeping `next` as `Option<usize>` cleanly separates end-of-input (`None`, which clears the valid bit) from a loop-start offset of `0` (`Some(0)`, which keeps the input valid so the next `decode()` resolves bit `< 32` to packet 0's `first_frame_bit`). Finite loop counts decrement as before and malformed packets still clear the valid bit on `xma::read_frame(...) == None`. - Verified locally merged cleanly onto `origin/main` (`63bcca43`): - `cargo xtask policy` passes (`191 files ok`). - `cargo clippy -p victory-hle` (`--lib`, `--tests`, and `--features diagnostics` `--lib`/`--tests`, `-D warnings`) is clean. - `victory-hle` `modules::audio` passes (`9/9`, including `a_loop_to_the_start_of_the_buffer_keeps_the_input_valid`) under both default and `--features diagnostics` builds.
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/2714:upstream-pr/2714'
git switch 'upstream-pr/2714'

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/2714'
git switch 'upstream-pr/2714'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2714'
git switch 'upstream-pr/2714'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2714'
git switch 'main'
git merge --squash 'upstream-pr/2714'
git switch 'main'
git merge --ff-only 'upstream-pr/2714'
git switch 'main'
git merge 'upstream-pr/2714'
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!2712
No description provided.