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

Manually merged
github merged 2 commits from gh-pr/536/head into gh-pr/536/base 2026-11-26 04:07:30 +00:00
Owner

@⁠AnoHunted on GitHub · 2026-11-24 04:39 UTC · original
AnoHunted:xma-write-block-wrap → main · +172 −2 · 1 files · 2 commits · merged 2026-11-25 00:20 UTC

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.

**@⁠AnoHunted** on GitHub · 2026-11-24 04:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/536) `AnoHunted:xma-write-block-wrap` → `main` · +172 −2 · 1 files · 2 commits · merged 2026-11-25 00:20 UTC 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.
The decoder fills an XMA voice's output ring until the write block
(word 0, bits 27-31) comes round to the title's read block (word 9,
bits 0-4). The write block wraps modulo the ring size (word 0, bits
22-26), and so does a read block moved on by command 18, but a read block
the title set up at or past the ring's end was compared as it was: no
write block ever equalled it. With a stream that loops forever the pass
never ended, holding that voice's lock, so the title's next command on
the voice (advance, disable) waited for good, and releasing the context
arrays did too.

Take the read block modulo the ring size as well, as the write side
already does. A test sets up read block 6 on a ring of four with an
endless loop and requires the pass to end within seconds, with blocks 0
and 1 filled.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The write block (context word 0, bits 27-31) was used as it is for the first
block of a pass, so one at or past the ring size (bits 22-26) was written
past the ring's end, possibly into another APU allocation, before it wrapped
with (write + 1) % size. Take it modulo the ring first, as the read block is
taken, and as advance_read does.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:07:28 +00:00
github manually merged commit 7a5d85e6a2 into gh-pr/536/base 2026-11-26 04:07:30 +00:00
Author
Owner

@⁠Exorion1er on GitHub · 2026-11-24 09:33 UTC · original

#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).

**@⁠Exorion1er** on GitHub · 2026-11-24 09:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/536#issuecomment-7127574564) #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).
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!536
No description provided.