apu: Opus packets decoded by a thread of the connection, not in the title's call #175
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!175
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-175"
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?
@Ekabusto on GitHub · 2026-12-02 09:44 UTC · original
Ekabusto:perf/apu-off-title-thread→main· +205 −52 · 1 files · 1 commits · openWhat
XApuEnqueueCommanddecoded each Opus packet inside the title's call. On the console the audio decoder is hardware beside the CPU: the title queues a command and later pollsXApuDequeueResult(PENDING_RESULTS) or waits on the connection's event. This moves the decoding to one thread per connection, the way the console works.QUEUE_FULL) and thetotalout parameter are still counted at the call; error codes are checked in the same order as before.XApuDisconnectstops the thread, after the command it is running, before freeing the memory and closing the event.Why
A
perfprofile (30 s driving in a busy scene, diag build) had 26 % of the busiest title thread's samples inopus_pure, called fromXApuEnqueueCommand.Measured
Release builds, RX 9070 XT + Ryzen 9 5900X, 1440p, Series X profile, ~30 s driving the same route, before/after:
To be clear: this does not raise fps here. The thread that was decoding is not on this title's frame path (the timeline's critical path is the title's own code on other threads). The change frees about a quarter of a title thread and matches the console's behavior; it may matter more on CPUs with fewer cores.
Tests
cargo test -p victory-hle --lib -- apu: both APU tests pass. They now wait for the connection's thread (settle) before reading results, since results are no longer ready at the call.cargo clippy -p victory-hle --all-targets: clean.🤖 Generated with Claude Code
@Kal0s-design on GitHub · 2026-12-03 19:19 UTC · original
Tested this on Windows 11 native (MSVC, toolchain 1.98.1), CPU only, no game run. Checked both the PR head and a local merge with current main (only apu.rs differs from main, it merges clean).
What I looked at in apu.rs:
closingand notifies, the guard is a temporary so it isn't held across join(), then joins and only after that closes the event and frees the memory (~297-307). The thread never runs title code, so it can't call Disconnect itself. Commands still queued at disconnect are dropped without results, which seems fine since the handle is gone after that.closingandcommands_leftunder the lock before waiting, and Enqueue pushes under the lock before notify.queued[stream]still goes up at enqueue and down at dequeue, same as before, so QUEUE_FULL can't drift. INVALID_STREAM / QUEUE_FULL / INVALID_COMMAND are still returned at the call in the same order, andtotalis the same value as before.Tests:
cargo test -p victory-hle --lib: main 157 passed / 3 failed / 1 ignored, PR merged with main the same 157 / 3 / 1, PR head alone 154 / 3 / 1 (it's behind main). The 3 failures are the same gameinput tests on all three and fail on main too, so they're unrelated to this PR.cargo clippy -p victory-hle --all-targets: no warnings in apu.rs. The 3 in victory-hle are in other files the PR doesn't touch.One small thing I only found by reading, not by a test. If the decoder thread ever panicked, the stream would just stop producing results and the title would keep polling, and Disconnect drops the join error with
let _ = worker.join(). On main the same panic would have happened in the title's call. I couldn't make it panic, even with the garbage packets, so maybe not worth more than a log line on the join error.Otherwise I didn't find anything to change. Looks good to me.
AI-assisted: yes
@Luxuride on GitHub · 2026-12-04 12:01 UTC · original
Land this one. It is the smallest correct version of the APU-async fix, it merges cleanly today, and it is the only one of the three PRs on this issue whose tests actually run the async path (
settle(handle)atapu.rs:561waits for real quiescence instead of timing).Two things before you do:
apu.rs:340copies only the command descriptor, whoseinput/outputare still title addresses, and the worker dereferences them later atapu.rs:439. That is contract-legal on the console (the packet buffer is the title's until the result is dequeued), but a title that reuses its buffer on the next submit now gets its bytes read after it overwrote them. Copying the packet bytes at submit removes the question; at minimum say in the body that you checked the title's submit loop.VICTORY_APU_SYNC-style switch is the difference between "ship it" and "hold it".apu.rs:146's#[cfg(test)] idle: Condvarliving in the shared state struct is harmless, just note it.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.