fix(agc): drop queued library prebuilds when the prebuild pool closes #8678
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8678"
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 CPritch on 2026-10-20T20:52:21Z.
What
Driver::stopcallsCloseRegistrationPreparation()beforedevice.Reset(), which runs the teardown pipeline cache save.RegistrationPreparePool::Close()waited until its queue was empty, so with cold library caches the one-thread prebuild pool built every queued library before the process could exit (#8470).When the prebuild pool closes it now drops the tasks that have not started, removes their tickets from
unfinishedand notifiesidle, so a concurrentAwaitSubmitteddoes not wait for them, and waits for the running task as before. The shader preparation pool still runs its whole queue at close, andAwaitLibraryPrebuilds(device replacement) andSubmitafter close are unchanged, as MarcZX10 described on #8470. A dropped prebuild is submitted again when its shader registers in a later session, so after an early exit the library cache fills over more sessions than before.agc_driver_shutdown_threads_queued_prebuildsgates one running prebuild, queues three more and closes on another thread. A second thread callsAwaitLibraryPrebuilds()before the close. The test requires that close waits for the running one and returns once it ends, that the waiter returns too, and that none of the queued ones ran. With the ticket erase removed, the waiter never returns and the test fails ("a waiter for the library prebuilds did not return after closing dropped the queued ones").Related: #7474 saves the pipeline cache on an immediate guest exit through libc's exit drain; it does not touch
Driver::stopor the pools.Tested
GTA V (PPSA04263 01.010.002), Performance mode: boot, Resume Story, 60 s after the Story loads, then SIGINT (SDL turns it into the normal quit path). Every run started with no pipeline cache file and
__GL_SHADER_DISK_CACHE=0, in the order main, PR, main, PR. Time from SIGINT to exit, all runs exited on their own and wrote the teardown save:44e3389c883751168dTeardown save on the RTX 4060: main 275479.1 and 275620.2 KiB, this PR 65340.0 and 65024.0 KiB (it lacks the libraries main built from the queue after SIGINT). Boot to the loaded Story was the same on both sides (90 to 102 s).
On the laptop,
ctest -R 'agc_driver_shutdown|agc_driver_prepared_graphics_prebuild' -VwithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andVK_LOADER_DEBUG=error(loader 1.4.363 reports a missing layer only with it), on main4036fab1b: main 11 of 11, this PR 12 of 12; nowas not found but was requested by env var VK_INSTANCE_LAYERSorVUID-line. The shutdown thread tests do not load Vulkan; the three prebuild policy tests ran on the RTX 5060 with Khronos validation 1.4.363 loaded. The new test with main'sShaderRegistry.cppfails with "closing ran the queued library prebuilds" (50 of 50); with this PR it passes 200 of 200.agc_driver_registration_prepare_stack(#6598) passes. On the RTX 4060 (mainc6145997e), the nineagc_driver_shutdown_threads_*tests pass, and the new one passes 100 of 100 repeats.Not tested: Windows, AMD, other titles.
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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T20:56:33Z.
Review: COMMENTED
The ticket removal and
idle.notify_all()look consistent withAwaitSubmitted's predicate. The queued-prebuild test currently verifies the running task is joined and queued work is dropped, but it does not start anAwaitLibraryPrebuilds()waiter before close. Your #8470 comment said you planned to add that case; please include it so the waiter guarantee claimed in the PR description is protected against regression. I have not submitted an approval while that promised coverage is missing.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:08:56Z.
Review: COMMENTED
One small test-race concern:
waitingbecomes true whenever the waiter future is not ready after 20 ms, including if the detached thread has not been scheduled yet. In that case the test does not proveAwaitLibraryPrebuilds()blocks while the running task is held. A start handshake immediately before the call would reduce the false-positive window; a test hook/barrier at the pool wait point would make the assertion definitive. The close-side assertions still exercise dropping queued work and joining the running task.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:54:53Z.
Review: COMMENTED
Thanks for adding the
AwaitLibraryPrebuilds()waiter case and the dropped-ticket negative control. The firstwaitingassertion still has the scheduling race from my earlier note: after launching the detached thread, a 20 ms timeout only proves its future is not ready; it does not prove the thread reachedAwaitLibraryPrebuilds()beforeCloseRegistrationPreparation()starts. A start promise set immediately before the call would make the test deterministic about thread scheduling; a hook at the pool wait point would prove the stronger condition directly. Can you add that handshake before I approve?Imported from boykopovar/AnyPS5. Originally posted by CPritch on 2026-10-21T07:23:20Z.
@MarcZX10 added the start handshake in
8cd100e48: the waiter thread sets a promise immediately before callingAwaitLibraryPrebuilds(), and the test waits for it before the 20 ms check, sowaitingcan no longer pass because the thread hasn't been scheduled. A hook inside the pool's wait would make it exact, but it would need a test-only seam inRegistrationPreparePool, so I've left that out unless you'd prefer it. 200 of 200 repeats pass.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T07:46:25Z.
Windows run of
8cd100e486merged ontomainb77bd58806(f641bc3c31, clean), one of the hosts the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON. GPU: NVIDIA GeForce RTX 4070 SUPER, driver 616.92, picked withANYPS5_GPU=4070(the machine also has a GTX 1650 SUPER).Built
libSceAgcDriverandagc_driver_shutdown_threads_testswith no errors; the build prints twomemcmpbound warnings, whichmainprints the same way fromGraphics/src/PipelineLibrary.cpp, a file this PR does not change.ctest --repeat until-fail:50on the newagc_driver_shutdown_threads_queued_prebuilds: passes all 50 repeats.--repeat until-fail:3on the eightagc_driver_shutdown_threads_*tests: all pass. On the previous head703102d6cathe nine shutdown tests also passed twice each. Not run: AMD, a title.