perf(agc): refresh pure data words of a cached draw stage instead of recapturing it #6093

Merged
adriadam10 merged 1 commit from upstream-pr/6093 into main 2026-10-14 22:15:55 +00:00
adriadam10 commented 2026-10-14 21:44:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T21:44:02Z.


What

A draw stage whose captured words differ from a cached variant only at pure data positions is now a draw-cache hit: the live words are patched into the cached compiled result instead of capturing and materializing the stage again. This is the dispatch cache's EqualData hit (DispatchLookup.cpp) ported to draws.

  • Insert (cacheDrawStages): each stage records its pure data positions from its resource capture (DataWordPositions on the flattened SRT binding), minus the words the draw decode reads (decodeReads), so a word that drives the decode, an address or a descriptor is never refreshed.
  • Lookup (validateVariant): a stage that differs only at those positions returns EqualData; lookupDraw builds the stage's live words and patches them with patchDataWords, now shared with the dispatch path (moved out of DispatchLookup.cpp, same behaviour).
  • A patched draw takes no draw recipe (the recipe holds the unpatched build).
  • APS5_NO_DRAW_STAGE_DATA_HITS=1 turns it off (also off under stamp validation). APS5_VERIFY_DRAW_DATA_HITS=1 (the existing switch of the data-only hits) builds the stage anyway and throws if runs, words, variant, push constants or bindings differ from the patched result.
  • APS5_PROFILE_DRAW=1 gets a line [draw-cache] stage data hits (10 s): ... (stages hit, words refreshed, verified, inserts with data positions).

Why: on titles whose draw keys repeat but whose constants change every draw, the stage misses on its data and the whole capture runs again. Reports in #1201 (front end ~110 ms/frame vs ~32 ms in Graphics::Draw), #4943 (Besiege, Diablo II, Minecraft Dungeons II, Hades II) and #494 (Hades II) name this step: refresh the constants in a cached stage instead of comparing them. #494 covers changed user words, #4943 equal contents behind moved pointers, #5609 bound buffer bases; this covers the data words themselves. Pure data words only: V# bases are not refreshed here.

Template resources: with movable buffers (the default) a template hit already refreshes data-role bindings through MovedReadOnlyBuffers, which compares their words with the (patched) descriptor, so a refreshed constant reaches the GPU without a new template.

Tested

Linux, AMD Radeon 660M (RADV, Mesa 26.2.4).

  • New case StageDataHitsRefreshTheirWords in agc_driver_draw_cache_reuse (and its _off/_verify runs): a pixel shader reads a constant through its user words; three draws at 0.25 insert once and hit once (colour 64), then the constant becomes 1.0 and one draw is a hit with 1 stage data hit / 1 word refreshed, no insert, colour 255. With APS5_NO_DRAW_STAGE_DATA_HITS=1 it misses on the fragment stage and still draws 255; with verify the hit is checked once. The colour check needed a triangle that covers pixels and GuestMemory::FlushGpuWrites before reading the target, so the case has its own vertex shader.
  • Mutations, each failing the test: drawing with the unpatched compiled result (colour stays 64); not accepting EqualData (counters); not copying the live words (verify throws differs ... in its words).
  • Full ctest -R '^agc' before and after rebasing on main: everything passes except agc_driver_tessellation (fails on main too) and agc_driver_preparation_scope_settle under -j4 (passes 15/15 alone; also red in an unrelated train run 38623010537).
  • No in-game numbers: this machine can't run titles. Profile lines (APS5_PROFILE_DRAW=1, the new stage data hits line) and one APS5_VERIFY_DRAW_DATA_HITS=1 run with no throw on Astro's Playroom / Besiege / Diablo II would be welcome.

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 (#494 is merged)
  • Unblocks: none directly; draw front-end cost in #1201, #4943, #494
  • GPUs tested: AMD Radeon 660M (RADV REMBRANDT), Mesa 26.2.4, Linux (CachyOS, kernel 7.2.9)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4864964166 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6093). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T21:44:02Z. --- ### What A draw stage whose captured words differ from a cached variant only at pure data positions is now a draw-cache hit: the live words are patched into the cached compiled result instead of capturing and materializing the stage again. This is the dispatch cache's `EqualData` hit (`DispatchLookup.cpp`) ported to draws. - Insert (`cacheDrawStages`): each stage records its pure data positions from its resource capture (`DataWordPositions` on the flattened SRT binding), minus the words the draw decode reads (`decodeReads`), so a word that drives the decode, an address or a descriptor is never refreshed. - Lookup (`validateVariant`): a stage that differs only at those positions returns `EqualData`; `lookupDraw` builds the stage's live words and patches them with `patchDataWords`, now shared with the dispatch path (moved out of `DispatchLookup.cpp`, same behaviour). - A patched draw takes no draw recipe (the recipe holds the unpatched build). - `APS5_NO_DRAW_STAGE_DATA_HITS=1` turns it off (also off under stamp validation). `APS5_VERIFY_DRAW_DATA_HITS=1` (the existing switch of the data-only hits) builds the stage anyway and throws if runs, words, variant, push constants or bindings differ from the patched result. - `APS5_PROFILE_DRAW=1` gets a line `[draw-cache] stage data hits (10 s): ...` (stages hit, words refreshed, verified, inserts with data positions). Why: on titles whose draw keys repeat but whose constants change every draw, the stage misses on its data and the whole capture runs again. Reports in #1201 (front end ~110 ms/frame vs ~32 ms in `Graphics::Draw`), #4943 (Besiege, Diablo II, Minecraft Dungeons II, Hades II) and #494 (Hades II) name this step: refresh the constants in a cached stage instead of comparing them. #494 covers changed user words, #4943 equal contents behind moved pointers, #5609 bound buffer bases; this covers the data words themselves. Pure data words only: V# bases are not refreshed here. Template resources: with movable buffers (the default) a template hit already refreshes data-role bindings through `MovedReadOnlyBuffers`, which compares their words with the (patched) descriptor, so a refreshed constant reaches the GPU without a new template. ### Tested Linux, AMD Radeon 660M (RADV, Mesa 26.2.4). - New case `StageDataHitsRefreshTheirWords` in `agc_driver_draw_cache_reuse` (and its `_off`/`_verify` runs): a pixel shader reads a constant through its user words; three draws at 0.25 insert once and hit once (colour 64), then the constant becomes 1.0 and one draw is a hit with 1 stage data hit / 1 word refreshed, no insert, colour 255. With `APS5_NO_DRAW_STAGE_DATA_HITS=1` it misses on the fragment stage and still draws 255; with verify the hit is checked once. The colour check needed a triangle that covers pixels and `GuestMemory::FlushGpuWrites` before reading the target, so the case has its own vertex shader. - Mutations, each failing the test: drawing with the unpatched compiled result (colour stays 64); not accepting `EqualData` (counters); not copying the live words (verify throws `differs ... in its words`). - Full `ctest -R '^agc'` before and after rebasing on main: everything passes except `agc_driver_tessellation` (fails on main too) and `agc_driver_preparation_scope_settle` under `-j4` (passes 15/15 alone; also red in an unrelated train run 38623010537). - No in-game numbers: this machine can't run titles. Profile lines (`APS5_PROFILE_DRAW=1`, the new `stage data hits` line) and one `APS5_VERIFY_DRAW_DATA_HITS=1` run with no throw on Astro's Playroom / Besiege / Diablo II would be welcome. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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 (#494 is merged) - [x] Unblocks: none directly; draw front-end cost in #1201, #4943, #494 - [x] GPUs tested: AMD Radeon 660M (RADV REMBRANDT), Mesa 26.2.4, Linux (CachyOS, kernel 7.2.9) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-14 21:49:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T21:49:46Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5631 core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheReuse.cpp L127, L151
#5897 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCapture.cpp L76
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6179255611 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6093#issuecomment-6179255611). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T21:49:46Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5631 | `core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheReuse.cpp` [L127](https://github.com/boykopovar/AnyPS5/blob/922abe6a4e2b5030ef5308c25a51c1a478c3c1f2/core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheReuse.cpp#L127), [L151](https://github.com/boykopovar/AnyPS5/blob/922abe6a4e2b5030ef5308c25a51c1a478c3c1f2/core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheReuse.cpp#L151) | | | | #5897 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCapture.cpp` [L76](https://github.com/boykopovar/AnyPS5/blob/922abe6a4e2b5030ef5308c25a51c1a478c3c1f2/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCapture.cpp#L76) | | |
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!6093
No description provided.