perf(agc): keep a reused image table's cache entries while nothing was erased #15659

Closed
XatiX wants to merge 2 commits from upstream-pr/15659 into main
XatiX commented 2026-11-04 00:48:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XatiX on 2026-11-04T00:48:25Z.


What

When an image table is reused (FindReusedTable), CachedTableTextures first proves that every kept element is still in the sampled texture cache, with one findTexture hash lookup and one weak pointer lock per element. A table of about 14,000 entries repeats this on every draw that reuses it, even when nothing has left the cache since the previous reuse.

The reused table now keeps the cache iterators it proved, together with the cache's erasures count at that time. While the count is unchanged, the next reuse takes those iterators instead of looking every element up again. A sampled cache entry leaves the cache only through eraseTexture, which bumps erasures, and std::list iterators stay valid until their entry is erased, so the kept iterators still name the entries that were proved. findSampledEntry already uses the same count for its memo. The entries are still touched and their textures returned as before.

ImageTableReuseCounts reports the full lookups as entryLookups. In agc_driver_image_table_reuse, three dispatches of one table in one epoch now expect exactly one full lookup for the two reuses. On main this fails with a table reused twice while the texture cache dropped nothing looked its textures up again on the second reuse. The existing step for a kept table whose textures the cache dropped still covers the erasure path: with the erasures check removed, both agc_driver_image_table_reuse tests crash on stale iterators.

Tested

  • Windows 11 Pro 26300, NVIDIA GeForce RTX 5080, driver 617.42.
  • ctest -V -R "table|texture|storage|sampled|bindless" with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1, on the same machine. The table, texture and storage execution tests were built. Each log starts with its tested revision and these variables, and the build settings are attached.
    • This change (d0cffb2567): 117/117 passed.
    • Control: ShaderResources.cpp from main 1c8c0efc8c, with the new test. 115/117 passed; only agc_driver_image_table_reuse and agc_driver_image_table_reuse_draw_pipeline fail, both at the new check.
    • Neither log reports the layer as not found, and neither has a VUID- error. The same 4 tests skip in both (multisampled pass order and 3 packed16 storage formats). Logs attached.
  • Performance: PPSA18653 (Age of Mythology: Retold v01.043), first-run welcome screen, idle, 3840x2160.
    • Captured with APS5_TRACE_SECONDS=20:60 after a warm run, with no other trace or profile switch, and the log not redirected.
    • main does not reach this screen on its own. Both builds carry #15327, the opt-in clock change (#15656), #15563, #15611, #15655 and a local change. The base is 2e9401cb00, which is that stack with this commit reverted. The change is 462334bc76, the same stack with it. Traces attached.
base change
presents in the window 26 29
frame p50 / p90 2376 / 2489 ms 2101 / 2220 ms
Resources.Complete per frame 1163 ms 934 ms
{"commit":"2e9401cb0068","dirty":false,"env":{"APS5_FAIL_UNKNOWN_CLOCKS":"1","APS5_TRACE_SECONDS":"20:60"},"gpu":"NVIDIA GeForce RTX 5080","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"AMD Ryzen 7 9800X3D 8-Core Processor","cpu_threads":16,"memory_mib":32404,"title_id":"PPSA18653","title":"Age of Mythology: Retold","content_version":"01.043.000","resolution":"3840x2160","window":{"spec":"seconds 20:60","first_present":499,"ms":60433.357},"presents":26,"frame_ms":{"p50":2376.245,"p90":2488.916,"p99":2528.053,"max":2528.053},"gpu_busy_ms_per_present":261.139,"worker_busy_pct":{"queue worker 0x0":99.940},"top_phases_ms_per_frame":{"Driver.Packet":2322.631,"Driver.Packet.draw":2259.760,"Driver.Draw":2259.364,"Driver.Draw.draw_and_resource_release":1298.953,"Graphics.Draw":1273.410,"Graphics.Draw.draw_and_resource_release":1265.634,"Resources.Complete":1163.255,"Driver.Draw.shader_compile_and_link":942.973},"trace_dropped":false,"trace":"aps5-trace-2e9401cb0068-23068.json.gz"}
{"commit":"462334bc769d","dirty":false,"env":{"APS5_FAIL_UNKNOWN_CLOCKS":"1","APS5_TRACE_SECONDS":"20:60"},"gpu":"NVIDIA GeForce RTX 5080","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"AMD Ryzen 7 9800X3D 8-Core Processor","cpu_threads":16,"memory_mib":32404,"title_id":"PPSA18653","title":"Age of Mythology: Retold","content_version":"01.043.000","resolution":"3840x2160","window":{"spec":"seconds 20:60","first_present":503,"ms":60517.607},"presents":29,"frame_ms":{"p50":2100.817,"p90":2219.649,"p99":2263.247,"max":2263.247},"gpu_busy_ms_per_present":274.498,"worker_busy_pct":{"queue worker 0x0":99.935},"top_phases_ms_per_frame":{"Driver.Packet":2085.153,"Driver.Packet.draw":2021.594,"Driver.Draw":2021.203,"Driver.Draw.draw_and_resource_release":1065.119,"Graphics.Draw":1040.327,"Graphics.Draw.draw_and_resource_release":1032.766,"Driver.Draw.shader_compile_and_link":940.006,"Resources.Complete":934.589},"trace_dropped":false,"trace":"aps5-trace-462334bc769d-20744.json.gz"}
  • Other titles not measured.
  • tools/check_conventions.py passes. tools/pr_overlap.py --branch reports:
    • #15563 at ShaderResources.cpp L2070-2076: the loop condition here is element.rejected, and #15563 adds || element.live. Whichever merges second keeps both.
    • #10256 at ShaderResources.hpp L157, which adds an adjacent field. A merge keeps both.

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 in code; the measurement is stacked on #15327 and #15563
  • Fixes: none
  • Unblocks: none. It speeds up PPSA18653 #15328
  • GPUs tested: NVIDIA GeForce RTX 5080, driver 617.42, Windows 11 Pro 26300
  • AI-assisted: yes

aps5-trace-2e9401cb0068-23068.json.gz
aps5-trace-462334bc769d-20744.json.gz
table-cache-entries-build-settings.txt
table-cache-entries-change-d0cffb2567-ctest.log
table-cache-entries-main-1c8c0efc8c-control-ctest.log

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5146893173 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15659). Originally posted by [XatiX](https://github.com/XatiX) on 2026-11-04T00:48:25Z. --- ### What When an image table is reused (`FindReusedTable`), `CachedTableTextures` first proves that every kept element is still in the sampled texture cache, with one `findTexture` hash lookup and one weak pointer lock per element. A table of about 14,000 entries repeats this on every draw that reuses it, even when nothing has left the cache since the previous reuse. The reused table now keeps the cache iterators it proved, together with the cache's `erasures` count at that time. While the count is unchanged, the next reuse takes those iterators instead of looking every element up again. A sampled cache entry leaves the cache only through `eraseTexture`, which bumps `erasures`, and `std::list` iterators stay valid until their entry is erased, so the kept iterators still name the entries that were proved. `findSampledEntry` already uses the same count for its memo. The entries are still touched and their textures returned as before. `ImageTableReuseCounts` reports the full lookups as `entryLookups`. In `agc_driver_image_table_reuse`, three dispatches of one table in one epoch now expect exactly one full lookup for the two reuses. On `main` this fails with `a table reused twice while the texture cache dropped nothing looked its textures up again on the second reuse`. The existing step for a kept table whose textures the cache dropped still covers the erasure path: with the `erasures` check removed, both `agc_driver_image_table_reuse` tests crash on stale iterators. ### Tested - Windows 11 Pro 26300, NVIDIA GeForce RTX 5080, driver 617.42. - `ctest -V -R "table|texture|storage|sampled|bindless"` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`, on the same machine. The table, texture and storage execution tests were built. Each log starts with its tested revision and these variables, and the build settings are attached. - This change (`d0cffb2567`): 117/117 passed. - Control: `ShaderResources.cpp` from `main` `1c8c0efc8c`, with the new test. 115/117 passed; only `agc_driver_image_table_reuse` and `agc_driver_image_table_reuse_draw_pipeline` fail, both at the new check. - Neither log reports the layer as not found, and neither has a `VUID-` error. The same 4 tests skip in both (multisampled pass order and 3 packed16 storage formats). Logs attached. - Performance: PPSA18653 (Age of Mythology: Retold v01.043), first-run welcome screen, idle, 3840x2160. - Captured with `APS5_TRACE_SECONDS=20:60` after a warm run, with no other trace or profile switch, and the log not redirected. - `main` does not reach this screen on its own. Both builds carry #15327, the opt-in clock change (#15656), #15563, #15611, #15655 and a local change. The base is `2e9401cb00`, which is that stack with this commit reverted. The change is `462334bc76`, the same stack with it. Traces attached. | | base | change | |---|---|---| | presents in the window | 26 | 29 | | frame p50 / p90 | 2376 / 2489 ms | 2101 / 2220 ms | | `Resources.Complete` per frame | 1163 ms | 934 ms | ```json {"commit":"2e9401cb0068","dirty":false,"env":{"APS5_FAIL_UNKNOWN_CLOCKS":"1","APS5_TRACE_SECONDS":"20:60"},"gpu":"NVIDIA GeForce RTX 5080","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"AMD Ryzen 7 9800X3D 8-Core Processor","cpu_threads":16,"memory_mib":32404,"title_id":"PPSA18653","title":"Age of Mythology: Retold","content_version":"01.043.000","resolution":"3840x2160","window":{"spec":"seconds 20:60","first_present":499,"ms":60433.357},"presents":26,"frame_ms":{"p50":2376.245,"p90":2488.916,"p99":2528.053,"max":2528.053},"gpu_busy_ms_per_present":261.139,"worker_busy_pct":{"queue worker 0x0":99.940},"top_phases_ms_per_frame":{"Driver.Packet":2322.631,"Driver.Packet.draw":2259.760,"Driver.Draw":2259.364,"Driver.Draw.draw_and_resource_release":1298.953,"Graphics.Draw":1273.410,"Graphics.Draw.draw_and_resource_release":1265.634,"Resources.Complete":1163.255,"Driver.Draw.shader_compile_and_link":942.973},"trace_dropped":false,"trace":"aps5-trace-2e9401cb0068-23068.json.gz"} ``` ```json {"commit":"462334bc769d","dirty":false,"env":{"APS5_FAIL_UNKNOWN_CLOCKS":"1","APS5_TRACE_SECONDS":"20:60"},"gpu":"NVIDIA GeForce RTX 5080","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"AMD Ryzen 7 9800X3D 8-Core Processor","cpu_threads":16,"memory_mib":32404,"title_id":"PPSA18653","title":"Age of Mythology: Retold","content_version":"01.043.000","resolution":"3840x2160","window":{"spec":"seconds 20:60","first_present":503,"ms":60517.607},"presents":29,"frame_ms":{"p50":2100.817,"p90":2219.649,"p99":2263.247,"max":2263.247},"gpu_busy_ms_per_present":274.498,"worker_busy_pct":{"queue worker 0x0":99.935},"top_phases_ms_per_frame":{"Driver.Packet":2085.153,"Driver.Packet.draw":2021.594,"Driver.Draw":2021.203,"Driver.Draw.draw_and_resource_release":1065.119,"Graphics.Draw":1040.327,"Graphics.Draw.draw_and_resource_release":1032.766,"Driver.Draw.shader_compile_and_link":940.006,"Resources.Complete":934.589},"trace_dropped":false,"trace":"aps5-trace-462334bc769d-20744.json.gz"} ``` - Other titles not measured. - `tools/check_conventions.py` passes. `tools/pr_overlap.py --branch` reports: - #15563 at `ShaderResources.cpp` L2070-2076: the loop condition here is `element.rejected`, and #15563 adds `|| element.live`. Whichever merges second keeps both. - #10256 at `ShaderResources.hpp` L157, which adds an adjacent field. A merge keeps both. ### 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](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 in code; the measurement is stacked on #15327 and #15563 - [x] Fixes: none - [x] Unblocks: none. It speeds up PPSA18653 #15328 - [x] GPUs tested: NVIDIA GeForce RTX 5080, driver 617.42, Windows 11 Pro 26300 - [x] AI-assisted: yes [aps5-trace-2e9401cb0068-23068.json.gz](https://github.com/user-attachments/files/34346378/aps5-trace-2e9401cb0068-23068.json.gz) [aps5-trace-462334bc769d-20744.json.gz](https://github.com/user-attachments/files/34346379/aps5-trace-462334bc769d-20744.json.gz) [table-cache-entries-build-settings.txt](https://github.com/user-attachments/files/34346380/table-cache-entries-build-settings.txt) [table-cache-entries-change-d0cffb2567-ctest.log](https://github.com/user-attachments/files/34346381/table-cache-entries-change-d0cffb2567-ctest.log) [table-cache-entries-main-1c8c0efc8c-control-ctest.log](https://github.com/user-attachments/files/34346382/table-cache-entries-main-1c8c0efc8c-control-ctest.log) 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull request closed

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!15659
No description provided.