perf(agc-driver): join host-import spans only over whole aligned windows #3335

Closed
Tamalero wants to merge 1 commit from upstream-pr/3335 into main
Tamalero commented 2026-10-11 08:06:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-11T08:06:12Z.


What

Follow-up to #3158, from the data in my comment there (https://github.com/boykopovar/AnyPS5/pull/3158#issuecomment-6105102035).

Cause: a span is the whole chain of adjacent registered ranges with the same access. A title that grows a heap 16 KiB at a time re-imports the whole chain on every growth. Ratchet & Clank: Rift Apart re-imported about 1.5 TiB while loading its first scene, and NVIDIA refused grown spans (VK_ERROR_OUT_OF_DEVICE_MEMORY), which leaves those ranges copied per draw.

Fix: ranges are now joined only when a chain covers a whole aligned window: 8 MiB by default, APS5_HOST_IMPORT_WINDOW_MIB on the device. Until the window is complete each range is imported on its own, and a span never crosses a window edge. Growth therefore re-imports a range at most once more, when its window completes, instead of the chain on every growth. A single range larger than the window is imported whole. The window is applied before #3324's fallback, so a window whose alias Windows refuses still drops to one range at a time. SetHostImportWindow(0) keeps the unbounded spans, which the existing tests use, so #3158's tests are unchanged.

Joining any part of a window was tried first and still churned: each 16 KiB growth re-imported the window's partial span, about 2 GB per second in Ratchet (68 GB re-imported after 30 s for 8 GB live).

Tested

CachyOS (Linux 7.2), RTX 4090, NVIDIA 615.78, GCC Release.

  • New importWindowTests in agc_driver_graphics: a full window is one span, a partly filled window imports its range alone, a view crossing a window edge gets no import, and completing one window leaves the other window's import in place. With the window ignored it fails.
  • ctest -R '^agc': 358/359 (agc_driver_dcc_keys_first_write, #2188). agc_driver_bda_device and agc_driver_bda_span_reads pass.
  • Rebased onto main 1be0a7ce (with #3324); the tests below are from that tree.
  • tools/check_conventions.py passes.
  • Ratchet & Clank: Rift Apart, intro and first scene load, APS5_TRACE_HOST_IMPORT=1, whole run (about 4 min, ending at #3274):
#3158 (unbounded) this PR (8 MiB)
Imported in total / live ~1.5 TiB re-imported over the load 11.0 GB / 9.4 GB
Refused imports yes (-2) 0
Kernel slab memory not recorded 0.9 GB, flat

Not measured on AMD/RADV.

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 (follow-up to #3158)
  • AI-assisted: yes (Claude Code)

Tested and written by Claude (AI assistant) on a contributor's machine.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4817609936 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3335). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-11T08:06:12Z. --- ### What Follow-up to #3158, from the data in my comment there (https://github.com/boykopovar/AnyPS5/pull/3158#issuecomment-6105102035). **Cause:** a span is the whole chain of adjacent registered ranges with the same access. A title that grows a heap 16 KiB at a time re-imports the whole chain on every growth. Ratchet & Clank: Rift Apart re-imported about 1.5 TiB while loading its first scene, and NVIDIA refused grown spans (`VK_ERROR_OUT_OF_DEVICE_MEMORY`), which leaves those ranges copied per draw. **Fix:** ranges are now joined only when a chain covers a whole aligned window: 8 MiB by default, `APS5_HOST_IMPORT_WINDOW_MIB` on the device. Until the window is complete each range is imported on its own, and a span never crosses a window edge. Growth therefore re-imports a range at most once more, when its window completes, instead of the chain on every growth. A single range larger than the window is imported whole. The window is applied before #3324's fallback, so a window whose alias Windows refuses still drops to one range at a time. `SetHostImportWindow(0)` keeps the unbounded spans, which the existing tests use, so #3158's tests are unchanged. Joining *any* part of a window was tried first and still churned: each 16 KiB growth re-imported the window's partial span, about 2 GB per second in Ratchet (68 GB re-imported after 30 s for 8 GB live). ### Tested CachyOS (Linux 7.2), RTX 4090, NVIDIA 615.78, GCC Release. - New `importWindowTests` in `agc_driver_graphics`: a full window is one span, a partly filled window imports its range alone, a view crossing a window edge gets no import, and completing one window leaves the other window's import in place. With the window ignored it fails. - `ctest -R '^agc'`: 358/359 (`agc_driver_dcc_keys_first_write`, #2188). `agc_driver_bda_device` and `agc_driver_bda_span_reads` pass. - Rebased onto `main` `1be0a7ce` (with #3324); the tests below are from that tree. - `tools/check_conventions.py` passes. - Ratchet & Clank: Rift Apart, intro and first scene load, `APS5_TRACE_HOST_IMPORT=1`, whole run (about 4 min, ending at #3274): | | #3158 (unbounded) | this PR (8 MiB) | |---|---|---| | Imported in total / live | ~1.5 TiB re-imported over the load | 11.0 GB / 9.4 GB | | Refused imports | yes (`-2`) | 0 | | Kernel slab memory | not recorded | 0.9 GB, flat | Not measured on AMD/RADV. ### 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 (follow-up to #3158) - [x] AI-assisted: yes (Claude Code) *Tested and written by Claude (AI assistant) on a contributor's machine.* 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-11 08:07:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T08:07:21Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106973617 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3335#issuecomment-6106973617). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T08:07:21Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
oneandonlydean commented 2026-10-11 10:10:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T10:10:48Z.


Carried as #3425 with your commit kept under your name and one change on top: the window is fixed at 8 MiB instead of read from APS5_HOST_IMPORT_WINDOW_MIB (environment switches aren't accepted). It also fixes a device loss #3158 causes on NVIDIA; details there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107933352 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3335#issuecomment-6107933352). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T10:10:48Z. --- Carried as #3425 with your commit kept under your name and one change on top: the window is fixed at 8 MiB instead of read from `APS5_HOST_IMPORT_WINDOW_MIB` (environment switches aren't accepted). It also fixes a device loss #3158 causes on NVIDIA; details there.

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