perf(agc): repeat a draw shape's resident targets and pipeline instead of looking them up again #11696

Merged
Astronaut10 merged 5 commits from upstream-pr/11696 into main 2026-10-28 13:49:04 +00:00
Astronaut10 commented 2026-10-27 03:38:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Astronaut10 on 2026-10-27T03:38:13Z.


What

The draw committer looks up every draw's resident color target images and its pipeline again, although consecutive draws of the same register shape almost always reuse both. This keeps a small per-thread memo (up to 4096 shapes, 4 pipeline choices each) in prepareDraw, keyed on the shape key the driver already computes for data-only draw hits (key registers without user words, device serial and shader snapshots, the same invariant #494 relies on). decodeDraw reads only those inputs, so the shape determines the draw's State.

  • Target hit: the new RepeatStorageSurface repeats the storage cache's hit path on the remembered image (array window, the multisample and resident-depth guard over the whole viewed surface, the depth-surface check, the depth-plane flush when stale, allocated levels, moved metadata, Refresh, LRU splice and hit counters) and finds it by image instead of rebuilding the SurfaceKey. Any refusal falls back to CachedStorageSurface.
  • Pipeline hit: requires equal attachment layout, fragment outputs, vertex bindings and attributes, set-layout keys and, per stage, stage, Identity() and push offset, plus PushConstantStages: everything pipelineKey reads that the shape does not determine. The new TouchCachedPipeline then finds the stored pipeline by its hash under the store mutex, checks it is the same object through a weak_ptr, and splices it to the front of the LRU.
  • Stencil replay, proxied and multisampled targets keep the ordinary path; AcquireFramebuffer is unchanged.
  • APS5_NO_SHAPE_MEMO turns the memo off; APS5_VERIFY_SHAPE_MEMO also runs the ordinary lookups beside every hit, throws on a difference and prints [shape-memo] counts.

Tested

CachyOS (Linux 7.3), Ryzen 7 5700X3D, RX 9070 XT (RADV, Mesa 26.2.5), 3840x2160. PPSA21564 (ASTRO BOT 01.007.000), started into underwater_aerial_garden with -lvl, standing at the spawn with no input, 20 s after the level started, warm caches.

Plain main runs this scene at 0.15 FPS (6-8 s per frame, refused host imports), so both sides carry #7844, which is unrelated to this change. Base 1050ece9ca18: main 09f9a63f6b + #7844 (31342e632b). Change e1fcaed1ce50: this branch at deec3d1824 (the four commits now on the branch) + #7844. The two differ only in this PR's files. The branch head c7123a3da3 is the same four commits rebased onto main f5e3dc5e3b without conflicts. Switches on both: APS5_DEPTH_PLANE_COPY_MIB=512 APS5_DRAW_PIPELINE=1 APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1 APS5_NO_PAD_INPUT=1.

Clean runs, 120 s each, A/B/B/A then B/A/A/B, four per side, no run excluded; frame times from every frame of the steady window:

A: main + #7844 B: this PR + #7844 change
FPS per run 2.520 / 2.533 / 2.491 / 2.494 2.542 / 2.567 / 2.511 / 2.495
FPS mean 2.510 2.529 +0.8 % (95 % about -1.1 to +2.7 %)
Graphics.Draw ms per frame 234.0 228.2 -2.5 % (95 % -4.6 to -0.3 %)
GPU busy ms per present 248.9 246.2 unchanged
frames, p50 / p95 / p99 ms 1230, 397.8 / 416.2 / 449.9 1241, 394.1 / 414.7 / 445.9
frames > 500 ms / > 1 s 8 / 2 8 / 1

The claim is the committer's draw preparation: 2.5 % less with the full-range guard. The FPS change is within its spread at four runs per side; on main the committer also waits on labels. Earlier measurements of the same memo before the guard fix: on main 27ad7244d2 + #7844, Graphics.Draw -3.5 % and FPS +1.3 % (95 % -0.3 to +2.9 %); on a base that also had #9858, FPS +2.0 % (95 % +1.1 to +2.9 %). Those bases differ, so the gap is not attributed to the guard.

APS5_VERIFY_SHAPE_MEMO=1 on e1fcaed1ce50 from boot to the level and 60 s in it: 3,039,657 target and 1,107,060 pipeline hits checked against the ordinary lookups, no difference.

Summary lines of the two traces of this pair (10 s each, captured as the Performance report form describes; APS5_TRACE_EVENTS raised so the queue worker's buffer does not fill):

{"commit":"1050ece9ca18","dirty":false,"env":{"APS5_DEPTH_PLANE_COPY_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_NO_PAD_INPUT":"1","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"4194304","APS5_TRACE_SECONDS":"33:10"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.5-arch3.1","os":"Linux 7.3.0-4-cachyos","cpu":"AMD Ryzen 7 5700X3D 8-Core Processor","cpu_threads":16,"memory_mib":31992,"title_id":"PPSA21564","title":"ASTRO BOT","content_version":"01.007.000","resolution":"3840x2160","window":{"spec":"seconds 33:10","first_present":221,"ms":10362.348},"presents":26,"frame_ms":{"p50":401.422,"p90":406.123,"p99":428.952,"max":428.952},"gpu_busy_ms_per_present":249.285,"worker_busy_pct":{"queue worker 0x0":98.843,"queue worker 0x40":97.127,"queue worker 0x48":96.264,"queue worker 0x46":1.850},"top_phases_ms_per_frame":{"Driver.Packet":1170.037,"Driver.Packet.memory_wait":711.534,"Driver.Packet.draw":285.892,"Driver.Draw":285.012,"Driver.DrawFinish":244.424,"Driver.Draw.prepare":241.603,"Graphics.Draw":231.932,"Graphics.Draw.draw_and_resource_release":195.383},"trace_dropped":false,"trace":"aps5-trace-1050ece9ca18-196082.json.gz"}
{"commit":"e1fcaed1ce50","dirty":false,"env":{"APS5_DEPTH_PLANE_COPY_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_NO_PAD_INPUT":"1","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"4194304","APS5_TRACE_SECONDS":"34:10"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.5-arch3.1","os":"Linux 7.3.0-4-cachyos","cpu":"AMD Ryzen 7 5700X3D 8-Core Processor","cpu_threads":16,"memory_mib":31992,"title_id":"PPSA21564","title":"ASTRO BOT","content_version":"01.007.000","resolution":"3840x2160","window":{"spec":"seconds 34:10","first_present":216,"ms":10120.334},"presents":26,"frame_ms":{"p50":394.492,"p90":408.093,"p99":426.187,"max":426.187},"gpu_busy_ms_per_present":249.765,"worker_busy_pct":{"queue worker 0x0":98.836,"queue worker 0x48":96.510,"queue worker 0x40":97.203,"queue worker 0x46":2.264},"top_phases_ms_per_frame":{"Driver.Packet":1144.746,"Driver.Packet.memory_wait":698.690,"Driver.Packet.draw":270.060,"Driver.Draw":269.102,"Driver.DrawFinish":230.172,"Driver.Draw.prepare":226.265,"Graphics.Draw":225.755,"Graphics.Draw.draw_and_resource_release":189.304},"trace_dropped":false,"trace":"aps5-trace-e1fcaed1ce50-196318.json.gz"}

Tests:

  • agc_pipeline_store_touch: a touch returns the stored pipeline as a hit, refuses another pipeline, an empty weak_ptr and a cleared store, and keeps a touched pipeline from being the LRU victim; it fails when the LRU splice is removed.
  • agc_repeat_storage_guard: remembers a surface's storage image, then checks the repeat path and the lookup agree with no guarded target (same image), with a 4x target that starts where the surface ends (same image), and with one that starts 64 KiB into the surface (the same refusal). It fails with a guard over the surface's first byte only.
  • 76 focused tests (pipeline store, library, journal and cache, graphics, draw cache reuse, relocation and data hits, every *_draw_pipeline test, color and linear target tests, depth storage reuse, the two above) with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and ctest -V on main f5e3dc5e3b (74 of 74) and on c7123a3da3 (76 of 76); agc_driver_linear_target_direct_write_completion skips on both. Neither log reports the layer missing. Both have the same 6 VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 from agc_driver_srgb8_color_target; this change adds none.
  • All agc and guest memory tests pass apart from two that fail on main as well: agc_driver_tessellation (crashes inside RADV in LinkPipelineFromLibraries) and agc_idle_publish_wait ("the idle publish's bytes are wrong").

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 XT, RADV Mesa 26.2.5, Linux 7.3 (CachyOS)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5028194740 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11696). Originally posted by [Astronaut10](https://github.com/Astronaut10) on 2026-10-27T03:38:13Z. --- ### What The draw committer looks up every draw's resident color target images and its pipeline again, although consecutive draws of the same register shape almost always reuse both. This keeps a small per-thread memo (up to 4096 shapes, 4 pipeline choices each) in `prepareDraw`, keyed on the shape key the driver already computes for data-only draw hits (key registers without user words, device serial and shader snapshots, the same invariant #494 relies on). `decodeDraw` reads only those inputs, so the shape determines the draw's `State`. - Target hit: the new `RepeatStorageSurface` repeats the storage cache's hit path on the remembered image (array window, the multisample and resident-depth guard over the whole viewed surface, the depth-surface check, the depth-plane flush when stale, allocated levels, moved metadata, `Refresh`, LRU splice and hit counters) and finds it by image instead of rebuilding the `SurfaceKey`. Any refusal falls back to `CachedStorageSurface`. - Pipeline hit: requires equal attachment layout, fragment outputs, vertex bindings and attributes, set-layout keys and, per stage, stage, `Identity()` and push offset, plus `PushConstantStages`: everything `pipelineKey` reads that the shape does not determine. The new `TouchCachedPipeline` then finds the stored pipeline by its hash under the store mutex, checks it is the same object through a `weak_ptr`, and splices it to the front of the LRU. - Stencil replay, proxied and multisampled targets keep the ordinary path; `AcquireFramebuffer` is unchanged. - `APS5_NO_SHAPE_MEMO` turns the memo off; `APS5_VERIFY_SHAPE_MEMO` also runs the ordinary lookups beside every hit, throws on a difference and prints `[shape-memo]` counts. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> CachyOS (Linux 7.3), Ryzen 7 5700X3D, RX 9070 XT (RADV, Mesa 26.2.5), 3840x2160. PPSA21564 (ASTRO BOT 01.007.000), started into `underwater_aerial_garden` with `-lvl`, standing at the spawn with no input, 20 s after the level started, warm caches. Plain `main` runs this scene at 0.15 FPS (6-8 s per frame, refused host imports), so both sides carry #7844, which is unrelated to this change. Base `1050ece9ca18`: `main` `09f9a63f6b` + #7844 (`31342e632b`). Change `e1fcaed1ce50`: this branch at `deec3d1824` (the four commits now on the branch) + #7844. The two differ only in this PR's files. The branch head `c7123a3da3` is the same four commits rebased onto `main` `f5e3dc5e3b` without conflicts. Switches on both: `APS5_DEPTH_PLANE_COPY_MIB=512 APS5_DRAW_PIPELINE=1 APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1 APS5_NO_PAD_INPUT=1`. Clean runs, 120 s each, A/B/B/A then B/A/A/B, four per side, no run excluded; frame times from every frame of the steady window: | | A: main + #7844 | B: this PR + #7844 | change | | --- | --- | --- | --- | | FPS per run | 2.520 / 2.533 / 2.491 / 2.494 | 2.542 / 2.567 / 2.511 / 2.495 | | | FPS mean | 2.510 | 2.529 | +0.8 % (95 % about -1.1 to +2.7 %) | | `Graphics.Draw` ms per frame | 234.0 | 228.2 | -2.5 % (95 % -4.6 to -0.3 %) | | GPU busy ms per present | 248.9 | 246.2 | unchanged | | frames, p50 / p95 / p99 ms | 1230, 397.8 / 416.2 / 449.9 | 1241, 394.1 / 414.7 / 445.9 | | | frames > 500 ms / > 1 s | 8 / 2 | 8 / 1 | | The claim is the committer's draw preparation: 2.5 % less with the full-range guard. The FPS change is within its spread at four runs per side; on `main` the committer also waits on labels. Earlier measurements of the same memo before the guard fix: on `main` `27ad7244d2` + #7844, `Graphics.Draw` -3.5 % and FPS +1.3 % (95 % -0.3 to +2.9 %); on a base that also had #9858, FPS +2.0 % (95 % +1.1 to +2.9 %). Those bases differ, so the gap is not attributed to the guard. `APS5_VERIFY_SHAPE_MEMO=1` on `e1fcaed1ce50` from boot to the level and 60 s in it: 3,039,657 target and 1,107,060 pipeline hits checked against the ordinary lookups, no difference. Summary lines of the two traces of this pair (10 s each, captured as the Performance report form describes; `APS5_TRACE_EVENTS` raised so the queue worker's buffer does not fill): ```json {"commit":"1050ece9ca18","dirty":false,"env":{"APS5_DEPTH_PLANE_COPY_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_NO_PAD_INPUT":"1","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"4194304","APS5_TRACE_SECONDS":"33:10"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.5-arch3.1","os":"Linux 7.3.0-4-cachyos","cpu":"AMD Ryzen 7 5700X3D 8-Core Processor","cpu_threads":16,"memory_mib":31992,"title_id":"PPSA21564","title":"ASTRO BOT","content_version":"01.007.000","resolution":"3840x2160","window":{"spec":"seconds 33:10","first_present":221,"ms":10362.348},"presents":26,"frame_ms":{"p50":401.422,"p90":406.123,"p99":428.952,"max":428.952},"gpu_busy_ms_per_present":249.285,"worker_busy_pct":{"queue worker 0x0":98.843,"queue worker 0x40":97.127,"queue worker 0x48":96.264,"queue worker 0x46":1.850},"top_phases_ms_per_frame":{"Driver.Packet":1170.037,"Driver.Packet.memory_wait":711.534,"Driver.Packet.draw":285.892,"Driver.Draw":285.012,"Driver.DrawFinish":244.424,"Driver.Draw.prepare":241.603,"Graphics.Draw":231.932,"Graphics.Draw.draw_and_resource_release":195.383},"trace_dropped":false,"trace":"aps5-trace-1050ece9ca18-196082.json.gz"} {"commit":"e1fcaed1ce50","dirty":false,"env":{"APS5_DEPTH_PLANE_COPY_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_NO_PAD_INPUT":"1","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"4194304","APS5_TRACE_SECONDS":"34:10"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.5-arch3.1","os":"Linux 7.3.0-4-cachyos","cpu":"AMD Ryzen 7 5700X3D 8-Core Processor","cpu_threads":16,"memory_mib":31992,"title_id":"PPSA21564","title":"ASTRO BOT","content_version":"01.007.000","resolution":"3840x2160","window":{"spec":"seconds 34:10","first_present":216,"ms":10120.334},"presents":26,"frame_ms":{"p50":394.492,"p90":408.093,"p99":426.187,"max":426.187},"gpu_busy_ms_per_present":249.765,"worker_busy_pct":{"queue worker 0x0":98.836,"queue worker 0x48":96.510,"queue worker 0x40":97.203,"queue worker 0x46":2.264},"top_phases_ms_per_frame":{"Driver.Packet":1144.746,"Driver.Packet.memory_wait":698.690,"Driver.Packet.draw":270.060,"Driver.Draw":269.102,"Driver.DrawFinish":230.172,"Driver.Draw.prepare":226.265,"Graphics.Draw":225.755,"Graphics.Draw.draw_and_resource_release":189.304},"trace_dropped":false,"trace":"aps5-trace-e1fcaed1ce50-196318.json.gz"} ``` Tests: - `agc_pipeline_store_touch`: a touch returns the stored pipeline as a hit, refuses another pipeline, an empty `weak_ptr` and a cleared store, and keeps a touched pipeline from being the LRU victim; it fails when the LRU splice is removed. - `agc_repeat_storage_guard`: remembers a surface's storage image, then checks the repeat path and the lookup agree with no guarded target (same image), with a 4x target that starts where the surface ends (same image), and with one that starts 64 KiB into the surface (the same refusal). It fails with a guard over the surface's first byte only. - 76 focused tests (pipeline store, library, journal and cache, graphics, draw cache reuse, relocation and data hits, every `*_draw_pipeline` test, color and linear target tests, depth storage reuse, the two above) with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `ctest -V` on `main` `f5e3dc5e3b` (74 of 74) and on `c7123a3da3` (76 of 76); `agc_driver_linear_target_direct_write_completion` skips on both. Neither log reports the layer missing. Both have the same 6 `VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605` from `agc_driver_srgb8_color_target`; this change adds none. - All `agc` and guest memory tests pass apart from two that fail on `main` as well: `agc_driver_tessellation` (crashes inside RADV in `LinkPipelineFromLibraries`) and `agc_idle_publish_wait` ("the idle publish's bytes are wrong"). ### 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 XT, RADV Mesa 26.2.5, Linux 7.3 (CachyOS) - [x] AI-assisted: yes 🤖 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!11696
No description provided.