[pr-fix][audio] Decode XMA on demand if its worker cannot start #248
Loading…
Reference in a new issue
No description provided.
Delete branch "andrewpozdnakov7-jpg/Darner:port/4800-fallback-when-xma-thread-fails"
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?
Contributor role (optional)
What it changes
When starting the XMA worker fails, main remembers the caller thread as though it were the decoder. Unparking it never performs a decode. Keep the failure separate from a working decoder and fill the affected voice synchronously on enable or read advancement. The two callers release the voice lock before waking the decoder.
Restores locally saved VIctory-NVIDIA work from December 1, 2026. Recovered revision: b97f584. Adapted by andrewpozdnakov7-jpg (GitHub profile).
How it was tested
5656a59onf3840d7.d57fea1passed the injected outcome fixture and the focused HLE type check.d57fea1based on Jesper-A's review: keep the existing XMA guard in the synchronous fallback. A focused fixture exercised the new call sites after releasing the voice-slot lock, with and without a worker. cargo check --locked -p darner-hle --lib --tests, xtask policy and git diff --check passed.Checklist
Checked for overlap
Code-read review of
5656a59. I did not build or run it.The main-branch bug is real (
audio.rs:943on main storesstd::thread::current()when the spawn fails, so nothing ever decodes), and the on-demand fallback is the right idea. One problem in it:Second read lock on the
XMARwLock from the same thread.xma_commandtakeslet xma = xma();(audio.rs:961), a read guard on the staticXMA, and keeps it for the whole command.ENABLE_XMAScallsxma.enable(i)andADVANCE_XMA_READcallsxma.advance_read(..)under it.wake_decoder(index)(audio.rs:615,664). With no decoder thread,wake_decodercallsxma().pump_voice(index)(audio.rs:955), which is a secondXMA.read()on the same thread.RwLock::read"might panic when called if the lock is already held by the current thread", and a recursive read can also block when a writer is queued.XMA.write()is taken ataudio.rs:373(context arrays allocated) andaudio.rs:382(released).xma_commandentersENABLE_XMA(S), and another thread allocates or releases the context arrays at that moment. The command thread then waits on itself. It is rare, but it sits in the fallback this PR adds.Suggested fix: do not re-enter
xma().enableandadvance_readalready have&self, so makewake_decoderreturn whether a decoder thread exists and pump throughself:(
wake_decoderwould drop itsindexargument and returndecoder.is_some()after the unpark.)pump_voicere-takes onlyvoices[index], and both callers have already droppedslot, so that is safe.Limitation worth a line in the body. In fallback mode a voice is pumped only on
ENABLE_XMA(S)andADVANCE_XMA_READ.decodereads the input-valid bits straight from context memory (audio.rs:737,context.field(0, 20, 2)), and its comment (audio.rs:739) says the title "can refill either input while the context stays enabled". A refill like that is not decoded until the next enable or advance. It is still better than main, which decodes nothing, but it is not equivalent to the worker.This comment was written with AI assistance (Claude Code).
Thanks for tracing the lock. The current head,
d57fea1, pumps the voice through the XMA instance the command already holds after releasing the voice lock. That removes the second global read-lock acquisition on the fallback path. The injected outcome fixture and focused HLE type check passed. I also recorded the input-ready limitation in the description.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.