fix(agc): remember shader variants that failed to prepare at use #7682

Open
BiladeiroSupremo wants to merge 1 commit from upstream-pr/7682 into main
BiladeiroSupremo commented 2026-10-18 22:42:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BiladeiroSupremo on 2026-10-18T22:42:25Z.


A draw or dispatch whose variant has no prepared entry prepares it in place. When that failed, nothing was kept, so every later draw of the variant ran the whole recompile again on the draw thread and failed the same way. The failure is now kept per variant (prepared state, code offset, prepared key and code); those draws throw the same error at once, and the variant is prepared again after a minute.

What

A draw or dispatch whose shader variant has no prepared entry prepares it in place (InvocationFor in ShaderRegistry.cpp). When that preparation threw, nothing was kept, so every later draw of the same variant ran the whole recompile again on the draw thread and failed the same way, every frame.

The failure is now kept per variant (prepared state, code offset, prepared key and code). Draws of that variant throw the same error at once (the caller skips them as before), and the variant is prepared again after a minute.

PR #7644 edits the same lines (ShaderRegistry.cpp L729-730) for its opt-in lazy ABI preparation; the two changes are independent and only overlap textually.

Tested

Windows 11 Pro 10.0.26300, MinGW-w64 GCC Release build of this branch on main 6e27fc8f0 with -DBUILD_TESTING=ON, AMD Radeon RX 9070: full ctest 1501 of 1513 passed. The 12 failures do not come from this change, it's because my windows profile has my name with ' on a letter: 9 fail the same way on main 6e27fc8f0 on this machine (select_tests, check_compile, windows_import_modules, agc_driver_division_output_modifiers, agc_driver_division_result_modifiers, agc_driver_f64_conversions, agc_driver_f64_transcendental, agc_driver_quad_pixel_mask, agc_driver_layered_volume_vertex_no_gpl), and 3 came from another change in the same test tree; on this branch alone agc_write_tracking, agc_driver_partially_resident_*, agc_driver_prepared_*, agc_shader_memory and guest_memory (31 tests) pass.

Seen on a downstream fork with the same code path: in PPSA03671 two gameplay shaders the recompiler rejects ("bindless storage image tables are unsupported") were recompiled and failed again ~170 times each in one session; with the change each failure is prepared once a minute at most.

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
  • GPUs tested: AMD Radeon RX 9070, driver 32.0.32015.2008, Windows 11 Pro 10.0.26300
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4913467944 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7682). Originally posted by [BiladeiroSupremo](https://github.com/BiladeiroSupremo) on 2026-10-18T22:42:25Z. --- A draw or dispatch whose variant has no prepared entry prepares it in place. When that failed, nothing was kept, so every later draw of the variant ran the whole recompile again on the draw thread and failed the same way. The failure is now kept per variant (prepared state, code offset, prepared key and code); those draws throw the same error at once, and the variant is prepared again after a minute. ### What A draw or dispatch whose shader variant has no prepared entry prepares it in place (`InvocationFor` in `ShaderRegistry.cpp`). When that preparation threw, nothing was kept, so every later draw of the same variant ran the whole recompile again on the draw thread and failed the same way, every frame. The failure is now kept per variant (prepared state, code offset, prepared key and code). Draws of that variant throw the same error at once (the caller skips them as before), and the variant is prepared again after a minute. PR #7644 edits the same lines (`ShaderRegistry.cpp` L729-730) for its opt-in lazy ABI preparation; the two changes are independent and only overlap textually. ### Tested Windows 11 Pro 10.0.26300, MinGW-w64 GCC Release build of this branch on `main` 6e27fc8f0 with `-DBUILD_TESTING=ON`, AMD Radeon RX 9070: full `ctest` 1501 of 1513 passed. The 12 failures do not come from this change, it's because my windows profile has my name with ' on a letter: 9 fail the same way on `main` 6e27fc8f0 on this machine (`select_tests`, `check_compile`, `windows_import_modules`, `agc_driver_division_output_modifiers`, `agc_driver_division_result_modifiers`, `agc_driver_f64_conversions`, `agc_driver_f64_transcendental`, `agc_driver_quad_pixel_mask`, `agc_driver_layered_volume_vertex_no_gpl`), and 3 came from another change in the same test tree; on this branch alone `agc_write_tracking`, `agc_driver_partially_resident_*`, `agc_driver_prepared_*`, `agc_shader_memory` and `guest_memory` (31 tests) pass. Seen on a downstream fork with the same code path: in PPSA03671 two gameplay shaders the recompiler rejects ("bindless storage image tables are unsupported") were recompiled and failed again ~170 times each in one session; with the change each failure is prepared once a minute at most. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/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 - [x] GPUs tested: AMD Radeon RX 9070, driver 32.0.32015.2008, Windows 11 Pro 10.0.26300 - [x] AI-assisted: yes
MaxLikesCode commented 2026-10-19 03:47:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MaxLikesCode on 2026-10-19T03:47:53Z.


A clean run on a second vendor, since 12 tests failed on your machine for path reasons: NVIDIA GeForce RTX 4090, driver 617.42, Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON with every execution test built. This head (01b2bf104) merged into main ad502d717.

  • The tests that failed on your machine because of the apostrophe in the profile path pass here: select_tests, check_compile, windows_import_modules, agc_driver_division_output_modifiers, agc_driver_division_result_modifiers, agc_driver_f64_conversions, agc_driver_f64_transcendental, agc_driver_quad_pixel_mask, agc_driver_layered_volume_vertex and agc_driver_layered_volume_vertex_no_gpl.
  • The 975 of 1553 tests tools/select_tests.py selects: 957 pass, 15 skip and 3 fail. The 3 failures are the ones main has on this GPU without this PR: agc_driver_bda_device (#7584), agc_driver_image_table_reuse (#7710) and agc_driver_pixel_lds (#7708). tools/check_skips.py --job windows accepts the skips.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6259219660 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7682#issuecomment-6259219660). Originally posted by [MaxLikesCode](https://github.com/MaxLikesCode) on 2026-10-19T03:47:53Z. --- A clean run on a second vendor, since 12 tests failed on your machine for path reasons: NVIDIA GeForce RTX 4090, driver 617.42, Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON` with every execution test built. This head (01b2bf104) merged into `main` ad502d717. - The tests that failed on your machine because of the apostrophe in the profile path pass here: `select_tests`, `check_compile`, `windows_import_modules`, `agc_driver_division_output_modifiers`, `agc_driver_division_result_modifiers`, `agc_driver_f64_conversions`, `agc_driver_f64_transcendental`, `agc_driver_quad_pixel_mask`, `agc_driver_layered_volume_vertex` and `agc_driver_layered_volume_vertex_no_gpl`. - The 975 of 1553 tests `tools/select_tests.py` selects: 957 pass, 15 skip and 3 fail. The 3 failures are the ones `main` has on this GPU without this PR: `agc_driver_bda_device` (#7584), `agc_driver_image_table_reuse` (#7710) and `agc_driver_pixel_lds` (#7708). `tools/check_skips.py --job windows` accepts the skips. AI-assisted: yes (Claude Code)
savvaniss commented 2026-10-19 09:32:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T09:32:09Z.


Windows regression check on an Intel UHD 770 and an AMD RX 9070 XT: no new failures in the full CTest results.

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, with VkCache emptied first. This head 01b2bf104 merged into main 6b8228b2b.

This PR adds no test, so I ran full CTest (--parallel 4) with it merged:

  • UHD 770: the same 7 failures as main alone, out of 1605. These are the image-table tests that #6647 addresses and agc_driver_sample_multisample_target (#6957).
  • RX 9070 XT: all 1602 pass, as they do on main alone, with no device-fault lines. I left out the three APS5_NO_GPL tests (agc_driver_draw_cache_reuse_off, agc_driver_stencil_replay_no_gpl, agc_driver_layered_volume_vertex_no_gpl). On main they fault the GPU in a parallel AMD run on Windows (#7809, fixed by #7828).

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6264114860 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7682#issuecomment-6264114860). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-19T09:32:09Z. --- Windows regression check on an Intel UHD 770 and an AMD RX 9070 XT: no new failures in the full CTest results. Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built. Intel UHD Graphics 770 (`8086:a780`), driver 32.0.101.7088. AMD Radeon RX 9070 XT (`1002:7550`), driver 32.0.31041.1004, with `VkCache` emptied first. This head `01b2bf104` merged into `main` `6b8228b2b`. This PR adds no test, so I ran full CTest (`--parallel 4`) with it merged: - UHD 770: the same 7 failures as `main` alone, out of 1605. These are the image-table tests that #6647 addresses and `agc_driver_sample_multisample_target` (#6957). - RX 9070 XT: all 1602 pass, as they do on `main` alone, with no `device-fault` lines. I left out the three `APS5_NO_GPL` tests (`agc_driver_draw_cache_reuse_off`, `agc_driver_stencil_replay_no_gpl`, `agc_driver_layered_volume_vertex_no_gpl`). On `main` they fault the GPU in a parallel AMD run on Windows (#7809, fixed by #7828). AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-19 16:57:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T16:57:37Z.

Review: CHANGES_REQUESTED


Thanks, the idea is sound and the callers all catch std::exception, so rethrowing a cached error is fine. Points to address:

  • ShaderRegistry.cpp:750-753: failures has no bound. An entry is only erased when the same identity is drawn again after 60 s, and the identity depends on guest data (code, key, code offset), so a title that keeps producing distinct failing variants grows it for the whole session. Please cap it (entries, derived sensibly) and drop expired entries when inserting, and log once when the cap is hit.
  • ShaderRegistry.cpp:760-769: the identity mixes the raw PreparedShaders* address, which can be reused after the object is freed, and is only a 64-bit hash: a collision (or a reused address) makes an unrelated variant throw a stale error. Key the map on the real data or keep the entry inside PreparedShaders so it dies with it.
  • No test: the PR adds none. A test that prepares a failing variant twice and shows the second call does not recompile (and that it retries after the interval, e.g. with the interval injectable) is needed so the behaviour stays pinned.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5574914086 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7682#pullrequestreview-5574914086). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T16:57:37Z. **Review:** CHANGES_REQUESTED --- Thanks, the idea is sound and the callers all catch `std::exception`, so rethrowing a cached error is fine. Points to address: - `ShaderRegistry.cpp:750-753`: `failures` has no bound. An entry is only erased when the same identity is drawn again after 60 s, and the identity depends on guest data (code, key, code offset), so a title that keeps producing distinct failing variants grows it for the whole session. Please cap it (entries, derived sensibly) and drop expired entries when inserting, and log once when the cap is hit. - `ShaderRegistry.cpp:760-769`: the identity mixes the raw `PreparedShaders*` address, which can be reused after the object is freed, and is only a 64-bit hash: a collision (or a reused address) makes an unrelated variant throw a stale error. Key the map on the real data or keep the entry inside `PreparedShaders` so it dies with it. - No test: the PR adds none. A test that prepares a failing variant twice and shows the second call does not recompile (and that it retries after the interval, e.g. with the interval injectable) is needed so the behaviour stays pinned.
adriadam10 commented 2026-10-24 02:23:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T02:23:48Z.

Review: CHANGES_REQUESTED


Thanks for the update. This is still changes, the head also conflicts with main now.

  • Main already remembers failed preparations: core/shader/recompiler/Recompiler.cpp keeps planFailure (rethrown in getSource) and emissionFailures, and APS5_NO_FAILURE_MEMO=1 turns it off. The string "bindless storage image tables are unsupported" from the PPSA03671 log does not exist on main, so the repeated recompile you saw is from the fork. Please show a failing variant on main that still goes through a full recompile on every draw (a test that prepares it twice and counts the work), otherwise this duplicates the existing memo.
  • If that case exists, the state belongs in PreparedShaders (ShaderRegistry.hpp): InvocationFor now runs under snapshot.prepared->mutex, so the global map and its mutex are not needed, and the entry dies with the shaders instead of keying on a reusable PreparedShaders* address plus a 64-bit hash. Compare codeOffset, the prepared key and the code word for word.
  • Bound it (a small cap per PreparedShaders, drop expired entries when inserting) and cover it with a test: second call does not prepare again, and it prepares again after the retry interval (make the interval injectable).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636409776 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7682#pullrequestreview-5636409776). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-24T02:23:48Z. **Review:** CHANGES_REQUESTED --- Thanks for the update. This is still `changes`, the head also conflicts with `main` now. - Main already remembers failed preparations: `core/shader/recompiler/Recompiler.cpp` keeps `planFailure` (rethrown in `getSource`) and `emissionFailures`, and `APS5_NO_FAILURE_MEMO=1` turns it off. The string "bindless storage image tables are unsupported" from the PPSA03671 log does not exist on `main`, so the repeated recompile you saw is from the fork. Please show a failing variant on `main` that still goes through a full recompile on every draw (a test that prepares it twice and counts the work), otherwise this duplicates the existing memo. - If that case exists, the state belongs in `PreparedShaders` (`ShaderRegistry.hpp`): `InvocationFor` now runs under `snapshot.prepared->mutex`, so the global map and its mutex are not needed, and the entry dies with the shaders instead of keying on a reusable `PreparedShaders*` address plus a 64-bit hash. Compare `codeOffset`, the prepared key and the code word for word. - Bound it (a small cap per `PreparedShaders`, drop expired entries when inserting) and cover it with a test: second call does not prepare again, and it prepares again after the retry interval (make the interval injectable).
MarcZX10 commented 2026-11-23 02:37:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:37:46Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change based on the code inspected; the review is incomplete because the prepared check output and full repository context were unavailable.

What I ran

Reviewed head 01b2bf1045c0cd73ba2f26b27ab9a02a7a0489bd using repo_read.py to read the prepared bundle and targeted source ranges. No build or tests were run.

Results

Check Result Note
Diff and source review passed One changed source file read
Build and tests not run No commands available
Negative control not run Not available in this review

Findings

Blocking

None found in the inspected code.

Non-blocking

None.

Not verified

The full changed source file was not read; only the added code and nearby preparation flow were inspected. No tests, build, concurrency stress, or runtime behavior were verified. The author-reported test results in the PR description were not independently run.

Files read: review/description.md, review/commits.md, review/manifest.json, review/diff.patch, core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp (selected ranges), and core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp (selected range). The prepared review bundle listed only ShaderRegistry.cpp as reviewed; no excluded-file manifest was available through the reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015966274 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7682#pullrequestreview-6015966274). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T02:37:46Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change based on the code inspected; the review is incomplete because the prepared check output and full repository context were unavailable. ## What I ran Reviewed head `01b2bf1045c0cd73ba2f26b27ab9a02a7a0489bd` using `repo_read.py` to read the prepared bundle and targeted source ranges. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and source review | passed | One changed source file read | | Build and tests | not run | No commands available | | Negative control | not run | Not available in this review | ## Findings ### Blocking None found in the inspected code. ### Non-blocking None. ## Not verified The full changed source file was not read; only the added code and nearby preparation flow were inspected. No tests, build, concurrency stress, or runtime behavior were verified. The author-reported test results in the PR description were not independently run. Files read: `review/description.md`, `review/commits.md`, `review/manifest.json`, `review/diff.patch`, `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` (selected ranges), and `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp` (selected range). The prepared review bundle listed only `ShaderRegistry.cpp` as reviewed; no excluded-file manifest was available through the reader. ## To get this to a good state Nothing is required.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/7682:upstream-pr/7682'
git switch 'upstream-pr/7682'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/7682'
git switch 'upstream-pr/7682'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/7682'
git switch 'upstream-pr/7682'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/7682'
git switch 'main'
git merge --squash 'upstream-pr/7682'
git switch 'main'
git merge --ff-only 'upstream-pr/7682'
git switch 'main'
git merge 'upstream-pr/7682'
git push origin 'main'
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!7682
No description provided.