Audio: the XMA decoder runs at time-critical priority #1509
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1509"
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?
Imported from fxceless/victory-fork. Originally posted by pwu2775-dev on 2026-11-28T07:20:05Z.
Problem
The game's audio crackles, and the crackle grows over a run: clean at the start, broken later in the world.
Each enabled XMA voice writes decoded samples into an output ring in title memory that the title reads through
ADVANCE_XMA_READ(command 18). The ring is shallow — the title asks for 1 to 31 blocks of 256 bytes, 2.7 ms each at 48 kHz mono, so 21 to 83 ms of audio in all. The frame timeline stalls far longer than that under memory pressure: 150 to 260 ms a frame measured on the affected run, whose private memory grew past 38 GiB on a 32 GiB machine (hard faults at 10,000–26,000 pages/s).At normal priority the single
victory XMA decoderthread then waits behind the thirty-odd frame threads (victory-list-0..7,victory-wide, the title's own workers) for its slice, a ring runs dry in between, and the title's mixer reads a partial block — the game plays that as a crackle. It grows as the run consumes more memory because the stalls grow with it.Live measurement on the affected run (thread priority raised externally on the running process, RTX 4070 / Ryzen 5 7500F / 32 GB):
Fix
The decoding thread raises itself to
THREAD_PRIORITY_TIME_CRITICALwhen it starts (windows-sysis already a dependency; no Cargo change). One line of behavior, with the reason documented at the function:ahead_of_other_programsraised the whole process for a similar reason, while the pipeline helpers may go below (VICTORY_HELPER_PRIORITY) because a frame feeds them — this thread is the other direction of that trade.Validation
cargo test -p victory-hle --locked --lib: 171 passed, 2 ignored (audio module's 8 tests all pass).cargo clippy -p victory-hle --all-targets: no new warnings (the crate's existing ones are indstorage.rs/xmem.rs, untouched).cargo build --release --locked -p victory: success.Known limits
Imported from fxceless/victory-fork. Originally posted by pwu2775-dev on 2026-11-29T07:08:38Z.
Live measurement on the machine that showed the crackle (RTX 4070 / Ryzen 5 7500F / 32 GB), this build with the fix active, second session in the same area:
So the priority fix removes the scheduling delay, and on lighter scenes that is the whole difference; under this run's memory pressure the remaining stalls are page waits, which a thread priority cannot skip. The two practical conclusions for the PR: the crackle tracks the hard-fault rate rather than the frame rate alone, and a deeper output path (decode-ahead into memory we own, handed to the ring under the title's read pointer) would be the follow-up that helps where this one tops out.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.