Skip to content

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

Merged
Marvisak merged 2 commits into
Marvisak:mainfrom
AnoHunted:xma-write-block-wrap
Nov 25, 2026
Merged

Marvisak merged 2 commits into
Marvisak:mainfrom
AnoHunted:xma-write-block-wrap

Conversation

@AnoHunted

Copy link
Copy Markdown
Contributor

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
  • Audio: an XMA read block past the ring's end wraps instead of filling forever #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 and others added 2 commits November 24, 2026 01:47
… forever

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 <noreply@anthropic.com>
…write

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.
@upipibi upipibi mentioned this pull request Nov 24, 2026
@Exorion1er

Copy link
Copy Markdown
Contributor

#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 mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…ng's end wraps before the first write

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nazmi pushed a commit to nazmi/VIctory that referenced this pull request Nov 24, 2026
…write

Applied as the net diff of upstream PR Marvisak#536 (head 7a5d85e), 2 commits: 7a5d85e,1054fe87.
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
@Marvisak
Marvisak merged commit 13de0cc into Marvisak:main Nov 25, 2026
Steenax6 pushed a commit to Steenax6/VIctory-NVID that referenced this pull request Nov 26, 2026
…write

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.

Source: Marvisak/VIctory 7a5d85e (AnoHunted), merged upstream as PR Marvisak#536.

(cherry picked from commit 7a5d85e)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants