perf(agc): mirror a sparse descriptor heap instead of copying it per dispatch #3167

Merged
CnRJay merged 2 commits from upstream-pr/3167 into main 2026-10-11 08:07:04 +00:00
CnRJay commented 2026-10-10 23:55:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-10T23:55:23Z.


What

PPSA28416 (STAR WARS: Galactic Racer, UE5) binds a 4 GiB GPU heap of which 528 MiB is committed. With the cut from #2992 the heap is copied only up to its last backed byte, but it is still copied for every dispatch that binds it: 528 MiB at ~90 ms each, over thousands of dispatches during boot, which is the 0.1 FPS the title showed.

A sparse descriptor heap region is now bound to a persistent heap mirror of the registered range that backs it, instead of being copied:

  • The registered range is looked up for the part of the region that is needed (the later of its last committed byte and the start of its last view, plus 4 bytes), not for the whole 4 GiB reservation, which no registered range covers.
  • The mirror is a sparse mirror (pages still committed on demand) or a plain heap mirror of a fully committed range. A plain one is refreshed from the write watch like the heap mirrors of an address-based build.
  • servesView checks the view start against the extent of any mirror, so a view past the mirror falls back to the copy.
  • Writes go back through the mirror's own write-back; only changed 64 KiB blocks are read again.

This branch carries the commit of #2992 (rebased, as that PR conflicts with main); drop it when #2992 merges.

Tested

Windows 11, WinLibs GCC 15.2.0, Release, RTX 4080.

  • agc_driver_graphics (sparseHeapMirrorTests in BdaResources.cpp): a committed range smaller than the heap descriptor bound over it is mirrored, not copied (sparseBinds +1), the view is cut at the mirror, a GPU store is written back. Without the change it fails with a heap bound whole over a smaller registered range was copied.
  • Full suite: 756/756 pass (video-out tests skipped, as on main).
  • PPSA28416: [resources] guest upload ... copied drops from 4095 MiB (528 MiB really read) to 0.0 MiB per dispatch. Device time per dispatch during boot: 10.7 ms before (9500 dispatches, 101.8 s), 2.6 ms after (3600 dispatches, 9.5 s). The title then stops on garbage indirect dispatch arguments, which is a separate problem.

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
  • Generic behaviour, not specific to one title
  • Depends on: #2992 (its commit is included)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4815308872 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3167). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-10T23:55:23Z. --- ### What PPSA28416 (STAR WARS: Galactic Racer, UE5) binds a 4 GiB GPU heap of which 528 MiB is committed. With the cut from #2992 the heap is copied only up to its last backed byte, but it is still copied for every dispatch that binds it: 528 MiB at ~90 ms each, over thousands of dispatches during boot, which is the 0.1 FPS the title showed. A sparse descriptor heap region is now bound to a persistent heap mirror of the registered range that backs it, instead of being copied: - The registered range is looked up for the part of the region that is needed (the later of its last committed byte and the start of its last view, plus 4 bytes), not for the whole 4 GiB reservation, which no registered range covers. - The mirror is a sparse mirror (pages still committed on demand) or a plain heap mirror of a fully committed range. A plain one is refreshed from the write watch like the heap mirrors of an address-based build. - `servesView` checks the view start against the extent of any mirror, so a view past the mirror falls back to the copy. - Writes go back through the mirror's own write-back; only changed 64 KiB blocks are read again. This branch carries the commit of #2992 (rebased, as that PR conflicts with `main`); drop it when #2992 merges. ### Tested Windows 11, WinLibs GCC 15.2.0, Release, RTX 4080. - `agc_driver_graphics` (`sparseHeapMirrorTests` in `BdaResources.cpp`): a committed range smaller than the heap descriptor bound over it is mirrored, not copied (`sparseBinds` +1), the view is cut at the mirror, a GPU store is written back. Without the change it fails with `a heap bound whole over a smaller registered range was copied`. - Full suite: 756/756 pass (video-out tests skipped, as on `main`). - PPSA28416: `[resources] guest upload ... copied` drops from 4095 MiB (528 MiB really read) to 0.0 MiB per dispatch. Device time per dispatch during boot: 10.7 ms before (9500 dispatches, 101.8 s), 2.6 ms after (3600 dispatches, 9.5 s). The title then stops on garbage indirect dispatch arguments, which is a separate problem. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: #2992 (its commit is included) - [x] AI-assisted: yes
Dextroid17 commented 2026-10-11 00:04:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-11T00:04:39Z.

Review: COMMENTED


These two are one line of work on one title, and the second is only safe because of the first — so they want to land in order: #2992 cuts what a copied sparse region costs to its last backed byte, and #3167 removes the per-dispatch copy of a bound heap altogether.

The measurement chain is complete, which is unusual. PPSA28416 binds a 4 GiB GPU heap with 528 MiB committed; before the cut, every dispatch that bound it allocated the whole 4 GiB and failed with vkAllocateMemory … -2; after it, the copy was still 528 MiB per dispatch at ~90 ms, thousands of times during boot, which is the 0.1 FPS the title showed. Stating the intermediate step as well as the final one is what makes the second change's value checkable rather than asserted.

The mirror design is the right answer where a copy is not. Binding a sparse descriptor heap to a persistent mirror of the registered range that actually backs it — looked up for the part that is needed rather than the whole reservation, no part of which any registered range covers — removes the copy instead of shortening it, and committing pages on demand keeps the mirror proportional to what is really used. Refreshing a fully-committed plain mirror from the write watch, the way an address-based build does, is what keeps it honest, and servesView bounding a view start against each mirror's extent is the check that would otherwise be missing.

One thing worth naming in the descriptions: #2992 is currently conflicting, and this change's cut depends on it. So the sequence is a rebase of the first and then this one — and with GuestBufferMemory.hpp touched by both, that order is not optional.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481269134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3167#pullrequestreview-5481269134). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-11T00:04:39Z. **Review:** COMMENTED --- These two are one line of work on one title, and the second is only safe because of the first — so they want to land in order: #2992 cuts what a copied sparse region costs to its last backed byte, and #3167 removes the per-dispatch copy of a bound heap altogether. **The measurement chain is complete, which is unusual.** PPSA28416 binds a 4 GiB GPU heap with 528 MiB committed; before the cut, every dispatch that bound it allocated the whole 4 GiB and failed with `vkAllocateMemory … -2`; after it, the copy was still 528 MiB per dispatch at ~90 ms, thousands of times during boot, which is the 0.1 FPS the title showed. Stating the intermediate step as well as the final one is what makes the second change's value checkable rather than asserted. **The mirror design is the right answer where a copy is not.** Binding a sparse descriptor heap to a persistent mirror of the registered range that actually backs it — looked up for the part that is needed rather than the whole reservation, no part of which any registered range covers — removes the copy instead of shortening it, and committing pages on demand keeps the mirror proportional to what is really used. Refreshing a fully-committed plain mirror from the write watch, the way an address-based build does, is what keeps it honest, and `servesView` bounding a view start against each mirror's extent is the check that would otherwise be missing. **One thing worth naming in the descriptions: #2992 is currently conflicting, and this change's cut depends on it.** So the sequence is a rebase of the first and then this one — and with `GuestBufferMemory.hpp` touched by both, that order is not optional. Written with AI assistance.
Silverash-i8 commented 2026-10-11 01:57:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T01:57:29Z.


Windows run, since the PR has no Intel or Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto main d31b57a4 in one build with #3217, #3202, #3167, #3137, #2863, #2849 and #2847, on an RTX 5060 Laptop and the Arrow Lake iGPU (ANYPS5_GPU=Intel).

  • agc_driver_bda_device and agc_driver_bda_span_reads (BdaResources.cpp) pass on both GPUs.

Full ctest of that build on both GPUs has no failure that isn't also on plain main here (guest_filesystem needs the symlink privilege, #3169; the Intel ones are listed on #2114 and #3207).

AI-assisted (Claude Code); I ran this on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104401372 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3167#issuecomment-6104401372). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-11T01:57:29Z. --- Windows run, since the PR has no Intel or Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto `main` d31b57a4 in one build with #3217, #3202, #3167, #3137, #2863, #2849 and #2847, on an RTX 5060 Laptop and the Arrow Lake iGPU (`ANYPS5_GPU=Intel`). - `agc_driver_bda_device` and `agc_driver_bda_span_reads` (`BdaResources.cpp`) pass on both GPUs. Full `ctest` of that build on both GPUs has no failure that isn't also on plain `main` here (`guest_filesystem` needs the symlink privilege, #3169; the Intel ones are listed on #2114 and #3207). AI-assisted (Claude Code); I ran this on my machine.
Mouhand-Kaddo commented 2026-10-11 07:34:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:34:18Z.


Additional platform validation of standalone PR head 2a430701e4a29733769ecf922f1604ee34a6f178 (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.

1 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_graphics.

Command after building: ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^agc_driver_graphics$".

This scope checks CPU-side behavior; no GPU execution result is claimed.

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.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106723155 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3167#issuecomment-6106723155). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-11T07:34:18Z. --- <!-- anyps5-platform-validation:2a430701e4a29733769ecf922f1604ee34a6f178 --> Additional platform validation of standalone PR head `2a430701e4a29733769ecf922f1604ee34a6f178` (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`. 1 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_graphics`. Command after building: `ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^agc_driver_graphics$"`. This scope checks CPU-side behavior; no GPU execution result is claimed. 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. No title/gameplay validation. These results cover the standalone head, not a merge with current main.
adriadam10 commented 2026-10-11 08:02:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:02:42Z.


Rebased onto current main, dropping the first commit (the original #2992 commit): #2992 landed in a different form, so that commit conflicted and is no longer needed. The two commits of this PR are untouched.

Checked on the rebased tree: scoped build + ctest of libSceAgcDriver and neighbours; agc_driver_graphics, agc_driver_bda_device and agc_driver_bda_span_reads pass. sparseHeapMirrorTests is _WIN32-only like the existing heap mirror tests, so it doesn't run on Linux; Windows runs by @Silverash-i8 (RTX 5060 + Arrow Lake iGPU) and the author's own cover it. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106937607 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3167#issuecomment-6106937607). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T08:02:42Z. --- Rebased onto current `main`, dropping the first commit (the original #2992 commit): #2992 landed in a different form, so that commit conflicted and is no longer needed. The two commits of this PR are untouched. Checked on the rebased tree: scoped build + ctest of libSceAgcDriver and neighbours; `agc_driver_graphics`, `agc_driver_bda_device` and `agc_driver_bda_span_reads` pass. `sparseHeapMirrorTests` is `_WIN32`-only like the existing heap mirror tests, so it doesn't run on Linux; Windows runs by @Silverash-i8 (RTX 5060 + Arrow Lake iGPU) and the author's own cover it. Merging once CI is green.
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!3167
No description provided.