perf(agc): draws that differ only in user data reuse their shape's decode and stages #494

Merged
MichonGoddijn231849 merged 2 commits from upstream-pr/494 into main 2026-10-14 21:32:51 +00:00
MichonGoddijn231849 commented 2026-10-04 09:11:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T09:11:12Z.


What

Split out of #291, as discussed there. It builds on #493 (merged), which keys draws on the user words each stage reads.

A draw that misses the cache often differs from an earlier draw only in user data, for example a per-object constant buffer pointer. Such a draw decoded and compiled from scratch. Now:

  • The draw key also yields a shape: the key without the user words the stages read (and without the merged-stage pointer registers).
  • On a key miss whose shape has an entry, the draw copies that entry's decode and re-reads only the user words and merged-stage pointers.
  • Each compiled stage is reused if its captured memory reads still hold; the rest are compiled.
  • A new key of a shape replaces the shape's previous entry instead of keeping both, and starts without that entry's variants, which were compiled under other user words.

APS5_NO_DRAW_DATA_HITS=1 disables it. APS5_VERIFY_DRAW_DATA_HITS=1 also decodes and compiles everything in full and throws when the results differ. APS5_TRACE_DRAW_CACHE counts why keys missed (new registers, user words only, evicted, never inserted), and the profile line counts data-only hits and reused or compiled stages.

#291's time-based failure memo is not part of this: #422 memoizes source failures already, and a skip that ends on a timer isn't exact.

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.

  • ctest: everything that passes on main here passes.
  • Rebased on main a56c905df (2026-10-13), starting from gjonn's rebase of this series onto 6ac63bf0c (thanks). On Windows (MinGW GCC 15.2, RTX 5080) the whole agc_* suite passes on the top of the series: 483 tests, 1 skipped (agc_driver_stencil_ref_export).
  • In-game, this change was tested as part of #291: GTA V (PPSA04264) Story Mode, and Dreaming Sarah (PPSA02929) whose title menu text shows with data-only hits on. This split version hasn't been re-run in a game.

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (#493 is merged)
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4733191222 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-04T09:11:12Z. --- ### What Split out of #291, as discussed there. It builds on #493 (merged), which keys draws on the user words each stage reads. A draw that misses the cache often differs from an earlier draw only in user data, for example a per-object constant buffer pointer. Such a draw decoded and compiled from scratch. Now: - The draw key also yields a shape: the key without the user words the stages read (and without the merged-stage pointer registers). - On a key miss whose shape has an entry, the draw copies that entry's decode and re-reads only the user words and merged-stage pointers. - Each compiled stage is reused if its captured memory reads still hold; the rest are compiled. - A new key of a shape replaces the shape's previous entry instead of keeping both, and starts without that entry's variants, which were compiled under other user words. `APS5_NO_DRAW_DATA_HITS=1` disables it. `APS5_VERIFY_DRAW_DATA_HITS=1` also decodes and compiles everything in full and throws when the results differ. `APS5_TRACE_DRAW_CACHE` counts why keys missed (new registers, user words only, evicted, never inserted), and the profile line counts data-only hits and reused or compiled stages. #291's time-based failure memo is not part of this: #422 memoizes source failures already, and a skip that ends on a timer isn't exact. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0. - `ctest`: everything that passes on `main` here passes. - Rebased on `main` a56c905df (2026-10-13), starting from gjonn's rebase of this series onto 6ac63bf0c (thanks). On Windows (MinGW GCC 15.2, RTX 5080) the whole `agc_*` suite passes on the top of the series: 483 tests, 1 skipped (`agc_driver_stencil_ref_export`). - In-game, this change was tested as part of #291: GTA V (PPSA04264) Story Mode, and Dreaming Sarah (PPSA02929) whose title menu text shows with data-only hits on. This split version hasn't been re-run in a game. ### 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 in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none (#493 is merged) - [x] AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-04 09:52:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:52:56Z.


Thanks, the data-only path reads right to me. The same shape means the same registers apart from the user words and merged pointers, the copied decode re-reads exactly those, and a stage is only reused when its own user words are unchanged and its captured reads validate. So the result should match a full decode and compile.

Two things before I'd take it:

  1. The supersede in insertDrawEntry runs whether or not data hits are on: cacheDrawStages passes the shape whenever the register key is used. So with APS5_NO_DRAW_DATA_HITS=1, a new key of a shape still erases the previous key's entry, and the draw then decodes and compiles in full. That's worse than main rather than the old behaviour. Could the shape (and so the supersede) only be passed when drawDataHits() is on?
  2. With data hits on, two draws of one shape that alternate with stable user words (two objects with their own constant pointers, every frame) used to be two key hits. Now each one erases the other's entry, so every draw misses its key and recompiles the stage whose words differ. Did you see that pattern in GTA V? The APS5_TRACE_DRAW_CACHE counters (superseded, data-only hits, stages compiled) from a run of this split version, plus one run with APS5_VERIFY_DRAW_DATA_HITS=1, would show whether keeping the previous entry and only pointing the shape at the newest key works better.

A small one: this commit drops <algorithm> and <array> from DrawRegisterKey.cpp while it still uses std::min and std::array. It builds through other headers, but I'd keep them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978699832 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-5978699832). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T09:52:56Z. --- Thanks, the data-only path reads right to me. The same shape means the same registers apart from the user words and merged pointers, the copied decode re-reads exactly those, and a stage is only reused when its own user words are unchanged and its captured reads validate. So the result should match a full decode and compile. Two things before I'd take it: 1. The supersede in `insertDrawEntry` runs whether or not data hits are on: `cacheDrawStages` passes the shape whenever the register key is used. So with `APS5_NO_DRAW_DATA_HITS=1`, a new key of a shape still erases the previous key's entry, and the draw then decodes and compiles in full. That's worse than main rather than the old behaviour. Could the shape (and so the supersede) only be passed when `drawDataHits()` is on? 2. With data hits on, two draws of one shape that alternate with stable user words (two objects with their own constant pointers, every frame) used to be two key hits. Now each one erases the other's entry, so every draw misses its key and recompiles the stage whose words differ. Did you see that pattern in GTA V? The `APS5_TRACE_DRAW_CACHE` counters (superseded, data-only hits, stages compiled) from a run of this split version, plus one run with `APS5_VERIFY_DRAW_DATA_HITS=1`, would show whether keeping the previous entry and only pointing the shape at the newest key works better. A small one: this commit drops `<algorithm>` and `<array>` from DrawRegisterKey.cpp while it still uses `std::min` and `std::array`. It builds through other headers, but I'd keep them.
MichonGoddijn231849 commented 2026-10-05 15:40:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-05T15:40:41Z.


Thanks. Both points and the includes are done in 795b8bc9, on top of a rebase onto current main:

  1. The shape (and so drawShapes) is only passed to insertDrawEntry when drawDataHits() is on. With APS5_NO_DRAW_DATA_HITS=1 nothing is keyed by shape, so it behaves like #493 alone.
  2. The supersede is gone. A new key of a shape keeps the previous key's entry, and the shape only points at its newest key. Two objects of one shape with their own stable user words keep their own key hits again. Entries are still bounded by the normal LRU (APS5_DRAW_CACHE_ENTRIES), and an evicted key's shape link is dropped as before.
  3. DrawRegisterKey.cpp keeps <algorithm> and <array>.

The rebase had one conflict: main's null pixel program (#469) reads RSRC2 as 0 when it's unset, and this PR had moved that read into readUserWords. DrawProgram now carries nullPixel, so the data-only path re-reads the user words the same way.

I haven't measured the APS5_TRACE_DRAW_CACHE counters or a APS5_VERIFY_DRAW_DATA_HITS=1 run in GTA V on this version yet. I'll post both here once I have them. Build and ctest are clean apart from the failures main has locally (agc_driver_f32_output_modifier, agc_driver_scalar_sop1 and the relinker Python tests). #493 is rebased too, with its commit unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5997826751 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-5997826751). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-05T15:40:41Z. --- Thanks. Both points and the includes are done in 795b8bc9, on top of a rebase onto current `main`: 1. The shape (and so `drawShapes`) is only passed to `insertDrawEntry` when `drawDataHits()` is on. With `APS5_NO_DRAW_DATA_HITS=1` nothing is keyed by shape, so it behaves like #493 alone. 2. The supersede is gone. A new key of a shape keeps the previous key's entry, and the shape only points at its newest key. Two objects of one shape with their own stable user words keep their own key hits again. Entries are still bounded by the normal LRU (`APS5_DRAW_CACHE_ENTRIES`), and an evicted key's shape link is dropped as before. 3. `DrawRegisterKey.cpp` keeps `<algorithm>` and `<array>`. The rebase had one conflict: `main`'s null pixel program (#469) reads RSRC2 as 0 when it's unset, and this PR had moved that read into `readUserWords`. `DrawProgram` now carries `nullPixel`, so the data-only path re-reads the user words the same way. I haven't measured the `APS5_TRACE_DRAW_CACHE` counters or a `APS5_VERIFY_DRAW_DATA_HITS=1` run in GTA V on this version yet. I'll post both here once I have them. Build and ctest are clean apart from the failures `main` has locally (`agc_driver_f32_output_modifier`, `agc_driver_scalar_sop1` and the relinker Python tests). #493 is rebased too, with its commit unchanged.
oneandonlydean commented 2026-10-06 05:34:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T05:34:18Z.


Thanks, both points are done in 795b8bc9. The shape is only passed when drawDataHits() is on, so APS5_NO_DRAW_DATA_HITS=1 doesn't touch shapes at all. And with the supersede gone, a shape's earlier keys keep their entries, under the normal LRU.

It conflicts with main now in DrawCacheStatistics.cpp: #798 moved the periodic reports off the GPU workers and replaced the std::fprintf(stderr, ...) calls with AgcDriver::ProfilePrint_nid_no_patch(...). Keeping your text assembly (with profileDrawCacheLines) and printing it through ProfilePrint_nid_no_patch("%s", text.c_str()) should resolve it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6010065516 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6010065516). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T05:34:18Z. --- Thanks, both points are done in 795b8bc9. The shape is only passed when `drawDataHits()` is on, so `APS5_NO_DRAW_DATA_HITS=1` doesn't touch shapes at all. And with the supersede gone, a shape's earlier keys keep their entries, under the normal LRU. It conflicts with main now in `DrawCacheStatistics.cpp`: #798 moved the periodic reports off the GPU workers and replaced the `std::fprintf(stderr, ...)` calls with `AgcDriver::ProfilePrint_nid_no_patch(...)`. Keeping your `text` assembly (with `profileDrawCacheLines`) and printing it through `ProfilePrint_nid_no_patch("%s", text.c_str())` should resolve it.
MichonGoddijn231849 commented 2026-10-06 15:29:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-06T15:29:23Z.


Rebased onto current main (now 9f52b1ed). The DrawCacheStatistics.cpp conflict is resolved as you suggested: the text assembly with profileDrawCacheLines stays and goes out through ProfilePrint_nid_no_patch("%s", text.c_str()). Its two profile lines are the same format strings as main's, and the PR adds no other stderr reports. Builds; the driver tests pass apart from agc_driver_scalar_sop1, which fails without this PR too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6019644743 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6019644743). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-06T15:29:23Z. --- Rebased onto current `main` (now 9f52b1ed). The `DrawCacheStatistics.cpp` conflict is resolved as you suggested: the `text` assembly with `profileDrawCacheLines` stays and goes out through `ProfilePrint_nid_no_patch("%s", text.c_str())`. Its two profile lines are the same format strings as `main`'s, and the PR adds no other `stderr` reports. Builds; the driver tests pass apart from `agc_driver_scalar_sop1`, which fails without this PR too.
MichonGoddijn231849 commented 2026-10-07 08:17:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T08:17:20Z.


Rebased onto current main (now 35c8550e). One conflict, in DrawDecode.cpp: #1037 made unwritten user-data registers read as zero (readUserData) in the loop this PR moves into readUserWords. readUserWords now uses readUserData, so the full decode and a data-only hit's refresh read the same words. #493's commit is still included first. Builds; the driver tests pass apart from agc_driver_scalar_sop1 (fixed by #928).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6033897598 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6033897598). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-07T08:17:20Z. --- Rebased onto current `main` (now 35c8550e). One conflict, in `DrawDecode.cpp`: #1037 made unwritten user-data registers read as zero (`readUserData`) in the loop this PR moves into `readUserWords`. `readUserWords` now uses `readUserData`, so the full decode and a data-only hit's refresh read the same words. #493's commit is still included first. Builds; the driver tests pass apart from `agc_driver_scalar_sop1` (fixed by #928).
MichonGoddijn231849 commented 2026-10-07 17:31:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T17:31:16Z.


Rebased onto current main and the rebased #493 (now cf9195e6), no conflicts. The draw-path PRs #1191, #1193, #1201 and #1202 build on this one. Build and ctest pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6043249878 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6043249878). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-07T17:31:16Z. --- Rebased onto current `main` and the rebased #493 (now cf9195e6), no conflicts. The draw-path PRs #1191, #1193, #1201 and #1202 build on this one. Build and ctest pass.
MichonGoddijn231849 commented 2026-10-09 08:32:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:32:01Z.


Closing: superseded by #639. Prepared artifacts no longer depend on user data (it is read at runtime from the shader data block), so draws that differ only in user data already share one shader, which is what this PR added.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077376668 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6077376668). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-09T08:32:01Z. --- Closing: superseded by #639. Prepared artifacts no longer depend on user data (it is read at runtime from the shader data block), so draws that differ only in user data already share one shader, which is what this PR added.
MichonGoddijn231849 commented 2026-10-09 08:32:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:32:34Z.


Reopening, I closed this too quickly: #639 removes the per-draw compile, but the decode reuse and the captured-stage reuse for draws that differ only in user words still apply. Parked as a draft until it is ported onto the prepared-shader path.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077384776 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6077384776). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-09T08:32:34Z. --- Reopening, I closed this too quickly: #639 removes the per-draw compile, but the decode reuse and the captured-stage reuse for draws that differ only in user words still apply. Parked as a draft until it is ported onto the prepared-shader path.
Mouhand-Kaddo commented 2026-10-10 10:22:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T10:22:37Z.


Additional platform validation of standalone PR head 7f13b7274f9ba5f6c9a1113f8b15d1ee849c1f6e (2026-10-11):

Linux: passed — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja; Release, BUILD_TESTING=ON.

3 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.

Checks: agc_driver, agc_driver_pm4, agc_driver_graphics.

Command after building: ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^agc_driver($|_graphics$|_pm4$)".

Vulkan: Mesa lavapipe 26.2.4 / LLVM 23.1.1 software Vulkan; no native Linux hardware-GPU result.

Internal limitation: heap-mirror subcases returned early because the guest arena was not write-watched in WSL. Zero CTest skips does not include that early return.

Focused driver, PM4 and graphics regression checks passed. No title replay, frame-time measurement, or comparison of draw-cache hit counters was performed; this does not quantify the performance gain.

No title/gameplay validation. These results cover the standalone head, not a merge with current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096523689 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6096523689). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-10T10:22:37Z. --- <!-- anyps5-platform-validation:7f13b7274f9ba5f6c9a1113f8b15d1ee849c1f6e --> Additional platform validation of standalone PR head `7f13b7274f9ba5f6c9a1113f8b15d1ee849c1f6e` (2026-10-11): **Linux: passed** — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja; Release, `BUILD_TESTING=ON`. 3 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run. Checks: `agc_driver`, `agc_driver_pm4`, `agc_driver_graphics`. Command after building: `ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^agc_driver($|_graphics$|_pm4$)"`. Vulkan: Mesa lavapipe 26.2.4 / LLVM 23.1.1 software Vulkan; no native Linux hardware-GPU result. Internal limitation: heap-mirror subcases returned early because the guest arena was not write-watched in WSL. Zero CTest skips does not include that early return. Focused driver, PM4 and graphics regression checks passed. No title replay, frame-time measurement, or comparison of draw-cache hit counters was performed; this does not quantify the performance gain. No title/gameplay validation. These results cover the standalone head, not a merge with current main.
Raghav314 commented 2026-10-11 04:10:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-11T04:10:13Z.


Tried this with Hades II (PPSA36082) on my machine, rebased locally onto current main plus the stuff the game needs to get in game. The data-only hits fire a lot there, but almost none of them actually reuse a stage. Standing in the hub, every 10 s about 215k draws find their shape, yet only ~7k stages get reused and ~420k get built again.

I dumped what the rebuilt stages look like next to the kept variant. Around 186k of them read the exact same runs and come out with the same variant, bindings and push constants. The only user word that differs is word 8 of the sprite vertex shader, a small per-draw value (0x0c to 0x33) that the stage never reads. The candidate check in lookupDraw drops a stage as soon as any user word differs, so these never even get validated.

So locally I made the check compare only the user words a stage reads:

  • the SRT walk records which user words it reads (in the GetUserData case of BasicEvaluator::EvaluateInst, through a mask pointer on SrtRuntime)
  • materializeResult adds the registers copied into the shader data (layout.userDataRegisters)
  • the driver adds the vertex fetch table registers, keeps the mask on the DispatchVariant, and lookupDraw only requires those words to match. Runs and words are still validated like before. If the walk reports nothing, every word counts.

For the sprite shader that ends up as words 2-3 plus the fetch tables. I checked it with APS5_VERIFY_DRAW_DATA_HITS=1: 145k reused stages per 10 s built again and compared, no mismatches. Then without verify:

before after
stages reused on data-only hits / 10 s ~7k ~201k
queue worker time per draw packet 32.1 us 27.3 us
capture per packet 6.6 us 4.1 us
hub fps (profiling on) 39.8 46.7

The fps is from two separate runs so I wouldn't read too much into it, the per-packet time is the better number.

The other big group (~248k per 10 s) is different: word 2 is a per-sprite pointer and word 4 a per-frame constant ring that moves by 0x200000 every frame. Both get copied straight into the push constants and the walk reads at the new addresses, so the stage really does change. Reusing those would need the push constants rebuilt from the new words and some proof that the pointer only feeds addresses, which I didn't try.

One thing to know if you want to do the mask: it adds a field to ShaderInvocation, so the disk cache encoder and format version need a bump. Can share the diff if it helps.

LLM assistance used.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105308377 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6105308377). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-10-11T04:10:13Z. --- Tried this with Hades II (PPSA36082) on my machine, rebased locally onto current main plus the stuff the game needs to get in game. The data-only hits fire a lot there, but almost none of them actually reuse a stage. Standing in the hub, every 10 s about 215k draws find their shape, yet only ~7k stages get reused and ~420k get built again. I dumped what the rebuilt stages look like next to the kept variant. Around 186k of them read the exact same runs and come out with the same variant, bindings and push constants. The only user word that differs is word 8 of the sprite vertex shader, a small per-draw value (0x0c to 0x33) that the stage never reads. The candidate check in `lookupDraw` drops a stage as soon as any user word differs, so these never even get validated. So locally I made the check compare only the user words a stage reads: - the SRT walk records which user words it reads (in the `GetUserData` case of `BasicEvaluator::EvaluateInst`, through a mask pointer on `SrtRuntime`) - `materializeResult` adds the registers copied into the shader data (`layout.userDataRegisters`) - the driver adds the vertex fetch table registers, keeps the mask on the `DispatchVariant`, and `lookupDraw` only requires those words to match. Runs and words are still validated like before. If the walk reports nothing, every word counts. For the sprite shader that ends up as words 2-3 plus the fetch tables. I checked it with `APS5_VERIFY_DRAW_DATA_HITS=1`: 145k reused stages per 10 s built again and compared, no mismatches. Then without verify: | | before | after | |---|---|---| | stages reused on data-only hits / 10 s | ~7k | ~201k | | queue worker time per draw packet | 32.1 us | 27.3 us | | capture per packet | 6.6 us | 4.1 us | | hub fps (profiling on) | 39.8 | 46.7 | The fps is from two separate runs so I wouldn't read too much into it, the per-packet time is the better number. The other big group (~248k per 10 s) is different: word 2 is a per-sprite pointer and word 4 a per-frame constant ring that moves by 0x200000 every frame. Both get copied straight into the push constants and the walk reads at the new addresses, so the stage really does change. Reusing those would need the push constants rebuilt from the new words and some proof that the pointer only feeds addresses, which I didn't try. One thing to know if you want to do the mask: it adds a field to `ShaderInvocation`, so the disk cache encoder and format version need a bump. Can share the diff if it helps. LLM assistance used.
MichonGoddijn231849 commented 2026-10-11 07:59:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T07:59:38Z.


@Raghav314 thanks, that's a good measurement, and the per-stage read mask is the right shape for it. This PR is parked as a draft, so please open your mask as its own PR on main rather than waiting on this one (with the disk cache format bump, and the APS5_VERIFY_DRAW_DATA_HITS run as its evidence); it doesn't depend on #494.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106914016 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6106914016). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-11T07:59:38Z. --- @Raghav314 thanks, that's a good measurement, and the per-stage read mask is the right shape for it. This PR is parked as a draft, so please open your mask as its own PR on main rather than waiting on this one (with the disk cache format bump, and the `APS5_VERIFY_DRAW_DATA_HITS` run as its evidence); it doesn't depend on #494.
Raghav314 commented 2026-10-12 01:03:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-12T01:03:47Z.


@MichonGoddijn231849 thanks. I looked at doing that, but on main the mask has nothing to attach to. It filters the data-hit candidates in lookupDraw, and that path comes from this PR. Main's draw path has no data hits. Its draw key hashes every user word (DrawLookup.cpp), so a sprite draw whose unread word 8 changed is just a miss, before any stage gets looked at. Masking the key instead doesn't work, because the mask is only known after the stage has been built. APS5_VERIFY_DRAW_DATA_HITS is also from this PR (main only has APS5_VERIFY_DATA_HITS for compute).

So on its own against main it would record the reads and never use them. The whole gain I measured was on draws (the sprite vertex shader), and I have nothing showing it helps main's compute data hits.

I'll open it as a PR on top of this one instead (12 files, +35/-4, including the disk cache format bump and the APS5_VERIFY_DRAW_DATA_HITS run).

LLM assistance used.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115918370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6115918370). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-10-12T01:03:47Z. --- @MichonGoddijn231849 thanks. I looked at doing that, but on main the mask has nothing to attach to. It filters the data-hit candidates in `lookupDraw`, and that path comes from this PR. Main's draw path has no data hits. Its draw key hashes every user word (`DrawLookup.cpp`), so a sprite draw whose unread word 8 changed is just a miss, before any stage gets looked at. Masking the key instead doesn't work, because the mask is only known after the stage has been built. `APS5_VERIFY_DRAW_DATA_HITS` is also from this PR (main only has `APS5_VERIFY_DATA_HITS` for compute). So on its own against main it would record the reads and never use them. The whole gain I measured was on draws (the sprite vertex shader), and I have nothing showing it helps main's compute data hits. I'll open it as a PR on top of this one instead (12 files, +35/-4, including the disk cache format bump and the `APS5_VERIFY_DRAW_DATA_HITS` run). LLM assistance used.
EagleBearerYS commented 2026-10-12 19:11:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-12T19:11:23Z.


Another data point, from Planet of Lana (PPSA19450) on Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, RTX 3070 Laptop. I rebased this onto main d146ec1b6 and again onto c36fd0a0e. agc_driver_draw_cache_reuse passes on both.

  • Verify mode: with APS5_VERIFY_DRAW_DATA_HITS=1, 240 s through the menus, a cutscene and gameplay, plus 300 s on the second rebase, gave no mismatch and no throw.
  • Cost per draw: I measured the same build with data hits on and with APS5_NO_DRAW_DATA_HITS=1, with Lana standing in the first village and APS5_PROFILE_DRAW=1. With data hits, the decode drops from 13-14 to 6.0 us per draw, and the draw packet from 140.5 to 130.4 us. [draw-cache] register key reports the decode skipped for 63,186 of 63,195 draws. The frame rate went from 71.2 to 75.1 presents per 10 s, but single runs on this PC vary by ~15%, so I wouldn't read anything into that.
  • Stage reuse is low, as @Raghav314 saw in Hades II. Lana's per-draw constants sit in ring buffers, so most data hits capture their reads at new addresses and compile again: in a later area, 32,894 stages were reused and 119,558 compiled per 10 s. Capture plus recompile is still ~23 us per draw.
  • Memory: in an instrumented run, the draw cache's objects stayed within its bound. The memory growth I saw on this stack came from the storage-image cache, not from here.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6130876516 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6130876516). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-12T19:11:23Z. --- Another data point, from Planet of Lana (PPSA19450) on Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, RTX 3070 Laptop. I rebased this onto `main` d146ec1b6 and again onto c36fd0a0e. `agc_driver_draw_cache_reuse` passes on both. - **Verify mode:** with `APS5_VERIFY_DRAW_DATA_HITS=1`, 240 s through the menus, a cutscene and gameplay, plus 300 s on the second rebase, gave no mismatch and no throw. - **Cost per draw:** I measured the same build with data hits on and with `APS5_NO_DRAW_DATA_HITS=1`, with Lana standing in the first village and `APS5_PROFILE_DRAW=1`. With data hits, the decode drops from 13-14 to 6.0 us per draw, and the draw packet from 140.5 to 130.4 us. `[draw-cache] register key` reports the decode skipped for 63,186 of 63,195 draws. The frame rate went from 71.2 to 75.1 presents per 10 s, but single runs on this PC vary by ~15%, so I wouldn't read anything into that. - **Stage reuse is low,** as @Raghav314 saw in Hades II. Lana's per-draw constants sit in ring buffers, so most data hits capture their reads at new addresses and compile again: in a later area, 32,894 stages were reused and 119,558 compiled per 10 s. Capture plus recompile is still ~23 us per draw. - **Memory:** in an instrumented run, the draw cache's objects stayed within its bound. The memory growth I saw on this stack came from the storage-image cache, not from here.
MichonGoddijn231849 commented 2026-10-13 15:45:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-13T15:45:47Z.


Rebased onto current main (a56c905df) as one commit, from @gjonn's rebase of the series (main's free-function decoder with its static-ABI mode; main's incremental register key is the shape key now). agc_driver_draw_cache_reuse and the rest of the agc_* suite pass on Windows.

@EagleBearerYS thanks for the Planet of Lana numbers. @Raghav314 your per-stage read mask can go on top of this head now.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6149413612 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6149413612). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-13T15:45:47Z. --- Rebased onto current `main` (a56c905df) as one commit, from @gjonn's rebase of the series (main's free-function decoder with its static-ABI mode; main's incremental register key is the shape key now). `agc_driver_draw_cache_reuse` and the rest of the `agc_*` suite pass on Windows. @EagleBearerYS thanks for the Planet of Lana numbers. @Raghav314 your per-stage read mask can go on top of this head now.
oneandonlydean commented 2026-10-14 00:10:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T00:10:26Z.


Thanks for the rebase. #5216 now conflicts here, and not only in text: a key gets its entry at its second sight, so a shape whose keys never repeat (per-frame user data) never gets an entry and its data-only hits never start. Before this goes in:

  • rebase onto main with an admission rule for shapes (for example, admit a key whose shape already has an entry), and say which one you chose;
  • a case in agc_driver_draw_cache_reuse that fails on main (a draw that differs only in user words reuses the decode), and the summary lines of main and of this change from one machine and scene, as CONTRIBUTING asks.
    If you'd rather we do the rebase over #5216, say so and we'll push it to your branch. #4943 changes the same lookup.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157891794 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6157891794). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T00:10:26Z. --- Thanks for the rebase. #5216 now conflicts here, and not only in text: a key gets its entry at its second sight, so a shape whose keys never repeat (per-frame user data) never gets an entry and its data-only hits never start. Before this goes in: - rebase onto main with an admission rule for shapes (for example, admit a key whose shape already has an entry), and say which one you chose; - a case in `agc_driver_draw_cache_reuse` that fails on main (a draw that differs only in user words reuses the decode), and the summary lines of main and of this change from one machine and scene, as CONTRIBUTING asks. If you'd rather we do the rebase over #5216, say so and we'll push it to your branch. #4943 changes the same lookup.
MichonGoddijn231849 commented 2026-10-14 08:36:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-14T08:36:05Z.


Yes please, if you can do the rebase over #5216 (and #4943) that's the cleaner way, since you know the new lookup. The admission rule I'd take: a key is admitted at its first sight when its shape already has an entry or was seen before, otherwise at its second sight as #5216 does. Remembering shapes in the same sightings table (or a small one next to it) keeps #5216's protection for keys that never repeat in shapes that also never repeat, and lets a shape whose user data changes every frame get its first entry on its second draw.

Once it's on the branch I'll add the agc_driver_draw_cache_reuse case (a draw that differs only in user words reuses the decode; it fails on main) and the summary lines of main and of the change from one machine and scene.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6164325218 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6164325218). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-14T08:36:05Z. --- Yes please, if you can do the rebase over #5216 (and #4943) that's the cleaner way, since you know the new lookup. The admission rule I'd take: a key is admitted at its first sight when its **shape** already has an entry or was seen before, otherwise at its second sight as #5216 does. Remembering shapes in the same sightings table (or a small one next to it) keeps #5216's protection for keys that never repeat in shapes that also never repeat, and lets a shape whose user data changes every frame get its first entry on its second draw. Once it's on the branch I'll add the `agc_driver_draw_cache_reuse` case (a draw that differs only in user words reuses the decode; it fails on `main`) and the summary lines of `main` and of the change from one machine and scene.
adriadam10 commented 2026-10-14 20:30:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T20:30:16Z.


Taking the rebase onto #5216 (with the shape admission rule above and a case in agc_driver_draw_cache_reuse) from here, so it isn't done twice.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6177786459 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6177786459). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T20:30:16Z. --- Taking the rebase onto #5216 (with the shape admission rule above and a case in `agc_driver_draw_cache_reuse`) from here, so it isn't done twice.
adriadam10 commented 2026-10-14 21:05:20 +00:00 (Migrated from github.com)

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


Took over the rebase onto #5216, as announced. Pushed on top of your commit:

  • Rebased onto main and resolved the conflicts with #5216 and the tessellation-instanced exclusion in Draw.cpp (stageEntries/compiledStages from main, your data-candidate reuse kept).
  • ReadUserWords now recomputes tailContinuation too, so a data-only hit refreshes it. sameDecode compares it.
  • Shape admission: a key whose shape was seen before but has no entry yet is admitted at its first sight. A shape that already has an entry serves data-only hits from that entry, and its new keys are still admitted at their second sight. This differs a little from your proposal: admitting every key of a known shape at first sight would bring back the per-draw insert churn that #5216 removed. Shapes are tracked in a second DrawKeySightings table.
  • agc_driver_draw_cache_reuse gets a new case, UserDataDrawsReuseTheirShape:
    • three draws with new pixel user words over a cached shape give 3 data-only hits, 0 inserts and the 3 vertex stages reused;
    • three keys of a new shape give 1 insert and 1 data-only hit.
  • A new test, agc_driver_draw_cache_reuse_verify, runs it with APS5_VERIFY_DRAW_DATA_HITS=1.
  • The case fails with the shape rule disabled ("inserted 0 draw entries, expected 1"). On main it doesn't compile, because main has no data-hit counters.

agc_driver_draw_cache_reuse, _off and _verify pass on RADV. The in-title numbers above were all measured before #5216. A before/after on one scene with this head would still be welcome. Merging once the Windows build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6178490648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6178490648). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T21:05:20Z. --- Took over the rebase onto #5216, as announced. Pushed on top of your commit: - Rebased onto main and resolved the conflicts with #5216 and the tessellation-instanced exclusion in `Draw.cpp` (`stageEntries`/`compiledStages` from main, your data-candidate reuse kept). - `ReadUserWords` now recomputes `tailContinuation` too, so a data-only hit refreshes it. `sameDecode` compares it. - Shape admission: a key whose shape was seen before but has no entry yet is admitted at its first sight. A shape that already has an entry serves data-only hits from that entry, and its new keys are still admitted at their second sight. This differs a little from your proposal: admitting every key of a known shape at first sight would bring back the per-draw insert churn that #5216 removed. Shapes are tracked in a second `DrawKeySightings` table. - `agc_driver_draw_cache_reuse` gets a new case, `UserDataDrawsReuseTheirShape`: - three draws with new pixel user words over a cached shape give 3 data-only hits, 0 inserts and the 3 vertex stages reused; - three keys of a new shape give 1 insert and 1 data-only hit. - A new test, `agc_driver_draw_cache_reuse_verify`, runs it with `APS5_VERIFY_DRAW_DATA_HITS=1`. - The case fails with the shape rule disabled ("inserted 0 draw entries, expected 1"). On main it doesn't compile, because main has no data-hit counters. `agc_driver_draw_cache_reuse`, `_off` and `_verify` pass on RADV. The in-title numbers above were all measured before #5216. A before/after on one scene with this head would still be welcome. Merging once the Windows build is green.
github-actions[bot] commented 2026-10-14 21:11:11 +00:00 (Migrated from github.com)

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


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
#5238 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp L8
#5364 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawRegisterKey.hpp L8
core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp L130-131
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp L72-83
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp L36, L63, L66-67
#5631 core/libs/prx/libSceAgcDriver/CMakeLists.txt L1616
core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheReuse.cpp L106, L129
#5751 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cpp L35-39
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6178593581 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/494#issuecomment-6178593581). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T21:11:11Z. --- <!-- 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 | |---|---|---|---| | #5238 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp` [L8](https://github.com/boykopovar/AnyPS5/blob/4808d9c2032129eaf9dc31015e7c8cfbffde7a5c/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp#L8) | | | | #5364 | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawRegisterKey.hpp` [L8](https://github.com/boykopovar/AnyPS5/blob/4808d9c2032129eaf9dc31015e7c8cfbffde7a5c/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawRegisterKey.hpp#L8)<br>`core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp` [L130-131](https://github.com/boykopovar/AnyPS5/blob/4808d9c2032129eaf9dc31015e7c8cfbffde7a5c/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp#L130-L131)<br>`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp` [L72-83](https://github.com/boykopovar/AnyPS5/blob/4808d9c2032129eaf9dc31015e7c8cfbffde7a5c/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp#L72-L83)<br>`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp` [L36](https://github.com/boykopovar/AnyPS5/blob/4808d9c2032129eaf9dc31015e7c8cfbffde7a5c/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp#L36), [L63](https://github.com/boykopovar/AnyPS5/blob/4808d9c2032129eaf9dc31015e7c8cfbffde7a5c/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp#L63), [L66-67](https://github.com/boykopovar/AnyPS5/blob/4808d9c2032129eaf9dc31015e7c8cfbffde7a5c/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp#L66-L67) | | | | #5631 | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` [L1616](https://github.com/boykopovar/AnyPS5/blob/4808d9c2032129eaf9dc31015e7c8cfbffde7a5c/core/libs/prx/libSceAgcDriver/CMakeLists.txt#L1616)<br>`core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheReuse.cpp` [L106](https://github.com/boykopovar/AnyPS5/blob/4808d9c2032129eaf9dc31015e7c8cfbffde7a5c/core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheReuse.cpp#L106), [L129](https://github.com/boykopovar/AnyPS5/blob/4808d9c2032129eaf9dc31015e7c8cfbffde7a5c/core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheReuse.cpp#L129) | | | | #5751 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cpp` [L35-39](https://github.com/boykopovar/AnyPS5/blob/4808d9c2032129eaf9dc31015e7c8cfbffde7a5c/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cpp#L35-L39) | | |
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!494
No description provided.