Audio: an XMA write block past the ring's end wraps before the first write #536

Merged
AnoHunted merged 2 commits from upstream-pr/536 into main 2026-11-25 00:20:04 +00:00
AnoHunted commented 2026-11-24 04:39:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AnoHunted on 2026-11-24T04:39:02Z.


Stacked on #248; only the top commit belongs here.

What

In pump, take the write block (context word 0, bits 27-31) modulo the ring size (word 0, bits 22-26) before the first write of a pass, as #248 does for the read block and as advance_read does.

Why

A write block at or past the ring size was used as it was for the first block of a pass: it was written at output + write * 256, past the end of the ring (possibly into another APU allocation), and only then wrapped with (write + 1) % size.

Tested

Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1. New test xma_write_blocks_past_the_ring_end_wrap: a ring of four blocks followed by a guard area filled with a pattern, write block 6 (block 2 of the ring), read block 1, a looping silent stream, one pass. It checks that the guard area is untouched, that blocks 2, 3 and 0 are written and block 1 is left for the title, and that the write block ends at 1 with the ring no longer writable.

  • cargo test -p victory-hle xma_ -- --test-threads=1 and cargo test --workspace -- --test-threads=1
  • #248 plus only the new test (fix reverted): the new test fails with "written past the ring" (the guard area was overwritten); the other 87 tests of the crate pass (cargo stops there, so later crates did not run).
  • This branch: 3 XMA tests pass; whole workspace 266 passed, 0 failed, 4 ignored.

AMD and other GPUs: not tested (no GPU code is touched).

Not tested

Behaviour against a real title; only the synthetic context above.

No game files were used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6574738420 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/536). Originally posted by [AnoHunted](https://github.com/AnoHunted) on 2026-11-24T04:39:02Z. --- Stacked on #248; only the top commit belongs here. ## What In `pump`, take the write block (context word 0, bits 27-31) modulo the ring size (word 0, bits 22-26) before the first write of a pass, as #248 does for the read block and as `advance_read` does. ## Why A write block at or past the ring size was used as it was for the first block of a pass: it was written at `output + write * 256`, past the end of the ring (possibly into another APU allocation), and only then wrapped with `(write + 1) % size`. ## Tested Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1. New test `xma_write_blocks_past_the_ring_end_wrap`: a ring of four blocks followed by a guard area filled with a pattern, write block 6 (block 2 of the ring), read block 1, a looping silent stream, one pass. It checks that the guard area is untouched, that blocks 2, 3 and 0 are written and block 1 is left for the title, and that the write block ends at 1 with the ring no longer writable. - `cargo test -p victory-hle xma_ -- --test-threads=1` and `cargo test --workspace -- --test-threads=1` - #248 plus only the new test (fix reverted): the new test fails with "written past the ring" (the guard area was overwritten); the other 87 tests of the crate pass (cargo stops there, so later crates did not run). - This branch: 3 XMA tests pass; whole workspace 266 passed, 0 failed, 4 ignored. AMD and other GPUs: not tested (no GPU code is touched). ## Not tested Behaviour against a real title; only the synthetic context above. No game files were used.
Exorion1er commented 2026-11-24 10:03:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Exorion1er on 2026-11-24T09:33:19Z.


#248 is fully contained here: the same one-line read-block fix (write == field(9, 0, 5) % size) and the same test, xma_read_blocks_past_the_ring_end_wrap, with identical code. This PR also adds the write-block wrap and its test. Merging both would give two tests with the same name, so #248 can close if this lands.

Checked by reading both diffs against main. Both merge cleanly. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7127574564 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/536#issuecomment-7127574564). Originally posted by [Exorion1er](https://github.com/Exorion1er) on 2026-11-24T09:33:19Z. --- #248 is fully contained here: the same one-line read-block fix (`write == field(9, 0, 5) % size`) and the same test, `xma_read_blocks_past_the_ring_end_wrap`, with identical code. This PR also adds the write-block wrap and its test. Merging both would give two tests with the same name, so #248 can close if this lands. Checked by reading both diffs against `main`. Both merge cleanly. AI-assisted (Claude Code).
mercuryVM commented 2026-11-24 12:03:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:51:45Z.

Review: APPROVED


Tested 7a5d85e on Windows 11, RTX 5070, MSVC: cargo test -p victory-hle 89 passed, including xma_write_blocks_past_the_ring_end_wrap and xma_read_blocks_past_the_ring_end_wrap. Clippy's 1 warning is the existing field_reassign_with_default at xmem.rs:747.

  • Taking the write block % size before the first write closes the same hole #248 closed for the read block. pump already returns early on size == 0, so the modulo can't divide by zero.
  • #248 is already on mercuryVM/VIctory main, so only the top commit is new there. It merges cleanly.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038681574 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/536#pullrequestreview-6038681574). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T11:51:45Z. **Review:** APPROVED --- Tested 7a5d85e on Windows 11, RTX 5070, MSVC: `cargo test -p victory-hle` 89 passed, including `xma_write_blocks_past_the_ring_end_wrap` and `xma_read_blocks_past_the_ring_end_wrap`. Clippy's 1 warning is the existing `field_reassign_with_default` at xmem.rs:747. - Taking the write block `% size` before the first write closes the same hole #248 closed for the read block. `pump` already returns early on `size == 0`, so the modulo can't divide by zero. - #248 is already on mercuryVM/VIctory main, so only the top commit is new there. It merges cleanly. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:04:07 +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!536
No description provided.