fix(libSceAudioOut): raise the output thread priority on Windows #6922
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6922"
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 boykopovar/AnyPS5. Originally posted by WallisSkill on 2026-10-16T18:52:50Z.
What
fix(libSceAudioOut): raise the output thread priority on Windows.Rebased on current
main(82f0c9aec).mainalready serializes output per port withg_outputMutexes(bd9d10b4c), so this PR no longer adds its own per-port locks and keepsmain's structure. Thanks to @blawesom for pointing this out. The rebase was redone frommain, not taken from the handoff branch.What remains is the priority change:
sceAudioOutOutputorsceAudioOutOutputsruns atTHREAD_PRIORITY_HIGHESTon Windows. It is set once per thread, after the handle checks and before the port locks are taken.SetThreadPriorityfails, the call throws with the Windows error code instead of continuing silently.Tested
Windows 11 Pro 26200, MinGW GCC 15.2.0.
AudioOut.cppcompiles on currentmainwith the project's flags.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py: the only overlap is #6879 (WASM). It touches the same include block and line 114 ofAudioOut.cpp, but not the same functions.mainnow has.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T19:16:29Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAudioOut/src/AudioOut.cppcore/libs/prx/libSceAudioOut/src/AudioOut.cppImported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T08:52:26Z.
Rebase handoff, with a heads-up —
mainlanded the same per-port output serialization independently (g_outputMutexes), so this PR's remaining delta after the rebase is the output thread priority raise (raiseOutputThreadPrioritybefore the port locks — three call sites) plus stylistic guard differences; the merged resolution keepsmain's structure and layers your priority calls onto it. If the priority raise alone is the intent, the PR may want retitling/reducing to that; the serialization itself is already onmain.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727), not this PRTo pick it up:
Head is
3d926f36c.Imported from boykopovar/AnyPS5. Originally posted by WallisSkill on 2026-10-18T17:51:15Z.
@blawesom thanks for the rebase handoff and the Linux run.
I took your suggestion and narrowed the PR. It is rebased on main (base
82f0c9aec) and keeps only the Windows output thread priority raise, since main'sg_outputMutexesalready serializes output per port. The title and description now match.What remains:
raiseOutputThreadPriority()setsTHREAD_PRIORITY_HIGHESTonce per thread (athread_localflag) insceAudioOutOutputandsceAudioOutOutputs, before the port locks are taken. IfSetThreadPriorityfails, it throws withGetLastError(). Linux and macOS are unchanged.Tested:
AudioOut.cppbuilds with MinGW GCC 15.2.0, andtools/check_conventions.py --base origin/mainpasses. The earlier version (per-port locks plus the priority raise) played Cat Quest III (PPSA15065) without audible stutter. The rebased priority-only version has not been run on a title yet, and the priority change has not been measured on its own.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T11:14:58Z.
Review: CHANGES_REQUESTED
Thanks for narrowing this down. A few points before it can merge:
AudioOut.cpp:135-144:mainalready has a thread-priority mechanism (core/libs/prx/libSceAgcDriver/Execution/src/ThreadPriority.cpp,APS5_THREAD_PRIORITY, off by default, logs what it set). This change raises a guest-called thread toTHREAD_PRIORITY_HIGHESTunconditionally, bypassing that opt-in, with no way to turn it off and no log. Please either route it through the same mode/Raisepath or explain why audio output should differ.AudioOut.cpp:140: ifSetThreadPriorityfails (restricted token, policy), the call throws and the title loses audio. For a performance hint a failure should not kill the output; if you keep throwing, say why that is right here.main'sg_outputMutexesmay be what fixed it. Please show a before/after with the priority raise alone (e.g. Cat Quest III, same scene, with and without it), or a measurement of output-call latency under CPU load.Imported from boykopovar/AnyPS5. Originally posted by WallisSkill on 2026-10-19T12:45:54Z.
@adriadam10 thanks for the careful review; you were right. I measured main without this PR (
c0607cc4b, priority untouched) in Cat Quest III (PPSA15065) on Windows 11, with a local counter on the main output port. Over about 8 minutes of play, 91,913 outputs of 5.3 ms went out with 0 underruns (the SDL queue was never empty when the next block arrived). The longest gap between twosceAudioOutOutputcalls was 13.6 ms, and the queue never held less than 37 ms of audio. No stutter was audible. So the stutter this PR started from was fixed by the per-port serialization that main already has, and the priority raise has nothing left to fix. I'm closing this PR. If a measurement under CPU load ever shows output calls being starved, I'll come back with an opt-in throughAPS5_THREAD_PRIORITYthat logs instead of throwing, plus a debt entry.Pull request closed