perf(agc): import chunk-crossing shared ranges without a buffer object of their own #24555

Merged
JJenkx merged 2 commits from upstream-pr/24555 into main 2026-11-21 04:11:40 +00:00
JJenkx commented 2026-11-20 19:33:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-20T19:33:21Z.


What

On Linux, a shared-backed guest range inside one 64 MiB chunk of the direct-memory file is bound into that chunk's udmabuf import. A range of 64 MiB or less that is not inside one chunk gets a udmabuf buffer object of its own. That covers a single run across a chunk boundary, or a range of several runs. amdgpu validates every imported buffer object at every command submission, so each such range adds to the cost of every vkQueueSubmit.

#23272 sent all of those ranges through the sparse path. It was reverted in #24052 because In Sound Mind (PPSA04921) then corrupted its heap in 3 of 4 runs. I had traced that corruption to inside a 1 MiB single-run sparse import that straddled a chunk boundary.

This PR splits the cases:

  1. Single-run ranges of 32 MiB or less that cross a chunk boundary take no sparse binding. They are bound into a 64 MiB udmabuf buffer that starts 32 MiB into the chunk below the boundary, through the same single-buffer bind path as the chunk imports. The window is created once and shared through the chunk-import cache, now keyed by the window's byte start instead of its index.
  2. Ranges of several runs, and single runs above 32 MiB not inside one chunk, take the existing sparse path at any size, as #23272 did.

A range the sparse path declines keeps a buffer object of its own, as before. That means one imported without the GPU lock and without a sparse queue of its own, or one whose backing it cannot bind.

Performance

Matched A/B in one build directory:

  • Builds: this branch (fbd98f83fdde) against its base, main c8f72e905cce.
  • Order: alternating rebuilds before each run.
  • Driver check: before every run, the loaded libs/libSceAgcDriver.prx was checked to be byte-identical to a fresh nid_patcher run of that build's unpatched library.
  • Conditions: pristine save before each run, identical scripted input, no compiler running during runs, APS5_NO_COMMITTER_CORE=1.

Spirit of the North (PPSA02306), mean FPS 150–235 s. CPU-bound here: GPU time was about 3.7 ms per frame.

Round Branch main
1 8.85 8.03
2 9.16 8.68
3 9.89 8.84
4 9.99 8.46
Mean 9.47 8.50 (+11%)

The branch is ahead in every round.

Under The Waves (PPSA08056), in a pair checked with a screenshot every 10 s so both runs show identical scenes, mean FPS 170–200 s: branch 7.53, main 4.90 (+54%). Details are in the comment below.

The Smurfs Dreams (PPSA21607), mean FPS over the village-gameplay window both builds reach (200–235 s), two rounds: branch 13.97 / 13.66, main 10.80 / 11.11 (+26%; the round with identical screenshots alone is +23%).

Infliction: Extended Cut (PPSA02688), mean FPS 60–175 s, forward-walk preset, two rounds: branch 4.54 / 6.08, main 4.14 / 4.16. The branch's second run is noisy.

Where the gap came from: on main d50640e26408, which still had #23272, Spirit of the North gave 11.37 FPS. A bisect with verified-fresh drivers put the first slow merge at #24052, the revert (8.47 FPS). With a temporary counter, this branch left 0 ranges importing a buffer object of their own in Spirit of the North. Before the multi-run part, 16 or more did.

Safety

In Sound Mind (PPSA04921), with pristine save and Cross every 12 s, 150 s per run:

  • with #23272: 3 of 4 runs crashed;
  • this branch: 10 of 10 clean: 4 runs on a diagnostic build with a counter, 3 runs on the exact branch head, and 3 runs of 300 s on the exact branch head.

The counter showed the offset window bind used over 512 times per run in this title. The few ranges left on their own import were small multi-run ranges the sparse path declined.

Tested

Linux 7.2.14, Ryzen 9 7950X, RX 6650 XT, RADV (Mesa 26.2.7), Release, /dev/udmabuf accessible (size_limit_mb 64).

  • New agc_driver_dma_buf_chunk_window:

    • a 2 MiB range inside one chunk is bound into the chunk import;
    • a 2 MiB range across the 64 MiB boundary is a dma-buf import bound into a chunk window, without a VkDeviceMemory of its own;
    • a GPU fill reaches the backing memory on both sides of the boundary, and nothing past the range.

    It fails on main c8f72e905cce, which reports "a 2 MiB range across a chunk boundary was imported as a buffer object of its own", and passes here.

  • All 97 import-related tests pass (ctest -R 'host_import|dma_buf|sparse|scattered_runs|import|chunk_window').

  • Merge check: the branch merges cleanly with current main 0af6acc89ea2.

Checklist

  • Based on current main; no other open PR changes which ranges take the chunk imports or the sparse path
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and licence notices
  • 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

AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5419137660 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24555). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-20T19:33:21Z. --- ### What On Linux, a shared-backed guest range inside one 64 MiB chunk of the direct-memory file is bound into that chunk's udmabuf import. A range of 64 MiB or less that is not inside one chunk gets a udmabuf buffer object of its own. That covers a single run across a chunk boundary, or a range of several runs. amdgpu validates every imported buffer object at every command submission, so each such range adds to the cost of every `vkQueueSubmit`. #23272 sent all of those ranges through the sparse path. It was reverted in #24052 because In Sound Mind (PPSA04921) then corrupted its heap in 3 of 4 runs. I had traced that corruption to inside a 1 MiB single-run sparse import that straddled a chunk boundary. This PR splits the cases: 1. **Single-run ranges of 32 MiB or less that cross a chunk boundary** take no sparse binding. They are bound into a 64 MiB udmabuf buffer that starts 32 MiB into the chunk below the boundary, through the same single-buffer bind path as the chunk imports. The window is created once and shared through the chunk-import cache, now keyed by the window's byte start instead of its index. 2. **Ranges of several runs, and single runs above 32 MiB** not inside one chunk, take the existing sparse path at any size, as #23272 did. A range the sparse path declines keeps a buffer object of its own, as before. That means one imported without the GPU lock and without a sparse queue of its own, or one whose backing it cannot bind. ### Performance Matched A/B in one build directory: - **Builds:** this branch (`fbd98f83fdde`) against its base, `main` `c8f72e905cce`. - **Order:** alternating rebuilds before each run. - **Driver check:** before every run, the loaded `libs/libSceAgcDriver.prx` was checked to be byte-identical to a fresh `nid_patcher` run of that build's `unpatched` library. - **Conditions:** pristine save before each run, identical scripted input, no compiler running during runs, `APS5_NO_COMMITTER_CORE=1`. Spirit of the North (PPSA02306), mean FPS 150–235 s. CPU-bound here: GPU time was about 3.7 ms per frame. | Round | Branch | `main` | |---|---|---| | 1 | 8.85 | 8.03 | | 2 | 9.16 | 8.68 | | 3 | 9.89 | 8.84 | | 4 | 9.99 | 8.46 | | Mean | **9.47** | **8.50** (+11%) | The branch is ahead in every round. Under The Waves (PPSA08056), in a pair checked with a screenshot every 10 s so both runs show identical scenes, mean FPS 170–200 s: branch **7.53**, `main` **4.90** (+54%). Details are in the comment below. The Smurfs Dreams (PPSA21607), mean FPS over the village-gameplay window both builds reach (200–235 s), two rounds: branch **13.97 / 13.66**, `main` **10.80 / 11.11** (+26%; the round with identical screenshots alone is +23%). Infliction: Extended Cut (PPSA02688), mean FPS 60–175 s, forward-walk preset, two rounds: branch 4.54 / 6.08, `main` 4.14 / 4.16. The branch's second run is noisy. **Where the gap came from:** on `main` `d50640e26408`, which still had #23272, Spirit of the North gave 11.37 FPS. A bisect with verified-fresh drivers put the first slow merge at #24052, the revert (8.47 FPS). With a temporary counter, this branch left 0 ranges importing a buffer object of their own in Spirit of the North. Before the multi-run part, 16 or more did. ### Safety In Sound Mind (PPSA04921), with pristine save and Cross every 12 s, 150 s per run: - with #23272: 3 of 4 runs crashed; - this branch: **10 of 10 clean**: 4 runs on a diagnostic build with a counter, 3 runs on the exact branch head, and 3 runs of 300 s on the exact branch head. The counter showed the offset window bind used over 512 times per run in this title. The few ranges left on their own import were small multi-run ranges the sparse path declined. ### Tested Linux 7.2.14, Ryzen 9 7950X, RX 6650 XT, RADV (Mesa 26.2.7), Release, `/dev/udmabuf` accessible (`size_limit_mb` 64). - **New `agc_driver_dma_buf_chunk_window`:** - a 2 MiB range inside one chunk is bound into the chunk import; - a 2 MiB range across the 64 MiB boundary is a dma-buf import bound into a chunk window, without a `VkDeviceMemory` of its own; - a GPU fill reaches the backing memory on both sides of the boundary, and nothing past the range. It fails on `main` `c8f72e905cce`, which reports "a 2 MiB range across a chunk boundary was imported as a buffer object of its own", and passes here. - **All 97 import-related tests pass** (`ctest -R 'host_import|dma_buf|sparse|scattered_runs|import|chunk_window'`). - **Merge check:** the branch merges cleanly with current `main` `0af6acc89ea2`. ### Checklist - [x] Based on current `main`; no other open PR changes which ranges take the chunk imports or the sparse path - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt and licence notices - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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 AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-20 20:28:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T20:28:23Z.

Review: COMMENTED


Reviewed — no blocking findings

The diff’s chunk-window and sparse-path changes are consistent with the described routing; no verified blocking defect was found in the source inspected.

What I ran

Reviewed head fbd98f83fddedeefcce045beb6f0543570a8dce5. Read the prepared diff and targeted source using repo_read.py; no tests or builds were run.

Results

Check Result Note
Diff and targeted source review passed Routing and test code inspected
Automated tests/build not run Author reports test results

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full changed source file was not read; only the functions around the changed hunks were inspected. The described hardware performance and safety runs, merge check, and reported test results were not independently verified. Files read: review/description.md, review/commits.md, review/manifest.json, review/diff.patch, core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp (targeted ranges), core/libs/prx/libSceAgcDriver/tests/execution/DmaBufChunkWindow.cpp, and docs/dev/debt/libSceAgcDriver.md (changed line context). files.json was not available as a review document; manifest/listing showed three changed files, with GuestBufferMemory.cpp excluded from the prepared folder because it was too large.

To get this to a good state

Nothing is required. The author’s reported Linux import tests and physical-console runs remain useful supporting evidence.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5998915281 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24555#pullrequestreview-5998915281). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T20:28:23Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The diff’s chunk-window and sparse-path changes are consistent with the described routing; no verified blocking defect was found in the source inspected. ## What I ran Reviewed head `fbd98f83fddedeefcce045beb6f0543570a8dce5`. Read the prepared diff and targeted source using `repo_read.py`; no tests or builds were run. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Routing and test code inspected | | Automated tests/build | not run | Author reports test results | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The full changed source file was not read; only the functions around the changed hunks were inspected. The described hardware performance and safety runs, merge check, and reported test results were not independently verified. Files read: `review/description.md`, `review/commits.md`, `review/manifest.json`, `review/diff.patch`, `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` (targeted ranges), `core/libs/prx/libSceAgcDriver/tests/execution/DmaBufChunkWindow.cpp`, and `docs/dev/debt/libSceAgcDriver.md` (changed line context). `files.json` was not available as a review document; manifest/listing showed three changed files, with `GuestBufferMemory.cpp` excluded from the prepared folder because it was too large. ## To get this to a good state Nothing is required. The author’s reported Linux import tests and physical-console runs remain useful supporting evidence.
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!24555
No description provided.