perf(agc): keep unfolded indirect draws on the GPU #18319

Merged
edubox merged 4 commits from upstream-pr/18319 into main 2026-11-14 04:37:37 +00:00
edubox commented 2026-11-11 07:34:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-11-11T07:34:59Z.


What

ClassifyIndirectDraw sent every indirect draw whose program does not read the offset register the packet names to the CPU path (Path::NotFolded), so the driver expanded the record list into one draw per record and ran the full resource build for each.

The program never reads that register, so the record's dword never reaches the fetch and the draw starts at the packet's fixed offset, exactly what the CPU path produces (its patch writes a register no program reads). The classifier now tags that dimension as Constant with the packet's fixed offset and keeps the draw on the GPU. APS5_NO_GPU_UNFOLDED_INDIRECT=1 restores the CPU path.

A Constant dimension is rewritten record by record with vkCmdUpdateBuffer, so the guard that keeps such draws on the CPU goes from 256 to 1024 records: the multi-draw count is a small field and the scratch stays at most 20 KiB. Without it the real multi-draw counts of the title (366, 460, 576 records) still fell back to one draw per record.

Tested

Linux (CachyOS, GCC 16.2.1, Release, NVIDIA RTX 4080 SUPER, driver 620.70.06).

Planet Zoo (PPSA18026, 01.009.002). Same build otherwise, APS5_PROFILE_DRAW=1, vpad pressing Cross every 6 s. Before, every DRAW_INDEX_INDIRECT_MULTI classified to cpu (patched SGPR not folded); during the Scenario_01 load a 3-record packet took 15.7 s of a 10 s window and the guest watchdog aborted with SIGILL after the 110 s deadline. After, all of them classify to gpu vertex=const 0 instance=const 0:

  • 10 s window in the loaded scene: 3-50 draw packets → ~300 draw packets.
  • DRAW_INDEX_INDIRECT_MULTI: 15.7 s of 10 s → 2.0-2.1 s.
  • the run kept presenting past 210 s without the watchdog abort.
before: [draw] indirect 0x38 ... count 3 ... analyzer v=-1 i=-1 ... -> cpu (patched SGPR not folded)
        [packets] queue 0x0 1 submissions: DRAW_INDEX_INDIRECT_MULTI x3 15676ms
after:  [draw] indirect 0x38 ... count 3 ... analyzer v=-1 i=-1 ... -> gpu vertex=const 0 instance=const 0
        [packets] queue 0x0 42 submissions: DRAW_INDEX_INDIRECT_MULTI x139 2113ms ...

Focused AGC tests on the same machine with ANYPS5_REQUIRE_VULKAN=1: agc_driver_draw_offset_indices, agc_driver_rect_list_indirect, the agc_driver_draw_* and agc_driver_draw_cache_reuse* variants and agc_driver_graphics/_maps_fallback (51/51 pass). agc_driver_draw_offset_indices now classifies a record whose program reads no offset register, and a 300-record list, to the GPU with both dimensions constant; agc_driver_draw_cache_reuse sets the kill switch so its CPU-path cache cases keep exercising that path.

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: PPSA18026 (Planet Zoo)
  • GPUs tested: NVIDIA GeForce RTX 4080 SUPER, driver 620.70.06, CachyOS Linux
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5255626371 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18319). Originally posted by [edubox](https://github.com/edubox) on 2026-11-11T07:34:59Z. --- ### What `ClassifyIndirectDraw` sent every indirect draw whose program does not read the offset register the packet names to the CPU path (`Path::NotFolded`), so the driver expanded the record list into one draw per record and ran the full resource build for each. The program never reads that register, so the record's dword never reaches the fetch and the draw starts at the packet's fixed offset, exactly what the CPU path produces (its patch writes a register no program reads). The classifier now tags that dimension as `Constant` with the packet's fixed offset and keeps the draw on the GPU. `APS5_NO_GPU_UNFOLDED_INDIRECT=1` restores the CPU path. A `Constant` dimension is rewritten record by record with `vkCmdUpdateBuffer`, so the guard that keeps such draws on the CPU goes from 256 to 1024 records: the multi-draw count is a small field and the scratch stays at most 20 KiB. Without it the real multi-draw counts of the title (366, 460, 576 records) still fell back to one draw per record. ### Tested Linux (CachyOS, GCC 16.2.1, Release, NVIDIA RTX 4080 SUPER, driver 620.70.06). Planet Zoo (PPSA18026, 01.009.002). Same build otherwise, `APS5_PROFILE_DRAW=1`, vpad pressing Cross every 6 s. Before, every `DRAW_INDEX_INDIRECT_MULTI` classified to `cpu (patched SGPR not folded)`; during the `Scenario_01` load a 3-record packet took 15.7 s of a 10 s window and the guest watchdog aborted with SIGILL after the 110 s deadline. After, all of them classify to `gpu vertex=const 0 instance=const 0`: - 10 s window in the loaded scene: 3-50 draw packets → ~300 draw packets. - `DRAW_INDEX_INDIRECT_MULTI`: 15.7 s of 10 s → 2.0-2.1 s. - the run kept presenting past 210 s without the watchdog abort. ``` before: [draw] indirect 0x38 ... count 3 ... analyzer v=-1 i=-1 ... -> cpu (patched SGPR not folded) [packets] queue 0x0 1 submissions: DRAW_INDEX_INDIRECT_MULTI x3 15676ms after: [draw] indirect 0x38 ... count 3 ... analyzer v=-1 i=-1 ... -> gpu vertex=const 0 instance=const 0 [packets] queue 0x0 42 submissions: DRAW_INDEX_INDIRECT_MULTI x139 2113ms ... ``` Focused AGC tests on the same machine with `ANYPS5_REQUIRE_VULKAN=1`: `agc_driver_draw_offset_indices`, `agc_driver_rect_list_indirect`, the `agc_driver_draw_*` and `agc_driver_draw_cache_reuse*` variants and `agc_driver_graphics`/`_maps_fallback` (51/51 pass). `agc_driver_draw_offset_indices` now classifies a record whose program reads no offset register, and a 300-record list, to the GPU with both dimensions constant; `agc_driver_draw_cache_reuse` sets the kill switch so its CPU-path cache cases keep exercising that path. ### 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: PPSA18026 (Planet Zoo) - [x] GPUs tested: NVIDIA GeForce RTX 4080 SUPER, driver 620.70.06, CachyOS Linux - [x] 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!18319
No description provided.