Skip to content

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

Open
BiladeiroSupremo wants to merge 1 commit into
boykopovar:mainfrom
BiladeiroSupremo:fix/agc-remember-failed-preparation
Open

BiladeiroSupremo wants to merge 1 commit into
boykopovar:mainfrom
BiladeiroSupremo:fix/agc-remember-failed-preparation

Conversation

@BiladeiroSupremo

Copy link
Copy Markdown
Contributor

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 6e27fc8 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 6e27fc8 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

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.
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6188 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6743 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 8592 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9563 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 11442 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 15499 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 18139 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 19181 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 20131 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 20153 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 21499 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 22082 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 22251 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 22328 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 22439 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 22628 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 23344 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 23553 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 24523 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 24906 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 25226 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 25279 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 25489 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 26165 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 26615 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp

@github-actions github-actions Bot added the agc libSceAgc* label Oct 18, 2026
@MaxLikesCode

Copy link
Copy Markdown
Contributor

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 (01b2bf1) merged into main ad502d7.

AI-assisted: yes (Claude Code)

@savvaniss

Copy link
Copy Markdown
Contributor

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:

AI-assisted: yes (Claude Code)

@adriadam10 adriadam10 self-assigned this Oct 19, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants