fix(agc): drain the registration preparation pool before the device is reset #2976
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2976"
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 SleglJan on 2026-10-10T19:16:58Z.
What
Carried from #2909 by @queeeef, which the intake pause closed; queeeef agreed to the carry there. The commit
8153d5abis unchanged (author Daan Dehing). It is based onmain57f96fd2and merges cleanly withmain4a747c48; none of the commits since its parent touch its four files. I'll handle the review follow-ups.Fixes #2891. Background registration preparations (#2583) copy the device's
SpirvTarget, whose capability and extension spans point into the device's shader profile.Driver::stopjoined the queue workers and reset the device without waiting for the detachedRegistrationPreparePool, so a preparation still queued or running read freed extension names inRecompileCacheKey::appendInterface. This is theagc_drivercrash at exit on RADV that #2891 and the review of #2589 report.RegistrationPreparePool::Closestops queueing and waits until no task is queued or running.Driver::stopcalls it (CloseRegistrationPreparation) after joining the queue workers and beforedevice.Reset(). The pool counts running tasks and destroys each task's captures before it reports idle.RegisterShaderholds its ownshared_ptrto the device for the duration, so the spans stay valid. ThrowingProcessShutdownthere instead would also be possible; happy to switch if preferred.PrepareRegisteredInBackgroundsubmits throughSubmitRegistrationPreparation, which the test also uses.This is the drain Celegans12 asked for in a comment on #2583 ("Could the pool be included in shutdown").
Overlap: #2856 conflicts trivially in
ShaderRegistry.hpp, where both add an#includeand a declaration next to each other. #2589 adds more submissions to the same pool and already conflicts withmain.Tested
queeeef's results:
Linux (Ubuntu 24.04, GCC 13.3), lavapipe (Mesa 25.2.8), main at
57f96fd. Full build with-DANYPS5_ENABLE_SPIRV_TOOLS=ONand the CI ctest invocation (--parallel 4 --timeout 120).agc_driver_registration_prepare_shutdown(0.2 s, no GPU needed): a latch-based shutdown test. A task on the preparation pool blocks on a latch while another thread runsLibcRunShutdown_nid_postfix. Shutdown must not return before the latch is released and the task has finished. A preparation submitted after shutdown must run on the caller's thread. It fails without theClosecall inDriver::stop("shutdown returned while a registration preparation was still running"). It also fails whenCloseignores running tasks, and whenSubmitignores the closed pool. It passes 30 of 30 repeated runs.guest_avplayer(links onlylibSceAvPlayerandlibc), aborted once under parallel load and passed 10 of 10 reruns alone and 10 of 10 under GPU load; it is unrelated.agc_driver_flat_storeis the only test over 30 s (50 s), as on main.agc_driver_tests: 0 of 30 runs fail. It did not crash onmainthere either; the crash has only been reproduced on RADV.tools/check_conventions.pyandtools/check_test_registration.pypass.Rerun of the #2891 loop on RADV (#2909 comment): Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Release with
BUILD_TESTING=ONandANYPS5_ENABLE_SPIRV_TOOLS=ON, RADV (Mesa 26.2.4, Ryzen 9 7950X3D iGPU, gfx1036) and RTX 3080 (NVIDIA 615.71.09).ctest -R '^agc_driver$'ran alone, one run at a time:main57f96fd2(the commit's parent)8153d5ab8153d5abmainwas 0 of 8 there in #2891, so this only checks for regressions)agc_driver_registration_prepare_shutdownpasses 30 of 30 there too.Windows (Yuva1024 on #2891,
main1476f769, RTX 4060, 4 copies in parallel): a rare heap-corruption exit ofagc_driver_testsstill happens with this change (1 of 400 runs, against 1 of 240 onmain). So this change doesn't fix it, and those runs can't tell whether it lowers it. That exit needs its own issue, since this PR closes #2891.@adriadam10, could you rerun your loop (10 of 30 on #2589) with this branch?
Checklist
main57f96fd2, merges cleanly with4a747c48; no other open PR implements the same functionsNotImplemented_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
https://claude.ai/code/session_01Fnrk5Dazjb2tLooVSpdRQq
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:39:48Z.
Rebased onto current
main(only conflict: adjacent#include <functional>/<initializer_list>inShaderRegistry.hpp).agc_driver_registration_prepare_shutdown,agc_driverand theprepared_*tests pass 10/10 repeats.Merging on green CI.
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-11T00:02:07Z.
Opened #3171 for the remaining Windows heap-corruption exit, with @Yuva1024's and @queeeef's data and the page-heap suggestion. Thanks for the review and the rebase.
AI-assisted: yes (Claude Code)