fix(agc): fail a template's proof on a released texture and audit it with the full walk #8047
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8047"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-19T18:44:46Z.
What
A cached
ShaderResources(a dispatch or draw template) is reused whenRevalidateproves it current. The fast proof checks each bound sampled texture's memory, keys and pending writes, but not whether the sampled lookup would still return the boundTexture. A template over an unchanged surface can therefore keep an object the lookup no longer returns (#8040). This PR makes two changes.fastRevalidateandfastRevalidateEachfail, with the new reasonreplaced texture, when a bound texture isReleased(). That is the flag #6492 sets when the sampled cache drops a texture something still holds. #6492 drops such templates at the nextResourceCache::Insert. Until that Insert,Findstill served them and their fast proof passed. With this change the full walk runs, its lookup returns the new entry, the proof fails, and the template is rebuilt. Cost: one atomic load per bound texture per proof.APS5_TEMPLATE_AUDIT_MSold (default 1000 ms,0turns it off) takes the full walk in place of the fast proof, with the new reasonaudit. This covers the case nothing marks: the lookup would now return something else for an unchanged surface, but no lookup has run, so no entry was replaced. For example, a snapshot's surface becomes host-imported and the lookup would view its storage image instead. The walk repeats the real lookups, a different answer fails the proof, the template is rebuilt, and the entry that lookup replaced is released, which then fails every other template binding it. An unchanged template passes the walk and goes back to the fast proof. The interval is a variable so the tests can use 250 ms, and it has a row indocs/dev/ENVIRONMENT.md.Fixes #8040
Tested
agc_driver_resource_cache_replaced_texture: a template over a write-watched snapshot takes the fast proof, the test clears the sampled cache without touching the memory, and the next proof has to fail. With main'sShaderResourcessources it fails on lavapipe witha template binding a texture whose cache entry left still proved current. With this change it passes.agc_driver_resource_cache_lookup_changed(250 ms interval, skips without host imports): past the interval, an unchanged template takes the full walk once, keeps its texture, and the next proof is fast again. Then the test host-imports the surface with no lookup in between. The proof past the interval has to fail, and the rebuild has to bind the storage view. With main's sources it fails on lavapipe witha proof past the audit interval did not take the full walk. With this change it passes.agc_driver_sampled_cache_budget_tests,agc_driver_recorder_tests,agc_driver_image_table_cache_bounds_testsandagc_driver_draw_cache_reuse_testson this branch (mainf52509acc), Linux, Release, GCC 16. On lavapipe (Mesa llvmpipe): 61 pass and 5 skip for missing capabilities. On an NVIDIA GeForce RTX 5070 Ti (driver 595.91.07,ANYPS5_REQUIRE_VULKAN=1): all 66 pass. The two new tests passed 20 of 20 repeats on lavapipe and 5 of 5 on the RTX 5070 Ti. The Khronos validation layer isn't installed on this machine, so I haven't done the validation-layer comparison against main yet.tools/check_conventions.py --base origin/mainpasses.ccb0c0926(before #6492) plus #6926, #6280, #6567 (merged since), the stencil-export workaround (never upstream), theImportWatchedpage-digest change from #7981, a guarded unit-shadow publish run in its wait-only mode (APS5_WB_GUARD_PUBLISH=wait, the same idea as #7984), and diagnostics that were off in these runs. The fix on that base was this audit plus an in-cache flag in place ofReleased(). That flag was the first version of the first change; #6492's flag marks the same erases.676269473with #6280, #6926, #7844 and the stencil workaround crawled in both runs that reached the level warm (median ratio 414 and 438, 5.92 and 5.55 presents per 10 s). The same set with onlylibSceAgcDriver.prxrebuilt with this fix (so the shader cache stayed warm): all three runs were normal from the first level window (median 213 to 214) at 8.84, 9.21 and 9.38 presents per 10 s, with no crash over the full 900 s. None of the five runs had a storage-cache eviction, so no run was rescued by one. Small sample: 2 base runs and 3 with the fix.Related
Released()and the lazy drop atInsert. This PR reuses the flag in the proof and adds the audit for the case where nothing is released.fastRevalidatenear these lines. It doesn't add an identity check, so the two don't overlap in purpose, but whichever lands second may need a rebase.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); this change adds no stubs.mdfiles or images added to the repository (attach them to this PR)AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T18:59:16Z.
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.
core/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cppdocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-19T19:13:44Z.
Results on a current-main base, with this PR's driver swapped in and nothing else changed.
Base:
main676269473plus #6280, #6926 and #7844, and a local stencil-export workaround that Demon's Souls needs on this NVIDIA box (not part of any PR). Demon's Souls (PPSA01341 v1.07), RTX 5070 Ti, NVIDIA 595.91.07, default texture cache budget, 900 s per run. The crawl measure is indexed indirect draws per (indirect + multi-indirect) draw per 10 s window: about 210 normally, about 410-440 in the crawl.No crashes in the three runs with the PR, and no storage cache evictions in any of the five, so none of them was rescued by an eviction. Small sample, but the base crawled in both runs that reached the level, and the PR runs were normal from the first level window.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T20:31:17Z.
Thanks for the current-main comparison. Two base runs crawled while the three PR runs were normal from the first level window, and none of the five had storage-cache evictions; that is useful evidence for the audit change, with the small sample size clearly stated. The description still says more current-main runs are queued. Please fold this table and its limitation into the Tested section so the PR summary reflects the new result.
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-19T21:42:04Z.
Done, the Tested section now has the five-run table result and the small-sample note.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T01:53:23Z.
Thanks for this. One small change to the new test, please.
resource-lookup-changedexits 77 with "skipped, the lookup-changed test requires host imports" and "skipped, the host import of the watched surface was refused". Neither text matches the device-limitation pattern intools/check_skips.py, so on any runner without host imports the job would fail instead of recording a skip. Linux CI's llvmpipe has host imports, so it doesn't show up today. Could you use the existing phrase "skipped, host imports are unavailable" for both? That one matches.Separately, the time-based audit (part 2) changes behaviour for every title, so it is going to the maintainer for a design call. The Released check (part 1) looks good.
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T01:56:42Z.
Windows runs of the tests (the PR ran them on Linux only), on NVIDIA and on an AMD iGPU.
Setup: Windows 11 26300, MinGW GCC 15.2 Release,
maineb7500680+ this PR (3c43ce33a, merges cleanly). GPUs: RTX 5070 Ti (NVIDIA 617.42) and Ryzen 5 9600X Radeon iGPU (ANYPS5_GPU=AMD, 32.0.21042.62), both withANYPS5_REQUIRE_VULKAN=1.agc_driver_resource_cache_replaced_textureandagc_driver_resource_cache_lookup_changedpassed 5 of 5 on each GPU. Neither skipped: host imports are available on both drivers.ShaderResources.cppandShaderResources.hppback to main and kept the tests. Both tests fail on both GPUs, with the messages the PR gives:a template binding a texture whose cache entry left still proved currentanda proof past the audit interval did not take the full walk.ctest -R "agc|shader|spirv|recomp"(825 tests, which include the sampled-cache-budget, recorder, image-table and draw-cache-reuse groups): on NVIDIA 2 failed (msaa_dcc_clear_4,pass_input_hazard); on AMD 5 failed (agc_trimmed_import,msaa_dcc_clear_4,layered_volume_vertex_no_gpl,draw_cache_reuse_off,stencil_replay_no_gpl). All of these also fail on main on this machine. No new failures.check_conventions.py --base origin/mainpasses.No title runs here, so the Demon's Souls result and the 2-3% audit cost are not re-measured. One small point from reading the code:
APS5_TEMPLATE_AUDIT_MSgoes throughstrtoull, so a value that is not a number reads as0and turns the audit off without a message.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T10:36:07Z.
I checked exact head
3c43ce33a074c1c6df0579e458a777f6c0224426:resource-lookup-changedstill prints “skipped, the lookup-changed test requires host imports” and “skipped, the host import of the watched surface was refused.” Neither matchesDEVICE_LIMITATIONintools/check_skips.py; the existing “skipped, host imports are unavailable” prefix does. Could you update both skip messages as requested so a host without import support is classified as a device skip?Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-20T15:12:27Z.
Both skip messages in
resource-lookup-changednow print the existing "skipped, host imports are unavailable", so a runner without host imports records a device skip (56ddbbbd0).I meant to rebase onto main, but the branch already had main merged in (
1cb64823e), so I added the commit on top of that merge instead of force-pushing over it. The branch merges cleanly with current main286908f91.On this head,
agc_driver_resource_cache_replaced_textureandagc_driver_resource_cache_lookup_changedpassed 3 of 3 each on lavapipe (llvmpipe) and on an RTX 5070 Ti (NVIDIA 595.91.07), both withANYPS5_REQUIRE_VULKAN=1. Neither skipped.check_skips.pyon the ctest junit andcheck_conventions.py --base origin/mainboth pass.Thanks @wachi35676 for the Windows runs on NVIDIA and AMD, and for the negative control.
AI-assisted: yes