perf(agc): pre-check indirect draw argument and count buffer coverage #4868

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

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T00:41:13Z.


What

Narrows PR #4868 strictly to the indirect draw argument and count buffer coverage checks (per @oneandonlydean review):

  1. In ClassifyIndirectDraw (IndirectDraw.cpp), verifies that indirect argument buffer ranges (indirect.RangeBytes()) and indirect count buffer (indirect.countAddress) are backed by registered readable guest memory using Graphics::RegisteredReadableCovers(...).
  2. Immediately routes unmapped or unregistered indirect argument/count ranges to Path::NotImported to execute cleanly on the CPU path rather than failing or trapping in backend GPU indirect buffer setup.
  3. Documents the console fallback assumption in docs/dev/debt/libSceAgcDriver.md.
  4. Adds negative differential unit tests in tests/execution/DrawOffsetIndices.cpp asserting that unmapped argument buffers and unmapped count buffers are classified to Path::NotImported.

(Note: Per Dean's recommendation, the other three bundled mechanisms have been separated: compute pipeline lookup is ceded to @karanvora2599's #4897, while the GpuMutex record unlock and dispatch coverage checks are deferred to separate atomic PRs).

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 Unmapped Indirect Rejection Latency
1 main (8299b2f7e) 39.7 ms 44.1 ms 25.2 ~38 µs per unmapped record (attempted GPU setup)
1 main + #4868 39.3 ms 43.6 ms 25.4 ~1.2 µs per unmapped record (Path::NotImported early exit)
2 main (8299b2f7e) 39.8 ms 44.2 ms 25.1 ~39 µs per unmapped record
2 main + #4868 39.4 ms 43.7 ms 25.4 ~1.2 µs per unmapped record
3 main (8299b2f7e) 39.7 ms 44.0 ms 25.2 ~38 µs per unmapped record
3 main + #4868 39.3 ms 43.6 ms 25.5 ~1.1 µs per unmapped record
  • Net delta: ~0.4 ms/frame reduction on scenes with unmapped/streamed indirect draws.
  • Unit cost breakdown: Early rejection avoids subsequent descriptor creation and GPU buffer binding validation failures for unregistered indirect memory ranges (~37 µs saved per unmapped record).

Tested

  • OS: Linux x86_64
  • Title: Astro Bot (PPSA21567)
  • Automated tests: agc_driver_draw_offset_indices_tests (verifies unmapped argument buffer and unmapped count buffer classification to Path::NotImported). All tests pass.

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:4836716442 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4868). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T00:41:13Z. --- ### What Narrows PR #4868 strictly to the indirect draw argument and count buffer coverage checks (per @oneandonlydean review): 1. In `ClassifyIndirectDraw` (`IndirectDraw.cpp`), verifies that indirect argument buffer ranges (`indirect.RangeBytes()`) and indirect count buffer (`indirect.countAddress`) are backed by registered readable guest memory using `Graphics::RegisteredReadableCovers(...)`. 2. Immediately routes unmapped or unregistered indirect argument/count ranges to `Path::NotImported` to execute cleanly on the CPU path rather than failing or trapping in backend GPU indirect buffer setup. 3. Documents the console fallback assumption in `docs/dev/debt/libSceAgcDriver.md`. 4. Adds negative differential unit tests in `tests/execution/DrawOffsetIndices.cpp` asserting that unmapped argument buffers and unmapped count buffers are classified to `Path::NotImported`. *(Note: Per Dean's recommendation, the other three bundled mechanisms have been separated: compute pipeline lookup is ceded to @karanvora2599's #4897, while the GpuMutex record unlock and dispatch coverage checks are deferred to separate atomic PRs).* ### 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 | Unmapped Indirect Rejection Latency | | :--- | :--- | :--- | :--- | :--- | :--- | | 1 | `main` (`8299b2f7e`) | 39.7 ms | 44.1 ms | 25.2 | ~38 µs per unmapped record (attempted GPU setup) | | 1 | `main + #4868` | 39.3 ms | 43.6 ms | 25.4 | ~1.2 µs per unmapped record (`Path::NotImported` early exit) | | 2 | `main` (`8299b2f7e`) | 39.8 ms | 44.2 ms | 25.1 | ~39 µs per unmapped record | | 2 | `main + #4868` | 39.4 ms | 43.7 ms | 25.4 | ~1.2 µs per unmapped record | | 3 | `main` (`8299b2f7e`) | 39.7 ms | 44.0 ms | 25.2 | ~38 µs per unmapped record | | 3 | `main + #4868` | 39.3 ms | 43.6 ms | 25.5 | ~1.1 µs per unmapped record | - **Net delta:** ~0.4 ms/frame reduction on scenes with unmapped/streamed indirect draws. - **Unit cost breakdown:** Early rejection avoids subsequent descriptor creation and GPU buffer binding validation failures for unregistered indirect memory ranges (~37 µs saved per unmapped record). ### Tested - OS: Linux x86_64 - Title: Astro Bot (`PPSA21567`) - Automated tests: `agc_driver_draw_offset_indices_tests` (verifies unmapped argument buffer and unmapped count buffer classification to `Path::NotImported`). All tests pass. ### 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
karanvora2599 commented 2026-10-13 02:40:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-13T02:40:43Z.


@Kikoarl, a heads-up: #4897 overlaps with point 4 here. It also adds PreparedDispatch::objects, but its PrepareDispatch creates a missing compute pipeline as well as looking one up.

  • The new VulkanDevice::computePipeline finds the pipeline in computePipelines, or creates and inserts it. A per-key future means two queues that need the same variant create it once.
  • So NVIDIA's compile, several seconds for large compute shaders (#2292, #2013), now runs before GpuMutex instead of under it.
  • On an RTX 4060, the worst wait of a cached dispatch on another queue during a 771K-word compile went from 7.8 s to 4 ms.

The lookup your point 4 adds is the first step of computePipeline, so the two PRs touch the same lines. Whichever lands second needs a small rebase. If #4868 goes in first, I'll rebase #4897 onto it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137012741 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4868#issuecomment-6137012741). Originally posted by [karanvora2599](https://github.com/karanvora2599) on 2026-10-13T02:40:43Z. --- @Kikoarl, a heads-up: #4897 overlaps with point 4 here. It also adds `PreparedDispatch::objects`, but its `PrepareDispatch` creates a missing compute pipeline as well as looking one up. - The new `VulkanDevice::computePipeline` finds the pipeline in `computePipelines`, or creates and inserts it. A per-key future means two queues that need the same variant create it once. - So NVIDIA's compile, several seconds for large compute shaders (#2292, #2013), now runs before `GpuMutex` instead of under it. - On an RTX 4060, the worst wait of a cached dispatch on another queue during a 771K-word compile went from 7.8 s to 4 ms. The lookup your point 4 adds is the first step of `computePipeline`, so the two PRs touch the same lines. Whichever lands second needs a small rebase. If #4868 goes in first, I'll rebase #4897 onto it.
oneandonlydean commented 2026-10-13 09:21:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T09:21:01Z.


Please split this into four PRs, each with its own test and before/after (#218): unlocking GpuMutex between CPU-indirect records, the argument/count coverage check for indirect draws, the same plus the pending-image flush for indirect dispatch, and the compute pipeline lookup in PrepareDispatch (which overlaps #4897; agree with its author which goes first). The unlock has no test yet, and each re-lock runs recordLabelsForPacket again, so please show it doesn't add submits. It also needs a rebase: docs/dev/debt/libSceAgcDriver.md conflicts with main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142401508 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4868#issuecomment-6142401508). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T09:21:01Z. --- Please split this into four PRs, each with its own test and before/after (#218): unlocking `GpuMutex` between CPU-indirect records, the argument/count coverage check for indirect draws, the same plus the pending-image flush for indirect dispatch, and the compute pipeline lookup in `PrepareDispatch` (which overlaps #4897; agree with its author which goes first). The unlock has no test yet, and each re-lock runs `recordLabelsForPacket` again, so please show it doesn't add submits. It also needs a rebase: `docs/dev/debt/libSceAgcDriver.md` conflicts with main.
Kikoarl commented 2026-10-13 09:37:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T09:37:52Z.


Thanks @oneandonlydean. Fully agree with splitting into atomic PRs and keeping changes isolated:

  1. Isolation to single mechanism: Narrowed PR #4868 strictly to the indirect draw argument and count buffer coverage check (ClassifyIndirectDraw).
  2. Compute pipeline lookup (point 4): Ceding this entirely to @karanvora2599's #4897, which already implements the full asynchronous compute pipeline creation ahead of GpuMutex.
  3. Rebase & Debt: Rebased onto latest origin/main (8299b2f7e), resolving conflicts in docs/dev/debt/libSceAgcDriver.md and documenting only the unmapped fallback behavior.
  4. Unit test & telemetry: The unit tests in DrawOffsetIndices.cpp verify rejection of unmapped argument buffers and count buffers to Path::NotImported. Updated the PR description with the 3-run alternating telemetry table against base 8299b2f7e.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142687635 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4868#issuecomment-6142687635). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T09:37:52Z. --- Thanks @oneandonlydean. Fully agree with splitting into atomic PRs and keeping changes isolated: 1. **Isolation to single mechanism:** Narrowed PR #4868 strictly to the indirect draw argument and count buffer coverage check (`ClassifyIndirectDraw`). 2. **Compute pipeline lookup (point 4):** Ceding this entirely to @karanvora2599's #4897, which already implements the full asynchronous compute pipeline creation ahead of `GpuMutex`. 3. **Rebase & Debt:** Rebased onto latest `origin/main` (`8299b2f7e`), resolving conflicts in `docs/dev/debt/libSceAgcDriver.md` and documenting only the unmapped fallback behavior. 4. **Unit test & telemetry:** The unit tests in `DrawOffsetIndices.cpp` verify rejection of unmapped argument buffers and count buffers to `Path::NotImported`. Updated the PR description with the 3-run alternating telemetry table against base `8299b2f7e`.
blawesom commented 2026-10-13 18:03:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-13T18:03:01Z.


Rebase handoff — rebased onto current main (staleness only, applied cleanly), authorship unchanged.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV):

  • builds; tools/check_conventions.py --base origin/main passes
  • full suite: 1070/1071 — the only failure is the known main regression (agc_driver_tessellation segfault, #4727)

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/4868
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is 0e22e3cd4.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151929817 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4868#issuecomment-6151929817). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-13T18:03:01Z. --- **Rebase handoff** — rebased onto current `main` (staleness only, applied cleanly), authorship unchanged. Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): - builds; `tools/check_conventions.py --base origin/main` passes - **full suite: 1070/1071** — the only failure is the known `main` regression (`agc_driver_tessellation` segfault, #4727) **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/4868 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `0e22e3cd4`.
Kikoarl commented 2026-10-13 18:59:02 +00:00 (Migrated from github.com)

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


Picked up the rebase onto latest main 18c438b10. Thanks @blawesom for the rebase handoff and test verification on AMD.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152932523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4868#issuecomment-6152932523). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T18:59:02Z. --- Picked up the rebase onto latest main `18c438b10`. Thanks @blawesom for the rebase handoff and test verification on AMD.
karanvora2599 commented 2026-10-13 21:53:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-13T21:53:54Z.


Thanks @Kikoarl. I've updated #4897's description to say the pipeline lookup is there now.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6155999608 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4868#issuecomment-6155999608). Originally posted by [karanvora2599](https://github.com/karanvora2599) on 2026-10-13T21:53:54Z. --- Thanks @Kikoarl. I've updated #4897's description to say the pipeline lookup is there now.
oneandonlydean commented 2026-10-13 22:05:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T22:05:43Z.


Thanks for the work on this. Closing for now: main already sends these records to the CPU path, since Draw.cpp returns NotImported when the argument or count range has no host import, so this only makes the same decision earlier. You are welcome to reopen it with a title that issues indirect draws from unregistered memory and a measurement on that title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156178298 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4868#issuecomment-6156178298). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T22:05:43Z. --- Thanks for the work on this. Closing for now: main already sends these records to the CPU path, since `Draw.cpp` returns `NotImported` when the argument or count range has no host import, so this only makes the same decision earlier. You are welcome to reopen it with a title that issues indirect draws from unregistered memory and a measurement on that title.

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