fix(agc): prioritize demanded shader preparation #4404

Merged
eljackjoestar-cmd merged 1 commit from upstream-pr/4404 into main 2026-10-13 10:42:40 +00:00
eljackjoestar-cmd commented 2026-10-12 09:35:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eljackjoestar-cmd on 2026-10-12T09:35:15Z.


What

Lost Soul Aside (PPSA26358) can stop during startup with LastObjectNotReadyForFinishDestroy is NULL while a game task waits in AwaitRegisteredPreparation. The registration pool processes jobs in FIFO order, so a shader needed immediately can sit behind hundreds of unrelated preparation jobs even with a warm disk cache.

Tag registration jobs with their prepared-state identity and move the requested job to the front when a caller waits for it. Record demand before consulting the queue, so a request arriving between snapshot publication and job submission also receives priority. Existing running jobs complete normally; queued work is retained, each job executes once, and preparation failures still propagate. Shader instruction semantics are unchanged.

Tested

Windows 11, GCC 15.2 Release, RTX 5070 (12 GB, driver 617.14), Ryzen 7 7800X3D, 32 GB RAM. Branch based on main fc1f063f5; head 68c2b0f74.

  • Full Windows Release build passes on this isolated rebased branch. agc_driver_prepared_publication passes without skips in 0.66 s. The regressions verify that demanded work runs first without duplication, both after enqueue and when demand arrives before enqueue.
  • Earlier negative control (not repeated for this rebase): making only the demand-prioritization function a no-op fails the regression with demanded preparation waited behind background work or ran twice. Restoring it passes.
  • Earlier local title integration passed all ten focused prepared-publication/prepared-shader tests, including synchronous and deferred modes (about 5.2 seconds total).
  • Earlier integration comparison: before this change, both cold-cache and warm-cache integration launches hit the startup fatal; the warm run reported zero cache misses. Crash stacks show a game task waiting for preparation while all eight preparation workers run other shaders.
  • In that earlier comparison, with this change, two separate fresh-cache launches reached the title screen on their first attempt, then entered loading after two X presses. Cache logs reported zero hits. The trace observed demanded work at positions 497 and 946 in queues of over a thousand jobs.

No game run was repeated for this rebase. Earlier title tests used the integration described in #4401, including unmerged rendering/ancillary/IR-memory/direct-memory fixes. This branch contains only the scheduling change and its regression tests. Level loading still exhausted available commit headroom and the memory guard stopped the game; gameplay and complete compatibility are not claimed. Rendering and startup audio are separate from this scheduling fix.

tools/check_conventions.py --base origin/main and git diff --check pass. Linux, console hardware and collaborator-triggered full CI were not run.

Checklist

  • Based on current main; no other open PR implements this demand-priority behavior. Related #2589 moves static ABI preparation to the background pool; this change prioritizes existing registration jobs.
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA26358 #4401 (startup fatal)
  • AI-assisted: yes (OpenAI Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4827546778 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4404). Originally posted by [eljackjoestar-cmd](https://github.com/eljackjoestar-cmd) on 2026-10-12T09:35:15Z. --- ### What Lost Soul Aside (PPSA26358) can stop during startup with `LastObjectNotReadyForFinishDestroy is NULL` while a game task waits in `AwaitRegisteredPreparation`. The registration pool processes jobs in FIFO order, so a shader needed immediately can sit behind hundreds of unrelated preparation jobs even with a warm disk cache. Tag registration jobs with their prepared-state identity and move the requested job to the front when a caller waits for it. Record demand before consulting the queue, so a request arriving between snapshot publication and job submission also receives priority. Existing running jobs complete normally; queued work is retained, each job executes once, and preparation failures still propagate. Shader instruction semantics are unchanged. ### Tested Windows 11, GCC 15.2 Release, RTX 5070 (12 GB, driver 617.14), Ryzen 7 7800X3D, 32 GB RAM. Branch based on main `fc1f063f5`; head `68c2b0f74`. - Full Windows Release build passes on this isolated rebased branch. `agc_driver_prepared_publication` passes without skips in 0.66 s. The regressions verify that demanded work runs first without duplication, both after enqueue and when demand arrives before enqueue. - Earlier negative control (not repeated for this rebase): making only the demand-prioritization function a no-op fails the regression with `demanded preparation waited behind background work or ran twice`. Restoring it passes. - Earlier local title integration passed all ten focused prepared-publication/prepared-shader tests, including synchronous and deferred modes (about 5.2 seconds total). - Earlier integration comparison: before this change, both cold-cache and warm-cache integration launches hit the startup fatal; the warm run reported zero cache misses. Crash stacks show a game task waiting for preparation while all eight preparation workers run other shaders. - In that earlier comparison, with this change, two separate fresh-cache launches reached the title screen on their first attempt, then entered loading after two X presses. Cache logs reported zero hits. The trace observed demanded work at positions 497 and 946 in queues of over a thousand jobs. No game run was repeated for this rebase. Earlier title tests used the integration described in #4401, including unmerged rendering/ancillary/IR-memory/direct-memory fixes. This branch contains only the scheduling change and its regression tests. Level loading still exhausted available commit headroom and the memory guard stopped the game; gameplay and complete compatibility are not claimed. Rendering and startup audio are separate from this scheduling fix. `tools/check_conventions.py --base origin/main` and `git diff --check` pass. Linux, console hardware and collaborator-triggered full CI were not run. ### Checklist - [x] Based on current `main`; no other open PR implements this demand-priority behavior. Related #2589 moves static ABI preparation to the background pool; this change prioritizes existing registration jobs. - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA26358 #4401 (startup fatal) - [x] AI-assisted: yes (OpenAI Codex)
xXPBSXx commented 2026-10-13 06:56:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T06:56:32Z.


Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main 88107b7de together with thirteen other open GPU PRs (their own commits cherry-picked, no merge commits), so only the tests that belong to this PR say something about it:

  • tests/execution/PreparedPublication.cpp (agc_driver_prepared_publication): 3 of 3 runs passed.

Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140091526 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4404#issuecomment-6140091526). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T06:56:32Z. --- Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main `88107b7de` together with thirteen other open GPU PRs (their own commits cherry-picked, no merge commits), so only the tests that belong to this PR say something about it: - `tests/execution/PreparedPublication.cpp` (`agc_driver_prepared_publication`): 3 of 3 runs passed. Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed. AI-assisted (Claude Code).
fdfawef324 commented 2026-10-13 08:01:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T08:01:03Z.


Tested on Windows with Black Myth: Wukong (PPSA23226). This PR fixes a hang there.

Without it: the title never presents a frame. With a warm shader cache, queue 0 stops executing after 173 submissions, at about 167 s. The queue worker is parked in AwaitRegisteredPreparation, behind the background preparation pool. The render thread waits for the last submission's completion label. At about 325 s Unreal aborts: GameThread timed out waiting for RenderThread after 120.00 secs. A cold-cache run stops the same way, at 270 s.

With this PR: APS5_TRACE_PREPARATION_WAIT=1 shows the shaders the worker waited on had been queued at these positions:

  • 2507 of 2509
  • 955 of 956
  • 905 of 906
  • 13 of 2525

The title now presents frames, the first at 45.6 s. Queue 0 executes 343 submissions, and Unreal reaches level and game-mode setup. There is no GameThread timeout. It runs until an unrelated crash at 262 s.

agc_driver_prepared_publication passes, and it fails when PrioritizeRegistrationPreparation is emptied. The PR merged cleanly onto main 6d7b87370 and onto my integration branch. That branch also carries #4508 and #4960, which this title needs to start.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141074098 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4404#issuecomment-6141074098). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-13T08:01:03Z. --- Tested on Windows with Black Myth: Wukong (PPSA23226). This PR fixes a hang there. **Without it:** the title never presents a frame. With a warm shader cache, queue 0 stops executing after 173 submissions, at about 167 s. The queue worker is parked in `AwaitRegisteredPreparation`, behind the background preparation pool. The render thread waits for the last submission's completion label. At about 325 s Unreal aborts: `GameThread timed out waiting for RenderThread after 120.00 secs`. A cold-cache run stops the same way, at 270 s. **With this PR:** `APS5_TRACE_PREPARATION_WAIT=1` shows the shaders the worker waited on had been queued at these positions: - 2507 of 2509 - 955 of 956 - 905 of 906 - 13 of 2525 The title now presents frames, the first at 45.6 s. Queue 0 executes 343 submissions, and Unreal reaches level and game-mode setup. There is no GameThread timeout. It runs until an unrelated crash at 262 s. `agc_driver_prepared_publication` passes, and it fails when `PrioritizeRegistrationPreparation` is emptied. The PR merged cleanly onto `main` 6d7b87370 and onto my integration branch. That branch also carries #4508 and #4960, which this title needs to start.
github-actions[bot] commented 2026-10-13 08:07:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T08:07:25Z.


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
#5007 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp L110
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp L796, L804, L830, L838-839, L852
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141174551 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4404#issuecomment-6141174551). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T08:07:25Z. --- <!-- 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 | |---|---|---|---| | #5007 | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp` [L110](https://github.com/boykopovar/AnyPS5/blob/53aea1ff3416b7f23853e85a80eb5aa87856a820/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp#L110)<br>`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` [L796](https://github.com/boykopovar/AnyPS5/blob/53aea1ff3416b7f23853e85a80eb5aa87856a820/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp#L796), [L804](https://github.com/boykopovar/AnyPS5/blob/53aea1ff3416b7f23853e85a80eb5aa87856a820/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp#L804), [L830](https://github.com/boykopovar/AnyPS5/blob/53aea1ff3416b7f23853e85a80eb5aa87856a820/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp#L830), [L838-839](https://github.com/boykopovar/AnyPS5/blob/53aea1ff3416b7f23853e85a80eb5aa87856a820/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp#L838-L839), [L852](https://github.com/boykopovar/AnyPS5/blob/53aea1ff3416b7f23853e85a80eb5aa87856a820/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp#L852) | | |
eljackjoestar-cmd commented 2026-10-13 08:22:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eljackjoestar-cmd on 2026-10-13T08:22:53Z.


Rebased cleanly onto main fc1f063f5. Full Windows Release build passes, and agc_driver_prepared_publication passes without skips (0.66 s), including demanded work both before and after enqueue. Conventions and whitespace checks pass. The PR description separates this fresh rebase validation from the earlier integration/game and negative-control results; no new game run is claimed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141422300 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4404#issuecomment-6141422300). Originally posted by [eljackjoestar-cmd](https://github.com/eljackjoestar-cmd) on 2026-10-13T08:22:53Z. --- Rebased cleanly onto main `fc1f063f5`. Full Windows Release build passes, and `agc_driver_prepared_publication` passes without skips (0.66 s), including demanded work both before and after enqueue. Conventions and whitespace checks pass. The PR description separates this fresh rebase validation from the earlier integration/game and negative-control results; no new game run is claimed.
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!4404
No description provided.