fix(agc): drain the registration preparation pool before the device i… #2909

Closed
queeeef wants to merge 1 commit from upstream-pr/2909 into main
queeeef commented 2026-10-10 18:23:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by queeeef on 2026-10-10T18:23:29Z.


What

Fixes #2891. Background registration preparations (#2583) copy the device's SpirvTarget, whose capability and extension spans point into the device's shader profile. Driver::stop joined the queue workers and reset the device without waiting for the detached RegistrationPreparePool, so a preparation still queued or running read freed extension names in RecompileCacheKey::appendInterface. This is the agc_driver crash at exit on RADV that #2891 and the review of #2589 report.

  • RegistrationPreparePool::Close stops queueing and waits until no task is queued or running. Driver::stop calls it (CloseRegistrationPreparation) after joining the queue workers and before device.Reset(). The pool counts running tasks and destroys each task's captures before it reports idle.
  • A preparation submitted after the pool is closed, by a registration racing shutdown, runs on the caller's thread. This is the pool's existing fallback for when no thread could be created. RegisterShader holds its own shared_ptr to the device for the duration, so the spans stay valid. Throwing ProcessShutdown there instead would also be possible; happy to switch if preferred.
  • PrepareRegisteredInBackground submits through SubmitRegistrationPreparation, which the test also uses.

This is the drain Celegans12 asked for in the #2583 review ("Could the pool be included in shutdown").

Tested

Linux (Ubuntu 24.04, GCC 13.3), lavapipe (Mesa 25.2.8), main at 57f96fd. Full build with -DANYPS5_ENABLE_SPIRV_TOOLS=ON and the CI ctest invocation (--parallel 4 --timeout 120).

  • New 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 runs LibcRunShutdown_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 the Close call in Driver::stop ("shutdown returned while a registration preparation was still running"). It also fails when Close ignores running tasks, and when Submit ignores the closed pool. It passes 30 of 30 repeated runs.
  • 701 of 702 tests pass. The one failure, guest_avplayer (links only libSceAvPlayer and libc), 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_store is the only test over 30 s (50 s), as on main.
  • agc_driver_tests: 0 of 30 runs fail. It also did not crash on main here; the crash needs RADV or NVIDIA timing. @SleglJan and @adriadam10, could you rerun your loop (7/8 and 10/30 crashes on main) with this branch?
  • tools/check_conventions.py and tools/check_test_registration.py pass.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code), reviewed and tested by me
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813459253 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2909). Originally posted by [queeeef](https://github.com/queeeef) on 2026-10-10T18:23:29Z. --- ### What Fixes #2891. Background registration preparations (#2583) copy the device's `SpirvTarget`, whose capability and extension spans point into the device's shader profile. `Driver::stop` joined the queue workers and reset the device without waiting for the detached `RegistrationPreparePool`, so a preparation still queued or running read freed extension names in `RecompileCacheKey::appendInterface`. This is the `agc_driver` crash at exit on RADV that #2891 and the review of #2589 report. - `RegistrationPreparePool::Close` stops queueing and waits until no task is queued or running. `Driver::stop` calls it (`CloseRegistrationPreparation`) after joining the queue workers and before `device.Reset()`. The pool counts running tasks and destroys each task's captures before it reports idle. - A preparation submitted after the pool is closed, by a registration racing shutdown, runs on the caller's thread. This is the pool's existing fallback for when no thread could be created. `RegisterShader` holds its own `shared_ptr` to the device for the duration, so the spans stay valid. Throwing `ProcessShutdown` there instead would also be possible; happy to switch if preferred. - `PrepareRegisteredInBackground` submits through `SubmitRegistrationPreparation`, which the test also uses. This is the drain Celegans12 asked for in the #2583 review ("Could the pool be included in shutdown"). ### Tested Linux (Ubuntu 24.04, GCC 13.3), lavapipe (Mesa 25.2.8), main at 57f96fd. Full build with `-DANYPS5_ENABLE_SPIRV_TOOLS=ON` and the CI ctest invocation (`--parallel 4 --timeout 120`). - New `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 runs `LibcRunShutdown_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 the `Close` call in `Driver::stop` ("shutdown returned while a registration preparation was still running"). It also fails when `Close` ignores running tasks, and when `Submit` ignores the closed pool. It passes 30 of 30 repeated runs. - 701 of 702 tests pass. The one failure, `guest_avplayer` (links only `libSceAvPlayer` and `libc`), 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_store` is the only test over 30 s (50 s), as on main. - `agc_driver_tests`: 0 of 30 runs fail. It also did not crash on main here; the crash needs RADV or NVIDIA timing. @SleglJan and @adriadam10, could you rerun your loop (7/8 and 10/30 crashes on main) with this branch? - `tools/check_conventions.py` and `tools/check_test_registration.py` pass. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code), reviewed and tested by me
github-actions[bot] commented 2026-10-10 18:33:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T18:33:08Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6100835094 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2909#issuecomment-6100835094). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T18:33:08Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
github-actions[bot] commented 2026-10-10 18:33:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T18:33:53Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2856 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp L12, L91-92
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6100841929 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2909#issuecomment-6100841929). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T18:33:53Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2856 | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp` [L12](https://github.com/boykopovar/AnyPS5/blob/1476f76941a789690fd0f9c84c1cc929bb6fe262/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp#L12), [L91-92](https://github.com/boykopovar/AnyPS5/blob/1476f76941a789690fd0f9c84c1cc929bb6fe262/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp#L91-L92) | | |
SleglJan commented 2026-10-10 19:07:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-10T19:07:28Z.


@queeeef Rerun of the #2891 loop on RADV, as you asked.

Setup: Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Release with BUILD_TESTING=ON and ANYPS5_ENABLE_SPIRV_TOOLS=ON. RADV is Mesa 26.2.4 on the Ryzen 9 7950X3D's iGPU (gfx1036), selected with VK_DRIVER_FILES; the RTX 3080 runs NVIDIA 615.71.09. ctest -R '^agc_driver$' ran alone, one run at a time, in the same build directory: 8153d5ab was built and run first, then 57f96fd2 was rebuilt and run.

runs that fail
RADV, main 57f96fd2 (the commit's parent) 26 of 30
RADV, 8153d5ab 0 of 30
RTX 3080, 8153d5ab 0 of 10 (main was 0 of 8 there in #2891, so this only checks for regressions)

agc_driver_registration_prepare_shutdown passes 30 of 30.

Since the intake pause closed this PR: if you and the maintainers are OK with it, I can open it under my account with your commit unchanged and you as the author.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101142042 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2909#issuecomment-6101142042). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-10T19:07:28Z. --- @queeeef Rerun of the #2891 loop on RADV, as you asked. Setup: Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Release with `BUILD_TESTING=ON` and `ANYPS5_ENABLE_SPIRV_TOOLS=ON`. RADV is Mesa 26.2.4 on the Ryzen 9 7950X3D's iGPU (gfx1036), selected with `VK_DRIVER_FILES`; the RTX 3080 runs NVIDIA 615.71.09. `ctest -R '^agc_driver$'` ran alone, one run at a time, in the same build directory: 8153d5ab was built and run first, then 57f96fd2 was rebuilt and run. | | runs that fail | |---|---| | RADV, `main` 57f96fd2 (the commit's parent) | 26 of 30 | | RADV, 8153d5ab | 0 of 30 | | RTX 3080, 8153d5ab | 0 of 10 (`main` was 0 of 8 there in #2891, so this only checks for regressions) | `agc_driver_registration_prepare_shutdown` passes 30 of 30. Since the intake pause closed this PR: if you and the maintainers are OK with it, I can open it under my account with your commit unchanged and you as the author. AI-assisted: yes (Claude Code)
queeeef commented 2026-10-10 19:11:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by queeeef on 2026-10-10T19:11:45Z.


@queeeef Rerun of the #2891 loop on RADV, as you asked.

Setup: Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Release with BUILD_TESTING=ON and ANYPS5_ENABLE_SPIRV_TOOLS=ON. RADV is Mesa 26.2.4 on the Ryzen 9 7950X3D's iGPU (gfx1036), selected with VK_DRIVER_FILES; the RTX 3080 runs NVIDIA 615.71.09. ctest -R '^agc_driver$' ran alone, one run at a time, in the same build directory: 8153d5a was built and run first, then 57f96fd was rebuilt and run.
runs that fail
RADV, main 57f96fd (the commit's parent) 26 of 30
RADV, 8153d5a 0 of 30
RTX 3080, 8153d5a 0 of 10 (main was 0 of 8 there in #2891, so this only checks for regressions)

agc_driver_registration_prepare_shutdown passes 30 of 30.

Since the intake pause closed this PR: if you and the maintainers are OK with it, I can open it under my account with your commit unchanged and you as the author.

AI-assisted: yes (Claude Code)

I'm fine with that

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101179038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2909#issuecomment-6101179038). Originally posted by [queeeef](https://github.com/queeeef) on 2026-10-10T19:11:45Z. --- > @queeeef Rerun of the #2891 loop on RADV, as you asked. > > Setup: Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Release with `BUILD_TESTING=ON` and `ANYPS5_ENABLE_SPIRV_TOOLS=ON`. RADV is Mesa 26.2.4 on the Ryzen 9 7950X3D's iGPU (gfx1036), selected with `VK_DRIVER_FILES`; the RTX 3080 runs NVIDIA 615.71.09. `ctest -R '^agc_driver$'` ran alone, one run at a time, in the same build directory: [8153d5a](https://github.com/boykopovar/AnyPS5/commit/8153d5abc28c93faeebcf25d086d6ba4394f6e98) was built and run first, then [57f96fd](https://github.com/boykopovar/AnyPS5/commit/57f96fd2b36563e8380c603a92b1ef0d9d3a6aa4) was rebuilt and run. > runs that fail > RADV, `main` [57f96fd](https://github.com/boykopovar/AnyPS5/commit/57f96fd2b36563e8380c603a92b1ef0d9d3a6aa4) (the commit's parent) 26 of 30 > RADV, [8153d5a](https://github.com/boykopovar/AnyPS5/commit/8153d5abc28c93faeebcf25d086d6ba4394f6e98) 0 of 30 > RTX 3080, [8153d5a](https://github.com/boykopovar/AnyPS5/commit/8153d5abc28c93faeebcf25d086d6ba4394f6e98) 0 of 10 (`main` was 0 of 8 there in #2891, so this only checks for regressions) > > `agc_driver_registration_prepare_shutdown` passes 30 of 30. > > Since the intake pause closed this PR: if you and the maintainers are OK with it, I can open it under my account with your commit unchanged and you as the author. > > AI-assisted: yes (Claude Code) I'm fine with that

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2909
No description provided.