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

Merged
oneandonlydean merged 2 commits from upstream-pr/3425 into main 2026-10-11 10:35:58 +00:00
oneandonlydean commented 2026-10-11 10:10:46 +00:00 (Migrated from github.com)

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


What

Carries #3335 (@Tamalero, closed by the intake pause), rebased onto main 85c7cf9b, with one change: the window is fixed at 8 MiB instead of read from APS5_HOST_IMPORT_WINDOW_MIB.

Since #3158, a title we test with loses the device on its first logo, 0.6-1.3 s after start, in 8 of 8 runs on NVIDIA; it ran at 60 fps before. A span is the whole run of adjacent registered ranges, and this title grows a heap next to its GPU memory in 64 KiB pieces, so every growth retires the span at 0x200230000 and imports it again:

[shadow] 382 retiled units of import 0x200230000 lost their slab before they were marked
[shadow] import 0x200230000+0x5bf0000 retired outside the device lock: 128 shadowed units lost
[gpu] host import of 0x200230000+0x7b40000 failed at vkAllocateMemory (-2); falling back to copies
...
[videoout] presentation failed: vkWaitForFences present: Vulkan result -4

with NVRM: Xid ... 109 ... CTX SWITCH TIMEOUT on the host. 5 of the 8 runs have 268-402 refused imports, starting at a span of 119-123 MiB; the other 3 lose the device or segfault without one.

With #3335, ranges are joined only where a run fills a whole aligned 8 MiB window, and a span never crosses a window edge. A range in a partly filled window is imported on its own, so a growth re-imports at most one window, once, when it completes. A buffer that crosses two imports is copied, as before #3158.

Tree Runs Result Frame rate (menu / gameplay)
main 77bd928a (before #3158) 1 pass 60.0 / 59.9 fps
main 85c7cf9b 2 device lost at 1.0-1.3 s 0
main 85c7cf9b + #3335 as posted 1 pass 60.0 / 59.9 fps
main 85c7cf9b + this branch 2 pass, no import refusals, no Xid 59.9 / 59.9 and 60.0 / 59.9 fps

Second commit:

  • VulkanDevice.cpp sets the window to 8 MiB without the environment variable; SetHostImportWindow stays for the tests.
  • TechnicalDebt's host-import entry records the window as a choice.

Not measured here: #3158's own title (PPSA05684, 1.34 → 2.76 fps from importing buffers that cross its 1 MiB heap pieces). Those pieces fill whole 8 MiB windows only if the heap is mapped that far, and a buffer that crosses a window edge is copied again, so its gain may be smaller than with unbounded spans. #3335 reports Ratchet & Clank: Rift Apart at 11.0 GB imported for 9.4 GB live and no refusals, against about 1.5 TiB re-imported with #3158.

Tested

Linux (CachyOS, GCC 16, Release, BUILD_TESTING=ON), RTX 4090, NVIDIA 610.57.04, on main 85c7cf9b:

  • the title above: 2 of 2 runs pass (220 s each, to gameplay); 2 of 2 fail on plain main (table);
  • full ctest: 802/810, with #3335's importWindowTests passing in agc_driver_graphics. The same 8 fail on plain main 85c7cf9b: agc_driver_dcc_keys_first_write (#3179), agc_driver_bda_device, agc_driver_f32_compare_constant and agc_driver_flat_apertures_0, _2, _3, _4, _5;
  • tools/check_conventions.py passes.

Not tested on Windows or on AMD.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818287360 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3425). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T10:10:46Z. --- ### What Carries #3335 (@Tamalero, closed by the intake pause), rebased onto `main` 85c7cf9b, with one change: the window is fixed at 8 MiB instead of read from `APS5_HOST_IMPORT_WINDOW_MIB`. Since #3158, a title we test with loses the device on its first logo, 0.6-1.3 s after start, in 8 of 8 runs on NVIDIA; it ran at 60 fps before. A span is the whole run of adjacent registered ranges, and this title grows a heap next to its GPU memory in 64 KiB pieces, so every growth retires the span at `0x200230000` and imports it again: ``` [shadow] 382 retiled units of import 0x200230000 lost their slab before they were marked [shadow] import 0x200230000+0x5bf0000 retired outside the device lock: 128 shadowed units lost [gpu] host import of 0x200230000+0x7b40000 failed at vkAllocateMemory (-2); falling back to copies ... [videoout] presentation failed: vkWaitForFences present: Vulkan result -4 ``` with `NVRM: Xid ... 109 ... CTX SWITCH TIMEOUT` on the host. 5 of the 8 runs have 268-402 refused imports, starting at a span of 119-123 MiB; the other 3 lose the device or segfault without one. With #3335, ranges are joined only where a run fills a whole aligned 8 MiB window, and a span never crosses a window edge. A range in a partly filled window is imported on its own, so a growth re-imports at most one window, once, when it completes. A buffer that crosses two imports is copied, as before #3158. | Tree | Runs | Result | Frame rate (menu / gameplay) | |---|---|---|---| | `main` 77bd928a (before #3158) | 1 | pass | 60.0 / 59.9 fps | | `main` 85c7cf9b | 2 | device lost at 1.0-1.3 s | 0 | | `main` 85c7cf9b + #3335 as posted | 1 | pass | 60.0 / 59.9 fps | | `main` 85c7cf9b + this branch | 2 | pass, no import refusals, no Xid | 59.9 / 59.9 and 60.0 / 59.9 fps | Second commit: - `VulkanDevice.cpp` sets the window to 8 MiB without the environment variable; `SetHostImportWindow` stays for the tests. - TechnicalDebt's host-import entry records the window as a choice. Not measured here: #3158's own title (PPSA05684, 1.34 → 2.76 fps from importing buffers that cross its 1 MiB heap pieces). Those pieces fill whole 8 MiB windows only if the heap is mapped that far, and a buffer that crosses a window edge is copied again, so its gain may be smaller than with unbounded spans. #3335 reports Ratchet & Clank: Rift Apart at 11.0 GB imported for 9.4 GB live and no refusals, against about 1.5 TiB re-imported with #3158. ### Tested Linux (CachyOS, GCC 16, Release, `BUILD_TESTING=ON`), RTX 4090, NVIDIA 610.57.04, on `main` 85c7cf9b: - the title above: 2 of 2 runs pass (220 s each, to gameplay); 2 of 2 fail on plain `main` (table); - full `ctest`: 802/810, with #3335's `importWindowTests` passing in `agc_driver_graphics`. The same 8 fail on plain `main` 85c7cf9b: `agc_driver_dcc_keys_first_write` (#3179), `agc_driver_bda_device`, `agc_driver_f32_compare_constant` and `agc_driver_flat_apertures_0`, `_2`, `_3`, `_4`, `_5`; - `tools/check_conventions.py` passes. Not tested on Windows or on AMD. ### 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 (Claude Code)
adriadam10 commented 2026-10-11 10:35:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T10:35:55Z.


Checked on Linux: PR merged onto current main, libSceAgcDriver build, agc_driver_graphics passes, and the new importWindowTests doesn't build without the change. Reviewed that a span only forms over a fully filled aligned window, otherwise the range is imported alone, and the test pins base/bytes, the window edge and that growth doesn't re-import another window. TechnicalDebt entry updated. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108134019 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3425#issuecomment-6108134019). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T10:35:55Z. --- Checked on Linux: PR merged onto current main, libSceAgcDriver build, `agc_driver_graphics` passes, and the new `importWindowTests` doesn't build without the change. Reviewed that a span only forms over a fully filled aligned window, otherwise the range is imported alone, and the test pins base/bytes, the window edge and that growth doesn't re-import another window. TechnicalDebt entry updated. Merging.
AlxcBTW commented 2026-10-11 12:06:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T12:06:57Z.


A data point from the other side of #3158: Sword of the Sea (PPSA25344, Unreal) gets about 2.2x slower in its main menu with this change.

Setup. Windows 11, RTX 5070 Laptop (616.92). Our Sword of the Sea tree is main from 2026-10-10 (57f96fd2b) plus #3158 as 78e2408ee and a few title fixes. I cherry-picked both commits of this PR onto it; the only conflicts were context lines. Runs alternate between the two trees, 180 s each, same env:

Tree Frame time Menu FPS
without this PR 309 ms 3.0-3.3
with this PR, run 1 706 ms 1.5
with this PR, run 2 686 ms 1.5-1.7

The picture is the same in all runs, and there are no host import failures or budget lines.

Why. The title binds a 368 MiB buffer that crosses two registered ranges, 320.75 MiB and 47.3 MiB next to it. Both are registered whole and early and never grow. With this PR, a range larger than the window is imported alone and never joined, so the buffer falls back to copies:

  • 192-202 uploads of 368.1 MiB per run, 330-480 ms each;
  • 115-154 GiB copied on the CPU outside imports per run, against 0 without the PR.
  • dispatch.q0_indirect becomes the top cost at about 260 ms per frame.

So the window fixes the heap that grows in 64 KiB pieces, but it also cuts the case #3158 was for: large ranges that are complete from the start. Could a span keep joining across window edges where every window it covers is already completely registered when it is first imported, and stop at a window that is still partly filled? A window that completes later would start a span of its own instead of extending an imported one. Then a growing heap never re-imports what is already imported, and ranges registered whole stay one import. I can run any variant on this title and post the numbers.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108847387 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3425#issuecomment-6108847387). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-11T12:06:57Z. --- A data point from the other side of #3158: Sword of the Sea (PPSA25344, Unreal) gets about 2.2x slower in its main menu with this change. **Setup.** Windows 11, RTX 5070 Laptop (616.92). Our Sword of the Sea tree is `main` from 2026-10-10 (57f96fd2b) plus #3158 as 78e2408ee and a few title fixes. I cherry-picked both commits of this PR onto it; the only conflicts were context lines. Runs alternate between the two trees, 180 s each, same env: | Tree | Frame time | Menu FPS | |---|---|---| | without this PR | 309 ms | 3.0-3.3 | | with this PR, run 1 | 706 ms | 1.5 | | with this PR, run 2 | 686 ms | 1.5-1.7 | The picture is the same in all runs, and there are no host import failures or budget lines. **Why.** The title binds a 368 MiB buffer that crosses two registered ranges, 320.75 MiB and 47.3 MiB next to it. Both are registered whole and early and never grow. With this PR, a range larger than the window is imported alone and never joined, so the buffer falls back to copies: - 192-202 uploads of 368.1 MiB per run, 330-480 ms each; - 115-154 GiB copied on the CPU outside imports per run, against 0 without the PR. - `dispatch.q0_indirect` becomes the top cost at about 260 ms per frame. So the window fixes the heap that grows in 64 KiB pieces, but it also cuts the case #3158 was for: large ranges that are complete from the start. Could a span keep joining across window edges where every window it covers is already completely registered when it is first imported, and stop at a window that is still partly filled? A window that completes later would start a span of its own instead of extending an imported one. Then a growing heap never re-imports what is already imported, and ranges registered whole stay one import. I can run any variant on this title and post the numbers. AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-11 22:54:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T22:54:52Z.


Yes, with one more condition: a span is made only from windows and large ranges that no import holds yet, and it is never extended afterwards. up4/host-import-join-registered-windows on oneandonlydean/AnyPS5 (bcc81c52) does that; a window filled later gets an import of its own, so a growing heap still re-imports nothing. GPU memory is imported when it is mapped, so your two ranges join only if both are registered before the first one is imported, and APS5_TRACE_HOST_IMPORT=1 will show whether they come out as one 368 MiB import. Could you run it on PPSA25344?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114820015 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3425#issuecomment-6114820015). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T22:54:52Z. --- Yes, with one more condition: a span is made only from windows and large ranges that no import holds yet, and it is never extended afterwards. `up4/host-import-join-registered-windows` on oneandonlydean/AnyPS5 (bcc81c52) does that; a window filled later gets an import of its own, so a growing heap still re-imports nothing. GPU memory is imported when it is mapped, so your two ranges join only if both are registered before the first one is imported, and `APS5_TRACE_HOST_IMPORT=1` will show whether they come out as one 368 MiB import. Could you run it on PPSA25344?
AlxcBTW commented 2026-10-11 22:56:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T22:56:18Z.


@oneandonlydean thanks, that's the shape I was hoping for. I'm building up4/host-import-join-registered-windows (bcc81c52) on current main now and will run it on PPSA25344 against plain main, alternating, with APS5_TRACE_HOST_IMPORT=1. I'll report whether the two ranges come out as one 368 MiB import, plus frame time and the 368 MiB upload / CPU-copy counts.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114831708 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3425#issuecomment-6114831708). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-11T22:56:18Z. --- @oneandonlydean thanks, that's the shape I was hoping for. I'm building `up4/host-import-join-registered-windows` (bcc81c52) on current `main` now and will run it on PPSA25344 against plain `main`, alternating, with `APS5_TRACE_HOST_IMPORT=1`. I'll report whether the two ranges come out as one 368 MiB import, plus frame time and the 368 MiB upload / CPU-copy counts. AI-assisted: yes (Claude Code)
AlxcBTW commented 2026-10-12 01:47:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T01:47:37Z.


@oneandonlydean thanks for up4/host-import-join-registered-windows (bcc81c52). I ran it on PPSA25344 against plain main, alternating, with APS5_TRACE_HOST_IMPORT=1. It does not join the two ranges, and nothing changes in the menu.

Setup. Windows 11, RTX 5070 Laptop (616.92). Both trees are main a11c8f7f7 (2026-10-11, includes this PR) plus our local patches for this title; B adds your commit (bcc81c52, cherry-picked cleanly). APS5_WRITE_WATCH_IMPORTS=watch, 180 s rows, A B A B.

Row Menu FPS between captures Frame / GPU / worker ms
A1 main 3.08 / 3.12 327 / 128 / 325
B1 yours 3.10 / 3.12 326 / 128 / 324
A2 main 3.15 / 3.16 323 / 128 / 321
B2 yours 3.08 / 3.16 325 / 129 / 323

1. The two ranges are still two imports in B. In B1 the trace has host import of 0x30b1900000+0x140c0000 (320.75 MiB) and, later, host import of 0x30c59c0000+0x2f50000 (47.3 MiB). The second starts exactly where the first ends. B2 is the same (0x30b18c0000 and 0x30c5980000); in A1 the pair is 0x30b1890000 and 0x30c5950000, also two imports. No 368 MiB import appears in any of the four runs, and the other large imports (576 MiB at 0x306b480000, 128 MiB, 43.75 MiB, 42 MiB) are single ranges.

2. Order. The trace has no timestamps and does not log registration, so I can only give the order of the import lines. The 320.75 MiB range is imported at stderr line 2826 (B1) and the 47.3 MiB range at line 3923: 1097 imports apart (live count 2342 → 3415). B2: lines 2828 and 3944. A1: 2816 and 4063. In all runs both come before the first 10 s [present] report, so during start-up. So the second range is imported long after the first. I can't tell from this whether it was registered before the first import (and your join was refused, for example by continuesRun comparing writable/gpu) or only afterwards. From the code, when both ranges are leased and agree on readable/writable/gpu, importRun should join them: neither is held by an import, and each is a whole run because both cross a window edge. So I think the 47.3 MiB range was not registered yet at the first import. I'd like to confirm that with a registration trace.

3. 368 MiB uploads and CPU copies, A vs B. The [buffers] line (regions copied on the CPU outside imports) at the 9000th copied region:

  • A1, B1 and B2 are identical: 5366 regions outside imports, 347,037 MiB. A2 at its 10,000th region: 5966, 386,006 MiB.
  • Bucket 0x30b0000000: 453 regions, 166,732 MiB, i.e. 368.1 MiB each, in A1, B1 and B2 (A2: 504 / 185,504 MiB at the 10,000th). That is the buffer across the two ranges, copied as before.
  • Bucket 0x30c0000000: 1812 regions, 173,952 MiB, i.e. 96.0 MiB each, also identical in A1, B1 and B2. I haven't checked whether these cross the same boundary.

So B copies exactly the same regions as A.

4. What would have to change. Only guesses, I have not tried any of them:

  • Join at bind time. When a buffer crosses two adjacent registered ranges that are held by separate imports, and both are larger than the window (so neither is a heap that grows in 64 KiB pieces), import the union once and retire the two. A range that is already complete does not grow, so this cannot restart the re-import churn #3158 caused. It costs one re-import of the retired pair, and the shadows of their retiled units are lost with them.
  • Defer the first import. Not knowable in general: nothing tells the driver that a neighbour is about to be registered.

I can add a one-line trace for GuestAllocations registrations (address, bytes, flags, tick) and a trace of the join decision in importRun, and run A and B again, if that helps. I can also run the bind-time variant if you write it.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116302042 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3425#issuecomment-6116302042). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-12T01:47:37Z. --- @oneandonlydean thanks for `up4/host-import-join-registered-windows` (bcc81c52). I ran it on PPSA25344 against plain `main`, alternating, with `APS5_TRACE_HOST_IMPORT=1`. It does not join the two ranges, and nothing changes in the menu. **Setup.** Windows 11, RTX 5070 Laptop (616.92). Both trees are `main` a11c8f7f7 (2026-10-11, includes this PR) plus our local patches for this title; B adds your commit (bcc81c52, cherry-picked cleanly). `APS5_WRITE_WATCH_IMPORTS=watch`, 180 s rows, A B A B. | Row | Menu FPS between captures | Frame / GPU / worker ms | |---|---|---| | A1 `main` | 3.08 / 3.12 | 327 / 128 / 325 | | B1 yours | 3.10 / 3.12 | 326 / 128 / 324 | | A2 `main` | 3.15 / 3.16 | 323 / 128 / 321 | | B2 yours | 3.08 / 3.16 | 325 / 129 / 323 | **1. The two ranges are still two imports in B.** In B1 the trace has `host import of 0x30b1900000+0x140c0000` (320.75 MiB) and, later, `host import of 0x30c59c0000+0x2f50000` (47.3 MiB). The second starts exactly where the first ends. B2 is the same (`0x30b18c0000` and `0x30c5980000`); in A1 the pair is `0x30b1890000` and `0x30c5950000`, also two imports. No 368 MiB import appears in any of the four runs, and the other large imports (576 MiB at `0x306b480000`, 128 MiB, 43.75 MiB, 42 MiB) are single ranges. **2. Order.** The trace has no timestamps and does not log registration, so I can only give the order of the import lines. The 320.75 MiB range is imported at stderr line 2826 (B1) and the 47.3 MiB range at line 3923: 1097 imports apart (live count 2342 → 3415). B2: lines 2828 and 3944. A1: 2816 and 4063. In all runs both come before the first 10 s `[present]` report, so during start-up. So the second range is imported long after the first. I can't tell from this whether it was registered before the first import (and your join was refused, for example by `continuesRun` comparing `writable`/`gpu`) or only afterwards. From the code, when both ranges are leased and agree on `readable`/`writable`/`gpu`, `importRun` should join them: neither is held by an import, and each is a `whole` run because both cross a window edge. So I think the 47.3 MiB range was not registered yet at the first import. I'd like to confirm that with a registration trace. **3. 368 MiB uploads and CPU copies, A vs B.** The `[buffers]` line (regions copied on the CPU outside imports) at the 9000th copied region: - A1, B1 and B2 are identical: 5366 regions outside imports, 347,037 MiB. A2 at its 10,000th region: 5966, 386,006 MiB. - Bucket `0x30b0000000`: 453 regions, 166,732 MiB, i.e. 368.1 MiB each, in A1, B1 and B2 (A2: 504 / 185,504 MiB at the 10,000th). That is the buffer across the two ranges, copied as before. - Bucket `0x30c0000000`: 1812 regions, 173,952 MiB, i.e. 96.0 MiB each, also identical in A1, B1 and B2. I haven't checked whether these cross the same boundary. So B copies exactly the same regions as A. **4. What would have to change.** Only guesses, I have not tried any of them: - *Join at bind time.* When a buffer crosses two adjacent registered ranges that are held by separate imports, and both are larger than the window (so neither is a heap that grows in 64 KiB pieces), import the union once and retire the two. A range that is already complete does not grow, so this cannot restart the re-import churn #3158 caused. It costs one re-import of the retired pair, and the shadows of their retiled units are lost with them. - *Defer the first import.* Not knowable in general: nothing tells the driver that a neighbour is about to be registered. I can add a one-line trace for `GuestAllocations` registrations (address, bytes, flags, tick) and a trace of the join decision in `importRun`, and run A and B again, if that helps. I can also run the bind-time variant if you write it. AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-12 05:16:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T05:16:24Z.


Thanks, that settles it: the first range is imported when it is mapped, so no rule at import time can join them. up4/host-import-bind-join on oneandonlydean/AnyPS5 (7787130) joins at bind time instead: a buffer bound across imports whose windows are completely registered gets one import over them, under the device lock, and the imports it replaces are retired then; growth beside an import still never re-imports it. Could you run it on PPSA25344 against main with APS5_TRACE_HOST_IMPORT=1? The lines to look for are host import of ... joins N registered ranges for a bind of 0x30b...+0x17010000, any not joined for a bind of ...: <reason> (the 96 MiB regions in bucket 0x30c0000000 will say why they are copied, if they still are), the [buffers] ... outside imports totals and the frame time.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6118208523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3425#issuecomment-6118208523). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T05:16:24Z. --- Thanks, that settles it: the first range is imported when it is mapped, so no rule at import time can join them. `up4/host-import-bind-join` on oneandonlydean/AnyPS5 (7787130) joins at bind time instead: a buffer bound across imports whose windows are completely registered gets one import over them, under the device lock, and the imports it replaces are retired then; growth beside an import still never re-imports it. Could you run it on PPSA25344 against `main` with `APS5_TRACE_HOST_IMPORT=1`? The lines to look for are `host import of ... joins N registered ranges for a bind of 0x30b...+0x17010000`, any `not joined for a bind of ...: <reason>` (the 96 MiB regions in bucket 0x30c0000000 will say why they are copied, if they still are), the `[buffers] ... outside imports` totals and the frame time.
AlxcBTW commented 2026-10-12 05:17:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T05:17:41Z.


@oneandonlydean thanks, building up4/host-import-bind-join (7787130) now. I'll run it against main on PPSA25344 with APS5_TRACE_HOST_IMPORT=1 and report the join/refusal lines, the [buffers] totals and the frame time.

For context: a local bind-time join prototype of ours takes the menu from 289 to 134 ms/frame (3.5 → 7.5 FPS, Windows default env), with CPU copies outside imports going from ~422 GB to ~18 GB per run. On our tree it only joined after an extra change: there the direct memory under those ranges is mapped as shared views, and the read-write alias for the joined import has to span several view runs. I'll check whether yours hits the same limit and say so with the numbers.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6118220734 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3425#issuecomment-6118220734). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-12T05:17:41Z. --- @oneandonlydean thanks, building `up4/host-import-bind-join` (7787130) now. I'll run it against `main` on PPSA25344 with `APS5_TRACE_HOST_IMPORT=1` and report the join/refusal lines, the `[buffers]` totals and the frame time. For context: a local bind-time join prototype of ours takes the menu from 289 to 134 ms/frame (3.5 → 7.5 FPS, Windows default env), with CPU copies outside imports going from ~422 GB to ~18 GB per run. On our tree it only joined after an extra change: there the direct memory under those ranges is mapped as shared views, and the read-write alias for the joined import has to span several view runs. I'll check whether yours hits the same limit and say so with the numbers. AI-assisted: yes (Claude Code)
AlxcBTW commented 2026-10-12 14:09:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T14:09:58Z.


@oneandonlydean thanks for up4/host-import-bind-join (7787130). On PPSA25344 it finds the 368 MiB bind and tries the join, but on main the joined import is never made: the read-write alias it needs throws, so the buffer is still copied and the frame time doesn't move. #4367's MapAlias change covers that case. With the same mechanism, our own bind-time join took the menu from 289 to 134 ms per frame.

Setup. Windows 11, RTX 5070 Laptop (616.92). The base is main a11c8f7f7 (2026-10-11) plus our local patches for this title. One of them keeps direct memory as shared views, as on main (it undoes #2054's private pages, which turn this menu red). Your commit was cherry-picked without conflicts. Upstream default env (APS5_RESOURCE_CACHE_ENTRIES=8192, APS5_PROFILE_DRAW=1), 180 s rows, A B A B, APS5_TRACE_HOST_IMPORT=1 on B.

Row Frame / GPU / worker ms Menu FPS between captures 368 MiB buffer
A1 main 332 / 93 / 330 3.10 / 2.94 copied
B1 + 7787130 347 / 95 / 345 3.08 / 3.18 copied
A2 main 313 / 92 / 311 3.13 / 3.12 copied
B2 + 7787130 303 / 94 / 301 3.37 / 3.48 copied

1. The join is tried once and never imported. B1 logs host import of 0x30b18b0000+0x17010000 joins 2 registered ranges for a bind of 0x30b18b0000+0x17010000 at stderr line 4454; B2 logs the same for 0x30b1cb0000 at line 4474. Neither run has a host import of ... ok (...), joined line after it, and the CPU copies don't change. At the 8000th copied region, A1, B1 and A2 match exactly: 5064 regions outside imports, 281,119 MiB. Of those, 366 × 368.1 MiB are in bucket 0x30b0000000 and 1464 × 96.0 MiB in bucket 0x30c0000000. B2 at the same point has 400 × 368.1 MiB and 1600 × 96.0 MiB.

2. Why. Both ranges are shared views here, so createImportEntry needs a read-write alias over the joined span. WindowsMappings::MapAlias only aliases one contiguous run of views of one section. These two ranges are views of two sections (one per direct memory allocation), so GuestArenaMapAlias throws. For a joined entry the catch then runs if (entry.joined) return refuse();, which adds the span to unjoined without a trace line. Every later bind of the buffer returns before importCovering traces anything. So the trace shows the attempt but not the refusal; a line in refuse() for joined entries would make it visible. The 96 MiB regions in 0x30c0000000 log no not joined line either. With our own join (point 3) they went away together with the 368 MiB copies, so I think they are binds across the same pair that hit the same unjoined entry.

3. With a multi-run MapAlias. #4367 (Angel21PC's alias runs from #2254, carried by @MarcZX100) lets MapAlias alias a range made of several runs: it reserves a placeholder the size of the range and maps one view per run of a section's consecutive pages into it. We measured the same mechanism, with an alias change of our own that #4367 replaces, together with our own bind-time join, A/B in one build by an env switch:

  • frame time 289 / 301 → 134 / 139 ms (3.5 → 7.5 FPS);
  • CPU copies outside imports 421,677 / 386,006 → 18,057 MiB per run;
  • the trace has host import of 0x30b1880000+0x17010000 ok (...), joined at bind.

Without the alias change our join is refused the same way: the tree before it logged host import join of 0x30b1cc0000+0x17010000 (2 ranges) refused. I haven't run your join on top of #4367 yet; I can, and our join is up as #4515 (on #4385 and #4367) for comparison.

4. The other not joined lines. B1 has 15 and B2 has 16, all a piece lies in a partly registered window. They are small binds: 2 MiB ones at 0x305f... (bucket 0x3050000000, 2386 × 2 MiB at the 8000th region) and 256 KiB and 3 MiB ones, mostly at 0x31d7.... After our join, the 2 MiB bucket is the largest copy left: 7339 × 2 MiB per run.

5. Retiring inside a bind. Your join retires the imports it replaces inside UploadFinish's region loop and inside HostImportFor. On main, retireImport destroys an import at once when the recorder is idle, because it only keeps the holder for a busy recorder. An earlier region of the same loop that already took one of those imports, or a HostImport* a caller took earlier under the same device lock, still names it. The region.direct reuse is guarded by the epoch, but a region that already took its import is not. Commands recorded afterwards in the same hold then use a destroyed buffer. This is the mechanism behind the start-up device losses in #4385, which keeps a retired import for every batch its hold opens (Recorder::KeepThroughHold). With that fix, retiring inside the loop is safe. Our own join joins in a pass before any region of the build takes an import, and never inside HostImportFor. This part is from reading the code. No run showed a device loss from it, but B never made a joined import either.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6125977898 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3425#issuecomment-6125977898). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-12T14:09:58Z. --- @oneandonlydean thanks for `up4/host-import-bind-join` (7787130). On PPSA25344 it finds the 368 MiB bind and tries the join, but on `main` the joined import is never made: the read-write alias it needs throws, so the buffer is still copied and the frame time doesn't move. #4367's `MapAlias` change covers that case. With the same mechanism, our own bind-time join took the menu from 289 to 134 ms per frame. **Setup.** Windows 11, RTX 5070 Laptop (616.92). The base is `main` a11c8f7f7 (2026-10-11) plus our local patches for this title. One of them keeps direct memory as shared views, as on `main` (it undoes #2054's private pages, which turn this menu red). Your commit was cherry-picked without conflicts. Upstream default env (`APS5_RESOURCE_CACHE_ENTRIES=8192`, `APS5_PROFILE_DRAW=1`), 180 s rows, A B A B, `APS5_TRACE_HOST_IMPORT=1` on B. | Row | Frame / GPU / worker ms | Menu FPS between captures | 368 MiB buffer | |---|---|---|---| | A1 `main` | 332 / 93 / 330 | 3.10 / 2.94 | copied | | B1 + 7787130 | 347 / 95 / 345 | 3.08 / 3.18 | copied | | A2 `main` | 313 / 92 / 311 | 3.13 / 3.12 | copied | | B2 + 7787130 | 303 / 94 / 301 | 3.37 / 3.48 | copied | **1. The join is tried once and never imported.** B1 logs `host import of 0x30b18b0000+0x17010000 joins 2 registered ranges for a bind of 0x30b18b0000+0x17010000` at stderr line 4454; B2 logs the same for `0x30b1cb0000` at line 4474. Neither run has a `host import of ... ok (...), joined` line after it, and the CPU copies don't change. At the 8000th copied region, A1, B1 and A2 match exactly: 5064 regions outside imports, 281,119 MiB. Of those, 366 × 368.1 MiB are in bucket `0x30b0000000` and 1464 × 96.0 MiB in bucket `0x30c0000000`. B2 at the same point has 400 × 368.1 MiB and 1600 × 96.0 MiB. **2. Why.** Both ranges are shared views here, so `createImportEntry` needs a read-write alias over the joined span. `WindowsMappings::MapAlias` only aliases one contiguous run of views of one section. These two ranges are views of two sections (one per direct memory allocation), so `GuestArenaMapAlias` throws. For a joined entry the catch then runs `if (entry.joined) return refuse();`, which adds the span to `unjoined` without a trace line. Every later bind of the buffer returns before `importCovering` traces anything. So the trace shows the attempt but not the refusal; a line in `refuse()` for joined entries would make it visible. The 96 MiB regions in `0x30c0000000` log no `not joined` line either. With our own join (point 3) they went away together with the 368 MiB copies, so I think they are binds across the same pair that hit the same `unjoined` entry. **3. With a multi-run `MapAlias`.** #4367 (Angel21PC's alias runs from #2254, carried by @MarcZX100) lets `MapAlias` alias a range made of several runs: it reserves a placeholder the size of the range and maps one view per run of a section's consecutive pages into it. We measured the same mechanism, with an alias change of our own that #4367 replaces, together with our own bind-time join, A/B in one build by an env switch: - frame time 289 / 301 → 134 / 139 ms (3.5 → 7.5 FPS); - CPU copies outside imports 421,677 / 386,006 → 18,057 MiB per run; - the trace has `host import of 0x30b1880000+0x17010000 ok (...), joined at bind`. Without the alias change our join is refused the same way: the tree before it logged `host import join of 0x30b1cc0000+0x17010000 (2 ranges) refused`. I haven't run your join on top of #4367 yet; I can, and our join is up as #4515 (on #4385 and #4367) for comparison. **4. The other `not joined` lines.** B1 has 15 and B2 has 16, all `a piece lies in a partly registered window`. They are small binds: 2 MiB ones at `0x305f...` (bucket `0x3050000000`, 2386 × 2 MiB at the 8000th region) and 256 KiB and 3 MiB ones, mostly at `0x31d7...`. After our join, the 2 MiB bucket is the largest copy left: 7339 × 2 MiB per run. **5. Retiring inside a bind.** Your join retires the imports it replaces inside `UploadFinish`'s region loop and inside `HostImportFor`. On `main`, `retireImport` destroys an import at once when the recorder is idle, because it only keeps the holder for a busy recorder. An earlier region of the same loop that already took one of those imports, or a `HostImport*` a caller took earlier under the same device lock, still names it. The `region.direct` reuse is guarded by the epoch, but a region that already took its import is not. Commands recorded afterwards in the same hold then use a destroyed buffer. This is the mechanism behind the start-up device losses in #4385, which keeps a retired import for every batch its hold opens (`Recorder::KeepThroughHold`). With that fix, retiring inside the loop is safe. Our own join joins in a pass before any region of the build takes an import, and never inside `HostImportFor`. This part is from reading the code. No run showed a device loss from it, but B never made a joined import either. AI-assisted: yes (Claude Code)
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!3425
No description provided.