fix(agc): look up cached draws at the fixed pixel push slot #2900

Merged
JAB-dev merged 1 commit from upstream-pr/2900 into main 2026-10-10 18:43:31 +00:00
JAB-dev commented 2026-10-10 18:17:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-10T18:17:53Z.


What

Fixes a regression from #2661: with pipeline libraries on (the default), cached draws were never reused, which cost Animal Well about 10 FPS on Windows (42 -> 52 FPS with this fix). It's a one-line change and keeps #2661's single fragment library.

Why: #2661 places the pixel shader's push constants at the fixed fragment slot (byte 128) and the draw cache records that offset, but Driver::lookupDraw still expected the old stacked offset after the vertex shader's push bytes. Every pixel stage missed as a layout mismatch, so each draw was captured and materialized again and no draw recipe was used.

The lookup now advances its cursor with Graphics::StagePushOffset, as Driver::draw and PrepareGraphicsStages do. Without pipeline libraries StagePushOffset returns the cursor unchanged, so that path is unaffected.

Draw-cache counters in PPSA22520 (Animal Well):

APS5_PROFILE_DRAW, 10 s main 57f96fd2b with this PR
draw-cache lookups 43321 48710
hits 0 48710
misses: layout (push offset) 43321 0
draw recipe hits none reported 48997

Tested

Windows 11, WinLibs GCC 15.2.0, RTX 4070 SUPER (NVIDIA, pipeline libraries on by default). Measured on main 57f96fd2b; rebased onto 9f87be5cc, which changes nothing in the draw path.

  • PPSA22520, the same 50 s scene from boot, mean FPS: main 42.5 / 41.8, this PR 52.8 / 51.0 (two runs each). Reverting only #2661 gave 50.9 / 53.7.
  • agc_pipeline_library, agc_pipeline_library_off, agc_pipeline_library_fast_only, agc_driver, agc_driver_graphics, agc_recorder_kept_bytes pass.
  • tools/check_conventions.py --base origin/main passes.
  • No test covers lookupDraw hits: the driver tests don't draw through the draw cache, so this has no new test. Full ctest not run. Linux not tested.

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 (attach them to this PR)
  • New third-party code is a submodule built from source: N/A, no third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813424833 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2900). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-10T18:17:53Z. --- ### What Fixes a regression from #2661: with pipeline libraries on (the default), cached draws were never reused, which cost Animal Well about 10 FPS on Windows (42 -> 52 FPS with this fix). It's a one-line change and keeps #2661's single fragment library. Why: #2661 places the pixel shader's push constants at the fixed fragment slot (byte 128) and the draw cache records that offset, but `Driver::lookupDraw` still expected the old stacked offset after the vertex shader's push bytes. Every pixel stage missed as a layout mismatch, so each draw was captured and materialized again and no draw recipe was used. The lookup now advances its cursor with `Graphics::StagePushOffset`, as `Driver::draw` and `PrepareGraphicsStages` do. Without pipeline libraries `StagePushOffset` returns the cursor unchanged, so that path is unaffected. Draw-cache counters in PPSA22520 (Animal Well): | `APS5_PROFILE_DRAW`, 10 s | `main` 57f96fd2b | with this PR | |---|---|---| | draw-cache lookups | 43321 | 48710 | | hits | 0 | 48710 | | misses: layout (push offset) | 43321 | 0 | | draw recipe hits | none reported | 48997 | ### Tested Windows 11, WinLibs GCC 15.2.0, RTX 4070 SUPER (NVIDIA, pipeline libraries on by default). Measured on `main` 57f96fd2b; rebased onto 9f87be5cc, which changes nothing in the draw path. - PPSA22520, the same 50 s scene from boot, mean FPS: `main` 42.5 / 41.8, this PR 52.8 / 51.0 (two runs each). Reverting only #2661 gave 50.9 / 53.7. - `agc_pipeline_library`, `agc_pipeline_library_off`, `agc_pipeline_library_fast_only`, `agc_driver`, `agc_driver_graphics`, `agc_recorder_kept_bytes` pass. - `tools/check_conventions.py --base origin/main` passes. - No test covers `lookupDraw` hits: the driver tests don't draw through the draw cache, so this has no new test. Full ctest not run. Linux not tested. ### 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 (attach them to this PR) - [x] New third-party code is a submodule built from source: N/A, no third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
AlxcBTW commented 2026-10-10 20:59:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-10T20:59:43Z.


A regression test for this fix, if you want one: AlxcBTW/AnyPS5#29 (24103825) moves the stage walk out of lookupDraw into Driver::MatchDrawEntry, which takes the guest memory validation as a callback, and adds agc_driver_draw_cache_layout, which checks the walk without a device. With fixed slots the fragment variant at the slot has to hit and one packed after the vertex push constants is never validated; without them it is the other way round, and a variant at neither offset is a layout miss. With this PR's StagePushOffset line removed from MatchDrawEntry, the test fails with the fixed-slot lookup picked the wrong fragment variant, while agc_driver still passes, so the existing tests don't cover this. Full CI passed on top of main 262c0316 (Windows 720/720, Linux 712/712), and agc_driver* passes 254/254 on an RTX 5070 Laptop.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102118891 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2900#issuecomment-6102118891). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-10T20:59:43Z. --- A regression test for this fix, if you want one: AlxcBTW/AnyPS5#29 ([`24103825`](https://github.com/AlxcBTW/AnyPS5/commit/24103825a94ab3634b0f1ba31b617565c60c886e)) moves the stage walk out of `lookupDraw` into `Driver::MatchDrawEntry`, which takes the guest memory validation as a callback, and adds `agc_driver_draw_cache_layout`, which checks the walk without a device. With fixed slots the fragment variant at the slot has to hit and one packed after the vertex push constants is never validated; without them it is the other way round, and a variant at neither offset is a layout miss. With this PR's `StagePushOffset` line removed from `MatchDrawEntry`, the test fails with `the fixed-slot lookup picked the wrong fragment variant`, while `agc_driver` still passes, so the existing tests don't cover this. [Full CI](https://github.com/AlxcBTW/AnyPS5/actions/runs/38084367532) passed on top of `main` 262c0316 (Windows 720/720, Linux 712/712), and `agc_driver*` passes 254/254 on an RTX 5070 Laptop. AI-assisted: yes (Claude Code).
JAB-dev commented 2026-10-10 21:02:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-10T21:02:02Z.


Thanks! I opened #2980 a bit earlier with a test for this: it submits the same draw twice through the driver and requires the second one to hit the draw cache. With the StagePushOffset line removed it fails with pipeline libraries on. Yours checks the walk without a device, so it also runs where there's no Vulkan device. Fine with me if either or both go in.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102139070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2900#issuecomment-6102139070). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-10T21:02:02Z. --- Thanks! I opened #2980 a bit earlier with a test for this: it submits the same draw twice through the driver and requires the second one to hit the draw cache. With the `StagePushOffset` line removed it fails with pipeline libraries on. Yours checks the walk without a device, so it also runs where there's no Vulkan device. Fine with me if either or both go in.
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!2900
No description provided.