perf(agc): bind chunk-crossing shared imports into the 64 MiB chunk imports #23272

Merged
JJenkx merged 2 commits from upstream-pr/23272 into main 2026-11-19 22:21:48 +00:00
JJenkx commented 2026-11-18 21:41:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-18T21:41:16Z.


What

On Linux, a shared-backed guest range that lies inside one 64 MiB chunk of the direct-memory file is bound into that chunk's udmabuf import (b7443c4424), and a range above 64 MiB is one sparse buffer bound to the chunk imports (5894feff7e). A range at or below 64 MiB that crosses a chunk boundary, or has several backing runs, still became a udmabuf import of its own, because createSparseDmaBufImport returned early for entry.bytes <= ImportChunkBytes.

amdgpu validates every imported buffer object at every command submission, so each such range adds to the cost of every vkQueueSubmit. This drops the size condition: those ranges now take the existing sparse path and add no buffer object of their own. A range inside one chunk still takes the plain chunk import first, and every other condition of the sparse path (sparse binding, a sparse queue of its own or the GPU mutex, 64 KiB block alignment, chunk memory types, the backing file covering the last chunk) is unchanged.

Performance

Infliction: Extended Cut (PPSA02688) is CPU-bound on the draw committer at about 7 FPS, submitting about 4,900 times per 10 s. A DWARF perf profile puts Recorder::Submit at 19% of the committer's samples, nearly all of it in amdgpu_cs_ioctl. At 170 s the title has about 3,070 live host imports (5.4 GiB), almost all of them dma-buf: about 2,700 are bound into 87 shared chunk imports, but about 380 crossing ranges are udmabuf buffer objects of their own.

The comparison changes only this condition: a local build of main feb04e7e3f66 (plus the one-line #21747 change Infliction needs to reach gameplay, and a local import counter) with an environment switch that skips entry.bytes <= ImportChunkBytes, which is exactly what this PR removes. Runs alternate, 180 s each, the same scripted input, mean FPS over 120 to 175 s; submit cost is the marginal vkQueueSubmit time over the last 50 s from the [recorder] profile lines (APS5_PROFILE_DRAW=1).

Run Condition Mean FPS vkQueueSubmit Submits per 10 s Import buffer objects of their own
A1 as on main 7.72 456 µs 4,910 381
B1 this PR 9.01 131 µs 5,810 3
A2 as on main 7.15 521 µs 4,768 390
B2 this PR 8.75 138 µs 5,788 3

Means 7.44 against 8.88 FPS (+19%); the ranges do not overlap. All four runs exit 0. The second pair ran under a higher host load (17 to 19) with a low-priority build running alongside both, more of it during B2. Linux 7.2.14, Ryzen 9 7950X, RX 6650 XT, RADV Mesa 26.2.7, Release.

Why the count matters: a standalone Vulkan test (not in the tree) that imports N buffers and times 200 empty vkQueueSubmit calls on the same machine gives, for 2 MiB each, 0.25 / 0.84 / 1.81 ms per submit with 500 / 1,500 / 3,000 udmabuf imports (about 0.6 µs per buffer object), against 6.6 / 19.7 / 42.6 ms with host-pointer imports; buffer device address does not change it.

Tested

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

  • New agc_driver_sparse_dma_buf_straddle: a 2 MiB memfd-backed range inside one 64 MiB chunk is bound into the chunk import (unchanged); a 2 MiB range across the 64 MiB boundary must be dma-buf, bound into chunk imports and without a VkDeviceMemory of its own, and a GPU fill over it must land in both chunks and nowhere outside it. With main's condition it fails with straddling import: a 2 MiB range across a chunk boundary was imported as a buffer object of its own instead of being bound into the two chunk imports; with this change it passes.
  • agc_driver_sparse_dma_buf_import and agc_driver_scattered_runs pass.
  • Full ctest -j 12 at this head (code identical to b40458da3b17; the head commit differs only in the debt entry's wording): 6158 of 6162 pass. The four failures, agc_driver_host_write_shadowed_unit, agc_driver_image_table_packed_guards, guest_libressl3_aes_wrap and guest_libressl3_aes, fail the same way on main 6f023a5bae9f built with the same options (0 of 4 pass there); none of them involves imports of shared memory.

Checklist

  • Based on current main; no other open PR implements the same functions (#21649 adds a bind probe to the same sparse path; it does not change which ranges take it)
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 6650 XT, RADV (Mesa 26.2.7), Linux 7.2.14
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5384569756 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23272). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-18T21:41:16Z. --- ### What On Linux, a shared-backed guest range that lies inside one 64 MiB chunk of the direct-memory file is bound into that chunk's udmabuf import (b7443c44247d), and a range above 64 MiB is one sparse buffer bound to the chunk imports (5894feff7e0e). A range at or below 64 MiB that crosses a chunk boundary, or has several backing runs, still became a udmabuf import of its own, because `createSparseDmaBufImport` returned early for `entry.bytes <= ImportChunkBytes`. amdgpu validates every imported buffer object at every command submission, so each such range adds to the cost of every `vkQueueSubmit`. This drops the size condition: those ranges now take the existing sparse path and add no buffer object of their own. A range inside one chunk still takes the plain chunk import first, and every other condition of the sparse path (sparse binding, a sparse queue of its own or the GPU mutex, 64 KiB block alignment, chunk memory types, the backing file covering the last chunk) is unchanged. ### Performance Infliction: Extended Cut (PPSA02688) is CPU-bound on the draw committer at about 7 FPS, submitting about 4,900 times per 10 s. A DWARF `perf` profile puts `Recorder::Submit` at 19% of the committer's samples, nearly all of it in `amdgpu_cs_ioctl`. At 170 s the title has about 3,070 live host imports (5.4 GiB), almost all of them dma-buf: about 2,700 are bound into 87 shared chunk imports, but about 380 crossing ranges are udmabuf buffer objects of their own. The comparison changes only this condition: a local build of `main` `feb04e7e3f66` (plus the one-line #21747 change Infliction needs to reach gameplay, and a local import counter) with an environment switch that skips `entry.bytes <= ImportChunkBytes`, which is exactly what this PR removes. Runs alternate, 180 s each, the same scripted input, mean FPS over 120 to 175 s; submit cost is the marginal `vkQueueSubmit` time over the last 50 s from the `[recorder]` profile lines (`APS5_PROFILE_DRAW=1`). | Run | Condition | Mean FPS | `vkQueueSubmit` | Submits per 10 s | Import buffer objects of their own | |---|---|---|---|---|---| | A1 | as on `main` | 7.72 | 456 µs | 4,910 | 381 | | B1 | this PR | 9.01 | 131 µs | 5,810 | 3 | | A2 | as on `main` | 7.15 | 521 µs | 4,768 | 390 | | B2 | this PR | 8.75 | 138 µs | 5,788 | 3 | Means 7.44 against 8.88 FPS (+19%); the ranges do not overlap. All four runs exit 0. The second pair ran under a higher host load (17 to 19) with a low-priority build running alongside both, more of it during B2. Linux 7.2.14, Ryzen 9 7950X, RX 6650 XT, RADV Mesa 26.2.7, Release. Why the count matters: a standalone Vulkan test (not in the tree) that imports N buffers and times 200 empty `vkQueueSubmit` calls on the same machine gives, for 2 MiB each, 0.25 / 0.84 / 1.81 ms per submit with 500 / 1,500 / 3,000 udmabuf imports (about 0.6 µs per buffer object), against 6.6 / 19.7 / 42.6 ms with host-pointer imports; buffer device address does not change it. ### Tested Linux 7.2.14, Ryzen 9 7950X, RX 6650 XT, RADV (Mesa 26.2.7), GCC 16.2.1, Release, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`, `/dev/udmabuf` accessible (`size_limit_mb` 64). - New `agc_driver_sparse_dma_buf_straddle`: a 2 MiB memfd-backed range inside one 64 MiB chunk is bound into the chunk import (unchanged); a 2 MiB range across the 64 MiB boundary must be dma-buf, bound into chunk imports and without a `VkDeviceMemory` of its own, and a GPU fill over it must land in both chunks and nowhere outside it. With `main`'s condition it fails with `straddling import: a 2 MiB range across a chunk boundary was imported as a buffer object of its own instead of being bound into the two chunk imports`; with this change it passes. - `agc_driver_sparse_dma_buf_import` and `agc_driver_scattered_runs` pass. - Full `ctest -j 12` at this head (code identical to `b40458da3b17`; the head commit differs only in the debt entry's wording): 6158 of 6162 pass. The four failures, `agc_driver_host_write_shadowed_unit`, `agc_driver_image_table_packed_guards`, `guest_libressl3_aes_wrap` and `guest_libressl3_aes`, fail the same way on `main` `6f023a5bae9f` built with the same options (0 of 4 pass there); none of them involves imports of shared memory. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (#21649 adds a bind probe to the same sparse path; it does not change which ranges take it) - [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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 6650 XT, RADV (Mesa 26.2.7), Linux 7.2.14 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-18 23:27:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T23:27:53Z.

Review: APPROVED


Reviewed — looks good

The reviewed change at b4b3f14924779ee25117a0103e592571bd9d0c6e has no verified blocking defects; the reported test and performance results are author supplied and were not run in this review.

What I ran

Read the prepared description, commit list, manifest, diff, changed test, changed documentation, and the relevant import implementation and caller at the pinned head. No tests or builds were run.

Results

Check Result Note
Diff and targeted source review passed Import path and fallback inspected
Reported runtime tests and performance runs not run Results are author supplied
Negative control not run No local execution environment

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full text of GuestBufferMemory.cpp was excluded by the review bundle size limit; only the changed hunk and the relevant surrounding function and caller were read through the repository reader. The performance measurements and test outcomes in the PR description were not independently reproduced. No tests were run.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5966880525 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23272#pullrequestreview-5966880525). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T23:27:53Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change at `b4b3f14924779ee25117a0103e592571bd9d0c6e` has no verified blocking defects; the reported test and performance results are author supplied and were not run in this review. ## What I ran Read the prepared description, commit list, manifest, diff, changed test, changed documentation, and the relevant import implementation and caller at the pinned head. No tests or builds were run. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Import path and fallback inspected | | Reported runtime tests and performance runs | not run | Results are author supplied | | Negative control | not run | No local execution environment | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The full text of `GuestBufferMemory.cpp` was excluded by the review bundle size limit; only the changed hunk and the relevant surrounding function and caller were read through the repository reader. The performance measurements and test outcomes in the PR description were not independently reproduced. No tests were run. ## To get this to a good state Nothing is required.
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!23272
No description provided.