Audio: an XMA read block past the ring's end wraps instead of filling forever #248
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!248
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/248/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@AnoHunted on GitHub · 2026-11-24 01:48 UTC · original
AnoHunted:xma-read-block-wrap→main· +85 −1 · 1 files · 1 commits · closed without mergingWhat
pumpincrates/victory-hle/src/modules/audio.rscompares the write block with the title'sread block taken modulo the ring size (
context.field(9, 0, 5) % size), as the write block(
(write + 1) % size) and command 18 (advance_read) already are. One line and a comment.xma_read_blocks_past_the_ring_end_wrap: a context set up like the one inxma_contexts_decode_into_their_output_rings(the synthetic silent stream, a ring of fourblocks), but looping forever over the whole stream (loop count 255) and with read block 6. It
runs an XMA pass on a thread of its own and requires it to end within 5 s, with blocks 0 and 1
written, blocks 2 and 3 untouched, the write block on 2 and the ring no longer writable. If the
pass does not end, the test clears the context's "writable" bit as a full ring would, so the
stuck pass ends, the contexts are released, and the test fails without holding up the rest of
the suite.
Why
A pass fills a voice's ring until the write block (word 0, bits 27-31) comes round to the read
block (word 9, bits 0-4). The write block wraps modulo the ring size (word 0, bits 22-26), but a
read block the title set up at or past the size was compared as it was: no write block ever
equalled it, and "writable" was never cleared. With an input that ends, the pass went round the
ring until the input ran out, writing over blocks the title had not read yet. With a stream that
loops forever it never returned. It holds that voice's lock while it runs, so:
good; titles send them from their mixer thread;
AcpHalReleaseShapeContextswaited for good for the context arrays' lock.Why modulo, not a clamp or an error: the module already treats both offsets as positions on the
ring. The write block wraps, and command 18 already takes the read block modulo the size, so a
read block out of range is brought into range the first time the title advances it; the passes
before that now agree with it. Xenia's XMA context decoder, which reads the same fields, does
the same: it puts both offsets on its ring buffer, whose
set_read_offsetandset_write_offsettake them modulo the capacity. I know of no documented error status for this case. A pass now
writes at most one ring's worth of blocks (plus one, see below).
Also checked in
pump, not changed: every turn of its loop writes a block and moves the writeblock on, whatever the input does, so with the read block in range a pass ends within one ring
however the input buffers and loops are set up. A write block at or past the ring size is not
this bug (the pass still ends) but has a cost of its own: the first block of the pass is written
past the ring's end before the write block wraps.
Tested
Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1.
cargo test -p victory-hle -- modules::audiofails the newtest after 5.0 s ("the XMA pass never ended"); the five other audio tests pass. All of
cargo test -p victory-hle -- --test-threads=4: 86 passed, 1 failed (the new test), finished in5.02 s, so the stuck pass is ended and the rest of the crate runs.
cargo test -p victory-hle -- modules::audiogives 6 passed, 0 failed; the new testtakes 0.003 s (
--report-time).cargo test --workspace -- --test-threads=4, run side by side: main 264 passed, 0 failed,4 ignored; this branch 265 passed (the new test), 0 failed, 4 ignored.
cargo clippy -p victory-hle --all-targets: the same single warning on main and here (inxmem.rs), nothing inaudio.rs.rustfmt --checkonaudio.rs: nothing in the changed lines(the same older differences at
Xma::pump,dump_inputand inaudio/capture.rsas on main).cargo xtask policy: 151 files ok.Not tested
was not observed; the choice follows the module's write side and Xenia.
Open PRs on this file: #88 (
advance_read), #112 (formatting), #130 (a profiler scope indecode), #194 (the loop skip indecode), #237 (the heap lock inpumpanddecode) and thedraft integration #231 each merge with this branch without a textual conflict in
audio.rs(
git merge-tree; not tested together); none of them changes the comparison inpump.AI-assisted (Claude Code, Claude Opus 5.5). No game files were used.
@jeremygold02 on GitHub · 2026-11-24 05:34 UTC · original
Tested current PR head
1054fe87de08038e887d6f7c6f44e5b07ac7a9f9.cargo test --locked -p victory-hle --lib audio -- --test-threads=1: 6 passed, 81 filtered out. The newxma_read_blocks_past_the_ring_end_wraptest uses a four-block ring and read index 6, expecting the decoder to wrap to block 2. A looping two-packet silent stream must finish its pass within five seconds; the test checks that blocks 0–1 were written, blocks 2–3 stayed title-writable, and the sentinel bytes in the untouched half of the ring remain unchanged. The target also passed XMA ring decoding, queue-drop counting, and heap mapping/address reuse cases (ring-wrap regression test).The test uses a synthetic silent XMA stream and in-memory ring, so it does not cover real title audio, media assets, or a host audio device.
@AnoHunted on GitHub · 2026-11-24 10:21 UTC · original
As @Exorion1er noted, #536 contains this change and its test unchanged, plus the write-block wrap. Merging both would give two tests with the same name, so I'm closing this one in favour of #536. Thanks @jeremygold02 and @mercuryVM for testing it; those results apply to #536's first commit as is.
Pull request closed