fix(agc): wait for queued registration preparations before accepting a submission #5007
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5007"
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 gravelas on 2026-10-13T08:00:21Z.
What
Goat Simulator 3 (PPSA04159) stops at startup with a write of 0 at a compiled-out debug hook (app.exe+0x2511b7b): the engine's garbage collector waits for a render command fence, gives up after 10 s and reaches a fatal path. With another program loading the CPU it happened on every launch (11 of 11), without load about one launch in four.
Since registered shaders are prepared in the background (
6db5c1369), a draw whose shader the title registered just before its submission waits for that preparation inside the queue worker, inAwaitRegisteredPreparation. A GPU trace (APS5_TRACE_GPU=1) of a failing launch shows:The title takes a submission of seconds for a hung GPU. On the console shaders are compiled ahead of time, so a submission never waits for one.
Driver::Submitnow waits, on the submitting thread and before it accepts the commands, until the registration preparations queued before the call have run (RegistrationPreparePool::AwaitSubmitted: each queued task gets a sequence number, and the call returns once no task numbered at or before the newest one at the call is queued or running, so a later task finishing first does not end the wait). The queue worker then finds every such preparation settled, and the submission's GPU side stays short: the same submission is done in about 180 ms.APS5_SYNC_SHADER_PREPARE=1(nothing is queued) or when the pool has no threads (tasks run inline).Submitand would need a rebase against each other.agc_driver_prepared_shadersgains cases: a task queued on the registration pool that sleeps 50 ms has run whenAwaitRegistrationPreparationreturns; and with a 300 ms task queued before the wait and a fast one queued after it began, the wait does not return before the slow task is done (a count of finished tasks fails this, because the fast task finishes first).Tested
BUILD_TESTING=ON:ctest -R "agc|shader" -j6passes 473 of 473, as onmain, andagc_driver_recorder_testspasses its default run.tools/check_conventions.py --base origin/mainpasses.APS5_SYNC_SHADER_PREPARE=1instead, 0 of 3 crashed, which isolates the background wait as the cause. On currentmainthe title stops earlier, at its first draw with clip distances (clip distances, layer, viewport or auxiliary vertex exports is unsupported (register 0x207 = 0x00400001), which #423 and #1077 cover), so these numbers are from that local branch:mainof 2026-10-12 with #1077 merged.Checklist
main; no other open PR implements the same functions (#4404 prioritizes queued preparations; see above)NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T09:41:45Z.
Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main
2a2a3dc65together with nine other open GPU PRs (their own commits applied, no merge commits; one further PR, #5024, conflicted with them and was left out), so only the tests that belong to this PR say something about it:tests/execution/PreparedShaders.cpp, whichctestruns asagc_driver_prepared_shadersand its variants_indirect,_uncached,_debug,_debug_failure,_deferred,_deferred_undecodable,_registered_workgroupand_registered_workgroup_sync: 3 of 3 runs passed for each.Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-14T05:45:20Z.
Rebase handoff — rebased onto current
main, authorship unchanged. This one was a real architectural merge of the preparation worker pool:main's demanded-preparation prioritization (PreparedShaders*on tasks,Prioritizerotating the queue) and this PR's sequence-based await (AwaitSubmitted/AwaitRegistrationPreparation, theunfinishedset) are both kept — the task struct carriessequence,functionandpreparedtogether, the demanded tasks still jump the queue with their sequence intact, and the await predicate is unchanged.sequencealive for theunfinished.erasethat follows — resetting the whole task would deadlock every await. That's how it's merged.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); the prepared-shaders family (all 4 variants plus indirect) passesTo pick it up:
Head is
f1982baa3.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:33:40Z.
Rebased onto current
main(conflict inShaderRegistry.cppwith the demanded-preparation work: both kept,sequenceis read before the task is reset sounfinished.erasestill gets it).Checked on Linux (RADV, Release): scoped libSceAgcDriver build + ctest 550/551, the only failure is
agc_driver_tessellation(segfault, also onmain). Allagc_driver_prepared_shaders*pass, 15 repeats without a hang. WithAwaitSubmittedturned into a no-op,agc_driver_prepared_shadersfails on "a submission did not wait for the registration preparation queued before it". Game behaviour (Goat Simulator 3) not reproduced here; relying on the reported runs. Merging once the full Build is green.