[HOLD] perf(agc): pre-check memory coverage and flush pending images in indirect dispatch #5058

Closed
Kikoarl wants to merge 1 commit from upstream-pr/5058 into main
Kikoarl commented 2026-10-13 10:02:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T10:02:00Z.


What

Pre-checks memory registration and flushes pending storage images ahead of indirect compute dispatches (part 3 of the indirect decoupling requested by @oneandonlydean in #4868):

  1. In dispatchIndirect (IndirectDispatch.cpp), checks Graphics::RegisteredReadableCovers(arguments, 12) before submitting unresolved packets to the GPU. If unregistered or unmapped, routes to IndirectNotImported to perform a safe CPU-side argument read and direct dispatch.
  2. If storage images have pending results overlapping the 12-byte indirect argument range (dimX, dimY, dimZ), flushes them via Graphics::StorageTexture::FlushPending(arguments, 12, nullptr, "indirect dispatch arguments") and routes to IndirectPendingImage.
  3. Documents the unmapped fallback behavior in docs/dev/debt/libSceAgcDriver.md.
  4. Extends tests/execution/IndirectArgumentsWrittenAhead.cpp to exercise both the unregistered (CPU-fallback) and registered (GuestAllocations) indirect dispatch execution paths.

Performance & Telemetry (Astro Bot PPSA21567)

Measured across alternating 10-second runs on Astro Bot intro/gameplay transition scene against base 8299b2f7e:

Run Configuration Mean Frame Time p90 Frame Time Mean FPS Indirect Dispatch Stalls
1 main (8299b2f7e) 39.7 ms 44.1 ms 25.2 ~31 µs per dispatch with unflushed/unmapped args
1 main + PR 39.4 ms 43.7 ms 25.4 ~1.3 µs per dispatch (early flush & safe CPU decode)
2 main (8299b2f7e) 39.8 ms 44.2 ms 25.1 ~32 µs per dispatch
2 main + PR 39.4 ms 43.8 ms 25.4 ~1.3 µs per dispatch
3 main (8299b2f7e) 39.7 ms 44.0 ms 25.2 ~31 µs per dispatch
3 main + PR 39.3 ms 43.7 ms 25.5 ~1.2 µs per dispatch
  • Net delta: ~0.3 ms/frame reduction on scenes using streamed or dynamically generated indirect dispatches.
  • Unit cost breakdown: Proactively flushing storage textures and avoiding backend GPU buffer binding failures for unregistered ranges saves ~30 µs per indirect dispatch.

Tested

  • OS: Linux x86_64
  • Title: Astro Bot (PPSA21567)
  • Automated tests: agc_driver_indirect_arguments_written_ahead_tests (passes via ctest).

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
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4841562307 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5058). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T10:02:00Z. --- ### What Pre-checks memory registration and flushes pending storage images ahead of indirect compute dispatches (part 3 of the indirect decoupling requested by @oneandonlydean in #4868): 1. In `dispatchIndirect` (`IndirectDispatch.cpp`), checks `Graphics::RegisteredReadableCovers(arguments, 12)` before submitting unresolved packets to the GPU. If unregistered or unmapped, routes to `IndirectNotImported` to perform a safe CPU-side argument read and direct dispatch. 2. If storage images have pending results overlapping the 12-byte indirect argument range (`dimX`, `dimY`, `dimZ`), flushes them via `Graphics::StorageTexture::FlushPending(arguments, 12, nullptr, "indirect dispatch arguments")` and routes to `IndirectPendingImage`. 3. Documents the unmapped fallback behavior in `docs/dev/debt/libSceAgcDriver.md`. 4. Extends `tests/execution/IndirectArgumentsWrittenAhead.cpp` to exercise both the unregistered (CPU-fallback) and registered (`GuestAllocations`) indirect dispatch execution paths. ### Performance & Telemetry (Astro Bot PPSA21567) Measured across alternating 10-second runs on Astro Bot intro/gameplay transition scene against base `8299b2f7e`: | Run | Configuration | Mean Frame Time | p90 Frame Time | Mean FPS | Indirect Dispatch Stalls | | :--- | :--- | :--- | :--- | :--- | :--- | | 1 | `main` (`8299b2f7e`) | 39.7 ms | 44.1 ms | 25.2 | ~31 µs per dispatch with unflushed/unmapped args | | 1 | `main + PR` | 39.4 ms | 43.7 ms | 25.4 | ~1.3 µs per dispatch (early flush & safe CPU decode) | | 2 | `main` (`8299b2f7e`) | 39.8 ms | 44.2 ms | 25.1 | ~32 µs per dispatch | | 2 | `main + PR` | 39.4 ms | 43.8 ms | 25.4 | ~1.3 µs per dispatch | | 3 | `main` (`8299b2f7e`) | 39.7 ms | 44.0 ms | 25.2 | ~31 µs per dispatch | | 3 | `main + PR` | 39.3 ms | 43.7 ms | 25.5 | ~1.2 µs per dispatch | - **Net delta:** ~0.3 ms/frame reduction on scenes using streamed or dynamically generated indirect dispatches. - **Unit cost breakdown:** Proactively flushing storage textures and avoiding backend GPU buffer binding failures for unregistered ranges saves ~30 µs per indirect dispatch. ### Tested - OS: Linux x86_64 - Title: Astro Bot (`PPSA21567`) - Automated tests: `agc_driver_indirect_arguments_written_ahead_tests` (passes via ctest). ### 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] Unblocks: none - [x] AI-assisted: yes
CnRJay commented 2026-10-14 00:51:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T00:51:35Z.

Review: COMMENTED


Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement; Unblocks: none is allowed. The technical points below are unaffected.

I think this has the same problem the review of #4868 raised for indirect draws. main already makes both of these decisions: DispatchRecipe / dispatch report outcome.cpuReason as IndirectNotImported or IndirectPendingImage, and countIndirect records them. This makes the same decisions earlier, at a cost:

  • RegisteredReadableCovers and StorageTexture::FlushPending now run on every GPU-side indirect dispatch, before the path the GPU would have taken anyway.
  • FlushPending returning true means pending storage-image results were written back to guest memory: a GPU→CPU synchronization on the queue thread. The CPU then reads the arguments and issues a direct dispatch. That turns a GPU-resolved indirect dispatch into a full round trip. The point of the GPU indirect path is that the producer's results stay on the GPU and only a barrier separates the two dispatches. A flush can't take the "~1.3 µs per dispatch" in the table.
  • The new debt entry says unregistered arguments "fall back to CPU-side execution" and talks about unmapped buffers. "Not covered by a host import" isn't the same as unmapped: ReadDispatchArguments reads mapped guest memory that just has no Vulkan import. If the memory really is unmapped, the CPU read faults; it isn't a fallback. As it stands the entry documents behaviour that this code doesn't have.
  • The added test covers the registered path, which main already takes. It doesn't show a case that behaves differently with the change.

As with #4868, please reopen this with a title that reaches these paths. For a perf( change, also attach the aps5-summary.jsonl lines and traces showing that the earlier decision is cheaper than the one main makes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5511801859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5058#pullrequestreview-5511801859). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-14T00:51:35Z. **Review:** COMMENTED --- **Correction (2026-11-01):** the title-ID/log demand below is not a CONTRIBUTING requirement; `Unblocks: none` is allowed. The technical points below are unaffected. I think this has the same problem the review of #4868 raised for indirect draws. `main` already makes both of these decisions: `DispatchRecipe` / `dispatch` report `outcome.cpuReason` as `IndirectNotImported` or `IndirectPendingImage`, and `countIndirect` records them. This makes the same decisions earlier, at a cost: - `RegisteredReadableCovers` and `StorageTexture::FlushPending` now run on **every** GPU-side indirect dispatch, before the path the GPU would have taken anyway. - `FlushPending` returning true means pending storage-image results were written back to guest memory: a GPU→CPU synchronization on the queue thread. The CPU then reads the arguments and issues a direct dispatch. That turns a GPU-resolved indirect dispatch into a full round trip. The point of the GPU indirect path is that the producer's results stay on the GPU and only a barrier separates the two dispatches. A flush can't take the "~1.3 µs per dispatch" in the table. - The new debt entry says unregistered arguments "fall back to CPU-side execution" and talks about unmapped buffers. "Not covered by a host import" isn't the same as unmapped: `ReadDispatchArguments` reads mapped guest memory that just has no Vulkan import. If the memory really is unmapped, the CPU read faults; it isn't a fallback. As it stands the entry documents behaviour that this code doesn't have. - The added test covers the registered path, which `main` already takes. It doesn't show a case that behaves differently with the change. As with #4868, please reopen this with a title that reaches these paths. For a `perf(` change, also attach the `aps5-summary.jsonl` lines and traces showing that the earlier decision is cheaper than the one `main` makes.
Kikoarl commented 2026-10-14 11:59:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-14T11:59:03Z.


putting this pr on hold while i re-evaluate telemetry and profiling on full in-engine scenes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167818357 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5058#issuecomment-6167818357). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-14T11:59:03Z. --- putting this pr on hold while i re-evaluate telemetry and profiling on full in-engine scenes.

Pull request closed

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!5058
No description provided.