perf(agc): keep adjacent ranges one import serves as one region of the cached address space #4428

Merged
hypermoist merged 1 commit from upstream-pr/4428 into main 2026-10-13 14:18:14 +00:00
hypermoist commented 2026-10-12 10:53:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-12T10:53:59Z.


What

GuestBufferMemory::AcquireRegistered publishes a cached address space with one region per registered range, while one host import can serve a whole run of adjacent ranges (importRun). A V# that crosses the boundary between two such ranges is then not inside any one region, so the build dissolves the shared space into its own regions: on Killing Floor 3 (PPSA08427) that is about 10k regions copied, sorted and looked up, 700-1,300 times per 10 s at the title screen.

When the space is published, adjacent ranges served by the same import (same import, contiguous, same writability, no mirror, not sparse, inside the import) are kept as one region. A V# across them is inside that region and is bound in place from the import, the same binding a V# inside one range already gets.

Tested

Linux (CachyOS, kernel 7.2.9), RTX 3060 (NVIDIA 615.78.08), GCC 16.2.1, Release.

  • agc_driver_graphics gets a case (spaceImportRunTests in tests/BdaResources.cpp): two adjacent 64 KiB read-only ranges one import serves, and a V# across their boundary. On current main it fails (a V# across one import's ranges dissolved the cached address space); with this change the second build is a space hit and nothing dissolves.
  • Killing Floor 3 (PPSA08427, 02.011.000), on our fork with the same settings before and after: dissolved builds went from 694-1,260 to 0 per 10 s, the title screen from 15-25 to 34-36 presents per 10 s and the main menu from 17-21 to 31-35. The title does not run on main alone: it stops before its first frame at clip distances, layer, viewport or auxiliary vertex exports is unsupported (register 0x207 = 0x0040000f) (#423).

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: none
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01Uzy15wqYTt6iWyxYXEzUWo

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4828371160 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4428). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-12T10:53:59Z. --- ### What `GuestBufferMemory::AcquireRegistered` publishes a cached address space with one region per registered range, while one host import can serve a whole run of adjacent ranges (`importRun`). A V# that crosses the boundary between two such ranges is then not inside any one region, so the build dissolves the shared space into its own regions: on Killing Floor 3 (PPSA08427) that is about 10k regions copied, sorted and looked up, 700-1,300 times per 10 s at the title screen. When the space is published, adjacent ranges served by the same import (same import, contiguous, same writability, no mirror, not sparse, inside the import) are kept as one region. A V# across them is inside that region and is bound in place from the import, the same binding a V# inside one range already gets. ### Tested Linux (CachyOS, kernel 7.2.9), RTX 3060 (NVIDIA 615.78.08), GCC 16.2.1, Release. - `agc_driver_graphics` gets a case (`spaceImportRunTests` in `tests/BdaResources.cpp`): two adjacent 64 KiB read-only ranges one import serves, and a V# across their boundary. On current `main` it fails (`a V# across one import's ranges dissolved the cached address space`); with this change the second build is a space hit and nothing dissolves. - Killing Floor 3 (PPSA08427, 02.011.000), on our fork with the same settings before and after: dissolved builds went from 694-1,260 to 0 per 10 s, the title screen from 15-25 to 34-36 presents per 10 s and the main menu from 17-21 to 31-35. The title does not run on `main` alone: it stops before its first frame at `clip distances, layer, viewport or auxiliary vertex exports is unsupported (register 0x207 = 0x0040000f)` (#423). ### 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: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Uzy15wqYTt6iWyxYXEzUWo
AlxcBTW commented 2026-10-12 13:27:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T13:27:22Z.


@hypermoist I tested this on Sword of the Sea (PPSA25344) in the opening cutscene. In this scene, partial overlaps used to dissolve the cached address space in about a third of all address-based builds. With this PR the dissolves are gone.

Setup. Windows 11, RTX 5070 Laptop (616.92). Two 900 s in-scene rows, each a lab branch of main plus local patches for this title. The before-row has no #4428. The after-row has this PR cherry-picked unchanged, but it also carries other local changes: dispatch template relocation, a draw-path change and several experiments. So only the [address] dissolve counters below are attributable to this PR. One of those changes is a local overlay that also targets partial overlaps. It printed "0 overlays used" in every window of the after-row, so the counters come from this PR, not from it. No FPS claims.

[address], per 10 s, last 20 windows before (no #4428) after (with #4428)
address-based builds 1016 1894
space hits 1015 1893
dissolved: overlap 365 (max 429) 0 (max 0)
dissolved: overlap, whole row 25584 over 77 windows 0 over 72 windows

For context only: the before-row spent 132 s of 247 s of dispatch resource time in "resources: A locked (bda)", the locked stage A of address-based builds, which includes the dissolve and re-merge. The after-row spent 2 s of 78 s there (cumulative [dispatch] phase totals, APS5_PROFILE_DRAW=1). The other changes in the after-row also shrink resource time, so that ratio is not this PR's alone.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6125234226 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4428#issuecomment-6125234226). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-12T13:27:22Z. --- @hypermoist I tested this on Sword of the Sea (PPSA25344) in the opening cutscene. In this scene, partial overlaps used to dissolve the cached address space in about a third of all address-based builds. With this PR the dissolves are gone. **Setup.** Windows 11, RTX 5070 Laptop (616.92). Two 900 s in-scene rows, each a lab branch of `main` plus local patches for this title. The before-row has no #4428. The after-row has this PR cherry-picked unchanged, but it also carries other local changes: dispatch template relocation, a draw-path change and several experiments. So only the `[address]` dissolve counters below are attributable to this PR. One of those changes is a local overlay that also targets partial overlaps. It printed "0 overlays used" in every window of the after-row, so the counters come from this PR, not from it. No FPS claims. | `[address]`, per 10 s, last 20 windows | before (no #4428) | after (with #4428) | |---|---:|---:| | address-based builds | 1016 | 1894 | | space hits | 1015 | 1893 | | dissolved: overlap | 365 (max 429) | 0 (max 0) | | dissolved: overlap, whole row | 25584 over 77 windows | 0 over 72 windows | For context only: the before-row spent 132 s of 247 s of dispatch resource time in "resources: A locked (bda)", the locked stage A of address-based builds, which includes the dissolve and re-merge. The after-row spent 2 s of 78 s there (cumulative `[dispatch]` phase totals, `APS5_PROFILE_DRAW=1`). The other changes in the after-row also shrink resource time, so that ratio is not this PR's alone. AI-assisted: yes (Claude Code)
blawesom commented 2026-10-12 13:29:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T13:29:48Z.


Rebase handoff — rebased onto current main, authorship unchanged.

One test-file conflict with main's newer BDA tests: both sides add independent test functions at the same spot — kept main's failedImportRemapTests and this PR's spaceImportRunTests, with both called.

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: 952/952 passed

To pick it up:

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

Head is fd7ce3ff2.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6125274552 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4428#issuecomment-6125274552). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-12T13:29:48Z. --- **Rebase handoff** — rebased onto current `main`, authorship unchanged. One test-file conflict with main's newer BDA tests: both sides add independent test functions at the same spot — kept main's `failedImportRemapTests` and this PR's `spaceImportRunTests`, with both called. 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: 952/952 passed** **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/4428 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `fd7ce3ff2`.
github-actions[bot] commented 2026-10-13 07:28:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T07:28:40Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4448 core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp L177, L1204-1205
#4979 core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp L1204
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140568570 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4428#issuecomment-6140568570). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T07:28:40Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4448 | `core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp` [L177](https://github.com/boykopovar/AnyPS5/blob/8c772ad34228c6e22b6587cf750ae3bdd8e5c137/core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp#L177), [L1204-1205](https://github.com/boykopovar/AnyPS5/blob/8c772ad34228c6e22b6587cf750ae3bdd8e5c137/core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp#L1204-L1205) | | | | #4979 | `core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp` [L1204](https://github.com/boykopovar/AnyPS5/blob/8c772ad34228c6e22b6587cf750ae3bdd8e5c137/core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp#L1204) | | |
TideOPL commented 2026-10-13 10:14:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-13T10:14:54Z.


Tested on Minecraft Dungeons II (PPSA16064) gameplay at the Squid Coast spawn: Windows 11, RTX 5070, trace window 25-40 s after the HUD (#4526 trace, APS5_TRACE_SECONDS=25:15). Base: main + #4367 #4515 #4517 + #3816 + #425 + #3763 + local patches MCD2 needs.

On MCD2 this removes a run-to-run bimodality. In about half the runs, about 4 address-based dispatches per frame dissolved the cached space ([address] dissolved: overlap, about 320 per 10 s): a V# crosses the boundary of two adjacent registered ranges that one joined import (#4517) serves. Each dissolved build then sorts and merges about 1,200 regions (sort ~630 us + merge ~730 us + bindings ~650 us). With this PR (together with #4248) there are no dissolves in any run.

Together with #4248, #4012 and #4603, interleaved, 3 runs each: p50 118.6 / 130.6 / 129.1 ms -> 110.9 / 110.8 / 111.9 ms, p99 127-141 -> 121-127 ms.

Not run: Linux, AMD, the PR's own tests.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6143311426 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4428#issuecomment-6143311426). Originally posted by [TideOPL](https://github.com/TideOPL) on 2026-10-13T10:14:54Z. --- Tested on Minecraft Dungeons II (PPSA16064) gameplay at the Squid Coast spawn: Windows 11, RTX 5070, trace window 25-40 s after the HUD (#4526 trace, `APS5_TRACE_SECONDS=25:15`). Base: `main` + #4367 #4515 #4517 + #3816 + #425 + #3763 + local patches MCD2 needs. On MCD2 this removes a run-to-run bimodality. In about half the runs, about 4 address-based dispatches per frame dissolved the cached space (`[address] dissolved: overlap`, about 320 per 10 s): a V# crosses the boundary of two adjacent registered ranges that one joined import (#4517) serves. Each dissolved build then sorts and merges about 1,200 regions (sort ~630 us + merge ~730 us + bindings ~650 us). With this PR (together with #4248) there are no dissolves in any run. Together with #4248, #4012 and #4603, interleaved, 3 runs each: p50 118.6 / 130.6 / 129.1 ms -> 110.9 / 110.8 / 111.9 ms, p99 127-141 -> 121-127 ms. Not run: Linux, AMD, the PR's own tests. AI-assisted (Claude Code).
adriadam10 commented 2026-10-13 14:09:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:09:09Z.


Checked the region merge in AcquireRegistered (same import, contiguous, same writability, no mirror, not sparse, inside the import; order preserved), the new spaceImportRunTests case (fails without the change, passes with it) and the libSceAgcDriver ctest scope on RADV; also confirmed by @AlxcBTW and @TideOPL on real titles. Merging once the full build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147458200 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4428#issuecomment-6147458200). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:09:09Z. --- Checked the region merge in `AcquireRegistered` (same import, contiguous, same writability, no mirror, not sparse, inside the import; order preserved), the new `spaceImportRunTests` case (fails without the change, passes with it) and the `libSceAgcDriver` ctest scope on RADV; also confirmed by @AlxcBTW and @TideOPL on real titles. Merging once the full build 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!4428
No description provided.