perf(agc): reuse the open render pass's attachments when the next draw's targets are unchanged #16115

Merged
Nesyth merged 6 commits from upstream-pr/16115 into main 2026-11-15 10:49:56 +00:00
Nesyth commented 2026-11-05 17:42:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nesyth on 2026-11-05T17:42:49Z.


What

Every draw looks up its color and depth attachments again. For each color target refreshResidentTarget finds the resident image in the storage cache and refreshes it (StorageTexture::Refresh), then takes its attachment view. The depth target goes through DepthSurfaceViewWithStencilWriteIntent. In a run of draws into the same targets inside one render pass the answer does not change.

This PR keeps the attachments of the last recorded draw on each thread (AttachmentMemo in Graphics/src/Draw.cpp). The next draw takes them instead of the lookup when all of these hold:

  • The recorder is the same (by Id()), its render pass is still open, and Recorder::RenderPassGeneration() is unchanged. The generation moves when a pass ends (endOpenRenderPass) and when a new batch opens (ensureOpen).
  • The collect epoch is nonzero, and it, GuestMemory::ProofSerial() and StorageTexture::PendingSerial() are unchanged.
  • Every color and depth target compares equal field by field (sameColorTarget, sameDepthTarget), and so do depth write, stencil test and the stencil write intent.
  • Each resident image still exists, has the same Version(), is still the storage cache's (StorageImageCached) and serves the target's DCC keys (StorageImageServesKeys), the checks DrawWithRecipe makes on its stored targets.
  • With a depth target, DepthSurfacesSerial() and DepthSurfacesReleased() are unchanged.

Only plain resident targets are kept: no multisampled, staged, partial-write or non-resident color target, a single-sample depth target, and no APS5_DUMP_TARGETS. A draw that is not recorded clears the memo.

The memo serves draws only while ShaderResources::EpochProofs() holds, that is with APS5_DRAW_PIPELINE. That is when StorageTexture::refresh itself skips its work because the collect epoch, the proof serial and the pending serial are unchanged, and the memo relies on the same three. Without APS5_DRAW_PIPELINE nothing changes.

  • APS5_NO_PASS_ATTACHMENT_MEMO=1 turns the memo off. It is a runtime switch (RuntimeSwitch::NoPassAttachmentMemo), so APS5_AB can toggle it.
  • APS5_VERIFY_PASS_ATTACHMENTS=1 runs the full lookup for every draw the memo would serve, compares the images and views, and prints the first twenty that differ.
  • With APS5_PIPELINE_STATS or APS5_PROFILE_DRAW, a [pass-attachments] line every 10 s counts hits, misses by reason, stores and verified hits, as the [finisher] line does.

The memo lives in HostThreadLocal, like the shape memo, and holds weak references to the images, so it keeps no image alive and an entry from another device or recorder never matches. Both variables have rows in docs/dev/ENVIRONMENT.md, and the APS5_DRAW_PIPELINE paragraph of docs/dev/ARCHITECTURE.md describes the memo. docs/dev/TRACING.md now says that APS5_AB takes any runtime switch, not only APS5_NO_BARRIER_BATCH. agc_driver_draw_cache_reuse_pass_attachments_verify is a new registration of agc_driver_draw_cache_reuse_tests in draw-pipeline mode with APS5_VERIFY_PASS_ATTACHMENTS=1.

Tested

Windows 11 Pro 26300, Radeon RX 7900 XTX (AMD Software 26.10.1), Ryzen 7 7800X3D, MinGW-w64 GCC 15.2, Ninja, Release, BUILD_TESTING=ON, this head rebased on current main 4741457fed.

  • Full build on main 4741457fed (ninja -C build): clean.
  • Focused tests: the agc_driver_recorder, agc_driver_graphics, every _draw_pipeline registration and the agc_driver_draw_cache_reuse tests, 52 tests, ANYPS5_REQUIRE_VULKAN=1, -j4: 100% pass, 0 failed.
  • The _draw_pipeline tests also pass with APS5_NO_PASS_ATTACHMENT_MEMO=1 and with APS5_VERIFY_PASS_ATTACHMENTS=1 (the registered ..._pass_attachments_verify test): 0 differences.
  • In game, PPSA04264, Performance graphics mode, open-world gameplay, this branch alone on main 4741457fed with APS5_DRAW_PIPELINE=1 in both arms. Within one run: APS5_AB=30:APS5_NO_PASS_ATTACHMENT_MEMO, 30 s phases from 190 s, 20 phases, each B phase against its neighbouring A phases. Draws per present swing with the scene, so frame time is fitted against commits per present with a common slope (residual SD 2.0 ms, n 19).
memo (A) no memo (B) B against neighbouring A
committer per commit 22.41 µs 25.48 µs +3.07 ± 0.19 µs (n 10)
frame time at equal commits per present 85.9 ms 94.6 ms +8.73 ± 0.92 ms (+10.2 ± 1.1 %)
presents per 10 s 119.1 108.6 -8.7 ± 4.2, inside the scene's swing

The memo answered 256,477 lookups per 10 s and missed 59,514: 33,708 without a memo, 10,941 after the pass ended, 9,355 on moved serials, 4,977 on changed targets, 533 on the depth surface. No errors in the run.

Performance report

Captures of PPSA04264 on main 4741457fed and on this head, same scene, machine and settings (APS5_DRAW_PIPELINE=1, trace window 240-300 s). The two traces, both digests and a second pair of boots are in the report comment.

{"commit":"4741457fed42","dirty":false,"env":{"APS5_DRAW_PIPELINE":"1","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"240:60","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 7900 XTX","driver":"AMD proprietary driver 26.10.1 (LLPC)","os":"Windows 10.0.26300","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":31860,"title_id":"PPSA04264","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 240:60","first_present":3623,"ms":60028.203},"presents":436,"frame_ms":{"p50":136.663,"p90":143.590,"p99":177.093,"max":250.592},"gpu_busy_ms_per_present":34.217,"worker_busy_pct":{"queue worker 0x0":95.244},"top_phases_ms_per_frame":{"Driver.Packet":124.285,"Graphics.Draw":96.804,"Driver.Packet.draw":90.558,"Driver.Draw":89.662,"Graphics.Draw.draw_and_resource_release":84.355,"Driver.DrawFinish":76.874,"Driver.Draw.prepare":68.527,"Driver.DrawFinish.shader_compile_and_link":47.988},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.458,"events_lost":2605270,"totals_full":false},"draw committer":{"events_full_after_s":12.260,"events_lost":1036681,"totals_full":false},"draw finisher":{"events_full_after_s":11.992,"events_lost":1070545,"totals_full":false}},"trace":"aps5-trace-4741457fed42-55484.json.gz"}
{"commit":"52db2c452344","dirty":false,"env":{"APS5_DRAW_PIPELINE":"1","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"240:60","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 7900 XTX","driver":"AMD proprietary driver 26.10.1 (LLPC)","os":"Windows 10.0.26300","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":31860,"title_id":"PPSA04264","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 240:60","first_present":4124,"ms":60041.678},"presents":511,"frame_ms":{"p50":115.283,"p90":121.044,"p99":175.815,"max":260.759},"gpu_busy_ms_per_present":34.410,"worker_busy_pct":{"queue worker 0x0":94.539},"top_phases_ms_per_frame":{"Driver.Packet":105.033,"Graphics.Draw":77.302,"Driver.Packet.draw":72.982,"Driver.Draw":72.157,"Graphics.Draw.draw_and_resource_release":65.879,"Driver.DrawFinish":61.665,"Driver.Draw.prepare":53.279,"Driver.DrawFinish.shader_compile_and_link":43.277},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.879,"events_lost":2441542,"totals_full":false},"draw committer":{"events_full_after_s":15.403,"events_lost":783342,"totals_full":false},"draw finisher":{"events_full_after_s":13.879,"events_lost":907879,"totals_full":false}},"trace":"aps5-trace-52db2c452344-54932.json.gz"}

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 7900 XTX, AMD Software 26.10.1, Windows 11 Pro 26300
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5176018764 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16115). Originally posted by [Nesyth](https://github.com/Nesyth) on 2026-11-05T17:42:49Z. --- ### What Every draw looks up its color and depth attachments again. For each color target `refreshResidentTarget` finds the resident image in the storage cache and refreshes it (`StorageTexture::Refresh`), then takes its attachment view. The depth target goes through `DepthSurfaceViewWithStencilWriteIntent`. In a run of draws into the same targets inside one render pass the answer does not change. This PR keeps the attachments of the last recorded draw on each thread (`AttachmentMemo` in `Graphics/src/Draw.cpp`). The next draw takes them instead of the lookup when all of these hold: - The recorder is the same (by `Id()`), its render pass is still open, and `Recorder::RenderPassGeneration()` is unchanged. The generation moves when a pass ends (`endOpenRenderPass`) and when a new batch opens (`ensureOpen`). - The collect epoch is nonzero, and it, `GuestMemory::ProofSerial()` and `StorageTexture::PendingSerial()` are unchanged. - Every color and depth target compares equal field by field (`sameColorTarget`, `sameDepthTarget`), and so do depth write, stencil test and the stencil write intent. - Each resident image still exists, has the same `Version()`, is still the storage cache's (`StorageImageCached`) and serves the target's DCC keys (`StorageImageServesKeys`), the checks `DrawWithRecipe` makes on its stored targets. - With a depth target, `DepthSurfacesSerial()` and `DepthSurfacesReleased()` are unchanged. Only plain resident targets are kept: no multisampled, staged, partial-write or non-resident color target, a single-sample depth target, and no `APS5_DUMP_TARGETS`. A draw that is not recorded clears the memo. The memo serves draws only while `ShaderResources::EpochProofs()` holds, that is with `APS5_DRAW_PIPELINE`. That is when `StorageTexture::refresh` itself skips its work because the collect epoch, the proof serial and the pending serial are unchanged, and the memo relies on the same three. Without `APS5_DRAW_PIPELINE` nothing changes. - `APS5_NO_PASS_ATTACHMENT_MEMO=1` turns the memo off. It is a runtime switch (`RuntimeSwitch::NoPassAttachmentMemo`), so `APS5_AB` can toggle it. - `APS5_VERIFY_PASS_ATTACHMENTS=1` runs the full lookup for every draw the memo would serve, compares the images and views, and prints the first twenty that differ. - With `APS5_PIPELINE_STATS` or `APS5_PROFILE_DRAW`, a `[pass-attachments]` line every 10 s counts hits, misses by reason, stores and verified hits, as the `[finisher]` line does. The memo lives in `HostThreadLocal`, like the shape memo, and holds weak references to the images, so it keeps no image alive and an entry from another device or recorder never matches. Both variables have rows in `docs/dev/ENVIRONMENT.md`, and the `APS5_DRAW_PIPELINE` paragraph of `docs/dev/ARCHITECTURE.md` describes the memo. `docs/dev/TRACING.md` now says that `APS5_AB` takes any runtime switch, not only `APS5_NO_BARRIER_BATCH`. `agc_driver_draw_cache_reuse_pass_attachments_verify` is a new registration of `agc_driver_draw_cache_reuse_tests` in draw-pipeline mode with `APS5_VERIFY_PASS_ATTACHMENTS=1`. ### Tested Windows 11 Pro 26300, Radeon RX 7900 XTX (AMD Software 26.10.1), Ryzen 7 7800X3D, MinGW-w64 GCC 15.2, Ninja, Release, `BUILD_TESTING=ON`, this head rebased on current `main` `4741457fed`. - Full build on `main` `4741457fed` (`ninja -C build`): clean. - Focused tests: the `agc_driver_recorder`, `agc_driver_graphics`, every `_draw_pipeline` registration and the `agc_driver_draw_cache_reuse` tests, 52 tests, `ANYPS5_REQUIRE_VULKAN=1`, `-j4`: 100% pass, 0 failed. - The `_draw_pipeline` tests also pass with `APS5_NO_PASS_ATTACHMENT_MEMO=1` and with `APS5_VERIFY_PASS_ATTACHMENTS=1` (the registered `..._pass_attachments_verify` test): 0 differences. - **In game, PPSA04264**, Performance graphics mode, open-world gameplay, this branch alone on `main` `4741457fed` with `APS5_DRAW_PIPELINE=1` in both arms. Within one run: `APS5_AB=30:APS5_NO_PASS_ATTACHMENT_MEMO`, 30 s phases from 190 s, 20 phases, each B phase against its neighbouring A phases. Draws per present swing with the scene, so frame time is fitted against commits per present with a common slope (residual SD 2.0 ms, n 19). | | memo (A) | no memo (B) | B against neighbouring A | |---|---|---|---| | committer per commit | 22.41 µs | 25.48 µs | +3.07 ± 0.19 µs (n 10) | | frame time at equal commits per present | 85.9 ms | 94.6 ms | +8.73 ± 0.92 ms (+10.2 ± 1.1 %) | | presents per 10 s | 119.1 | 108.6 | -8.7 ± 4.2, inside the scene's swing | The memo answered 256,477 lookups per 10 s and missed 59,514: 33,708 without a memo, 10,941 after the pass ended, 9,355 on moved serials, 4,977 on changed targets, 533 on the depth surface. No errors in the run. ### Performance report Captures of PPSA04264 on `main` `4741457fed` and on this head, same scene, machine and settings (`APS5_DRAW_PIPELINE=1`, trace window 240-300 s). The two traces, both digests and a second pair of boots are in [the report comment](https://github.com/boykopovar/AnyPS5/pull/16115#issuecomment-6682575959). ```json {"commit":"4741457fed42","dirty":false,"env":{"APS5_DRAW_PIPELINE":"1","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"240:60","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 7900 XTX","driver":"AMD proprietary driver 26.10.1 (LLPC)","os":"Windows 10.0.26300","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":31860,"title_id":"PPSA04264","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 240:60","first_present":3623,"ms":60028.203},"presents":436,"frame_ms":{"p50":136.663,"p90":143.590,"p99":177.093,"max":250.592},"gpu_busy_ms_per_present":34.217,"worker_busy_pct":{"queue worker 0x0":95.244},"top_phases_ms_per_frame":{"Driver.Packet":124.285,"Graphics.Draw":96.804,"Driver.Packet.draw":90.558,"Driver.Draw":89.662,"Graphics.Draw.draw_and_resource_release":84.355,"Driver.DrawFinish":76.874,"Driver.Draw.prepare":68.527,"Driver.DrawFinish.shader_compile_and_link":47.988},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.458,"events_lost":2605270,"totals_full":false},"draw committer":{"events_full_after_s":12.260,"events_lost":1036681,"totals_full":false},"draw finisher":{"events_full_after_s":11.992,"events_lost":1070545,"totals_full":false}},"trace":"aps5-trace-4741457fed42-55484.json.gz"} ``` ```json {"commit":"52db2c452344","dirty":false,"env":{"APS5_DRAW_PIPELINE":"1","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"240:60","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 7900 XTX","driver":"AMD proprietary driver 26.10.1 (LLPC)","os":"Windows 10.0.26300","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":31860,"title_id":"PPSA04264","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 240:60","first_present":4124,"ms":60041.678},"presents":511,"frame_ms":{"p50":115.283,"p90":121.044,"p99":175.815,"max":260.759},"gpu_busy_ms_per_present":34.410,"worker_busy_pct":{"queue worker 0x0":94.539},"top_phases_ms_per_frame":{"Driver.Packet":105.033,"Graphics.Draw":77.302,"Driver.Packet.draw":72.982,"Driver.Draw":72.157,"Graphics.Draw.draw_and_resource_release":65.879,"Driver.DrawFinish":61.665,"Driver.Draw.prepare":53.279,"Driver.DrawFinish.shader_compile_and_link":43.277},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.879,"events_lost":2441542,"totals_full":false},"draw committer":{"events_full_after_s":15.403,"events_lost":783342,"totals_full":false},"draw finisher":{"events_full_after_s":13.879,"events_lost":907879,"totals_full":false}},"trace":"aps5-trace-52db2c452344-54932.json.gz"} ``` ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 7900 XTX, AMD Software 26.10.1, Windows 11 Pro 26300 - [x] AI-assisted: yes
gabichuuuuu commented 2026-11-07 20:07:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T20:07:47Z.

Review: COMMENTED


Windows check of head 52db2c4523 on the NVIDIA laptop GPU (driver 610) and the Intel iGPU in the same machine. Windows 11 x64, WinLibs GCC 15.2.0 r7, Release, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.

Merged onto main 6b733c4ef2 (clean), alternating with main from the same build directory:

^agc_driver_draw_cache_reuse_indirect$, NVIDIA ^agc_driver_draw_cache_reuse, NVIDIA same, Intel
main 20 of 20 (two rounds of 10) 2 of 2 runs pass 2 of 2 runs pass
this PR 20 of 20 (two rounds of 10) 2 of 2 runs pass, all 8 incl. the new pass_attachments_verify 2 of 2 runs pass

One failure earlier, not reproduced since. On main 4e44ed59b2 with this PR merged, 1 of 3 NVIDIA runs failed agc_driver_draw_cache_reuse_indirect with:

AGC graphics: with graphics pipeline libraries: the three draws made 2 draw-cache lookups (1 without an entry), expected 3 lookups with 2 absent

main passed all 3 of its runs in that batch. The 20 alternating runs above didn't reproduce it on either side, and this machine stalls now and then, so I can't tie it to the change. It's the ThirdDrawHitsTheCache count check, so if anything in the reused-pass path can skip a lookup under different timing, that would be the place to look.

Not run with VK_LAYER_KHRONOS_validation.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5814700541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16115#pullrequestreview-5814700541). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-07T20:07:47Z. **Review:** COMMENTED --- Windows check of head `52db2c4523` on the NVIDIA laptop GPU (driver 610) and the Intel iGPU in the same machine. Windows 11 x64, WinLibs GCC 15.2.0 r7, Release, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`. **Merged onto `main` `6b733c4ef2` (clean), alternating with `main` from the same build directory:** | | `^agc_driver_draw_cache_reuse_indirect$`, NVIDIA | `^agc_driver_draw_cache_reuse`, NVIDIA | same, Intel | |---|---|---|---| | `main` | 20 of 20 (two rounds of 10) | 2 of 2 runs pass | 2 of 2 runs pass | | this PR | 20 of 20 (two rounds of 10) | 2 of 2 runs pass, all 8 incl. the new `pass_attachments_verify` | 2 of 2 runs pass | **One failure earlier, not reproduced since.** On `main` `4e44ed59b2` with this PR merged, 1 of 3 NVIDIA runs failed `agc_driver_draw_cache_reuse_indirect` with: ``` AGC graphics: with graphics pipeline libraries: the three draws made 2 draw-cache lookups (1 without an entry), expected 3 lookups with 2 absent ``` `main` passed all 3 of its runs in that batch. The 20 alternating runs above didn't reproduce it on either side, and this machine stalls now and then, so I can't tie it to the change. It's the `ThirdDrawHitsTheCache` count check, so if anything in the reused-pass path can skip a lookup under different timing, that would be the place to look. Not run with `VK_LAYER_KHRONOS_validation`. AI-assisted: yes.
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!16115
No description provided.