perf(shader): reuse an unwritten image table snapshot read through a pointer #15655

Merged
XatiX merged 1 commit from upstream-pr/15655 into main 2026-11-04 19:18:38 +00:00
XatiX commented 2026-11-04 00:11:10 +00:00 (Migrated from github.com)

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


What

An image table snapshot is remembered per column (ColumnMemos). It is reused without reading the table again only when it carries a write stamp that the write watch still vouches for. Otherwise each capture reads and compares every record of the table. In two cases a column never got a usable stamp:

  • The column is addressed through a 64-bit pointer (column.address). Only base-addressed columns took a stamp before the compare.
  • The capture had already read pages of the table range before stamping. For example, the root page holds the SRT and the start of the table. ShaderMemory::stampWrites refused any range with a page the capture had fetched, because a write between that fetch and the collect would go unseen.

Now:

  • A pointer-addressed column stamps its remembered read range before the compare.
  • When the caller passed an explicit span query (pendingSpan, which the driver always does), stampWrites takes the stamp after the collect and then checks each page the capture already read: every valid word must still equal guest memory. A page read word by word, a page that differs, or a span with a pending GPU write still refuses the stamp. A write between the fetch and the collect therefore shows up as a difference.
  • Without an explicit span query, which only some tests construct, stampWrites refuses as before.

PPSA18653 reads its bindless table (about 2 MiB) through a pointer, from the page that holds the root. Every draw compared the whole table, about 5e9 word reads over a run, even though the table changes about once per frame. With this change, 2617 of 2625 table snapshots in a 10 s window were reused unwritten, against 0 of about 2250 before.

The new step pointer table unwritten reuse in agc_shader_memory sets up a pointer-addressed table on a write-watched root page, then captures it with an explicit span query that reports nothing pending:

  • the third capture must reuse the snapshot unwritten;
  • after a CPU write to an entry, the next capture must read it again.

On main it fails with a pointer-addressed table nothing wrote was compared again instead of reused. It also fails with either half of the change reverted.

Tested

  • Windows 11 Pro 26300, NVIDIA GeForce RTX 5080, driver 617.42.
  • ctest -V -R "shader_memory|image_table|snapshot|capture|bindless|srt|shader_replay|table" with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1, on the same machine. The image table and capture execution tests were built. Each log starts with its tested revision and these variables, and the build settings are attached.
    • This change (05584f417d): 105/105 passed.
    • Control: the three source files from main 1c8c0efc8c, with the new test. 103/105 passed; only agc_shader_memory and agc_shader_bindless fail, both on the new step (agc_shader_bindless runs the same binary).
    • Neither log reports the layer as not found, and neither has a VUID- error. The same 7 tests skip in both.
  • A wider selection that adds texture, storage, sampled, draw cache and relocation tests: 191/191 passed with the change, with no VUID- error.
  • 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 (APS5_FAIL_UNKNOWN_CLOCKS=1), #15563, #15611 and two local speed changes. The base is 58d69707d7 and the change is 462334bc76: the same tree plus this commit. Traces attached.
base change
presents in the window 27 29
frame p50 / p90 2321 / 2360 ms 2101 / 2220 ms
Driver.Draw.shader_compile_and_link per frame 1127 ms 938 ms
Shader.DrawStage per frame 888 ms 697 ms
{"commit":"58d69707d7c1","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":511,"ms":61273.908},"presents":27,"frame_ms":{"p50":2320.976,"p90":2359.531,"p99":2392.416,"max":2392.416},"gpu_busy_ms_per_present":272.669,"worker_busy_pct":{"queue worker 0x0":99.930},"top_phases_ms_per_frame":{"Driver.Packet":2267.522,"Driver.Packet.draw":2202.553,"Driver.Draw":2202.162,"Driver.Draw.shader_compile_and_link":1129.462,"Driver.Draw.draw_and_resource_release":1056.678,"Graphics.Draw":1033.070,"Graphics.Draw.draw_and_resource_release":1025.134,"Resources.Complete":925.705},"trace_dropped":false,"trace":"aps5-trace-58d69707d7c1-30700.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.

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-58d69707d7c1-30700.json.gz
aps5-trace-462334bc769d-20744.json.gz
table-stamp-build-settings.txt
table-stamp-change-05584f417d-ctest.log
table-stamp-main-1c8c0efc8c-control-ctest.log

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5146536637 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15655). Originally posted by [XatiX](https://github.com/XatiX) on 2026-11-04T00:11:10Z. --- ### What An image table snapshot is remembered per column (`ColumnMemos`). It is reused without reading the table again only when it carries a write stamp that the write watch still vouches for. Otherwise each capture reads and compares every record of the table. In two cases a column never got a usable stamp: - **The column is addressed through a 64-bit pointer** (`column.address`). Only base-addressed columns took a stamp before the compare. - **The capture had already read pages of the table range** before stamping. For example, the root page holds the SRT and the start of the table. `ShaderMemory::stampWrites` refused any range with a page the capture had fetched, because a write between that fetch and the collect would go unseen. Now: - A pointer-addressed column stamps its remembered read range before the compare. - When the caller passed an explicit span query (`pendingSpan`, which the driver always does), `stampWrites` takes the stamp after the collect and then checks each page the capture already read: every valid word must still equal guest memory. A page read word by word, a page that differs, or a span with a pending GPU write still refuses the stamp. A write between the fetch and the collect therefore shows up as a difference. - Without an explicit span query, which only some tests construct, `stampWrites` refuses as before. PPSA18653 reads its bindless table (about 2 MiB) through a pointer, from the page that holds the root. Every draw compared the whole table, about 5e9 word reads over a run, even though the table changes about once per frame. With this change, 2617 of 2625 table snapshots in a 10 s window were reused unwritten, against 0 of about 2250 before. The new step `pointer table unwritten reuse` in `agc_shader_memory` sets up a pointer-addressed table on a write-watched root page, then captures it with an explicit span query that reports nothing pending: - the third capture must reuse the snapshot unwritten; - after a CPU write to an entry, the next capture must read it again. On `main` it fails with `a pointer-addressed table nothing wrote was compared again instead of reused`. It also fails with either half of the change reverted. ### Tested - Windows 11 Pro 26300, NVIDIA GeForce RTX 5080, driver 617.42. - `ctest -V -R "shader_memory|image_table|snapshot|capture|bindless|srt|shader_replay|table"` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`, on the same machine. The image table and capture execution tests were built. Each log starts with its tested revision and these variables, and the build settings are attached. - This change (`05584f417d`): 105/105 passed. - Control: the three source files from `main` `1c8c0efc8c`, with the new test. 103/105 passed; only `agc_shader_memory` and `agc_shader_bindless` fail, both on the new step (`agc_shader_bindless` runs the same binary). - Neither log reports the layer as not found, and neither has a `VUID-` error. The same 7 tests skip in both. - A wider selection that adds texture, storage, sampled, draw cache and relocation tests: 191/191 passed with the change, with no `VUID-` error. - 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 (`APS5_FAIL_UNKNOWN_CLOCKS=1`), #15563, #15611 and two local speed changes. The base is `58d69707d7` and the change is `462334bc76`: the same tree plus this commit. Traces attached. | | base | change | |---|---|---| | presents in the window | 27 | 29 | | frame p50 / p90 | 2321 / 2360 ms | 2101 / 2220 ms | | `Driver.Draw.shader_compile_and_link` per frame | 1127 ms | 938 ms | | `Shader.DrawStage` per frame | 888 ms | 697 ms | ```json {"commit":"58d69707d7c1","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":511,"ms":61273.908},"presents":27,"frame_ms":{"p50":2320.976,"p90":2359.531,"p99":2392.416,"max":2392.416},"gpu_busy_ms_per_present":272.669,"worker_busy_pct":{"queue worker 0x0":99.930},"top_phases_ms_per_frame":{"Driver.Packet":2267.522,"Driver.Packet.draw":2202.553,"Driver.Draw":2202.162,"Driver.Draw.shader_compile_and_link":1129.462,"Driver.Draw.draw_and_resource_release":1056.678,"Graphics.Draw":1033.070,"Graphics.Draw.draw_and_resource_release":1025.134,"Resources.Complete":925.705},"trace_dropped":false,"trace":"aps5-trace-58d69707d7c1-30700.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. ### 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-58d69707d7c1-30700.json.gz](https://github.com/user-attachments/files/34344525/aps5-trace-58d69707d7c1-30700.json.gz) [aps5-trace-462334bc769d-20744.json.gz](https://github.com/user-attachments/files/34344526/aps5-trace-462334bc769d-20744.json.gz) [table-stamp-build-settings.txt](https://github.com/user-attachments/files/34344527/table-stamp-build-settings.txt) [table-stamp-change-05584f417d-ctest.log](https://github.com/user-attachments/files/34344529/table-stamp-change-05584f417d-ctest.log) [table-stamp-main-1c8c0efc8c-control-ctest.log](https://github.com/user-attachments/files/34344530/table-stamp-main-1c8c0efc8c-control-ctest.log) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!15655
No description provided.