fix(agc): keep hundreds of raw shader snapshots cached #10174

Merged
ntamas94 merged 1 commit from upstream-pr/10174 into main 2026-10-26 05:26:36 +00:00
ntamas94 commented 2026-10-23 12:02:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-23T12:02:19Z.


What

ReadRawShader caches snapshots of unregistered shader programs and evicts the least recently used one past 64 entries or 8 MiB. Each snapshot owns its prepared artifacts (snapshot.prepared), so an evicted program loses them, and its next use reads a new snapshot and prepares it again (was not registered; preparing its artifact at first use).

PS4 titles never register their shaders, so every program they draw with goes through this cache. Knowledge is Power (CUSA09558) uses 383 programs in its menus: with 64 entries the cache cycled through all of them and prepared them 341 136 times in a 240 s run, about 890 per program.

This raises the limit to 4096 entries or 64 MiB. The existing eviction check in tests/Submit.cpp now reads 400 more programs and requires the first one to keep its snapshot, then reads past 4096 and requires it to be evicted. The new check fails with the old limit.

Related open PRs, neither of which changes the limit:

  • #10103 keeps a held raw draw decode valid when this cache evicts its snapshots. Its regression churns 80 other snapshots to force an eviction and only prints whether one happened, so with this limit it still passes but no longer evicts; it would need more than 4096 programs to. Both merge cleanly with this branch.
  • #9899 moves ReadRawShader's range check and memoizes user-data callee links. It merges cleanly with this branch.

Tested

Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 2080, driver 617.14.

  • agc_driver, agc_driver_readonly_resummarize, agc_driver_eop_interrupts, agc_driver_small_copy_sync on main (8eb8e39207) and on this branch with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1 and ctest -V: all pass on both, neither log reports was not found but was requested by env var VK_INSTANCE_LAYERS, and neither has any VUID- error.
  • With the limit set back to 64, agc_driver fails with raw shader cache evicted a program while a title used only 401.
  • Knowledge is Power (CUSA09558), intro, then Cross every 15 s through APS5_PAD_INPUT_FILE into the menus, 240 s, with and without this change. It needs open PRs that main does not have yet (see #9718), so both runs used the same local stack and only libSceAgcDriver.prx differed:
before after
preparing its artifact at first use/dispatch lines 341 136 383
distinct programs 383 383
presents per 10 s in the menus (APS5_PROFILE_GPU) about 120 about 147

These are profile-log numbers from that stack, not a performance trace of main, so this is not a perf claim. One of two runs with the change stopped presenting after about 30 s (no crash event, ended by the timeout); the repeat ran the full 240 s. I don't know the cause or whether the run without the change can do the same.

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 under Silent stubs in their library's technical debt file
  • 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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none (measured on CUSA09558's menus; #9718 is the thread of Knowledge is Power: Decades, CUSA12435, not measured there yet)
  • GPUs tested: NVIDIA GeForce RTX 2080, driver 617.14, Windows 11 Pro 10.0.26200
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4982414285 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10174). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-23T12:02:19Z. --- ### What `ReadRawShader` caches snapshots of unregistered shader programs and evicts the least recently used one past 64 entries or 8 MiB. Each snapshot owns its prepared artifacts (`snapshot.prepared`), so an evicted program loses them, and its next use reads a new snapshot and prepares it again (`was not registered; preparing its artifact at first use`). PS4 titles never register their shaders, so every program they draw with goes through this cache. Knowledge is Power (CUSA09558) uses 383 programs in its menus: with 64 entries the cache cycled through all of them and prepared them 341 136 times in a 240 s run, about 890 per program. This raises the limit to 4096 entries or 64 MiB. The existing eviction check in `tests/Submit.cpp` now reads 400 more programs and requires the first one to keep its snapshot, then reads past 4096 and requires it to be evicted. The new check fails with the old limit. Related open PRs, neither of which changes the limit: - #10103 keeps a held raw draw decode valid when this cache evicts its snapshots. Its regression churns 80 other snapshots to force an eviction and only prints whether one happened, so with this limit it still passes but no longer evicts; it would need more than 4096 programs to. Both merge cleanly with this branch. - #9899 moves `ReadRawShader`'s range check and memoizes user-data callee links. It merges cleanly with this branch. ### Tested Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 2080, driver 617.14. - `agc_driver`, `agc_driver_readonly_resummarize`, `agc_driver_eop_interrupts`, `agc_driver_small_copy_sync` on `main` (8eb8e39207) and on this branch with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1`, `ANYPS5_REQUIRE_VULKAN=1` and `ctest -V`: all pass on both, neither log reports `was not found but was requested by env var VK_INSTANCE_LAYERS`, and neither has any `VUID-` error. - With the limit set back to 64, `agc_driver` fails with `raw shader cache evicted a program while a title used only 401`. - Knowledge is Power (CUSA09558), intro, then Cross every 15 s through `APS5_PAD_INPUT_FILE` into the menus, 240 s, with and without this change. It needs open PRs that `main` does not have yet (see #9718), so both runs used the same local stack and only `libSceAgcDriver.prx` differed: | | before | after | |---|---|---| | `preparing its artifact at first use/dispatch` lines | 341 136 | 383 | | distinct programs | 383 | 383 | | presents per 10 s in the menus (`APS5_PROFILE_GPU`) | about 120 | about 147 | These are profile-log numbers from that stack, not a performance trace of `main`, so this is not a `perf` claim. One of two runs with the change stopped presenting after about 30 s (no crash event, ended by the timeout); the repeat ran the full 240 s. I don't know the cause or whether the run without the change can do the same. ### 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 under Silent stubs in their library's technical debt file - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none (measured on CUSA09558's menus; #9718 is the thread of Knowledge is Power: Decades, CUSA12435, not measured there yet) - [x] GPUs tested: NVIDIA GeForce RTX 2080, driver 617.14, Windows 11 Pro 10.0.26200 - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 12:14:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T12:14:25Z.

Review: APPROVED


Reviewed exact head e284395f586dda6808250210cb225aef4df8021e. The snapshot list is refreshed on equal-content hits, so the raised limits preserve the existing LRU behavior; the updated test checks both retention through 401 programs and eviction after crossing 4096. The author also reports controlled before/after Windows GPU runs and that the new test fails when the old 64-entry limit is restored. Eligibility, conventions, intake, labels and report pass, while hosted product jobs are skipped by path policy. I commented separately on #10103 because its 80-entry churn will no longer force eviction after this limit change; that is a coverage interaction for the stacked change, not a correctness blocker in this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5628055984 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10174#pullrequestreview-5628055984). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T12:14:25Z. **Review:** APPROVED --- Reviewed exact head `e284395f586dda6808250210cb225aef4df8021e`. The snapshot list is refreshed on equal-content hits, so the raised limits preserve the existing LRU behavior; the updated test checks both retention through 401 programs and eviction after crossing 4096. The author also reports controlled before/after Windows GPU runs and that the new test fails when the old 64-entry limit is restored. Eligibility, conventions, intake, labels and report pass, while hosted product jobs are skipped by path policy. I commented separately on #10103 because its 80-entry churn will no longer force eviction after this limit change; that is a coverage interaction for the stacked change, not a correctness blocker in this PR.
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!10174
No description provided.