feat(agc): host import windows, least-recent eviction under the budget #290

Merged
MichonGoddijn231849 merged 3 commits from upstream-pr/290 into main 2026-10-14 02:27:19 +00:00
MichonGoddijn231849 commented 2026-10-01 21:57:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-01T21:57:56Z.


What

Split out of #167. GTA V's Story Mode load stopped at 30% with VK_ERROR_OUT_OF_DEVICE_MEMORY, and its large heaps took the whole import budget.

  • Windows: a guest allocation larger than 64 MiB is imported in windows around the range a draw or dispatch uses, not whole, so one large heap no longer takes the import budget.
    • The windows follow a grid from the start of the range, and the last one takes the remainder, so no window is smaller than the window size.
    • A use across window edges imports the cells it touches, grown to the union of the range's imports it overlaps. Uses across neighbouring edges therefore share one import instead of replacing each other's.
  • Whole-range imports: an address-based build (AcquireRegistered) imports a registered range whole. A window over its first byte does not serve it; the build replaces it.
  • Eviction: live imports stay under a budget:
    • APS5_HOST_IMPORT_MIB, else the larger of 6 GiB and half the physical memory, at most the largest host heap less 2 GiB (imports and type-3 mirrors share that heap; #167's rule).
    • Past it, the least recently used imports that no draw holds are retired first.
    • An import that would not fit even then is refused before anything is retired.
    • An address-based build never evicts. It imports every registered allocation, so evicting during its pass would retire imports the same pass needs. Past the budget its ranges use mirrors as before.
    • An import made when a range is mapped never evicts either: the map observer holds no GPU lock.
  • Refused imports are tried again at their next use; meanwhile the range is copied, as on main.

#167 derived the budget from the system memory heap (heap minus 2 GiB). With a fixed 6 GiB, GTA V's address-based draws (after #411) needed more than the budget, and every one of them re-imported guest memory (about 25 ms per build, 6.9 instead of 10 fps).

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.

  • New tests in agc_driver_graphics, each failing without its change:
    • a view in the last window of a range whose first window was imported binds through an import of the whole range;
    • an address-based build over the budget leaves the range's window in place;
    • two uses across neighbouring cell edges share one import over 10 rounds;
    • a range mapped at the budget is refused at map time and retires nothing.
  • agc_driver_host_import_windows (windows follow their range; ClearHostImports drops them), agc_driver_host_import_at_map, _teardown, agc_host_import_unmap, agc_driver_bda_device, agc_buffer_pool, agc_driver_pooled_buffer_range and tools/check_conventions.py pass, on main 82b1b2e7a.
  • Rebased on main 0214069e3 (2026-10-13): the whole agc_* suite passes on Windows (484 tests), the host import tests above included. The debt entry moved to docs/dev/debt/libSceAgcDriver.md (tools/debt_split.py resolve).
  • Earlier heads of this PR, which had a 15.8 GiB default budget on 32 GB:
    • GTA V (PPSA04264): with #411, the Story Mode load reached the world, all address-based builds reused the cached address space (no budget refusals), and the Prologue ran at ~10 fps instead of 6.9. Not rerun on this head, where the budget on 32 GB is 14 GiB.
    • Dreaming Sarah (PPSA02929): the title menu renders as on main.
  • Demon's Souls on Linux (@ponhei9502): with windows off, about 25 fps at the title instead of 4-15. The earlier crash with windows on is the whole-range bug fixed here.

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4710117444 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-01T21:57:56Z. --- ### What Split out of #167. GTA V's Story Mode load stopped at 30% with `VK_ERROR_OUT_OF_DEVICE_MEMORY`, and its large heaps took the whole import budget. - **Windows:** a guest allocation larger than 64 MiB is imported in windows around the range a draw or dispatch uses, not whole, so one large heap no longer takes the import budget. - The windows follow a grid from the start of the range, and the last one takes the remainder, so no window is smaller than the window size. - A use across window edges imports the cells it touches, grown to the union of the range's imports it overlaps. Uses across neighbouring edges therefore share one import instead of replacing each other's. - **Whole-range imports:** an address-based build (`AcquireRegistered`) imports a registered range whole. A window over its first byte does not serve it; the build replaces it. - **Eviction:** live imports stay under a budget: - `APS5_HOST_IMPORT_MIB`, else the larger of 6 GiB and half the physical memory, at most the largest host heap less 2 GiB (imports and type-3 mirrors share that heap; #167's rule). - Past it, the least recently used imports that no draw holds are retired first. - An import that would not fit even then is refused before anything is retired. - An address-based build never evicts. It imports every registered allocation, so evicting during its pass would retire imports the same pass needs. Past the budget its ranges use mirrors as before. - An import made when a range is mapped never evicts either: the map observer holds no GPU lock. - **Refused imports** are tried again at their next use; meanwhile the range is copied, as on `main`. #167 derived the budget from the system memory heap (heap minus 2 GiB). With a fixed 6 GiB, GTA V's address-based draws (after #411) needed more than the budget, and every one of them re-imported guest memory (about 25 ms per build, 6.9 instead of 10 fps). ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0. - New tests in `agc_driver_graphics`, each failing without its change: - a view in the last window of a range whose first window was imported binds through an import of the whole range; - an address-based build over the budget leaves the range's window in place; - two uses across neighbouring cell edges share one import over 10 rounds; - a range mapped at the budget is refused at map time and retires nothing. - `agc_driver_host_import_windows` (windows follow their range; `ClearHostImports` drops them), `agc_driver_host_import_at_map`, `_teardown`, `agc_host_import_unmap`, `agc_driver_bda_device`, `agc_buffer_pool`, `agc_driver_pooled_buffer_range` and `tools/check_conventions.py` pass, on `main` `82b1b2e7a`. - Rebased on `main` 0214069e3 (2026-10-13): the whole `agc_*` suite passes on Windows (484 tests), the host import tests above included. The debt entry moved to `docs/dev/debt/libSceAgcDriver.md` (`tools/debt_split.py resolve`). - Earlier heads of this PR, which had a 15.8 GiB default budget on 32 GB: - GTA V (PPSA04264): with #411, the Story Mode load reached the world, all address-based builds reused the cached address space (no budget refusals), and the Prologue ran at ~10 fps instead of 6.9. Not rerun on this head, where the budget on 32 GB is 14 GiB. - Dreaming Sarah (PPSA02929): the title menu renders as on `main`. - Demon's Souls on Linux (@ponhei9502): with windows off, about 25 fps at the title instead of 4-15. The earlier crash with windows on is the whole-range bug fixed here. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [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. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-02 00:24:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T00:24:43Z.


A note on host imports on Linux with NVIDIA, since this PR reworks importAllocation and adds the out-of-memory path.

On NVIDIA (RTX 4090, driver 610.57.04, Linux), a host import that the driver refuses and that is 64 KiB or smaller poisons the VkDevice. Every later device-local vkAllocateMemory returns -2 (VK_ERROR_OUT_OF_DEVICE_MEMORY) while VRAM is nearly empty, and imports of good anonymous memory fail too. Host-visible allocations still succeed. A refused import of 68 KiB or more fails cleanly and leaves the device usable.

A standalone probe (plain Vulkan, no AnyPS5 code) imports a read-only private file mapping and then allocates device-local memory:

Import Import result Later device-local 4 KiB / 64 KiB / 64 MiB Second VkDevice in the process, 64 MiB
anonymous RW, 4 KiB 0 0 / 0 / 0 0
file RO private, 4 KiB -2 -2 / -2 / -2 -2
file RO private, 64 KiB -2 -2 / -2 / -2 -2
file RO private, 68 KiB -2 0 / 0 / 0 0
file RO private, 1 MiB -2 0 / 0 / 0 0

How main reaches this on Linux:

  • importAllocation checks pages only on Windows (the VirtualQuery loop from #186).
  • On Linux it offers every registered range, including the relinked eboot's own read-only, file-backed pages. Address-based builds (TakeGpuDescriptor) lease and import all of them.
  • In PPSA21564 on my integration branch, the first address-based build offered a 4 KiB eboot page. Every texture, storage image and device buffer then failed with -2, and the title aborted about a second later.
  • The import budget plays no part: runs with 6 GiB and 16 GiB budgets failed at the same allocation.

Three parts of this PR meet that case:

  • The out-of-memory path: a refused import below 16 MiB goes into retryAfter and is offered again 4096 uses later. A small import refused this way poisons the device each time it is offered.
  • RelieveGpuMemory: after poisoning there is nothing to free. Retiring imports, trimming the pool and rerunning the draw still gets -2.
  • Import windows: the tail window of a large range can be smaller than 64 KiB, so small imports become more common.

What avoided it for me: on Linux, read /proc/self/maps for the range before attempting an import.

  • Import only if every page is readable and writable.
  • For 64 KiB or less, also require the pages to be anonymous or shared (guest direct memory is a shared memfd since #203).
  • Send everything else straight to the mirror or copy path a failed import takes now, so shaders read the same bytes.

That is about 85 lines plus tests, and it would sit in the same place this PR changes. I can send it as a follow-up once this lands, or it can be folded in here, whichever you prefer.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5943244995 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5943244995). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-02T00:24:43Z. --- A note on host imports on Linux with NVIDIA, since this PR reworks `importAllocation` and adds the out-of-memory path. On NVIDIA (RTX 4090, driver 610.57.04, Linux), a host import that the driver refuses and that is **64 KiB or smaller** poisons the `VkDevice`. Every later device-local `vkAllocateMemory` returns -2 (`VK_ERROR_OUT_OF_DEVICE_MEMORY`) while VRAM is nearly empty, and imports of good anonymous memory fail too. Host-visible allocations still succeed. A refused import of 68 KiB or more fails cleanly and leaves the device usable. A standalone probe (plain Vulkan, no AnyPS5 code) imports a read-only private file mapping and then allocates device-local memory: | Import | Import result | Later device-local 4 KiB / 64 KiB / 64 MiB | Second `VkDevice` in the process, 64 MiB | |---|---|---|---| | anonymous RW, 4 KiB | 0 | 0 / 0 / 0 | 0 | | file RO private, 4 KiB | -2 | -2 / -2 / -2 | -2 | | file RO private, 64 KiB | -2 | -2 / -2 / -2 | -2 | | file RO private, 68 KiB | -2 | 0 / 0 / 0 | 0 | | file RO private, 1 MiB | -2 | 0 / 0 / 0 | 0 | How main reaches this on Linux: - `importAllocation` checks pages only on Windows (the `VirtualQuery` loop from #186). - On Linux it offers every registered range, including the relinked eboot's own read-only, file-backed pages. Address-based builds (TakeGpuDescriptor) lease and import all of them. - In PPSA21564 on my integration branch, the first address-based build offered a 4 KiB eboot page. Every texture, storage image and device buffer then failed with -2, and the title aborted about a second later. - The import budget plays no part: runs with 6 GiB and 16 GiB budgets failed at the same allocation. Three parts of this PR meet that case: - **The out-of-memory path:** a refused import below 16 MiB goes into `retryAfter` and is offered again 4096 uses later. A small import refused this way poisons the device each time it is offered. - **`RelieveGpuMemory`:** after poisoning there is nothing to free. Retiring imports, trimming the pool and rerunning the draw still gets -2. - **Import windows:** the tail window of a large range can be smaller than 64 KiB, so small imports become more common. What avoided it for me: on Linux, read `/proc/self/maps` for the range before attempting an import. - Import only if every page is readable and writable. - For 64 KiB or less, also require the pages to be anonymous or shared (guest direct memory is a shared memfd since #203). - Send everything else straight to the mirror or copy path a failed import takes now, so shaders read the same bytes. That is about 85 lines plus tests, and it would sit in the same place this PR changes. I can send it as a follow-up once this lands, or it can be folded in here, whichever you prefer.
MichonGoddijn231849 commented 2026-10-02 08:05:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-02T08:05:21Z.


Thanks for the detailed probe, that's a nasty one. I changed the two parts of this PR that made it worse:

  • A refused import is no longer offered again. The retryAfter path is gone; a refused import goes to the copy path for good, as on main. Only an import of 16 MiB or more refused for memory retires imports and is tried once more, which is above the 64 KiB your table shows poisoning the device.
  • Import windows no longer leave a short tail. The last window of a range takes the remainder, so no window is smaller than the window size (64 MiB by default) unless the whole range is.

The /proc/self/maps check is Linux-only and I can't test it here, so a follow-up from you would be great once this lands.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5947873424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5947873424). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-02T08:05:21Z. --- Thanks for the detailed probe, that's a nasty one. I changed the two parts of this PR that made it worse: - A refused import is no longer offered again. The `retryAfter` path is gone; a refused import goes to the copy path for good, as on `main`. Only an import of 16 MiB or more refused for memory retires imports and is tried once more, which is above the 64 KiB your table shows poisoning the device. - Import windows no longer leave a short tail. The last window of a range takes the remainder, so no window is smaller than the window size (64 MiB by default) unless the whole range is. The `/proc/self/maps` check is Linux-only and I can't test it here, so a follow-up from you would be great once this lands.
oneandonlydean commented 2026-10-02 10:01:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T10:01:59Z.


Thanks, both changes look right to me. With retryAfter gone and no short tail windows, a refused small import is no longer offered again. The first refusal of an import of 64 KiB or less still poisons the device on NVIDIA, as it does on main today, so I'll send the /proc/self/maps check as a follow-up once this lands.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5949850140 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5949850140). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-02T10:01:59Z. --- Thanks, both changes look right to me. With `retryAfter` gone and no short tail windows, a refused small import is no longer offered again. The first refusal of an import of 64 KiB or less still poisons the device on NVIDIA, as it does on main today, so I'll send the `/proc/self/maps` check as a follow-up once this lands.
MichonGoddijn231849 commented 2026-10-02 16:16:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-02T16:16:17Z.


Pushed e558b8e0, a fix for a bug in this PR that I found while debugging GTA V.

A window made while a smaller import of the same allocation was still held, or a window spanning other cells than an existing one, left two live imports over the same bytes. UnitShadow's lookups assume imports never overlap, so a write-back shadowed in one import stayed hidden from reads through the other. A cube map then read stale bytes although its faces had just been written back.

A new import now takes in every import it would overlap and replaces them, and is not made while a build still holds one of them. This is the same rule this PR already applied to an import at the same base. With that invariant, findImport is back to main's single-predecessor lookup, and the unique flag is gone.

Tested: GTA V with this change reaches the world and renders as before. ctest passes. I haven't re-run Dreaming Sarah on this commit yet.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5956469394 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5956469394). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-02T16:16:17Z. --- Pushed e558b8e0, a fix for a bug in this PR that I found while debugging GTA V. A window made while a smaller import of the same allocation was still held, or a window spanning other cells than an existing one, left two live imports over the same bytes. `UnitShadow`'s lookups assume imports never overlap, so a write-back shadowed in one import stayed hidden from reads through the other. A cube map then read stale bytes although its faces had just been written back. A new import now takes in every import it would overlap and replaces them, and is not made while a build still holds one of them. This is the same rule this PR already applied to an import at the same base. With that invariant, `findImport` is back to `main`'s single-predecessor lookup, and the `unique` flag is gone. Tested: GTA V with this change reaches the world and renders as before. `ctest` passes. I haven't re-run Dreaming Sarah on this commit yet.
oneandonlydean commented 2026-10-02 22:24:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T22:24:55Z.


A note for after this lands, so the two out-of-memory paths do not stack.

My integration branch replaces the fixed 2048 MiB budgets of the texture and storage image caches with limits from VK_EXT_memory_budget: a soft limit per cache from the heap budget, and a hard limit from the budget's free space minus headroom. It evicts by age and never evicts a texture used in the current frame. On VK_ERROR_OUT_OF_DEVICE_MEMORY at texture or storage image creation, it evicts every entry not used this frame and retries once. In PPSA21564 this cut texture rebuilds in a long intro run from about 52k to 3k, and took one level from 0.4 to about 2 FPS.

Once this PR is merged, I plan to rebase that change so that:

  • the cache eviction becomes one more step in AllocateGpuMemory's recovery, after the buffer pool trim, instead of a retry of its own. A texture allocation then retries with both the pool and the caches trimmed;
  • the draw and dispatch level recovery here (drop the shared resource cache, retire imports, run once more) stays the last resort, unchanged.

If you would rather keep AllocateGpuMemory to the pool trim only, I can keep the texture retry at its call sites instead. Nothing is needed in this PR either way.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5962424526 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5962424526). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-02T22:24:55Z. --- A note for after this lands, so the two out-of-memory paths do not stack. My integration branch replaces the fixed 2048 MiB budgets of the texture and storage image caches with limits from `VK_EXT_memory_budget`: a soft limit per cache from the heap budget, and a hard limit from the budget's free space minus headroom. It evicts by age and never evicts a texture used in the current frame. On `VK_ERROR_OUT_OF_DEVICE_MEMORY` at texture or storage image creation, it evicts every entry not used this frame and retries once. In PPSA21564 this cut texture rebuilds in a long intro run from about 52k to 3k, and took one level from 0.4 to about 2 FPS. Once this PR is merged, I plan to rebase that change so that: - the cache eviction becomes one more step in `AllocateGpuMemory`'s recovery, after the buffer pool trim, instead of a retry of its own. A texture allocation then retries with both the pool and the caches trimmed; - the draw and dispatch level recovery here (drop the shared resource cache, retire imports, run once more) stays the last resort, unchanged. If you would rather keep `AllocateGpuMemory` to the pool trim only, I can keep the texture retry at its call sites instead. Nothing is needed in this PR either way.
oneandonlydean commented 2026-10-02 22:32:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T22:32:15Z.


The Linux CI failure on d3e1f345 is in configuredBudget(): the lambda's two returns deduce unsigned long long (strtoull(...) << 20u) and std::uint64_t (std::max<std::uint64_t>), which are different types with GCC on Linux, so GuestBufferMemory.cpp does not compile. Declaring the return type fixes it: static const std::uint64_t budget = []() -> std::uint64_t {.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5962512903 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5962512903). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-02T22:32:15Z. --- The Linux CI failure on d3e1f345 is in `configuredBudget()`: the lambda's two returns deduce `unsigned long long` (`strtoull(...) << 20u`) and `std::uint64_t` (`std::max<std::uint64_t>`), which are different types with GCC on Linux, so `GuestBufferMemory.cpp` does not compile. Declaring the return type fixes it: `static const std::uint64_t budget = []() -> std::uint64_t {`.
oneandonlydean commented 2026-10-03 02:47:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-03T02:47:43Z.


Thanks for the build fix. I suspect the remaining Linux failure is not from this PR: agc_driver_vopc_compare fails with thread 1 compare 39 is 0, expected 1, and compare 39 is the f16 NLE case (!(ha <= hb)) that #399 changed. The same failure shows up on unrelated PRs (#312, run 37071265405, and #407, run 37065871874), while main passed at 7d40a57d with #399 in, so it looks intermittent on llvmpipe. A rerun of the linux job would likely pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5964789713 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5964789713). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-03T02:47:43Z. --- Thanks for the build fix. I suspect the remaining Linux failure is not from this PR: `agc_driver_vopc_compare` fails with `thread 1 compare 39 is 0, expected 1`, and compare 39 is the f16 NLE case (`!(ha <= hb)`) that #399 changed. The same failure shows up on unrelated PRs (#312, run 37071265405, and #407, run 37065871874), while `main` passed at 7d40a57d with #399 in, so it looks intermittent on llvmpipe. A rerun of the linux job would likely pass.
MichonGoddijn231849 commented 2026-10-03 08:26:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-03T08:26:04Z.


Thanks for tracing the vopc_compare failure; I can't rerun jobs here, so I rebased onto d3ec1f15 and CI runs again. On your memory-budget plan: making the cache eviction one more step in AllocateGpuMemory after the buffer pool trim sounds right to me, with the draw and dispatch level recovery kept as the last resort. Go ahead once this lands.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5967164856 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5967164856). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-03T08:26:04Z. --- Thanks for tracing the vopc_compare failure; I can't rerun jobs here, so I rebased onto d3ec1f15 and CI runs again. On your memory-budget plan: making the cache eviction one more step in `AllocateGpuMemory` after the buffer pool trim sounds right to me, with the draw and dispatch level recovery kept as the last resort. Go ahead once this lands.
ThisIsAkill commented 2026-10-03 20:34:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-03T20:34:35Z.


Test note, Linux (GCC 16.2), RTX 3070 8 GiB, 46 GiB RAM, PPSA21567. Base: main d3ec1f15 + #285, plus a local experiment that lets one compute shader get past an unrelated record-time failure (#479). The run is not on clean main.

  • Without this PR: in that dispatch, host imports of guest ranges failed at vkAllocateMemory (-2) (one 3232 MiB import refused under the 6144 MiB default budget), then vkAllocateMemory texture -2 was fatal. VRAM use was about 1.1 GiB at the time. APS5_HOST_IMPORT_MIB=2048 did not help.
  • With this PR (4 commits cherry-picked onto the same base): the same imports still fail with -2 but fall back to copies, no allocation is fatal, VRAM peaks at about 1.9 GiB, and the title continues to presentation.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5973238852 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5973238852). Originally posted by [ThisIsAkill](https://github.com/ThisIsAkill) on 2026-10-03T20:34:35Z. --- Test note, Linux (GCC 16.2), RTX 3070 8 GiB, 46 GiB RAM, PPSA21567. Base: `main` d3ec1f15 + #285, plus a local experiment that lets one compute shader get past an unrelated record-time failure (#479). The run is not on clean `main`. - Without this PR: in that dispatch, host imports of guest ranges failed at `vkAllocateMemory` (-2) (one 3232 MiB import refused under the 6144 MiB default budget), then `vkAllocateMemory texture` -2 was fatal. VRAM use was about 1.1 GiB at the time. `APS5_HOST_IMPORT_MIB=2048` did not help. - With this PR (4 commits cherry-picked onto the same base): the same imports still fail with -2 but fall back to copies, no allocation is fatal, VRAM peaks at about 1.9 GiB, and the title continues to presentation.
MichonGoddijn231849 commented 2026-10-03 20:43:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-03T20:43:04Z.


Thanks for testing this on Linux with an 8 GiB card; that's exactly the case the fallback is for. The refused 3232 MiB import falling back to copies instead of a fatal vkAllocateMemory matches what I see on Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5973302701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5973302701). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-03T20:43:04Z. --- Thanks for testing this on Linux with an 8 GiB card; that's exactly the case the fallback is for. The refused 3232 MiB import falling back to copies instead of a fatal `vkAllocateMemory` matches what I see on Windows.
oneandonlydean commented 2026-10-04 05:49:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:49:50Z.


This conflicts with main after today's merges; once it's rebased I'm happy to see it in.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977065811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5977065811). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T05:49:50Z. --- This conflicts with main after today's merges; once it's rebased I'm happy to see it in.
MichonGoddijn231849 commented 2026-10-04 08:24:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T08:24:30Z.


Rebased onto main (9f9a8f5a). The only conflict was in refreshImports: main now frees the old device's import buffers there, and this PR's memory-count decrement goes next to that. All 4 commits applied otherwise unchanged.

ctest on Windows (RTX 5080): the same failures as on main here. agc_driver_flip, and once agc_driver, sometimes end with a heap-corruption exit (0xc0000374) under ctest -j 8, and pass when run alone. main hits the same exit in agc_driver_flip on every -j 8 run I tried, so I don't think it comes from this PR. linux_entry_argv and windows_icon fail on main locally too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978082690 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5978082690). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-04T08:24:30Z. --- Rebased onto `main` (9f9a8f5a). The only conflict was in `refreshImports`: `main` now frees the old device's import buffers there, and this PR's memory-count decrement goes next to that. All 4 commits applied otherwise unchanged. ctest on Windows (RTX 5080): the same failures as on `main` here. `agc_driver_flip`, and once `agc_driver`, sometimes end with a heap-corruption exit (0xc0000374) under `ctest -j 8`, and pass when run alone. `main` hits the same exit in `agc_driver_flip` on every `-j 8` run I tried, so I don't think it comes from this PR. `linux_entry_argv` and `windows_icon` fail on `main` locally too.
oneandonlydean commented 2026-10-04 09:51:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:51:34Z.


Thanks for the rebase. The resolution in refreshImports looks right to me: the old device's imports are destroyed once there, each one's CountGpuMemory decrement sits next to that, and liveBytes is reset with the map, so nothing is counted twice. Merged with current main it builds and passes the full ctest here. It's ready to merge from my side; since it changes how guest memory is imported for every draw, I'll run it on PPSA21564 on my integration branch first.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978687662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5978687662). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T09:51:34Z. --- Thanks for the rebase. The resolution in `refreshImports` looks right to me: the old device's imports are destroyed once there, each one's `CountGpuMemory` decrement sits next to that, and `liveBytes` is reset with the map, so nothing is counted twice. Merged with current main it builds and passes the full ctest here. It's ready to merge from my side; since it changes how guest memory is imported for every draw, I'll run it on PPSA21564 on my integration branch first.
MichonGoddijn231849 commented 2026-10-04 10:10:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T10:10:25Z.


Rebased again after today's merges. #401 changed the buffer pool's free slots to keyed lists, so this PR's BufferPool::Trim now walks the keyed slots (a separate small commit on top). Build and ctest are clean apart from the failures main has locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978883414 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5978883414). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-04T10:10:25Z. --- Rebased again after today's merges. #401 changed the buffer pool's free slots to keyed lists, so this PR's `BufferPool::Trim` now walks the keyed slots (a separate small commit on top). Build and ctest are clean apart from the failures `main` has locally.
oneandonlydean commented 2026-10-04 22:37:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:37:47Z.


Thanks for the second rebase. The BufferPool::Trim change is right for #401's keyed slots: it walks every list under each key, counts evictions from the tier's slots counter and resets it along with retainedBytes, so the counters stay consistent with free. The other four commits are unchanged apart from context. It's in my next PPSA21564 test batch; I'll merge after that if it passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985217449 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5985217449). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T22:37:47Z. --- Thanks for the second rebase. The `BufferPool::Trim` change is right for #401's keyed slots: it walks every list under each key, counts evictions from the tier's `slots` counter and resets it along with `retainedBytes`, so the counters stay consistent with `free`. The other four commits are unchanged apart from context. It's in my next PPSA21564 test batch; I'll merge after that if it passes.
ThisIsAkill commented 2026-10-05 01:04:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-05T01:04:20Z.


@MichonGoddijn231849 a suggestion for the relief step, from Astro Bot (PPSA21567) on an 8 GB RTX 3070. That's on oneandonlydean's astrobot branch, which has a sampled-texture and storage-image residency cache that main doesn't.

There, 3 of the 5 fatal out-of-memory stops I hit today were device-buffer allocations in dispatches (vkAllocateMemory device buffer: Vulkan result -2, in compute shaders 0x5007d2800 twice and 0x500797d00). The other 2 were image allocations (a storage texture in 0x5005a5400, a texture in 0x50740a700). On that branch, an image made through one of the caches can at most evict that one cache before retrying. At the same time, the two texture caches were holding about 4.3 GB: sampled textures 2.7 GB, sitting at their soft target of 3/8 of the memory budget, and storage images 1.55 GB. That's from a local counter on vkAllocateMemory/vkFreeMemory by call site, with the same breakdown in two runs. Device-local memory was about 6.1 GB of 8 at that point.

On that branch, DeviceMemoryExhausted is only caught inside texture and storage-image creation, which evict their own cache and retry. So a buffer that can't be allocated fails while idle textures stay resident, and an image allocation can only free its own cache. Your RelieveGpuMemory would be the natural place to also evict idle entries from those caches: their RunEvictionPass with the exhausted policy only evicts entries not used since the current frame started, and in-flight users keep their shared_ptr. Freeing both caches and the buffer pool together, before the retry, would cover both kinds of failure.

I also checked the obvious alternative, a smaller cache instead of recovery. Lowering the sampled cache's soft target to 1.5 GB (APS5_TEXTURE_CACHE_MIB=1536) made it worse: 2 of 2 runs stopped out of memory at the intro's texture burst around minute 6, against 0 of 2 baseline runs, and their lowest 10-second frame rate dropped from about 7.0 to 5.5-6.3 fps. The likely reason (not measured): below the scene's working set, the cache keeps evicting textures that are soon re-created, while the evicted copies are still alive. So the memory has to come back when an allocation fails, rather than by keeping the cache small. The sync and release wait your relief already does matter here: about 40-50 batches are in flight at that point, and an evicted texture's memory only returns after the batches that use it finish (the release queue itself was never backed up: 0 pending at every 10-second report).

One question before anyone writes it: the relief takes GpuMutex and would then take each cache's mutex. Do you know whether any path holds a texture cache's mutex and then waits for GpuMutex? If one does, the order would need to be the other way round, or the eviction moved outside the lock.

This only matters once #290 and that cache meet, on astrobot or if the residency cache goes upstream.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986357702 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5986357702). Originally posted by [ThisIsAkill](https://github.com/ThisIsAkill) on 2026-10-05T01:04:20Z. --- @MichonGoddijn231849 a suggestion for the relief step, from Astro Bot (PPSA21567) on an 8 GB RTX 3070. That's on oneandonlydean's `astrobot` branch, which has a sampled-texture and storage-image residency cache that `main` doesn't. There, 3 of the 5 fatal out-of-memory stops I hit today were device-buffer allocations in dispatches (`vkAllocateMemory device buffer: Vulkan result -2`, in compute shaders `0x5007d2800` twice and `0x500797d00`). The other 2 were image allocations (a storage texture in `0x5005a5400`, a texture in `0x50740a700`). On that branch, an image made through one of the caches can at most evict that one cache before retrying. At the same time, the two texture caches were holding about **4.3 GB**: sampled textures 2.7 GB, sitting at their soft target of 3/8 of the memory budget, and storage images 1.55 GB. That's from a local counter on `vkAllocateMemory`/`vkFreeMemory` by call site, with the same breakdown in two runs. Device-local memory was about 6.1 GB of 8 at that point. On that branch, `DeviceMemoryExhausted` is only caught inside texture and storage-image creation, which evict their own cache and retry. So a buffer that can't be allocated fails while idle textures stay resident, and an image allocation can only free its own cache. Your `RelieveGpuMemory` would be the natural place to also evict idle entries from those caches: their `RunEvictionPass` with the exhausted policy only evicts entries not used since the current frame started, and in-flight users keep their `shared_ptr`. Freeing both caches and the buffer pool together, before the retry, would cover both kinds of failure. I also checked the obvious alternative, a smaller cache instead of recovery. Lowering the sampled cache's soft target to 1.5 GB (`APS5_TEXTURE_CACHE_MIB=1536`) made it worse: 2 of 2 runs stopped out of memory at the intro's texture burst around minute 6, against 0 of 2 baseline runs, and their lowest 10-second frame rate dropped from about 7.0 to 5.5-6.3 fps. The likely reason (not measured): below the scene's working set, the cache keeps evicting textures that are soon re-created, while the evicted copies are still alive. So the memory has to come back when an allocation fails, rather than by keeping the cache small. The sync and release wait your relief already does matter here: about 40-50 batches are in flight at that point, and an evicted texture's memory only returns after the batches that use it finish (the release queue itself was never backed up: 0 pending at every 10-second report). One question before anyone writes it: the relief takes `GpuMutex` and would then take each cache's mutex. Do you know whether any path holds a texture cache's mutex and then waits for `GpuMutex`? If one does, the order would need to be the other way round, or the eviction moved outside the lock. This only matters once #290 and that cache meet, on `astrobot` or if the residency cache goes upstream.
MichonGoddijn231849 commented 2026-10-05 15:40:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-05T15:40:58Z.


@ThisIsAkill thanks, the numbers are convincing, especially the 1.5 GB run being worse. I agree the relief is the place to free idle cache entries, and both caches plus the buffer pool together before the retry makes sense.

On the lock order, for main at least: GpuMutex is only taken in the driver's packet, draw and dispatch paths (Execution/src/Driver), never inside Graphics/, where the texture and storage-image caches live. So on main a cache's mutex is always taken with the GPU lock already held, which is the same order the relief would use (GpuMutex, then each cache). The relief also only runs once the failing packet has unwound. relieveMemory is called from the packet loop after the exception, and RelieveGpuMemory returns at once if the thread still holds GpuMutex. So no cache lock is held at that point.

I can't check the residency cache on astrobot, since it isn't on main. If any of its paths takes the cache mutex and then the GPU lock (an eviction that syncs the recorder, for example), the eviction would have to move outside the cache lock. I'd do this as a follow-up once #290 and that cache meet, rather than in this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5997831789 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5997831789). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-05T15:40:58Z. --- @ThisIsAkill thanks, the numbers are convincing, especially the 1.5 GB run being worse. I agree the relief is the place to free idle cache entries, and both caches plus the buffer pool together before the retry makes sense. On the lock order, for `main` at least: `GpuMutex` is only taken in the driver's packet, draw and dispatch paths (`Execution/src/Driver`), never inside `Graphics/`, where the texture and storage-image caches live. So on `main` a cache's mutex is always taken with the GPU lock already held, which is the same order the relief would use (`GpuMutex`, then each cache). The relief also only runs once the failing packet has unwound. `relieveMemory` is called from the packet loop after the exception, and `RelieveGpuMemory` returns at once if the thread still holds `GpuMutex`. So no cache lock is held at that point. I can't check the residency cache on `astrobot`, since it isn't on `main`. If any of its paths takes the cache mutex and then the GPU lock (an eviction that syncs the recorder, for example), the eviction would have to move outside the cache lock. I'd do this as a follow-up once #290 and that cache meet, rather than in this PR.
ThisIsAkill commented 2026-10-05 16:12:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-05T16:12:01Z.


@MichonGoddijn231849 thanks. Agreed on both points: the relief is the place to free idle cache entries, and it's a follow-up once #290 and the residency cache meet, not part of this PR.

Your concern holds on astrobot. There, the sampled-texture lookup holds the cache's mutex while it compares guest memory, and that goes through FlushForAccess (Recorder.cpp), which takes GpuMutex. That's cache → GPU, the opposite of the relief's order. In my local prototype I matched the branch's order: the relief evicts each cache under its own mutex while not holding GpuMutex (it requires that it isn't held), and only then takes GpuMutex for the sync and the release wait.

What the prototype showed (PPSA21567, RTX 3070 8 GB, details and numbers on #357: measurement, fallback A/B):

  • Evicting "not used since the current frame started" (the exhausted policy) depends on when in the frame the failure lands:
    • One frame touches about 3.2–3.8 GB of the ~4 GB sampled cache. So mid-frame, every entry has already been used, and the relief frees 0 MiB: in one run 4 of 17 reliefs freed 0 MiB; in another, all 7 did.
    • Right after a flip, almost nothing has been touched yet, and it evicts 2.9–3.9 GB at once: the scene's whole working set, which the next frame loads again.
  • At the failure, device-local memory was 7.0–7.2 GB of 8: sampled textures 3.7–4.2 GB, device buffers 1.3–1.6 GB, storage textures 0.9–1.3 GB. The failing requests are small (5–60 MiB), so the card is simply full.
  • Falling back to system memory when device-local allocation fails (and, separately, pageable device-local memory with priorities) removes the crash, but in Snowy Canyon fps drops from about 9 to 0.1–0.2 and doesn't recover. The intro never triggers it and runs unchanged at about 5.4 fps.

So on 8 GB cards in heavy levels, eviction alone won't save the run. The working set itself is the problem. I'm measuring next how much of the sampled cache is duplicate copies of one guest surface (the cache key is the whole T#) and how much is top mips.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5998368679 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-5998368679). Originally posted by [ThisIsAkill](https://github.com/ThisIsAkill) on 2026-10-05T16:12:01Z. --- @MichonGoddijn231849 thanks. Agreed on both points: the relief is the place to free idle cache entries, and it's a follow-up once #290 and the residency cache meet, not part of this PR. **Your concern holds on `astrobot`.** There, the sampled-texture lookup holds the cache's mutex while it compares guest memory, and that goes through `FlushForAccess` (`Recorder.cpp`), which takes `GpuMutex`. That's cache → GPU, the opposite of the relief's order. In my local prototype I matched the branch's order: the relief evicts each cache under its own mutex while **not** holding `GpuMutex` (it requires that it isn't held), and only then takes `GpuMutex` for the sync and the release wait. **What the prototype showed** (PPSA21567, RTX 3070 8 GB, details and numbers on #357: [measurement](https://github.com/boykopovar/AnyPS5/discussions/357#discussioncomment-18759717), [fallback A/B](https://github.com/boykopovar/AnyPS5/discussions/357#discussioncomment-18760723)): - Evicting "not used since the current frame started" (the exhausted policy) depends on *when* in the frame the failure lands: - One frame touches about 3.2–3.8 GB of the ~4 GB sampled cache. So mid-frame, every entry has already been used, and the relief frees **0 MiB**: in one run 4 of 17 reliefs freed 0 MiB; in another, all 7 did. - Right after a flip, almost nothing has been touched yet, and it evicts 2.9–3.9 GB at once: the scene's whole working set, which the next frame loads again. - At the failure, device-local memory was 7.0–7.2 GB of 8: sampled textures 3.7–4.2 GB, device buffers 1.3–1.6 GB, storage textures 0.9–1.3 GB. The failing requests are small (5–60 MiB), so the card is simply full. - Falling back to system memory when device-local allocation fails (and, separately, pageable device-local memory with priorities) removes the crash, but in Snowy Canyon fps drops from about 9 to **0.1–0.2** and doesn't recover. The intro never triggers it and runs unchanged at about 5.4 fps. So on 8 GB cards in heavy levels, eviction alone won't save the run. The working set itself is the problem. I'm measuring next how much of the sampled cache is duplicate copies of one guest surface (the cache key is the whole T#) and how much is top mips.
MichonGoddijn231849 commented 2026-10-06 15:48:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-06T15:48:12Z.


@ThisIsAkill thanks, that's a clear result. On 8 GB in heavy levels the working set doesn't fit, so eviction only buys time, and the system-memory fallback trades the crash for 0.1 fps. Agreed that it's beyond this PR. The duplicate measurement sounds like the right next step: if T#s that differ only in swizzle, format view or mip clamps each get their own image, one image with several views could save a lot. I'm happy to adapt the relief to whatever the residency cache ends up with once you have numbers.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6019997962 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6019997962). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-06T15:48:12Z. --- @ThisIsAkill thanks, that's a clear result. On 8 GB in heavy levels the working set doesn't fit, so eviction only buys time, and the system-memory fallback trades the crash for 0.1 fps. Agreed that it's beyond this PR. The duplicate measurement sounds like the right next step: if T#s that differ only in swizzle, format view or mip clamps each get their own image, one image with several views could save a lot. I'm happy to adapt the relief to whatever the residency cache ends up with once you have numbers.
fisherjoey commented 2026-10-07 13:24:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-07T13:24:14Z.


A data point from Linux for the new default budget, in case it helps.

Demon's Souls (PPSA01341 v1.07) registers just over 6 GiB of host imports by its attract movie (956 imports, 6178 MiB live). Under the current 6144 MiB default, the allocation that falls off the budget depends on registration order. In two runs it was the title's 64 MiB render target (0x3e2300000+0x3fc0000 in one of them). That range was refused again on every lookup (474 refusals, 30217 MiB, by the end of the run), and its storage image was written back through the CPU path on every queue 0x30 dispatch that hooked it, under the GPU mutex.

Attract movie, per 10 s:

6144 MiB (main default) APS5_HOST_IMPORT_MIB=16384 max(6 GiB, RAM / 2) = 15588 MiB
presents 59-63 383-399 271-286
title fps 6.2-6.8 38.3-40.2 25.1-28.9
budget refusals 474 (whole run) 0 0
CPU write-backs (write-changed) 31 calls, 1976 MiB, 6.8 s 0 0
queue 0x30 GPU mutex held 8020 ms 914-923 ms 618 ms
queue 0 waited for the mutex 5286-6927 ms 1799-1812 ms 1265 ms

The last column is the same formula as this PR, applied locally as a one-line change to main's importAllocation. I have not run this PR itself. The gap between 28 and 40 fps in the last two columns is not the budget. Both runs had no refusals and no CPU write-backs, and the difference comes from indirect-dispatch recipe rebuilds that some runs show and others don't (I'll open a separate issue for that).

One forced-exhaustion run (APS5_HOST_IMPORT_MIB=6000) refused a 120 MiB allocation instead. It was asked for 173,749 times in about 130 s and the attract movie ran at 9.4-12.9 fps.

A Linux-only aside on the copy path, for when eviction cannot keep a range imported: when the texels changed, most of the cost of a 64 MiB CPU write-back is userfaultfd write-protect faults. In 30 s, GuestMemory::WriteChanged ran 228 times, and 36 of those calls took 128-512 ms (about 7.3 s in total). Every one of the 568,866 page faults inside the write-back was inside WriteChanged, about one per 4 KiB page. Windows' GetWriteWatch doesn't fault per page.

Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti (595.91.07), Ryzen 5 7600X, 32 GB. main at c1241ad0 with #157, #861, #864 and #1051, plus the path fix from #1047.

I can run this PR on the title if that's useful.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6038891519 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6038891519). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-07T13:24:14Z. --- A data point from Linux for the new default budget, in case it helps. Demon's Souls (PPSA01341 v1.07) registers just over 6 GiB of host imports by its attract movie (956 imports, 6178 MiB live). Under the current 6144 MiB default, the allocation that falls off the budget depends on registration order. In two runs it was the title's 64 MiB render target (`0x3e2300000+0x3fc0000` in one of them). That range was refused again on every lookup (474 refusals, 30217 MiB, by the end of the run), and its storage image was written back through the CPU path on every queue 0x30 dispatch that hooked it, under the GPU mutex. Attract movie, per 10 s: | | 6144 MiB (`main` default) | `APS5_HOST_IMPORT_MIB=16384` | max(6 GiB, RAM / 2) = 15588 MiB | |---|---|---|---| | presents | 59-63 | 383-399 | 271-286 | | title fps | 6.2-6.8 | 38.3-40.2 | 25.1-28.9 | | budget refusals | 474 (whole run) | 0 | 0 | | CPU write-backs (`write-changed`) | 31 calls, 1976 MiB, 6.8 s | 0 | 0 | | queue 0x30 GPU mutex held | 8020 ms | 914-923 ms | 618 ms | | queue 0 waited for the mutex | 5286-6927 ms | 1799-1812 ms | 1265 ms | The last column is the same formula as this PR, applied locally as a one-line change to `main`'s `importAllocation`. I have not run this PR itself. The gap between 28 and 40 fps in the last two columns is not the budget. Both runs had no refusals and no CPU write-backs, and the difference comes from indirect-dispatch recipe rebuilds that some runs show and others don't (I'll open a separate issue for that). One forced-exhaustion run (`APS5_HOST_IMPORT_MIB=6000`) refused a 120 MiB allocation instead. It was asked for 173,749 times in about 130 s and the attract movie ran at 9.4-12.9 fps. A Linux-only aside on the copy path, for when eviction cannot keep a range imported: when the texels changed, most of the cost of a 64 MiB CPU write-back is userfaultfd write-protect faults. In 30 s, `GuestMemory::WriteChanged` ran 228 times, and 36 of those calls took 128-512 ms (about 7.3 s in total). Every one of the 568,866 page faults inside the write-back was inside `WriteChanged`, about one per 4 KiB page. Windows' `GetWriteWatch` doesn't fault per page. Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti (595.91.07), Ryzen 5 7600X, 32 GB. `main` at c1241ad0 with #157, #861, #864 and #1051, plus the path fix from #1047. I can run this PR on the title if that's useful.
adriadam10 commented 2026-10-07 13:34:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T13:34:48Z.


@oneandonlydean you said on Oct 4 you'd merge this after your PPSA21564 batch; did it pass?

From our side, merged onto current main (e79c971f9): build and full ctest pass (396/396, RADV gfx1035), CI green, no conflicts. fisherjoey's Demon's Souls numbers above back the RAM/2 default on Linux too.

One nit for @MichonGoddijn231849, not blocking: BufferPool::Trim catches (...); catching std::bad_alloc and std::system_error (what reserve and the lock can throw) keeps it from hiding anything else.

Note: nothing in ctest reaches the import windows (>64 MiB ranges) or the out-of-memory retry, so those rest on the game runs.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6039095127 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6039095127). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T13:34:48Z. --- @oneandonlydean you said on Oct 4 you'd merge this after your PPSA21564 batch; did it pass? From our side, merged onto current `main` (e79c971f9): build and full ctest pass (396/396, RADV gfx1035), CI green, no conflicts. fisherjoey's Demon's Souls numbers above back the RAM/2 default on Linux too. One nit for @MichonGoddijn231849, not blocking: `BufferPool::Trim` catches `(...)`; catching `std::bad_alloc` and `std::system_error` (what `reserve` and the lock can throw) keeps it from hiding anything else. Note: nothing in ctest reaches the import windows (>64 MiB ranges) or the out-of-memory retry, so those rest on the game runs.
MichonGoddijn231849 commented 2026-10-07 17:38:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T17:38:41Z.


@adriadam10 done in 25bc2098: BufferPool::Trim now catches only std::bad_alloc and std::system_error. Build and ctest pass.

@fisherjoey thanks for the Demon's Souls numbers. The 64 MiB render target falling off a 6 GiB budget is the case the RAM / 2 default is meant for, and it's good to see it hold on Linux too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6043386501 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6043386501). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-07T17:38:41Z. --- @adriadam10 done in 25bc2098: `BufferPool::Trim` now catches only `std::bad_alloc` and `std::system_error`. Build and ctest pass. @fisherjoey thanks for the Demon's Souls numbers. The 64 MiB render target falling off a 6 GiB budget is the case the RAM / 2 default is meant for, and it's good to see it hold on Linux too.
oneandonlydean commented 2026-10-07 20:47:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-07T20:47:30Z.


Not yet, sorry. #290 is still in the queue for the regression run, and I haven't got a result for it. I'll post it here when I have one, and merge if it passes. Thanks for the full ctest on current main, and thanks to fisherjoey for the Linux numbers; they back the RAM / 2 default.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6046553266 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6046553266). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-07T20:47:30Z. --- Not yet, sorry. #290 is still in the queue for the regression run, and I haven't got a result for it. I'll post it here when I have one, and merge if it passes. Thanks for the full ctest on current main, and thanks to fisherjoey for the Linux numbers; they back the RAM / 2 default.
oneandonlydean commented 2026-10-08 07:13:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T07:13:15Z.


Sorry for the delay on this one. It now conflicts with main in GuestBufferMemory.{hpp,cpp} since #943 (udmabuf import), so please rebase. Also, the out-of-memory path retries the draw/dispatch and the ≥16 MiB import once after VK_ERROR_OUT_OF_DEVICE_MEMORY; retries after an error aren't allowed here (#182), so please throw there instead. Once it's rebased it goes to the front of the test queue.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6054640038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6054640038). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T07:13:15Z. --- Sorry for the delay on this one. It now conflicts with main in `GuestBufferMemory.{hpp,cpp}` since #943 (udmabuf import), so please rebase. Also, the out-of-memory path retries the draw/dispatch and the ≥16 MiB import once after `VK_ERROR_OUT_OF_DEVICE_MEMORY`; retries after an error aren't allowed here (#182), so please throw there instead. Once it's rebased it goes to the front of the test queue.
Celegans12 commented 2026-10-08 09:11:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-08T09:11:38Z.


Since you're about to rebase, here's how this PR (25bc20986) did in an hour of Ghost of Yōtei (PPSA26344 v1.008) today, plus one thing from our own merge with main's #1235 that might save you some debugging.

The run was stable: no FATAL, no vkAllocateMemory failure, and no refused heap mirror in 3,600 s, so the out-of-memory retry that oneandonlydean asked about never ran. The import windows stayed at the budget the whole time (5,961 of 6,144 MiB live at the end), and 7.1 M imports were refused along the way, against 5.6 M in a 3,000 s run before. Two caveats on those numbers: we set APS5_HOST_IMPORT_MIB=6144, and our tree carries a local patch that also counts mirrors and host buffers against the host-visible heap, so this isn't your default budget.

On #1235: main's leasedRangeOwner and sameRange match the registered range that starts at the import's base. A window further inside a larger range doesn't start there, so after a straight merge refreshImports retires all such windows on every refresh, and importAllocation never reuses them. What worked for us was to make both look up the readable range that contains [base, base + bytes) instead (a shared_ptr form of your containingRange), and to store that in entry.range. Also, main's auto-merged "retired: the range was mapped again" trace line right after that hunk reads a range variable, so the merge doesn't compile until refreshImports declares it. I'm happy to share our resolution if it helps, though you'll know better how it should look.

Details

Windows 11, RTX 3080 Laptop (16 GB), 32 GB RAM. Our integration tree on main c8a2f0632 + this PR at 25bc20986, resolved against #943 and #1235, + our open PRs (including #1085) + a local host-heap accounting patch. Private bytes peaked at 37,218 MiB.

[gpu] host import budget: 5961 MiB live of 6144 MiB (APS5_HOST_IMPORT_MIB); 7112428 imports (1177949 MiB) refused so far, last 0x1000000000+0x26c00000
[gpumem] live: host buffers 7461 MiB (52038), device buffers 2231 MiB (4372), host imports 6144 MiB (5178), textures 5292 MiB (21), storage images 3941 MiB (1201), depth surfaces 512 MiB (172), render targets 0 MiB (0), shadow slabs 1024 MiB (128); 63110 allocations
[buffers] image mirrors: 34937 ranges (5539.0 MiB, 34929 writable, 34929 heap 5509.1 MiB), ...

Previous run (3,000 s, same budget):

[gpu] host import budget: 6143 MiB live of 6144 MiB (APS5_HOST_IMPORT_MIB); 5645405 imports (954731 MiB) refused so far, last 0x200000000+0xa00000
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6056609585 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6056609585). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-08T09:11:38Z. --- Since you're about to rebase, here's how this PR (25bc20986) did in an hour of Ghost of Yōtei (PPSA26344 v1.008) today, plus one thing from our own merge with main's #1235 that might save you some debugging. The run was stable: no FATAL, no `vkAllocateMemory` failure, and no refused heap mirror in 3,600 s, so the out-of-memory retry that oneandonlydean asked about never ran. The import windows stayed at the budget the whole time (5,961 of 6,144 MiB live at the end), and 7.1 M imports were refused along the way, against 5.6 M in a 3,000 s run before. Two caveats on those numbers: we set `APS5_HOST_IMPORT_MIB=6144`, and our tree carries a local patch that also counts mirrors and host buffers against the host-visible heap, so this isn't your default budget. On #1235: main's `leasedRangeOwner` and `sameRange` match the registered range that starts at the import's base. A window further inside a larger range doesn't start there, so after a straight merge `refreshImports` retires all such windows on every refresh, and `importAllocation` never reuses them. What worked for us was to make both look up the readable range that contains [base, base + bytes) instead (a `shared_ptr` form of your `containingRange`), and to store that in `entry.range`. Also, main's auto-merged "retired: the range was mapped again" trace line right after that hunk reads a `range` variable, so the merge doesn't compile until `refreshImports` declares it. I'm happy to share our resolution if it helps, though you'll know better how it should look. <details><summary>Details</summary> Windows 11, RTX 3080 Laptop (16 GB), 32 GB RAM. Our integration tree on main c8a2f0632 + this PR at 25bc20986, resolved against #943 and #1235, + our open PRs (including #1085) + a local host-heap accounting patch. Private bytes peaked at 37,218 MiB. ``` [gpu] host import budget: 5961 MiB live of 6144 MiB (APS5_HOST_IMPORT_MIB); 7112428 imports (1177949 MiB) refused so far, last 0x1000000000+0x26c00000 [gpumem] live: host buffers 7461 MiB (52038), device buffers 2231 MiB (4372), host imports 6144 MiB (5178), textures 5292 MiB (21), storage images 3941 MiB (1201), depth surfaces 512 MiB (172), render targets 0 MiB (0), shadow slabs 1024 MiB (128); 63110 allocations [buffers] image mirrors: 34937 ranges (5539.0 MiB, 34929 writable, 34929 heap 5509.1 MiB), ... ``` Previous run (3,000 s, same budget): ``` [gpu] host import budget: 6143 MiB live of 6144 MiB (APS5_HOST_IMPORT_MIB); 5645405 imports (954731 MiB) refused so far, last 0x200000000+0xa00000 ``` </details>
MichonGoddijn231849 commented 2026-10-08 16:08:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-08T16:08:54Z.


Rebased onto main. Main has since added import ownership (an import is reused only while the same registered Range still owns it) and dma-buf imports, which touched the same code, so I folded the PR into one commit on top of them:

  • Windows: a window import is reused only while the registered range containing it still owns it (sameRange over the import's whole extent), so an unrelated registration no longer drops it and a remapped range's window is retired. dma-buf imports keep their own unwatch flag; the budget, least-recent eviction and the out-of-memory retry sit on top unchanged.
  • ClearHostImports (from main) destroyed imports without uncounting them from the GPU memory totals; it does now.
  • New ctest agc_driver_host_import_windows reaches imports through FillBuffer and checks window reuse after an unrelated registration, retirement after a remap, and the counter. Reverting to main's exact-base refresh rule, to containment-only, or dropping the uncount each fails it.
  • agc_driver_bda_device_tests needed a HostImportLimit stub beside its existing stubs (it does not link GuestBufferMemory.cpp).
    All 225 agc_ tests pass on Windows (RTX 5080).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6064049547 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6064049547). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-08T16:08:54Z. --- Rebased onto main. Main has since added import ownership (an import is reused only while the same registered Range still owns it) and dma-buf imports, which touched the same code, so I folded the PR into one commit on top of them: - Windows: a window import is reused only while the registered range containing it still owns it (`sameRange` over the import's whole extent), so an unrelated registration no longer drops it and a remapped range's window is retired. dma-buf imports keep their own unwatch flag; the budget, least-recent eviction and the out-of-memory retry sit on top unchanged. - `ClearHostImports` (from main) destroyed imports without uncounting them from the GPU memory totals; it does now. - New ctest `agc_driver_host_import_windows` reaches imports through `FillBuffer` and checks window reuse after an unrelated registration, retirement after a remap, and the counter. Reverting to main's exact-base refresh rule, to containment-only, or dropping the uncount each fails it. - `agc_driver_bda_device_tests` needed a `HostImportLimit` stub beside its existing stubs (it does not link `GuestBufferMemory.cpp`). All 225 `agc_` tests pass on Windows (RTX 5080).
MichonGoddijn231849 commented 2026-10-09 08:32:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:32:47Z.


Parked as a draft to keep my rebase load sane after #639. I'll rebase it when someone wants to review it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077387925 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6077387925). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-09T08:32:47Z. --- Parked as a draft to keep my rebase load sane after #639. I'll rebase it when someone wants to review it.
oneandonlydean commented 2026-10-09 09:21:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:21:46Z.


When you rebase: the out-of-memory retry needs to go. It should throw on VK_ERROR_OUT_OF_DEVICE_MEMORY instead of trying again (#182):

  • PacketExecution.cpp:62 retryOutOfMemory runs the dispatch packet a second time after relieveMemory;
  • Resources.cpp:82 calls vkAllocateMemory again after BufferPool::Trim;
  • GuestBufferMemory.cpp:500 creates the import again after trimming and retiring.

Evicting under the budget before an import is fine. The 24 new code comments need to go too; conventions fails on them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078112729 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6078112729). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:21:46Z. --- When you rebase: the out-of-memory retry needs to go. It should throw on `VK_ERROR_OUT_OF_DEVICE_MEMORY` instead of trying again (#182): - `PacketExecution.cpp:62` `retryOutOfMemory` runs the dispatch packet a second time after `relieveMemory`; - `Resources.cpp:82` calls `vkAllocateMemory` again after `BufferPool::Trim`; - `GuestBufferMemory.cpp:500` creates the import again after trimming and retiring. Evicting under the budget before an import is fine. The 24 new code comments need to go too; `conventions` fails on them.
MichonGoddijn231849 commented 2026-10-09 14:39:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T14:39:38Z.


Thanks, noted. Before this comes out of draft I will drop the retry paths (the second dispatch run in retryOutOfMemory, the second vkAllocateMemory after BufferPool::Trim, and the import retry), so VK_ERROR_OUT_OF_DEVICE_MEMORY throws as #182 asks, keep the eviction under the budget before an import, and remove the new code comments.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083131544 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6083131544). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-09T14:39:38Z. --- Thanks, noted. Before this comes out of draft I will drop the retry paths (the second dispatch run in `retryOutOfMemory`, the second `vkAllocateMemory` after `BufferPool::Trim`, and the import retry), so `VK_ERROR_OUT_OF_DEVICE_MEMORY` throws as #182 asks, keep the eviction under the budget before an import, and remove the new code comments.
MichonGoddijn231849 commented 2026-10-09 14:48:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T14:48:36Z.


Done in 39b87412: VK_ERROR_OUT_OF_DEVICE_MEMORY now throws everywhere (no second dispatch run, no second vkAllocateMemory after trimming the pool, no second import). After a failure the driver still relieves memory for the packets that follow, and imports are still retired under the budget before an import. The new code comments are gone, and check_conventions.py passes. Title and description updated to match.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083283987 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6083283987). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-09T14:48:36Z. --- Done in 39b87412: VK_ERROR_OUT_OF_DEVICE_MEMORY now throws everywhere (no second dispatch run, no second vkAllocateMemory after trimming the pool, no second import). After a failure the driver still relieves memory for the packets that follow, and imports are still retired under the budget before an import. The new code comments are gone, and `check_conventions.py` passes. Title and description updated to match.
NahuelGenchi commented 2026-10-09 16:39:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-09T16:39:01Z.


Tested on Linux with Sonic Origins (PPSA05324), merged onto the testing branch from #2021:

  • Setup: Ubuntu 26.04, kernel 7.0, RADV (Mesa 26.0.8), R9 380 2 GB (GFX8), 960x540 render size.
  • Merge: the only conflict was with my local diagnostics in PacketExecution.cpp.
  • Tests: agc_driver_host_import_windows passes.

Speed: the auto-save notice runs at about 60 fps instead of about 23, and the boot reaches it at 78 s instead of 116 s. The same settings without this PR are the baseline.

Windows over udmabuf's limit: several 128 MiB windows (+0x8000000) failed at UDMABUF_CREATE and were copied. udmabuf's default size_limit_mb is 64. With the default 64 MiB window, a window that spans two cells, or the last cell with its remainder, goes over that limit. Capping the window at the udmabuf limit on Linux may be worth it.

Separate from this PR, the title screen still loses the device here. About 10 s after the notice closes:

  • Imports of four whole heaps fail at UDMABUF_CREATE and are copied: 5000 MiB, 1126 + 873 MiB (one 2000 MB allocator) and 256 MiB. They look like the whole-allocation imports of address-based builds.
  • The copies fill GTT (7604 of 7611 MiB), and RADV fails the submit with Not enough memory for command submission, then VK_ERROR_DEVICE_LOST.
  • APS5_HOST_IMPORT_WINDOW_MIB=16 doesn't change it, because these imports are not windowed.

I'll add a result with a raised size_limit_mb.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085137737 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6085137737). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-09T16:39:01Z. --- Tested on Linux with Sonic Origins (PPSA05324), merged onto the testing branch from #2021: - **Setup:** Ubuntu 26.04, kernel 7.0, RADV (Mesa 26.0.8), R9 380 2 GB (GFX8), 960x540 render size. - **Merge:** the only conflict was with my local diagnostics in `PacketExecution.cpp`. - **Tests:** `agc_driver_host_import_windows` passes. **Speed:** the auto-save notice runs at about 60 fps instead of about 23, and the boot reaches it at 78 s instead of 116 s. The same settings without this PR are the baseline. **Windows over udmabuf's limit:** several 128 MiB windows (`+0x8000000`) failed at `UDMABUF_CREATE` and were copied. udmabuf's default `size_limit_mb` is 64. With the default 64 MiB window, a window that spans two cells, or the last cell with its remainder, goes over that limit. Capping the window at the udmabuf limit on Linux may be worth it. **Separate from this PR, the title screen still loses the device here.** About 10 s after the notice closes: - Imports of four whole heaps fail at `UDMABUF_CREATE` and are copied: 5000 MiB, 1126 + 873 MiB (one 2000 MB allocator) and 256 MiB. They look like the whole-allocation imports of address-based builds. - The copies fill GTT (7604 of 7611 MiB), and RADV fails the submit with `Not enough memory for command submission`, then `VK_ERROR_DEVICE_LOST`. - `APS5_HOST_IMPORT_WINDOW_MIB=16` doesn't change it, because these imports are not windowed. I'll add a result with a raised `size_limit_mb`.
NahuelGenchi commented 2026-10-09 16:51:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-09T16:51:02Z.


I re-ran the same test with udmabuf's size_limit_mb raised to 8192. Every import now succeeds, including the 128 MiB windows and the whole-heap imports. The device is still lost, though, and this time it is about the import budget.

  • Live imports reach 7291 MiB (APS5_TRACE_HOST_IMPORT=1): the 5000 MiB heap, 1126 + 873 MiB, 256 MiB and a few small ranges. The next vkQueueSubmit fails with radv/amdgpu: Not enough memory for command submission, then Vulkan result -4. That happens about 10 s after the auto-save notice closes.
  • The budget is the whole GTT heap here. This host has 15 GB of RAM, so the new default max(6 GiB, RAM / 2) comes to 7611 MiB. RADV's GTT heap is 7.43 GiB (also 7611 MiB), and RADV's own GTT allocations need room too. So the GTT heap runs out before the budget ever refuses an import.
  • APS5_HOST_IMPORT_MIB=6144 (the old default) refuses the 5000 MiB range, so that range goes to the copy path instead. The submit fails at the same point.

A default capped by the GTT heap's VK_EXT_memory_budget budget, minus some headroom, would keep the budget below what the driver can actually hold. It won't get this title to its title screen on this host, though. The address-based ranges alone need about 7.3 GB in GTT, whether they are imported or copied, so I'll try a larger GTT next (ttm.pages_limit).

The failed submit returns VK_ERROR_DEVICE_LOST (-4) here, not VK_ERROR_OUT_OF_DEVICE_MEMORY, so the out-of-memory handling from 39b87412 doesn't get a chance to run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085325550 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6085325550). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-09T16:51:02Z. --- I re-ran the same test with udmabuf's `size_limit_mb` raised to 8192. Every import now succeeds, including the 128 MiB windows and the whole-heap imports. The device is still lost, though, and this time it is about the import budget. - **Live imports reach 7291 MiB** (`APS5_TRACE_HOST_IMPORT=1`): the 5000 MiB heap, 1126 + 873 MiB, 256 MiB and a few small ranges. The next `vkQueueSubmit` fails with `radv/amdgpu: Not enough memory for command submission`, then `Vulkan result -4`. That happens about 10 s after the auto-save notice closes. - **The budget is the whole GTT heap here.** This host has 15 GB of RAM, so the new default `max(6 GiB, RAM / 2)` comes to 7611 MiB. RADV's GTT heap is 7.43 GiB (also 7611 MiB), and RADV's own GTT allocations need room too. So the GTT heap runs out before the budget ever refuses an import. - **`APS5_HOST_IMPORT_MIB=6144`** (the old default) refuses the 5000 MiB range, so that range goes to the copy path instead. The submit fails at the same point. A default capped by the GTT heap's `VK_EXT_memory_budget` budget, minus some headroom, would keep the budget below what the driver can actually hold. It won't get this title to its title screen on this host, though. The address-based ranges alone need about 7.3 GB in GTT, whether they are imported or copied, so I'll try a larger GTT next (`ttm.pages_limit`). The failed submit returns `VK_ERROR_DEVICE_LOST` (-4) here, not `VK_ERROR_OUT_OF_DEVICE_MEMORY`, so the out-of-memory handling from 39b87412 doesn't get a chance to run.
oneandonlydean commented 2026-10-09 20:14:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:14:21Z.


When you rebase: the out-of-memory retry needs to go. It should throw on VK_ERROR_OUT_OF_DEVICE_MEMORY instead of trying again (#182):

  • PacketExecution.cpp:62 retryOutOfMemory runs the dispatch packet a second time after relieveMemory;
  • Resources.cpp:82 calls vkAllocateMemory again after BufferPool::Trim;
  • GuestBufferMemory.cpp:500 creates the import again after trimming and retiring.

Evicting under the budget before an import is fine. The 24 new code comments need to go too; conventions fails on them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088504957 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6088504957). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:14:21Z. --- When you rebase: the out-of-memory retry needs to go. It should throw on `VK_ERROR_OUT_OF_DEVICE_MEMORY` instead of trying again (#182): - `PacketExecution.cpp:62` `retryOutOfMemory` runs the dispatch packet a second time after `relieveMemory`; - `Resources.cpp:82` calls `vkAllocateMemory` again after `BufferPool::Trim`; - `GuestBufferMemory.cpp:500` creates the import again after trimming and retiring. Evicting under the budget before an import is fine. The 24 new code comments need to go too; `conventions` fails on them.
MichonGoddijn231849 commented 2026-10-09 22:09:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T22:09:59Z.


These are already gone on the current head (39b87412, pushed at 14:47):

  • PacketExecution.cpp: retryOutOfMemory is removed; a failed dispatch or draw calls relieveMemory (eviction under the budget) and rethrows, so the packet never runs a second time.
  • Resources.cpp: the second vkAllocateMemory after BufferPool::Trim is removed; VK_ERROR_OUT_OF_DEVICE_MEMORY throws.
  • GuestBufferMemory.cpp: the second import after trimming and retiring is removed.

The conventions job passes on that head. Did you look at an older head? It stays a draft for now. I'm keeping the number of ready PRs down until some of the current ones merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090087678 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6090087678). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-09T22:09:59Z. --- These are already gone on the current head (39b87412, pushed at 14:47): - `PacketExecution.cpp`: `retryOutOfMemory` is removed; a failed dispatch or draw calls `relieveMemory` (eviction under the budget) and rethrows, so the packet never runs a second time. - `Resources.cpp`: the second `vkAllocateMemory` after `BufferPool::Trim` is removed; `VK_ERROR_OUT_OF_DEVICE_MEMORY` throws. - `GuestBufferMemory.cpp`: the second import after trimming and retiring is removed. The `conventions` job passes on that head. Did you look at an older head? It stays a draft for now. I'm keeping the number of ready PRs down until some of the current ones merge.
oneandonlydean commented 2026-10-10 05:16:21 +00:00 (Migrated from github.com)

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


Yes, that was the older head, sorry; 39b87412 is right. It conflicts with main in BufferPool.cpp and Resources.cpp now, so when you rebase and mark it ready it goes first in the test queue.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094124786 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6094124786). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T05:16:21Z. --- Yes, that was the older head, sorry; 39b87412 is right. It conflicts with main in `BufferPool.cpp` and `Resources.cpp` now, so when you rebase and mark it ready it goes first in the test queue.
MichonGoddijn231849 commented 2026-10-10 08:23:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-10T08:23:45Z.


Thanks. The rebase is more than conflict resolution now. Since this PR's base, main got Celegans12's host heap budget (#1085), shared dma-buf import chunks (b7443c44) and in-place draw-buffer reads from host imports (c903d1ad), about 480 changed lines in GuestBufferMemory.cpp alone. The import windows and least-recent eviction have to be rebuilt on #1085's budget instead of a second one next to it. I'm doing that today; I'll mark it ready once it builds and passes here, with GTA V checked on it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095645880 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6095645880). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-10T08:23:45Z. --- Thanks. The rebase is more than conflict resolution now. Since this PR's base, `main` got Celegans12's host heap budget (#1085), shared dma-buf import chunks (b7443c44) and in-place draw-buffer reads from host imports (c903d1ad), about 480 changed lines in `GuestBufferMemory.cpp` alone. The import windows and least-recent eviction have to be rebuilt on #1085's budget instead of a second one next to it. I'm doing that today; I'll mark it ready once it builds and passes here, with GTA V checked on it.
MichonGoddijn231849 commented 2026-10-10 08:55:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-10T08:55:42Z.


Rebased onto main (af1a8edf) as one commit, 87091dc4, and marked ready.

#1085's budget turned out to be the heap-mirror one (APS5_HEAP_MIRROR_MIB), so the import budget doesn't duplicate it after all. What had to change for main:

  • retireImport: takes the device now (main's signature). A retired import is still held by the active recorder while batches are in flight, so a draw that bound its VkBuffer in place (c903d1ad) keeps it until that batch completes.
  • In-place reads: a draw input read through HostImportFor (main's in-place vertex/index path) now counts as a use. Otherwise the least-recently-used eviction would pick imports the draws read every frame.
  • Main's dma-buf chunks and its retire-before-unmap: merged unchanged.

Tested on Windows, RTX 5080:

  • the full agc_* suite passes (306 of 306), including agc_driver_host_import_windows, agc_driver_host_import_teardown, the BDA tests and agc_driver_sampled_cache_budget(_memory);
  • check_conventions.py passes.

GTA V can't confirm it on main alone yet, because it stops at #1184's bindless table before gameplay. The same windows code runs on our integration branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095879547 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6095879547). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-10T08:55:42Z. --- Rebased onto `main` (af1a8edf) as one commit, `87091dc4`, and marked ready. #1085's budget turned out to be the heap-mirror one (`APS5_HEAP_MIRROR_MIB`), so the import budget doesn't duplicate it after all. What had to change for main: - **`retireImport`:** takes the device now (main's signature). A retired import is still held by the active recorder while batches are in flight, so a draw that bound its `VkBuffer` in place (c903d1ad) keeps it until that batch completes. - **In-place reads:** a draw input read through `HostImportFor` (main's in-place vertex/index path) now counts as a use. Otherwise the least-recently-used eviction would pick imports the draws read every frame. - **Main's dma-buf chunks and its retire-before-unmap:** merged unchanged. Tested on Windows, RTX 5080: - the full `agc_*` suite passes (306 of 306), including `agc_driver_host_import_windows`, `agc_driver_host_import_teardown`, the BDA tests and `agc_driver_sampled_cache_budget(_memory)`; - `check_conventions.py` passes. GTA V can't confirm it on `main` alone yet, because it stops at #1184's bindless table before gameplay. The same windows code runs on our integration branch.
oneandonlydean commented 2026-10-10 09:56:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T09:56:04Z.


Could you rebase this on main? It conflicts in PacketExecution.cpp. Astro Bot on current main stops on "guest snapshot differs from registered memory", and the 6 GiB budget was part of that stop before, so this is next in line once #374/#425 are done.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096328208 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6096328208). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T09:56:04Z. --- Could you rebase this on main? It conflicts in `PacketExecution.cpp`. Astro Bot on current main stops on "guest snapshot differs from registered memory", and the 6 GiB budget was part of that stop before, so this is next in line once #374/#425 are done.
MichonGoddijn231849 commented 2026-10-10 10:06:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-10T10:06:29Z.


Rebased onto main (be403084), head 2ab78478. The PacketExecution.cpp conflict was main's merged dispatch branch (pending waits, group look-ahead). Its dispatch/dispatchIndirect calls now go through relievingMemory (evict under the budget, then rethrow), as the two branches did before. A second commit adapts the new test to main's Mutation::Add gpu flag. The full agc_* suite passes here (319 of 319, Windows, RTX 5080), and so does check_conventions.py.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096404452 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6096404452). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-10T10:06:29Z. --- Rebased onto `main` (be403084), head `2ab78478`. The `PacketExecution.cpp` conflict was main's merged dispatch branch (pending waits, group look-ahead). Its `dispatch`/`dispatchIndirect` calls now go through `relievingMemory` (evict under the budget, then rethrow), as the two branches did before. A second commit adapts the new test to main's `Mutation::Add` `gpu` flag. The full `agc_*` suite passes here (319 of 319, Windows, RTX 5080), and so does `check_conventions.py`.
oneandonlydean commented 2026-10-10 18:08:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T18:08:34Z.


Conflicts with main again in BufferPool.hpp and Resources.cpp after 765619a00b (small host buffers sub-allocated from shared blocks); please rebase. It goes to the front of the test queue after that.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6100606590 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6100606590). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T18:08:34Z. --- Conflicts with main again in `BufferPool.hpp` and `Resources.cpp` after 765619a00b (small host buffers sub-allocated from shared blocks); please rebase. It goes to the front of the test queue after that.
MichonGoddijn231849 commented 2026-10-10 22:26:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-10T22:26:40Z.


@oneandonlydean rebased onto main b65d6b71 (with #1190): 58ea21db + 1f418944. The two conflicts were additive: main's slab path for small host buffers (765619a00b) stays first in Buffer's allocation, and the PR's counted AllocateGpuMemory takes over the dedicated allocation after it; BufferPool.hpp keeps both the slab members and the PR's Trim / RetainedBytes. The 324 agc tests pass on Windows (RTX 5080).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102841616 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6102841616). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-10T22:26:40Z. --- @oneandonlydean rebased onto main `b65d6b71` (with #1190): `58ea21db` + `1f418944`. The two conflicts were additive: main's slab path for small host buffers (765619a00b) stays first in `Buffer`'s allocation, and the PR's counted `AllocateGpuMemory` takes over the dedicated allocation after it; `BufferPool.hpp` keeps both the slab members and the PR's `Trim` / `RetainedBytes`. The 324 agc tests pass on Windows (RTX 5080).
oneandonlydean commented 2026-10-11 01:08:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:09Z.


Conflicts with main again in GuestBufferMemory.cpp (#1961 now imports GPU-mapped memory when it is mapped) and Resources.cpp (#2233); please rebase. It's first in the test queue once it's clean.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104051478 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6104051478). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T01:08:09Z. --- Conflicts with main again in `GuestBufferMemory.cpp` (#1961 now imports GPU-mapped memory when it is mapped) and `Resources.cpp` (#2233); please rebase. It's first in the test queue once it's clean.
MichonGoddijn231849 commented 2026-10-11 07:59:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T07:59:36Z.


@oneandonlydean will do, later today once main has been quiet for a while (it is merging every minute or two this morning; the last rebase was stale within an hour).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106913748 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6106913748). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-11T07:59:36Z. --- @oneandonlydean will do, later today once main has been quiet for a while (it is merging every minute or two this morning; the last rebase was stale within an hour).
oneandonlydean commented 2026-10-11 08:02:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T08:02:38Z.


@oneandonlydean will do, later today once main has been quiet for a while (it is merging every minute or two this morning; the last rebase was stale within an hour).

Thank you!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106937036 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6106937036). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T08:02:38Z. --- > @oneandonlydean will do, later today once main has been quiet for a while (it is merging every minute or two this morning; the last rebase was stale within an hour). Thank you!
adriadam10 commented 2026-10-11 11:39:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:39:30Z.

Review: DISMISSED


This conflicts with current main in three files, and the conflicts are not mechanical:

  • GuestBufferMemory.cpp: #1961 (GPU-mapped memory imports) overlaps the import path this PR reworks (windows, retireImport, eviction); 9 conflicting hunks.
  • Resources.cpp: #2233 and the shared small-buffer blocks overlap the counted AllocateGpuMemory; 3 hunks.
  • Texture.cpp: 1 large hunk.

Please rebase on main and re-run agc_driver_host_import_windows and the other agc_* tests on the rebased tree. The out-of-memory retries are gone in the current head (it throws, as #182 asks), which is what Dean asked for, and the reports on Linux (RADV) and Windows in this thread back the budget and windows. After the rebase it only needs a clean merge to go through.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5483158639 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#pullrequestreview-5483158639). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T11:39:30Z. **Review:** DISMISSED --- This conflicts with current `main` in three files, and the conflicts are not mechanical: - `GuestBufferMemory.cpp`: #1961 (GPU-mapped memory imports) overlaps the import path this PR reworks (windows, `retireImport`, eviction); 9 conflicting hunks. - `Resources.cpp`: #2233 and the shared small-buffer blocks overlap the counted `AllocateGpuMemory`; 3 hunks. - `Texture.cpp`: 1 large hunk. Please rebase on `main` and re-run `agc_driver_host_import_windows` and the other `agc_*` tests on the rebased tree. The out-of-memory retries are gone in the current head (it throws, as #182 asks), which is what Dean asked for, and the reports on Linux (RADV) and Windows in this thread back the budget and windows. After the rebase it only needs a clean merge to go through.
MichonGoddijn231849 commented 2026-10-11 12:14:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T12:14:58Z.


@adriadam10 thanks, tonight once main is quiet: rebased on main with #1961's GPU-mapped imports and #2233's shared small-buffer blocks merged into the windows/eviction path, then agc_driver_host_import_windows and the rest of the agc_* tests rerun on the rebased tree.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108911707 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6108911707). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-11T12:14:58Z. --- @adriadam10 thanks, tonight once main is quiet: rebased on `main` with #1961's GPU-mapped imports and #2233's shared small-buffer blocks merged into the windows/eviction path, then `agc_driver_host_import_windows` and the rest of the `agc_*` tests rerun on the rebased tree.
MichonGoddijn231849 commented 2026-10-11 14:07:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T14:07:52Z.


@adriadam10 rebased on main a11c8f7f7 (6dff2c5f8). The GuestBufferMemory.cpp merge keeps main's import runs (#1961, #3425) and puts this PR on top of them:

  • A run that is a single registered range larger than APS5_HOST_IMPORT_WINDOW_MIB (64 MiB by default) is imported in the windows the access touches. Main's window joins small adjacent ranges into runs; this window splits a big range, so the two compose. A window of an unchanged range counts as the same import when the registry is reconciled.
  • Callers that don't pass the accessed range (address-based builds, imports at map time) keep main's whole-run imports.
  • An import that the build being prepared may hold is never retired by an overlapping one, and the least recently used imports are evicted under the budget before main's refusal applies.
  • Resources.cpp keeps main's class allocation and exact-size buffer binding next to the counted AllocateGpuMemory. Main's new depth-copy texture now allocates through it too, so live counts stay balanced.

On the rebased tree (Windows, RTX 5080): agc_driver_host_import_windows and agc_driver_host_import_at_map pass, and 374/375 agc_* tests pass. The one failure is agc_driver_emulated_color_compare, where the recompiler refuses an sRGB format this device cannot sample ("samples or gathers an sRGB image the device cannot sample"). This PR doesn't touch the recompiler or that test.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109871434 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6109871434). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-11T14:07:52Z. --- @adriadam10 rebased on `main` a11c8f7f7 (6dff2c5f8). The `GuestBufferMemory.cpp` merge keeps main's import runs (#1961, #3425) and puts this PR on top of them: - A run that is a single registered range larger than `APS5_HOST_IMPORT_WINDOW_MIB` (64 MiB by default) is imported in the windows the access touches. Main's window joins small adjacent ranges into runs; this window splits a big range, so the two compose. A window of an unchanged range counts as the same import when the registry is reconciled. - Callers that don't pass the accessed range (address-based builds, imports at map time) keep main's whole-run imports. - An import that the build being prepared may hold is never retired by an overlapping one, and the least recently used imports are evicted under the budget before main's refusal applies. - `Resources.cpp` keeps main's class allocation and exact-size buffer binding next to the counted `AllocateGpuMemory`. Main's new depth-copy texture now allocates through it too, so live counts stay balanced. On the rebased tree (Windows, RTX 5080): `agc_driver_host_import_windows` and `agc_driver_host_import_at_map` pass, and 374/375 `agc_*` tests pass. The one failure is `agc_driver_emulated_color_compare`, where the recompiler refuses an sRGB format this device cannot sample ("samples or gathers an sRGB image the device cannot sample"). This PR doesn't touch the recompiler or that test.
MichonGoddijn231849 commented 2026-10-11 14:12:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T14:12:35Z.


Correction to my comment above: 6dff2c5f8 was missing three fixes from the merge (a closing brace in Resources.cpp, a name clash with main's importWindow variable, and main's exact-start leasedRangeOwner overload), so it did not build. The current head f7a2b5e1d has them, and passes the conventions check (I dropped the merge's explanatory comments).

On f7a2b5e1d itself: agc_driver_host_import_windows passes. 373/375 agc_* tests pass with ctest -j 4. One failure is agc_driver_emulated_color_compare, the sRGB refusal I mentioned above. The other, agc_driver_prepared_shaders_deferred, crashed once with heap corruption (0xc0000374) under the parallel run, then passed 10 of 10 runs on its own.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109912648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6109912648). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-11T14:12:35Z. --- Correction to my comment above: `6dff2c5f8` was missing three fixes from the merge (a closing brace in `Resources.cpp`, a name clash with main's `importWindow` variable, and main's exact-start `leasedRangeOwner` overload), so it did not build. The current head `f7a2b5e1d` has them, and passes the conventions check (I dropped the merge's explanatory comments). On `f7a2b5e1d` itself: `agc_driver_host_import_windows` passes. 373/375 `agc_*` tests pass with `ctest -j 4`. One failure is `agc_driver_emulated_color_compare`, the sRGB refusal I mentioned above. The other, `agc_driver_prepared_shaders_deferred`, crashed once with heap corruption (0xc0000374) under the parallel run, then passed 10 of 10 runs on its own.
ponhei9502 commented 2026-10-11 20:43:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ponhei9502 on 2026-10-11T20:43:19Z.


Test report from a Linux setup with Demon's Souls (PPSA01341 v1.07), head f7a2b5e1. Caveat first: this is from a mixed tree (main a11c8f7f + this PR + local work: #757, #425 and others), not from main + this PR alone, so please treat the failure below as a lead until someone reproduces it on a clean tree. Host: CachyOS, kernel 7.3-rc, Ryzen 5 7600, RTX 3080 10 GB (driver 615.78), 32 GB RAM, title rendering 1920x1080.

1. With the default 64 MiB windows the title dies in the first minute

[videoout] presentation failed: compute shader 0x8489e0900: AGC graphics: guest buffer view 0x85db7fd00+0x80 rounded up to its view range exceeds its GPU owner 0x800300000-0x860090000 (buffer 0, direct 1, mirror 0)

The owner region spans about 1.5 GiB and has a direct import, and the view lies inside the region. The check that throws compares the view against region.direct->base + region.direct->bytes. My reading (not verified with a debugger): the region's direct import is one window from windowRun, chosen for an earlier use, and a later view elsewhere in the same region is checked against that window's end instead of the region's. One run, reproducible on every start here.

2. With APS5_HOST_IMPORT_WINDOW_MIB=0 it runs, and it is a large gain

Same build, windows off, budget left at the default (15.5 GiB on this machine), retail route from launch through logos and intro to the title, 6-minute runs, title frames counted as GetOutputStatus calls per minute (minutes 2-5):

frames per minute median
without this PR (3 runs) about 200-900 3.6-15.2 fps
with this PR, windows off (2 runs) 1092 / 1521 / 2132 / 1728 and 1149 / 1464 / 2073 / 1692 25.4 and 24.4 fps

Before, the log showed the 6144 MiB budget full within minutes and hundreds to thousands of refused imports per run. Memory charged to the process peaked at 15.2 GB and 22.2 GB in the two runs (26 GB cap, no swap), with no stall.

Not tested: a clean main + this PR, any other title, Windows, and long sessions.

AI-assisted: yes (runs and log reading by Claude Code on the machine above).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113543549 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6113543549). Originally posted by [ponhei9502](https://github.com/ponhei9502) on 2026-10-11T20:43:19Z. --- Test report from a Linux setup with Demon's Souls (PPSA01341 v1.07), head f7a2b5e1. Caveat first: this is from a mixed tree (`main` a11c8f7f + this PR + local work: #757, #425 and others), not from `main` + this PR alone, so please treat the failure below as a lead until someone reproduces it on a clean tree. Host: CachyOS, kernel 7.3-rc, Ryzen 5 7600, RTX 3080 10 GB (driver 615.78), 32 GB RAM, title rendering 1920x1080. **1. With the default 64 MiB windows the title dies in the first minute** ``` [videoout] presentation failed: compute shader 0x8489e0900: AGC graphics: guest buffer view 0x85db7fd00+0x80 rounded up to its view range exceeds its GPU owner 0x800300000-0x860090000 (buffer 0, direct 1, mirror 0) ``` The owner region spans about 1.5 GiB and has a direct import, and the view lies inside the region. The check that throws compares the view against `region.direct->base + region.direct->bytes`. My reading (not verified with a debugger): the region's direct import is one window from `windowRun`, chosen for an earlier use, and a later view elsewhere in the same region is checked against that window's end instead of the region's. One run, reproducible on every start here. **2. With `APS5_HOST_IMPORT_WINDOW_MIB=0` it runs, and it is a large gain** Same build, windows off, budget left at the default (15.5 GiB on this machine), retail route from launch through logos and intro to the title, 6-minute runs, title frames counted as `GetOutputStatus` calls per minute (minutes 2-5): | | frames per minute | median | |---|---|---| | without this PR (3 runs) | about 200-900 | 3.6-15.2 fps | | with this PR, windows off (2 runs) | 1092 / 1521 / 2132 / 1728 and 1149 / 1464 / 2073 / 1692 | 25.4 and 24.4 fps | Before, the log showed the 6144 MiB budget full within minutes and hundreds to thousands of refused imports per run. Memory charged to the process peaked at 15.2 GB and 22.2 GB in the two runs (26 GB cap, no swap), with no stall. Not tested: a clean `main` + this PR, any other title, Windows, and long sessions. AI-assisted: yes (runs and log reading by Claude Code on the machine above).
adriadam10 commented 2026-10-11 21:22:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:22:42Z.

Review: DISMISSED


Rebased head f7a2b5e1d builds and passes here: libSceAgcDriver scope 387/387 on RADV, including agc_driver_host_import_windows (it fails to compile without the change). The out-of-memory retries are gone as asked.

One blocker, from @ponhei9502's Demon's Souls report above (default 64 MiB windows, dies in the first minute with guest buffer view ... rounded up to its view range exceeds its GPU owner ... direct 1; fine with APS5_HOST_IMPORT_WINDOW_MIB=0). Reading the code, a likely cause:

  • AcquireRegistered imports a whole registered range with importAllocation(context, state, range->address, lease, 0, false) (GuestBufferMemory.cpp:2284).
  • With end == 0 the early lookup is findImport(state, address, address + 1) (:697), so any existing window that contains the first byte is returned, although the region is the whole range (region.end = range end).
  • region.direct is then shorter than the region, and Descriptor limits the view to direct->base + direct->bytes (:3431), which throws for a view later in the range.

Fix direction: when no end is given, the early hit has to cover the whole run (or the whole-range request must not be served by a window), and the retire/replace logic below it then handles the window already there.

Please also add a test that covers it: a registered range larger than the window, a window made by an earlier access, then AcquireRegistered (address-based) and a Descriptor view in the last window. HostImportWindows.cpp only exercises FillBuffer. Nothing in ctest reaches relieveMemory/RelieveGpuMemory either; a test that forces the failure path would pin it.

Smaller points:

  • Driver::relieveMemory decides by parsing "Vulkan result -" out of what() (PacketExecution.cpp:36-40); a typed exception or a flag set by AllocateGpuMemory would not break if the message changes.
  • protectedUses = 256 (GuestBufferMemory.cpp:629) and the 1 s relief interval are unmeasured choices; add them under "Unknown function info"/choices in TechnicalDebt, with the numbers if you have them.
  • docs/dev/ARCHITECTURE.md has no word on host imports; a short paragraph (windows, LRU eviction, relief) under the memory/import diagram would keep it true.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5485014719 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#pullrequestreview-5485014719). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:22:42Z. **Review:** DISMISSED --- Rebased head `f7a2b5e1d` builds and passes here: libSceAgcDriver scope 387/387 on RADV, including `agc_driver_host_import_windows` (it fails to compile without the change). The out-of-memory retries are gone as asked. One blocker, from @ponhei9502's Demon's Souls report above (default 64 MiB windows, dies in the first minute with `guest buffer view ... rounded up to its view range exceeds its GPU owner ... direct 1`; fine with `APS5_HOST_IMPORT_WINDOW_MIB=0`). Reading the code, a likely cause: - `AcquireRegistered` imports a whole registered range with `importAllocation(context, state, range->address, lease, 0, false)` (`GuestBufferMemory.cpp:2284`). - With `end == 0` the early lookup is `findImport(state, address, address + 1)` (`:697`), so any existing window that contains the first byte is returned, although the region is the whole range (`region.end` = range end). - `region.direct` is then shorter than the region, and `Descriptor` limits the view to `direct->base + direct->bytes` (`:3431`), which throws for a view later in the range. Fix direction: when no end is given, the early hit has to cover the whole run (or the whole-range request must not be served by a window), and the retire/replace logic below it then handles the window already there. Please also add a test that covers it: a registered range larger than the window, a window made by an earlier access, then `AcquireRegistered` (address-based) and a `Descriptor` view in the last window. `HostImportWindows.cpp` only exercises `FillBuffer`. Nothing in ctest reaches `relieveMemory`/`RelieveGpuMemory` either; a test that forces the failure path would pin it. Smaller points: - `Driver::relieveMemory` decides by parsing `"Vulkan result -"` out of `what()` (`PacketExecution.cpp:36-40`); a typed exception or a flag set by `AllocateGpuMemory` would not break if the message changes. - `protectedUses = 256` (`GuestBufferMemory.cpp:629`) and the 1 s relief interval are unmeasured choices; add them under "Unknown function info"/choices in TechnicalDebt, with the numbers if you have them. - `docs/dev/ARCHITECTURE.md` has no word on host imports; a short paragraph (windows, LRU eviction, relief) under the memory/import diagram would keep it true.
MichonGoddijn231849 commented 2026-10-11 22:10:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T22:10:05Z.


@adriadam10 @ponhei9502 thanks, the reading was right. Rebased on current main (acc5d2949), head 32a35a00f.

The blocker: importAllocation without an end (the whole-range import of AcquireRegistered) now takes an early hit only from an import of the whole run. A window over the first byte no longer serves it; the retire logic below replaces that window. Requests with an end (the windowed path) keep the one-lookup fast path.

Tests, both in agc_driver_graphics (BdaResources.cpp):

  • importWholeRangeOverWindowTests: a 128 MiB registered range, its first 64 MiB window imported by an access, then AcquireRegistered and a Descriptor view in the last window. It must bind in an import of the whole range. Without the fix it fails with the reported message (guest buffer view ... rounded up to its view range exceeds its GPU owner ... direct 1).
  • importReliefTests: RelieveGpuMemory retires an import unused for 300 lookups and keeps one used in the last 256. It fails if the protection window does not match.

Smaller points:

  • relieveMemory no longer parses what(). AllocateGpuMemory already counts every out-of-memory result on its thread (OutOfMemoryFailures), and that count is now the only check.
  • TechnicalDebt has a "Host import windows and budget" line. It records the 64 MiB window, the whole-range import of address-based builds, the budget default and the relief, and marks the 64 MiB window, the 256-lookup protection, the quarter retired and the 1 s interval as unmeasured choices.
  • ARCHITECTURE has a short bullet on host imports, windows, the budget and the relief.

Rebase note: main's BufferPool::AllocateMemory (trim and retry once when out of memory) now owns the buffer allocations this PR counted. It now allocates through AllocateGpuMemory, so pooled buffers and slab blocks are counted as GPU memory and out-of-memory results are counted for the relief. Slab blocks count down when freed. main's retry is unchanged.

Run here (Windows, RTX 5080): agc_driver_graphics, agc_driver_host_import_windows, agc_host_import_unmap, agc_driver_host_import_at_map, agc_driver_host_import_teardown, agc_buffer_pool and agc_driver_pooled_buffer_range pass; check_conventions.py passes. Current main doesn't build libkernel on Windows (HostPoll in Socket.cpp), so I applied #4021 locally for the run, not on this branch.

@ponhei9502 if you can, a Demon's Souls run with the default 64 MiB windows on this head would confirm it on the title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114404835 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6114404835). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-11T22:10:05Z. --- @adriadam10 @ponhei9502 thanks, the reading was right. Rebased on current `main` (`acc5d2949`), head `32a35a00f`. **The blocker:** `importAllocation` without an end (the whole-range import of `AcquireRegistered`) now takes an early hit only from an import of the whole run. A window over the first byte no longer serves it; the retire logic below replaces that window. Requests with an end (the windowed path) keep the one-lookup fast path. **Tests,** both in `agc_driver_graphics` (`BdaResources.cpp`): - `importWholeRangeOverWindowTests`: a 128 MiB registered range, its first 64 MiB window imported by an access, then `AcquireRegistered` and a `Descriptor` view in the last window. It must bind in an import of the whole range. Without the fix it fails with the reported message (`guest buffer view ... rounded up to its view range exceeds its GPU owner ... direct 1`). - `importReliefTests`: `RelieveGpuMemory` retires an import unused for 300 lookups and keeps one used in the last 256. It fails if the protection window does not match. **Smaller points:** - `relieveMemory` no longer parses `what()`. `AllocateGpuMemory` already counts every out-of-memory result on its thread (`OutOfMemoryFailures`), and that count is now the only check. - TechnicalDebt has a "Host import windows and budget" line. It records the 64 MiB window, the whole-range import of address-based builds, the budget default and the relief, and marks the 64 MiB window, the 256-lookup protection, the quarter retired and the 1 s interval as unmeasured choices. - ARCHITECTURE has a short bullet on host imports, windows, the budget and the relief. **Rebase note:** `main`'s `BufferPool::AllocateMemory` (trim and retry once when out of memory) now owns the buffer allocations this PR counted. It now allocates through `AllocateGpuMemory`, so pooled buffers and slab blocks are counted as GPU memory and out-of-memory results are counted for the relief. Slab blocks count down when freed. `main`'s retry is unchanged. Run here (Windows, RTX 5080): `agc_driver_graphics`, `agc_driver_host_import_windows`, `agc_host_import_unmap`, `agc_driver_host_import_at_map`, `agc_driver_host_import_teardown`, `agc_buffer_pool` and `agc_driver_pooled_buffer_range` pass; `check_conventions.py` passes. Current `main` doesn't build `libkernel` on Windows (`HostPoll` in `Socket.cpp`), so I applied #4021 locally for the run, not on this branch. @ponhei9502 if you can, a Demon's Souls run with the default 64 MiB windows on this head would confirm it on the title.
oneandonlydean commented 2026-10-12 05:25:18 +00:00 (Migrated from github.com)

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


The whole-range path is fixed by reading and the points of the last review are in. A few things before this can go in:

  • GuestBufferMemory.cpp:2094: the map observer reaches importAllocation with evict = true and without the GPU lock (Lifecycle.cpp:68). Past the budget it retires imports there: RetireShadow drops their shadowed units (UnitShadow.cpp:773-779) and recorder->Keep runs unlocked. Pass 0, false, as AcquireRegistered does at :2294.
  • GuestBufferMemory.cpp:713-727 run before the refusals at :729-744. An address-based build whose whole-range import is refused (budget, or failed) still retires the range's windows, at every build: with APS5_HOST_IMPORT_MIB=100, a 128 MiB range and one window, 3 builds retired the window 3 times and the next access imported it again each time. Decide the refusal first and retire nothing when it refuses.
  • windowRun (:676-693): a use that crosses a cell edge replaces the windows it overlaps. Two uses across neighbouring edges of one range retire each other's window at every use (10 rounds of both: 20 imports of 128 MiB), and the second is copied when both are in one build (:715-721). Grow to the union of the overlapped windows instead.
  • relieveMemory (PacketExecution.cpp:35-57) runs before a rethrow that fails the driver (QueueWorker.cpp:166-169, Lifecycle.cpp:96), and VideoOut then terminates (VideoOutDriver.cpp:622). Which packet runs after it on main? If none, please drop it with RelieveGpuMemory, the limit, BufferPool::Trim, WaitForReleases, importReliefTests and the GPU memory counters. The counters also miss every retirement (retireImport, :216-226, never uncounts): with one 128 MiB import live they read 2816 MiB after 21 retirements.
  • APS5_HOST_IMPORT_WINDOW_MIB: #3425 removed a variable of this name. Please make the 64 MiB a constant with a setter for the tests, like SetHostImportWindow. APS5_TRACE_GPU_MEMORY goes with the counters.
  • :794-800: the create lambda is called once; inline it. It is also the only conflict with #2434 and one of the two with #3874.
  • The description says a refused import is never offered again; the budget refusal at :733-744 is tried at every lookup, as on main.

A test for each of the first three would fail on this head: an import at map time over the budget, an address-based build over the budget after a window, and two uses across neighbouring cell edges.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6118298014 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6118298014). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T05:25:18Z. --- The whole-range path is fixed by reading and the points of the last review are in. A few things before this can go in: - `GuestBufferMemory.cpp:2094`: the map observer reaches `importAllocation` with `evict = true` and without the GPU lock (`Lifecycle.cpp:68`). Past the budget it retires imports there: `RetireShadow` drops their shadowed units (`UnitShadow.cpp:773-779`) and `recorder->Keep` runs unlocked. Pass `0, false`, as `AcquireRegistered` does at `:2294`. - `GuestBufferMemory.cpp:713-727` run before the refusals at `:729-744`. An address-based build whose whole-range import is refused (budget, or `failed`) still retires the range's windows, at every build: with `APS5_HOST_IMPORT_MIB=100`, a 128 MiB range and one window, 3 builds retired the window 3 times and the next access imported it again each time. Decide the refusal first and retire nothing when it refuses. - `windowRun` (`:676-693`): a use that crosses a cell edge replaces the windows it overlaps. Two uses across neighbouring edges of one range retire each other's window at every use (10 rounds of both: 20 imports of 128 MiB), and the second is copied when both are in one build (`:715-721`). Grow to the union of the overlapped windows instead. - `relieveMemory` (`PacketExecution.cpp:35-57`) runs before a rethrow that fails the driver (`QueueWorker.cpp:166-169`, `Lifecycle.cpp:96`), and VideoOut then terminates (`VideoOutDriver.cpp:622`). Which packet runs after it on `main`? If none, please drop it with `RelieveGpuMemory`, the limit, `BufferPool::Trim`, `WaitForReleases`, `importReliefTests` and the GPU memory counters. The counters also miss every retirement (`retireImport`, `:216-226`, never uncounts): with one 128 MiB import live they read 2816 MiB after 21 retirements. - `APS5_HOST_IMPORT_WINDOW_MIB`: #3425 removed a variable of this name. Please make the 64 MiB a constant with a setter for the tests, like `SetHostImportWindow`. `APS5_TRACE_GPU_MEMORY` goes with the counters. - `:794-800`: the `create` lambda is called once; inline it. It is also the only conflict with #2434 and one of the two with #3874. - The description says a refused import is never offered again; the budget refusal at `:733-744` is tried at every lookup, as on `main`. A test for each of the first three would fail on this head: an import at map time over the budget, an address-based build over the budget after a window, and two uses across neighbouring cell edges.
Scramblrrrr commented 2026-10-12 10:09:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T10:09:55Z.


Preparing a Windows/RTX 5070 Ti 007 cross-test of #290 current head 32a35a00f, preserving your three commits/authorship: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-host-window-cross-test head 4e4083057. This is source-only, not built or staged yet; an unrelated quiet FPS test is still running.

Base is our older public-perf/cache-preserving sparse stack plus AlxcBTW's #4385 port a5c0c9a36. One include conflict and an architecture-text conflict resolved; omitted unrelated newer MSAA documentation not represented by this older stack. Tiny local integration commit adapts import accounting to #4385's extracted-node holder and our old immediate device-change path. No new upstream PR or duplicate implementation.

For the first game comparison I will explicitly keep APS5_HOST_IMPORT_MIB=6144 (our current budget), rather than raising it to the new physical-RAM default: the 32 GB host already hits the free-physical-RAM guard during campaign loading while GPU dedicated memory is only ~8 GB/16 GB. Native window/retirement and existing sparse/copy checks come first. No game improvement claim yet. AI-assisted: Codex. No title data uploaded.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6122140575 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6122140575). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T10:09:55Z. --- Preparing a Windows/RTX 5070 Ti 007 cross-test of #290 current head 32a35a00f, preserving your three commits/authorship: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-host-window-cross-test head 4e4083057. This is source-only, not built or staged yet; an unrelated quiet FPS test is still running. Base is our older public-perf/cache-preserving sparse stack plus AlxcBTW's #4385 port a5c0c9a36. One include conflict and an architecture-text conflict resolved; omitted unrelated newer MSAA documentation not represented by this older stack. Tiny local integration commit adapts import accounting to #4385's extracted-node holder and our old immediate device-change path. No new upstream PR or duplicate implementation. For the first game comparison I will explicitly keep APS5_HOST_IMPORT_MIB=6144 (our current budget), rather than raising it to the new physical-RAM default: the 32 GB host already hits the free-physical-RAM guard during campaign loading while GPU dedicated memory is only ~8 GB/16 GB. Native window/retirement and existing sparse/copy checks come first. No game improvement claim yet. AI-assisted: Codex. No title data uploaded.
Scramblrrrr commented 2026-10-12 10:17:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T10:17:23Z.


Host-window cross-test 4e4083057 is built/staged on Windows/RTX 5070 Ti: graphics SHA256 605581D6247E0DC376D7BB0364ECD1F2A24454E26E056093A9D856DCA74B949D. Native six-test set passed 6.86 s, no skips: host_import_windows, host_import_retire, graphics (includes split-heap written/copied-read/owner replacement/growth/gap and #3248 overlap cases), bda_device, draw_cache_reuse ON/OFF. Source-only preparation/port details in prior comment remain applicable; not full current-main/full suite.

Quiet 007 run now started with APS5_HOST_IMPORT_MIB=6144 explicitly and APS5_TRACE_GPU_MEMORY=1 (one category report per 10 seconds, not broad profiling), same other modules/cache/bounds. This branch is a5c0c9a36 + #290, and does NOT carry the separate #4410 delay experiment. Next will record rendered FPS and campaign memory/stop; no improvement claim yet. AI-assisted: Codex. No title data uploaded.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6122252216 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6122252216). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T10:17:23Z. --- Host-window cross-test 4e4083057 is built/staged on Windows/RTX 5070 Ti: graphics SHA256 605581D6247E0DC376D7BB0364ECD1F2A24454E26E056093A9D856DCA74B949D. Native six-test set passed 6.86 s, no skips: host_import_windows, host_import_retire, graphics (includes split-heap written/copied-read/owner replacement/growth/gap and #3248 overlap cases), bda_device, draw_cache_reuse ON/OFF. Source-only preparation/port details in prior comment remain applicable; not full current-main/full suite. Quiet 007 run now started with APS5_HOST_IMPORT_MIB=6144 explicitly and APS5_TRACE_GPU_MEMORY=1 (one category report per 10 seconds, not broad profiling), same other modules/cache/bounds. This branch is a5c0c9a36 + #290, and does NOT carry the separate #4410 delay experiment. Next will record rendered FPS and campaign memory/stop; no improvement claim yet. AI-assisted: Codex. No title data uploaded.
Scramblrrrr commented 2026-10-12 10:24:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T10:24:08Z.


Host-window stack 4e4083057 / SHA605581D6 reached fully rendered title frame858 ~1.61 FPS, ~20.08 decimal GB private, one bounded trim. Prior cc495 control title ~1.57; #4410 experiment ~1.61. One sample each/different camera/timing, so no demonstrated meaningful speed or resident-memory gain from #290 yet.

New coarse category trace at this stage is roughly: host imports 5575 MiB (~579 imports), host buffers 0.6 GiB, sampled textures and storage images each ~2 GiB, depth surfaces levelled near624 MiB/130 allocations, shadow slabs ~404 MiB. GPU dedicated use is ~7.7–8.1 GB of16.3 GB. Depth retention is unbounded in this older source, but the observed startup levelled off; I am not calling it this campaign's leak/cause. Moving through offline menu; will inspect available game graphics settings, record changes if any, and check campaign loading. Lazy snapshot #3991 is prepared separately a33e1e5fc, not built/staged. AI-assisted: Codex. No title data uploaded.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6122355347 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6122355347). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T10:24:08Z. --- Host-window stack 4e4083057 / SHA605581D6 reached fully rendered title frame858 ~1.61 FPS, ~20.08 decimal GB private, one bounded trim. Prior cc495 control title ~1.57; #4410 experiment ~1.61. One sample each/different camera/timing, so no demonstrated meaningful speed or resident-memory gain from #290 yet. New coarse category trace at this stage is roughly: host imports 5575 MiB (~579 imports), host buffers 0.6 GiB, sampled textures and storage images each ~2 GiB, depth surfaces levelled near624 MiB/130 allocations, shadow slabs ~404 MiB. GPU dedicated use is ~7.7–8.1 GB of16.3 GB. Depth retention is unbounded in this older source, but the observed startup levelled off; I am not calling it this campaign's leak/cause. Moving through offline menu; will inspect available game graphics settings, record changes if any, and check campaign loading. Lazy snapshot #3991 is prepared separately a33e1e5fc, not built/staged. AI-assisted: Codex. No title data uploaded.
Scramblrrrr commented 2026-10-12 11:12:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T11:12:33Z.


007 Windows cross-test on older #290 port efcd89969 hit a terminal buffer OOM: allocation2359296000, memoryType3, reclaimed627897488, initialResult=-2, attempts2. GPU sample~7585MiB of16303MiB. A read-only physical-device query confirms type3 is host-visible/coherent/cached on system heap1, while type4 is host-visible/coherent/device-local on heap0. maxMemoryAllocationSize is UINT64_MAX. Thus VRAM-use alone does not diagnose the failing heap.
I found #2809 and #4108; this is a different direction from #4108's texture fallback. Preparing a source-only buffer fallback on https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-buffer-allocation-fallback . After existing trim/retry, ordinary coherent host buffers may try ONE allowed memory type on a different heap, preserving pNext/device-address flags and required properties. No same-heap retry, no fallback on device loss, no explicit cached-property relaxation, no slab/device-buffer change. Mock tests prepared for success, exhausted fallback, incompatible types/coherence, same heap, device loss, flags/mapping and cleanup. NOT built/tested/staged yet; ongoing game remains isolated IR probe7a91759e4. No competing upstream PR. Will offer the tested commit after the quiet run, if it passes. AI-assisted: Codex. No title data uploaded.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6123114006 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6123114006). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T11:12:33Z. --- 007 Windows cross-test on older #290 port efcd89969 hit a terminal buffer OOM: allocation2359296000, memoryType3, reclaimed627897488, initialResult=-2, attempts2. GPU sample~7585MiB of16303MiB. A read-only physical-device query confirms type3 is host-visible/coherent/cached on system heap1, while type4 is host-visible/coherent/device-local on heap0. maxMemoryAllocationSize is UINT64_MAX. Thus VRAM-use alone does not diagnose the failing heap. I found #2809 and #4108; this is a different direction from #4108's texture fallback. Preparing a source-only buffer fallback on https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-buffer-allocation-fallback . After existing trim/retry, ordinary coherent host buffers may try ONE allowed memory type on a different heap, preserving pNext/device-address flags and required properties. No same-heap retry, no fallback on device loss, no explicit cached-property relaxation, no slab/device-buffer change. Mock tests prepared for success, exhausted fallback, incompatible types/coherence, same heap, device loss, flags/mapping and cleanup. NOT built/tested/staged yet; ongoing game remains isolated IR probe7a91759e4. No competing upstream PR. Will offer the tested commit after the quiet run, if it passes. AI-assisted: Codex. No title data uploaded.
Scramblrrrr commented 2026-10-12 11:22:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T11:22:30Z.


IR probe7a91759e4/SHA70E13C rendered title at frame872 1.68FPS/private19.26 decimalGB (later verified frame8921.76). Cold cache due recompiler source fingerprint: no valid warm-start speed comparison. Campaign Resume proceeded to2896 misses/2895 writes, then terminated with AGC driver: registered program refers to an incompatible shader binary type. Final private21.91GB, WS0.26GB/free5.44GB after four bounded trims. GPU sample8014MiB/16303MiB. Runtime table unsupported faults still occur at pc0x54 and0x80. Earlier 2.36GB allocation failure did not recur before this different stop; that is not proof it is fixed. No visible gameplay; black loading screen. Exact rejected/expected types missing from this diagnostic, so added a rejection-only message in fork codex/first-light-shader-kind-diagnostic f8956bece (no admission change).
Also carries source buffer fallback f06d93ce2: after trim/retry, ordinary coherent host buffers may try one compatible different heap, preserving required properties and device-address flags. Six native tests pass11.61s/no skips: buffer_pool, driver, graphics, sampled_cache_budget, draw_cache_reuse ON/OFF. Disabling the constructor fallback makes the new regression checks fail (CTest exit8); restored implementation passes. WIP tested on older integration, not current-main/full-suite. Staging f8956bece/SHA61BF39CB795089AD8D94DA1BD8D31C06E01ABA468F521426763ECF903A054027 for next guarded run. Coordination offered on #290; no duplicate upstream PR. AI-assisted: Codex. No title data uploaded.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6123261799 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6123261799). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T11:22:30Z. --- IR probe7a91759e4/SHA70E13C rendered title at frame872 ~1.68FPS/private19.26 decimalGB (later verified frame892~1.76). Cold cache due recompiler source fingerprint: no valid warm-start speed comparison. Campaign Resume proceeded to2896 misses/2895 writes, then terminated with `AGC driver: registered program refers to an incompatible shader binary type`. Final private21.91GB, WS0.26GB/free5.44GB after four bounded trims. GPU sample8014MiB/16303MiB. Runtime table unsupported faults still occur at pc0x54 and0x80. Earlier 2.36GB allocation failure did not recur before this different stop; that is not proof it is fixed. No visible gameplay; black loading screen. Exact rejected/expected types missing from this diagnostic, so added a rejection-only message in fork codex/first-light-shader-kind-diagnostic f8956bece (no admission change). Also carries source buffer fallback f06d93ce2: after trim/retry, ordinary coherent host buffers may try one compatible different heap, preserving required properties and device-address flags. Six native tests pass11.61s/no skips: buffer_pool, driver, graphics, sampled_cache_budget, draw_cache_reuse ON/OFF. Disabling the constructor fallback makes the new regression checks fail (CTest exit8); restored implementation passes. WIP tested on older integration, not current-main/full-suite. Staging f8956bece/SHA61BF39CB795089AD8D94DA1BD8D31C06E01ABA468F521426763ECF903A054027 for next guarded run. Coordination offered on #290; no duplicate upstream PR. AI-assisted: Codex. No title data uploaded.
Scramblrrrr commented 2026-10-12 11:52:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T11:52:07Z.


Latest warm-cache combined run (artifact f8956bece, SHA61BF39CB; diagnostic branch is now027090d37 after subject-only correction, source code identical) exited during campaign loading without a normal fatal log. Windows Application Error/WER confirms native heap corruption0xc0000374 at08:32:29 local, PID15216, ntdll detection point. Final private19.47 decimalGB/WS10.30/free5.09; GPU7993MiB/16303; only one bounded trim. Cache2625 hits/0 misses/0 writes. No logged fallback recovery or deferred-table failure before this earlier exit, so no evidence that the new fallback was exercised or caused it. Earlier cold IR run ended later with the registered-type rejection. Keeping dump local; investigating actual stack/objects, not blaming ntdll or claiming a cache bug from this alone.
Standalone buffer fallback on current main is now PR #4446, head55e666483/base3d8ffeb27. Four native tests pass5.29s/no skips; constructor fallback disabled gives failing regressions (CTest exit8), restored passes. Conventions including PR template pass. This is independently buildable and carries no 007 stack. No game/FPS fix claim. Offered integration to #290 author earlier. AI-assisted: Codex. No title data uploaded.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6123707445 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6123707445). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T11:52:07Z. --- Latest warm-cache combined run (artifact f8956bece, SHA61BF39CB; diagnostic branch is now027090d37 after subject-only correction, source code identical) exited during campaign loading without a normal fatal log. Windows Application Error/WER confirms native heap corruption0xc0000374 at08:32:29 local, PID15216, ntdll detection point. Final private19.47 decimalGB/WS10.30/free5.09; GPU7993MiB/16303; only one bounded trim. Cache2625 hits/0 misses/0 writes. No logged fallback recovery or deferred-table failure before this earlier exit, so no evidence that the new fallback was exercised or caused it. Earlier cold IR run ended later with the registered-type rejection. Keeping dump local; investigating actual stack/objects, not blaming ntdll or claiming a cache bug from this alone. Standalone buffer fallback on current main is now PR #4446, head55e666483/base3d8ffeb27. Four native tests pass5.29s/no skips; constructor fallback disabled gives failing regressions (CTest exit8), restored passes. Conventions including PR template pass. This is independently buildable and carries no 007 stack. No game/FPS fix claim. Offered integration to #290 author earlier. AI-assisted: Codex. No title data uploaded.
reyani-dev commented 2026-10-12 15:14:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-12T15:14:43Z.


A 16 GiB data point for the budget part. ASTRO BOT (PPSA21564, 01.007.000) on Windows 11, RTX 4070 Laptop (8 GiB VRAM, NVIDIA 616.92), 16 GiB RAM, unmodified main 33ae282e (after #4281), WinLibs GCC 15.2.0 r7. The driver reports Memory heap 1 size=7808.4 MiB (host, memory types 0/2/3), i.e. half of RAM.

  • Default APS5_HOST_IMPORT_MIB (6144): after about 150 s of loading, host import budget: 4483 MiB live of 6144 MiB; 2 imports (7808 MiB) refused so far, last 0x1000000000+0xc8000000. The fallback then fails: heap mirror of 0x1000000000+0xc8000000: vkAllocateMemory buffer: allocation=3355443200 memoryType=3 ... initialResult=-2 attempts=2. Earlier it had also refused 0x10c8000000+0x120000000 (4608 MiB).
  • APS5_HOST_IMPORT_MIB=16384: the large imports go through, and then imports themselves start failing in the driver: host import of 0x3018dc000+0x11ca4000 failed at vkAllocateMemory (-2); falling back to copies. Even a 298 MB mirror of that range then fails the same way.

So on this machine neither setting fits. The limit is the host heap of about 7.8 GiB, which imports and type-3 mirrors share. Two things that seem to matter for the windows and eviction here:

  • A RAM-derived budget probably needs to stay under the driver's host-heap size, not just RAM: here it is RAM/2.
  • A refused import that falls back to a whole-range type-3 mirror costs more host-heap space than the import would have. Windowing the mirror too, not just the import, looks like what would let a 16 GiB machine through.

I can rerun Astro Bot against a rebased head of this PR on this laptop when there is one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6127117291 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6127117291). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-12T15:14:43Z. --- A 16 GiB data point for the budget part. ASTRO BOT (PPSA21564, 01.007.000) on Windows 11, RTX 4070 Laptop (8 GiB VRAM, NVIDIA 616.92), 16 GiB RAM, unmodified `main` 33ae282e (after #4281), WinLibs GCC 15.2.0 r7. The driver reports `Memory heap 1 size=7808.4 MiB` (host, memory types 0/2/3), i.e. half of RAM. - **Default `APS5_HOST_IMPORT_MIB` (6144):** after about 150 s of loading, `host import budget: 4483 MiB live of 6144 MiB; 2 imports (7808 MiB) refused so far, last 0x1000000000+0xc8000000`. The fallback then fails: `heap mirror of 0x1000000000+0xc8000000: vkAllocateMemory buffer: allocation=3355443200 memoryType=3 ... initialResult=-2 attempts=2`. Earlier it had also refused `0x10c8000000+0x120000000` (4608 MiB). - **`APS5_HOST_IMPORT_MIB=16384`:** the large imports go through, and then imports themselves start failing in the driver: `host import of 0x3018dc000+0x11ca4000 failed at vkAllocateMemory (-2); falling back to copies`. Even a 298 MB mirror of that range then fails the same way. So on this machine neither setting fits. The limit is the host heap of about 7.8 GiB, which imports and type-3 mirrors share. Two things that seem to matter for the windows and eviction here: - A RAM-derived budget probably needs to stay under the driver's host-heap size, not just RAM: here it is RAM/2. - A refused import that falls back to a whole-range type-3 mirror costs more host-heap space than the import would have. Windowing the mirror too, not just the import, looks like what would let a 16 GiB machine through. I can rerun Astro Bot against a rebased head of this PR on this laptop when there is one.
MichonGoddijn231849 commented 2026-10-12 16:27:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-12T16:27:14Z.


@oneandonlydean thanks, all of it was right. Rebased on main 82b1b2e7a, head 5857f9eb5:

  • Map observer: imports at map time pass no eviction. The new test maps a range with the budget set to the live bytes plus that range minus one. It fails when the observer evicts (one import retired, the mapped range imported) and passes now.
  • Refusal first: importAllocation decides every refusal before it retires anything: alignment, a failed run, a held import, and the budget counting what may be evicted. The test makes 3 address-based builds over the budget after a window; the window stays the same import.
  • Neighbouring edges: windowRun grows the cells a use touches to the union of the range's imports it overlaps. The test does 10 rounds of two uses across neighbouring edges, each in its own build, and both share one import.
  • Relief: you're right that nothing on main runs after it, so it is gone, with RelieveGpuMemory, the limit, the BufferPool::Trim / WaitForReleases additions, the relief test and the GPU memory counters (and APS5_TRACE_GPU_MEMORY with them). The counters' missing uncount on retirement goes with them.
  • The window variable is gone: the window is a 64 MiB constant, with SetHostImportRangeWindow (and SetHostImportBudget) for the tests.
  • The create lambda is inlined.
  • The description now says a refused import is tried again at its next use.

@AchrafReyani thanks for the 16 GiB data point. The default budget is now capped at the largest host heap less 2 GiB (#167's rule), so on your laptop it comes to about 5.8 GiB instead of 8. That leaves room in the shared heap for type-3 mirrors. Windowing the mirrors too is a good idea, but it's a separate change from this PR. A rerun of Astro Bot on this head would show whether the cap is enough there.

@ponhei9502 the default 64 MiB windows should work on this head; a Demon's Souls run with them would confirm it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6128326687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6128326687). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-12T16:27:14Z. --- @oneandonlydean thanks, all of it was right. Rebased on `main` `82b1b2e7a`, head `5857f9eb5`: - **Map observer:** imports at map time pass no eviction. The new test maps a range with the budget set to the live bytes plus that range minus one. It fails when the observer evicts (one import retired, the mapped range imported) and passes now. - **Refusal first:** `importAllocation` decides every refusal before it retires anything: alignment, a failed run, a held import, and the budget counting what may be evicted. The test makes 3 address-based builds over the budget after a window; the window stays the same import. - **Neighbouring edges:** `windowRun` grows the cells a use touches to the union of the range's imports it overlaps. The test does 10 rounds of two uses across neighbouring edges, each in its own build, and both share one import. - **Relief:** you're right that nothing on `main` runs after it, so it is gone, with `RelieveGpuMemory`, the limit, the `BufferPool::Trim` / `WaitForReleases` additions, the relief test and the GPU memory counters (and `APS5_TRACE_GPU_MEMORY` with them). The counters' missing uncount on retirement goes with them. - **The window variable** is gone: the window is a 64 MiB constant, with `SetHostImportRangeWindow` (and `SetHostImportBudget`) for the tests. - The `create` lambda is inlined. - The description now says a refused import is tried again at its next use. @AchrafReyani thanks for the 16 GiB data point. The default budget is now capped at the largest host heap less 2 GiB (#167's rule), so on your laptop it comes to about 5.8 GiB instead of 8. That leaves room in the shared heap for type-3 mirrors. Windowing the mirrors too is a good idea, but it's a separate change from this PR. A rerun of Astro Bot on this head would show whether the cap is enough there. @ponhei9502 the default 64 MiB windows should work on this head; a Demon's Souls run with them would confirm it.
oneandonlydean commented 2026-10-13 03:47:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T03:47:05Z.


Thanks, the three fixes hold here: each new test fails when its fix is reverted, and the relief, the counters, the two variables and the lambda are gone. Still open on 5857f9eb5:

  • Conflicts with main in docs/dev/ARCHITECTURE.md and docs/dev/TechnicalDebt.md. The debt entry now goes in docs/dev/debt/libSceAgcDriver.md. The code merges with #4385 without a conflict, and the merged tree passes the agc_* tests here (460 of 460).
  • Past the budget the imports still don't settle when a frame uses a little more than fits. evictable (GuestBufferMemory.cpp:654-656) protects the last 256 lookups and a frame makes thousands, so windows that are all used in every frame retire each other every frame. A 3D title we test with holds 12.3 GiB of imports; the same tree with and without this PR, level parts in ms per frame over the same frames:
budget tree title, 12-32 s in menu level, first part level, crowd imports made
8192 MiB without 22.7, 22.9 fps 20.5, 20.0 fps 42.6, 42.1 ms 90.0, 91.8 ms 53, 53
8192 MiB 5857f9eb5 13.7, 11.4 fps 21.1, 20.9 fps 43.4, 43.4 ms 127.5, 120.0 ms 2,137, 2,190
5760 MiB 5857f9eb5 21.2 fps 20.1 fps 42.1 ms 92.1 ms 77
default without (6144 MiB) 21.7 fps 19.4 fps 42.4 ms 92.1 ms 63
default 5857f9eb5 (31.3 GiB here) 24.5 fps 22.3 fps 36.8 ms 83.9 ms 64

At 8192 MiB two windows replace each other for the rest of the level (0x101c000000+0x4000000 and 0x10a0000000+0x4000000 in turn, about 20 imports a second, 8188.6 MiB live), and each one moves the import epoch:

[address] 574 address-based builds (10 s) ... space hits 409 / rebuilds: generation 0, epoch 165

Four windows do the same for the first 30 s of the title (1,200 imports). Without the PR the import is refused and the set stays as it is. At 5760 MiB, which is what the new cap gives the 16 GiB laptop above, it settles: 77 imports, 42 refusals, every build from the cached space, same speed as without. An import that is used in every frame shouldn't be evicted for another one; refuse the new import there, as main does.

  • No test evicts anything: with :801 removed, or with evictable returning false, every test passes. One that would also pin the point above: three ranges under a budget for two, the third looked up 300 times between alternating uses of the other two. On this head 10 rounds make 19 imports.
  • Two uses across neighbouring cell edges in one build: the second is refused at :779 because the first one's window is held, and it is copied at every build (10 of 10). The new test puts each use in a build of its own.
  • :703: with a host heap of 2 GiB or less the cap is skipped and the budget is 6 GiB or more.

A 2D title we test with passes on main + this head, also with APS5_HOST_IMPORT_MIB=128.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137774820 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6137774820). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T03:47:05Z. --- Thanks, the three fixes hold here: each new test fails when its fix is reverted, and the relief, the counters, the two variables and the lambda are gone. Still open on 5857f9eb5: - Conflicts with `main` in `docs/dev/ARCHITECTURE.md` and `docs/dev/TechnicalDebt.md`. The debt entry now goes in `docs/dev/debt/libSceAgcDriver.md`. The code merges with #4385 without a conflict, and the merged tree passes the `agc_*` tests here (460 of 460). - Past the budget the imports still don't settle when a frame uses a little more than fits. `evictable` (`GuestBufferMemory.cpp:654-656`) protects the last 256 lookups and a frame makes thousands, so windows that are all used in every frame retire each other every frame. A 3D title we test with holds 12.3 GiB of imports; the same tree with and without this PR, level parts in ms per frame over the same frames: | budget | tree | title, 12-32 s in | menu | level, first part | level, crowd | imports made | |---|---|---|---|---|---|---| | 8192 MiB | without | 22.7, 22.9 fps | 20.5, 20.0 fps | 42.6, 42.1 ms | 90.0, 91.8 ms | 53, 53 | | 8192 MiB | 5857f9eb5 | 13.7, 11.4 fps | 21.1, 20.9 fps | 43.4, 43.4 ms | 127.5, 120.0 ms | 2,137, 2,190 | | 5760 MiB | 5857f9eb5 | 21.2 fps | 20.1 fps | 42.1 ms | 92.1 ms | 77 | | default | without (6144 MiB) | 21.7 fps | 19.4 fps | 42.4 ms | 92.1 ms | 63 | | default | 5857f9eb5 (31.3 GiB here) | 24.5 fps | 22.3 fps | 36.8 ms | 83.9 ms | 64 | At 8192 MiB two windows replace each other for the rest of the level (`0x101c000000+0x4000000` and `0x10a0000000+0x4000000` in turn, about 20 imports a second, 8188.6 MiB live), and each one moves the import epoch: ``` [address] 574 address-based builds (10 s) ... space hits 409 / rebuilds: generation 0, epoch 165 ``` Four windows do the same for the first 30 s of the title (1,200 imports). Without the PR the import is refused and the set stays as it is. At 5760 MiB, which is what the new cap gives the 16 GiB laptop above, it settles: 77 imports, 42 refusals, every build from the cached space, same speed as without. An import that is used in every frame shouldn't be evicted for another one; refuse the new import there, as `main` does. - No test evicts anything: with `:801` removed, or with `evictable` returning false, every test passes. One that would also pin the point above: three ranges under a budget for two, the third looked up 300 times between alternating uses of the other two. On this head 10 rounds make 19 imports. - Two uses across neighbouring cell edges in one build: the second is refused at `:779` because the first one's window is held, and it is copied at every build (10 of 10). The new test puts each use in a build of its own. - `:703`: with a host heap of 2 GiB or less the cap is skipped and the budget is 6 GiB or more. A 2D title we test with passes on `main` + this head, also with `APS5_HOST_IMPORT_MIB=128`.
fdfawef324 commented 2026-10-13 12:04:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T12:04:03Z.


Test note, Windows, Demon's Souls (PPSA01342), the loading screen after the opening cinematic.

Setup. Windows Server 2025, RTX 3060 12 GB (driver 32.0.15.9186), Ryzen 9 5900X, 32 GB, MinGW-w64 GCC 15.2. Base: an integration branch on main fc1f063f5 plus local merges, not clean main. This PR's two commits (5857f9eb5) were cherry-picked onto it. No APS5_HOST_IMPORT_MIB, so the new default applies. Here it is 14286 MiB: half of physical memory is 16335 MiB, and the cap is the 16335 MiB host heap less 2 GiB.

Rebase. Applying the two commits onto current main (c8eb1f52d) conflicts in three files, and one technical-debt entry has to move. The integration branch hit the same, and I resolved them like this:

  • GuestBufferMemory.cpp, struct HostImports: #3874 removed importsStampPages and dmaBufImportsStampPages. Keep them removed and add useCounter and buildFloor.
  • GuestBufferMemory.cpp, ImportMappedRanges: #4017 added if (!GpuMutex().HeldByThisThread() && wouldRetireImport(...)) return false; before the import. Keep that line, then this PR's importAllocation(context, state, range->address, current, 0, false). The map observer then neither replaces nor evicts without the GPU lock.
  • docs/dev/ARCHITECTURE.md: #425 added the depth-plane bullet at the same place. Keep both bullets.
  • docs/dev/TechnicalDebt.md: #4411 moved library entries to docs/dev/debt/. The "Host import windows and budget" entry goes after the "Host imports" entry in docs/dev/debt/libSceAgcDriver.md, with links one level deeper (../../../core/...). Left in TechnicalDebt.md, the entry fails check_conventions.py's debt-file rule.

With those resolutions, check_conventions.py passes. These tests pass:

  • agc_driver_graphics, which includes this PR's four new BdaResources cases;
  • agc_driver_host_import_windows, which ran here (it was not skipped);
  • agc_driver_host_import_at_map, agc_driver_host_import_teardown, agc_host_import_unmap, agc_parked_import_unmap, agc_host_import_retirement, agc_host_import_retire, agc_unit_shadow;
  • agc_driver_bda_device, agc_buffer_pool, agc_driver_pooled_buffer_range;
  • agc_driver_sampled_cache_budget (also _memory), agc_driver_storage_cache_budget, agc_driver_unimported_label_order, guest_buffer_reuse.

Run. Three runs on the same base and input script:

base, 6144 MiB (old default) base, APS5_HOST_IMPORT_MIB=12288 base + #290, default (14286 MiB)
host import budget lines 19 0 0
imports refused 118342 (144284 MiB), the last ones 0x383700000+0x7800000 again and again 0 0
first refusal just before the cinematic ends - -
presents per second, cinematic (7200 presents) 8.8 7.8 7.6
frame rate in the title bar when the run ended (loading screen) 0.10 1.54 1.14
loading screen until the crash at least 180 s about 84 s about 92 s

The "at least 180 s" comes from the 19 budget lines, which are printed at most once per 10 s.

  • Presents with this PR. APS5_PROFILE_DRAW=1 was set for this run only. Presents per 10 s after the cinematic: 59, 33, 11, 3, 7, 2, 11, 11. The two runs without the PR had no draw profile, and the 12 GiB run shared the machine with a build. The frame rates are therefore not an exact A/B.
  • Eviction. It probably never ran. The 12 GiB run never went over 12 GiB live, and this run printed no budget line. The PR prints that line only when eviction cannot make room, so this run did not show it directly.
  • Where the loading screen spends its time with this PR. The address-space cache rebuilds on almost every registry generation:
    • 10 to 152 generation rebuilds per 10 s;
    • lease 3 to 19 ms, imports pass 7 to 63 ms and mirror prepare 19 to 72 ms per build;
    • address-based builds drop from about 600 to 16 to 71 per 10 s.
  • Crash. All three runs end the same way, an access violation or a guest stack check failure on a BPE JobWorkerThread stack. That looks like #361, not this PR. None of them got past the black loading screen.

So on this title the PR does what the larger budget does: no refusals, and the loading screen at about 1 FPS instead of 0.1. The eviction path itself was not exercised here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6145117718 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6145117718). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-13T12:04:03Z. --- Test note, Windows, Demon's Souls (PPSA01342), the loading screen after the opening cinematic. **Setup.** Windows Server 2025, RTX 3060 12 GB (driver 32.0.15.9186), Ryzen 9 5900X, 32 GB, MinGW-w64 GCC 15.2. Base: an integration branch on `main` fc1f063f5 plus local merges, not clean `main`. This PR's two commits (5857f9eb5) were cherry-picked onto it. No `APS5_HOST_IMPORT_MIB`, so the new default applies. Here it is 14286 MiB: half of physical memory is 16335 MiB, and the cap is the 16335 MiB host heap less 2 GiB. **Rebase.** Applying the two commits onto current `main` (c8eb1f52d) conflicts in three files, and one technical-debt entry has to move. The integration branch hit the same, and I resolved them like this: - `GuestBufferMemory.cpp`, `struct HostImports`: #3874 removed `importsStampPages` and `dmaBufImportsStampPages`. Keep them removed and add `useCounter` and `buildFloor`. - `GuestBufferMemory.cpp`, `ImportMappedRanges`: #4017 added `if (!GpuMutex().HeldByThisThread() && wouldRetireImport(...)) return false;` before the import. Keep that line, then this PR's `importAllocation(context, state, range->address, current, 0, false)`. The map observer then neither replaces nor evicts without the GPU lock. - `docs/dev/ARCHITECTURE.md`: #425 added the depth-plane bullet at the same place. Keep both bullets. - `docs/dev/TechnicalDebt.md`: #4411 moved library entries to `docs/dev/debt/`. The "Host import windows and budget" entry goes after the "Host imports" entry in `docs/dev/debt/libSceAgcDriver.md`, with links one level deeper (`../../../core/...`). Left in `TechnicalDebt.md`, the entry fails `check_conventions.py`'s `debt-file` rule. With those resolutions, `check_conventions.py` passes. These tests pass: - `agc_driver_graphics`, which includes this PR's four new `BdaResources` cases; - `agc_driver_host_import_windows`, which ran here (it was not skipped); - `agc_driver_host_import_at_map`, `agc_driver_host_import_teardown`, `agc_host_import_unmap`, `agc_parked_import_unmap`, `agc_host_import_retirement`, `agc_host_import_retire`, `agc_unit_shadow`; - `agc_driver_bda_device`, `agc_buffer_pool`, `agc_driver_pooled_buffer_range`; - `agc_driver_sampled_cache_budget` (also `_memory`), `agc_driver_storage_cache_budget`, `agc_driver_unimported_label_order`, `guest_buffer_reuse`. **Run.** Three runs on the same base and input script: | | base, 6144 MiB (old default) | base, `APS5_HOST_IMPORT_MIB=12288` | base + #290, default (14286 MiB) | |---|---|---|---| | `host import budget` lines | 19 | 0 | 0 | | imports refused | 118342 (144284 MiB), the last ones `0x383700000+0x7800000` again and again | 0 | 0 | | first refusal | just before the cinematic ends | - | - | | presents per second, cinematic (7200 presents) | 8.8 | 7.8 | 7.6 | | frame rate in the title bar when the run ended (loading screen) | 0.10 | 1.54 | 1.14 | | loading screen until the crash | at least 180 s | about 84 s | about 92 s | The "at least 180 s" comes from the 19 budget lines, which are printed at most once per 10 s. - **Presents with this PR.** `APS5_PROFILE_DRAW=1` was set for this run only. Presents per 10 s after the cinematic: 59, 33, 11, 3, 7, 2, 11, 11. The two runs without the PR had no draw profile, and the 12 GiB run shared the machine with a build. The frame rates are therefore not an exact A/B. - **Eviction.** It probably never ran. The 12 GiB run never went over 12 GiB live, and this run printed no budget line. The PR prints that line only when eviction cannot make room, so this run did not show it directly. - **Where the loading screen spends its time with this PR.** The address-space cache rebuilds on almost every registry generation: - 10 to 152 generation rebuilds per 10 s; - lease 3 to 19 ms, imports pass 7 to 63 ms and mirror prepare 19 to 72 ms per build; - address-based builds drop from about 600 to 16 to 71 per 10 s. - **Crash.** All three runs end the same way, an access violation or a guest stack check failure on a `BPE JobWorkerThread` stack. That looks like #361, not this PR. None of them got past the black loading screen. So on this title the PR does what the larger budget does: no refusals, and the loading screen at about 1 FPS instead of 0.1. The eviction path itself was not exercised here.
EagleBearerYS commented 2026-10-13 13:41:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T13:41:06Z.


A data point from a 16 GB machine, in case it helps size the default: Resident Evil Village (PPSA01556, 01.210.000) on Windows 11 with an RTX 3070 Laptop GPU (8 GB) and 16 GB of RAM. Windows exposes 7,888 MiB of system memory as the host-visible heap (memory type 4, heap 1).

The title stops loading its first scene, on a local branch past its earlier stops:

[videoout] presentation failed: compute shader 0x207e467100: AGC graphics: vkAllocateMemory buffer: allocation=10485760 memoryType=4 reclaimed=0 initialResult=-2 attempts=1: Vulkan result -2

Same scene, the same build otherwise:

Import budget Imports live at the stop Imports refused Outcome
6,144 MiB (main's default) 6,143 MiB 51,654 (22,556 MiB) the next 10 MB pool buffer fails
4,096 MiB (APS5_HOST_IMPORT_MIB) 4,081-4,095 MiB a 770 MB range refused at each use and copied instead the same failure, or a crash in the game's physics on a null pointer
5,840 MiB (this PR's heap rule) 5,374 MiB 882 (27,594 MiB); the driver also refused 205 imports of 64 KiB-8 MiB with -2 the same failure

So on 16 GB, this PR's budget and eviction are not enough for this scene. The imports and the copies of what is not imported compete for the same 7,888 MiB. The GPU process used 6.3-7.5 GB of shared memory and 1.6-2.0 GB of its 8 GB of dedicated memory at those points. A 32 GB machine would have about twice the heap. I have not tested one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146895362 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6146895362). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-13T13:41:06Z. --- A data point from a 16 GB machine, in case it helps size the default: Resident Evil Village (PPSA01556, 01.210.000) on Windows 11 with an RTX 3070 Laptop GPU (8 GB) and 16 GB of RAM. Windows exposes 7,888 MiB of system memory as the host-visible heap (memory type 4, heap 1). The title stops loading its first scene, on a local branch past its earlier stops: ``` [videoout] presentation failed: compute shader 0x207e467100: AGC graphics: vkAllocateMemory buffer: allocation=10485760 memoryType=4 reclaimed=0 initialResult=-2 attempts=1: Vulkan result -2 ``` Same scene, the same build otherwise: | Import budget | Imports live at the stop | Imports refused | Outcome | |---|---|---|---| | 6,144 MiB (`main`'s default) | 6,143 MiB | 51,654 (22,556 MiB) | the next 10 MB pool buffer fails | | 4,096 MiB (`APS5_HOST_IMPORT_MIB`) | 4,081-4,095 MiB | a 770 MB range refused at each use and copied instead | the same failure, or a crash in the game's physics on a null pointer | | 5,840 MiB (this PR's heap rule) | 5,374 MiB | 882 (27,594 MiB); the driver also refused 205 imports of 64 KiB-8 MiB with -2 | the same failure | So on 16 GB, this PR's budget and eviction are not enough for this scene. The imports and the copies of what is not imported compete for the same 7,888 MiB. The GPU process used 6.3-7.5 GB of shared memory and 1.6-2.0 GB of its 8 GB of dedicated memory at those points. A 32 GB machine would have about twice the heap. I have not tested one.
fdfawef324 commented 2026-10-13 16:22:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T16:22:05Z.


A follow-up with GTA V (PPSA04264) Story Mode, the case in this PR's description. Same machine as my note above. The base is an integration branch with the open tessellation and image-table PRs GTA V needs to reach its menu. I cherry-picked this PR's two commits onto it.

base, 6144 MiB budget (old default) base, APS5_HOST_IMPORT_MIB=12288 base + this PR, default (14286 MiB here)
host import budget lines during the Story Mode load 2 (3,825 imports, 5,428 MiB refused) 0 0
Story Mode load the render thread reads address 0 about 20 s after "Entering Story Mode (60%)" completes; the prologue title card "Ludendorff, North Yankton, nine years ago." shows completes
next stop - AGC graphics: sample masks are unsupported on the first gameplay frames the same

So for this title the PR's default budget does what raising the budget by hand does, and the load no longer runs out of imports. As in the Demon's Souls runs, I can't tell whether eviction ran or the larger default was simply enough. No budget line was printed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150109388 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6150109388). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-13T16:22:05Z. --- A follow-up with GTA V (PPSA04264) Story Mode, the case in this PR's description. Same machine as my note above. The base is an integration branch with the open tessellation and image-table PRs GTA V needs to reach its menu. I cherry-picked this PR's two commits onto it. | | base, 6144 MiB budget (old default) | base, `APS5_HOST_IMPORT_MIB=12288` | base + this PR, default (14286 MiB here) | |---|---|---|---| | `host import budget` lines during the Story Mode load | 2 (3,825 imports, 5,428 MiB refused) | 0 | 0 | | Story Mode load | the render thread reads address 0 about 20 s after "Entering Story Mode (60%)" | completes; the prologue title card "Ludendorff, North Yankton, nine years ago." shows | completes | | next stop | - | `AGC graphics: sample masks are unsupported` on the first gameplay frames | the same | So for this title the PR's default budget does what raising the budget by hand does, and the load no longer runs out of imports. As in the Demon's Souls runs, I can't tell whether eviction ran or the larger default was simply enough. No budget line was printed.
MichonGoddijn231849 commented 2026-10-13 16:25:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-13T16:25:27Z.


Rebased onto current main (0214069e3). The conflicts were main's new retire guard before the import in AcquireRegistered, which is kept with this PR's call, and the debt split; the entry is now in docs/dev/debt/libSceAgcDriver.md. The agc_* suite passes on Windows (484 tests), including the host import tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150172616 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6150172616). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-13T16:25:27Z. --- Rebased onto current `main` (0214069e3). The conflicts were `main`'s new retire guard before the import in `AcquireRegistered`, which is kept with this PR's call, and the debt split; the entry is now in `docs/dev/debt/libSceAgcDriver.md`. The `agc_*` suite passes on Windows (484 tests), including the host import tests.
AlxcBTW commented 2026-10-13 18:00:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T18:00:05Z.


A heads-up for anyone combining this PR with the bind join (#4515, now on main, and #4517). The budget-first replace loop in importRunAt refuses a join whose new import would replace imports that the build in flight already holds. The join then fails silently, and the joined run is CPU-copied for the rest of that build. The join PRs' own tests don't see it, because they run without this PR's loop.

Minimal scenario (importJoinTests in tests/BdaResources.cpp):

  1. Register two adjacent ranges of 192 KiB each, with the import window at 128 KiB.
  2. Import each range alone with HostImportFor; both import fine.
  3. Open a build with AcquireRegistered(), then AddReadable(second - 16, 32), then Upload(true). The join pre-pass runs before any region confirms an import and wants to replace both imports.
  4. The replace loop sees pointerHeld(...) for them and returns nullptr. The check "a buffer bound across two adjacent ranges larger than the import window was not imported as one" fails.

A retired import stays alive through the retire-hold, and UploadFinish re-resolves every pointer after the pre-pass. So refusing a join for held overlaps isn't needed.

Fix (5 lines): a join no longer counts a held overlap as a reason to refuse.

Seen in practice:

  • Sword of the Sea (PPSA25344), a main-based build with this PR merged by hand and without the fix: 28,098 outside-import copies, 639 GB in 720 s. About 506 GB of that was 5,268 copies of ~96 MiB at one buffer class, the class the join exists for. With the fix, the join is back in effect. The after-number from our next cold row will follow here.
  • Palworld: ps54all hit the same thing independently with this PR merged into a join build (see #4517): the joins didn't happen and the copies stayed.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151876398 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6151876398). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-13T18:00:05Z. --- A heads-up for anyone combining this PR with the bind join (#4515, now on main, and #4517). The budget-first replace loop in `importRunAt` refuses a join whose new import would replace imports that the build in flight already holds. The join then fails silently, and the joined run is CPU-copied for the rest of that build. The join PRs' own tests don't see it, because they run without this PR's loop. **Minimal scenario** (`importJoinTests` in `tests/BdaResources.cpp`): 1. Register two adjacent ranges of 192 KiB each, with the import window at 128 KiB. 2. Import each range alone with `HostImportFor`; both import fine. 3. Open a build with `AcquireRegistered()`, then `AddReadable(second - 16, 32)`, then `Upload(true)`. The join pre-pass runs before any region confirms an import and wants to replace both imports. 4. The replace loop sees `pointerHeld(...)` for them and returns `nullptr`. The check "a buffer bound across two adjacent ranges larger than the import window was not imported as one" fails. A retired import stays alive through the retire-hold, and `UploadFinish` re-resolves every pointer after the pre-pass. So refusing a join for held overlaps isn't needed. **Fix (5 lines):** a join no longer counts a held overlap as a reason to refuse. - Commit: https://github.com/AlxcBTW/AnyPS5/commit/74e78fa5a - Branch, with this PR and #4517 on current main: https://github.com/AlxcBTW/AnyPS5/tree/ci/lab/fix-290-join-replaces-held - Linux and Windows CI are green (fork run 38440643324). **Seen in practice:** - **Sword of the Sea** (PPSA25344), a main-based build with this PR merged by hand and without the fix: 28,098 outside-import copies, 639 GB in 720 s. About 506 GB of that was 5,268 copies of ~96 MiB at one buffer class, the class the join exists for. With the fix, the join is back in effect. The after-number from our next cold row will follow here. - **Palworld:** ps54all hit the same thing independently with this PR merged into a join build (see #4517): the joins didn't happen and the copies stayed.
EagleBearerYS commented 2026-10-13 18:46:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T18:46:27Z.


An update to my data point above: with #4517 and #5249 cutting the per-build copies, the scene now loads at main's default 6 GiB import budget. Heap 1 still ends about 250 MiB past its budget, and #4446 moves that overflow to video memory (numbers: https://github.com/boykopovar/AnyPS5/pull/4446#issuecomment-6152703302).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152706284 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6152706284). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-13T18:46:27Z. --- An update to my data point above: with #4517 and #5249 cutting the per-build copies, the scene now loads at `main`'s default 6 GiB import budget. Heap 1 still ends about 250 MiB past its budget, and #4446 moves that overflow to video memory (numbers: https://github.com/boykopovar/AnyPS5/pull/4446#issuecomment-6152703302).
Scramblrrrr commented 2026-10-13 20:37:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T20:37:29Z.


Windows legacy-integration cross-test of the budget-first import replacement in canonical #290 head7f3fed864e77d0ec84e48d499bc08b39f206d2fd: author-preserved adaptation163c10711, final fixture/control corrections75c85dd5 andcd70602fafcdf27af41825b2ac9d7f6dc6fa0740. Public branch: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-import-budget-preservation . Our olderc990 adaptation retired overlaps before deciding whether a whole-range replacement fit; this port retains the existing adaptive cap and already-carried joined-held rule equivalent to AlxcBTW74e78fa5a. It does not duplicate the whole PR or claim current-main coverage.

Restored final8/8 controls PASS7.26s, Windows Release/GCC15.2/RTX5070Ti, Vulkan required: mocked graphics including the refused-whole-range window preservation fixture; BDA device; unmap/retirement; imported/copied sparse runs; alias handover/memory. Production-only negative restores only importRunAt from9ac345d4f, retains identical fixture plus budget/range-window controls: graphics FAILS exactly "an address-based build refused its whole-range import and retired the range's window (build0)"; BDA control PASSES. Positive restored/rebuilt, source/conventions clean.

Two fixture-adaptation attempts are not counted as negatives: first confused join-window and range-window controls and never created the intended window; second omitted the binding path's GPU mutex and cleanup masked the expected assertion with a deferred-import pin. Corrected fixture holds that mutex, matches the canonical range-window control, and produces the exact assertion above with old production. No skipped tests/full-suite/Linux claim.

Starting matched patched graphics/Agc/VideoOut atcd70602fa with existing3864 libc, same1GiB budget and bounded memory guard as previous title trial. No title RAM/FPS improvement claimed yet. AI-assisted: yes (Codex); synthetic code/aggregate results only, no title data attached.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6154713580 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6154713580). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-13T20:37:29Z. --- Windows legacy-integration cross-test of the budget-first import replacement in canonical #290 head7f3fed864e77d0ec84e48d499bc08b39f206d2fd: author-preserved adaptation163c10711, final fixture/control corrections75c85dd5 andcd70602fafcdf27af41825b2ac9d7f6dc6fa0740. Public branch: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-import-budget-preservation . Our olderc990 adaptation retired overlaps before deciding whether a whole-range replacement fit; this port retains the existing adaptive cap and already-carried joined-held rule equivalent to AlxcBTW74e78fa5a. It does not duplicate the whole PR or claim current-main coverage. Restored final8/8 controls PASS7.26s, Windows Release/GCC15.2/RTX5070Ti, Vulkan required: mocked graphics including the refused-whole-range window preservation fixture; BDA device; unmap/retirement; imported/copied sparse runs; alias handover/memory. Production-only negative restores only importRunAt from9ac345d4f, retains identical fixture plus budget/range-window controls: graphics FAILS exactly "an address-based build refused its whole-range import and retired the range's window (build0)"; BDA control PASSES. Positive restored/rebuilt, source/conventions clean. Two fixture-adaptation attempts are not counted as negatives: first confused join-window and range-window controls and never created the intended window; second omitted the binding path's GPU mutex and cleanup masked the expected assertion with a deferred-import pin. Corrected fixture holds that mutex, matches the canonical range-window control, and produces the exact assertion above with old production. No skipped tests/full-suite/Linux claim. Starting matched patched graphics/Agc/VideoOut atcd70602fa with existing3864 libc, same1GiB budget and bounded memory guard as previous title trial. No title RAM/FPS improvement claimed yet. AI-assisted: yes (Codex); synthetic code/aggregate results only, no title data attached.
ultraacademy657-dot commented 2026-10-13 20:39:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ultraacademy657-dot on 2026-10-13T20:39:13Z.


Windows/NVIDIA: large host-memory import fails with both compatible memory types

I tested a local experimental AnyPS5 build based on commit 488d08f20 on Windows, using an NVIDIA RTX 3080 and 16 GiB of system RAM.

The diagnostic trace showed that two smaller host imports succeeded before a larger registered allocation of approximately 6544 MiB failed:

compatibleTypes=0x00000018 memoryType=3 result=-2
compatibleTypes=0x00000018 memoryType=4 result=-2

Both compatible memory types returned VK_ERROR_OUT_OF_DEVICE_MEMORY (-2). Retrying with another compatible memory type did not resolve the allocation failure.

In an earlier run, the subsequent whole-range heap-mirror allocation also failed with Vulkan result -2.

The latest test was deliberately stopped by a safety guard after approximately 13 seconds, when available physical RAM fell to 2.31 GiB. This was a forced safety stop, not a spontaneous process exit.

These results rule out the memory-type selection order as a sufficient fix for this case. They do not establish the complete root cause or demonstrate a working solution.

No game files, executables, or log files are attached. The findings above are limited to the local diagnostic results.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6154743868 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6154743868). Originally posted by [ultraacademy657-dot](https://github.com/ultraacademy657-dot) on 2026-10-13T20:39:13Z. --- ### Windows/NVIDIA: large host-memory import fails with both compatible memory types I tested a local experimental AnyPS5 build based on commit `488d08f20` on Windows, using an NVIDIA RTX 3080 and 16 GiB of system RAM. The diagnostic trace showed that two smaller host imports succeeded before a larger registered allocation of approximately 6544 MiB failed: compatibleTypes=0x00000018 memoryType=3 result=-2 compatibleTypes=0x00000018 memoryType=4 result=-2 Both compatible memory types returned `VK_ERROR_OUT_OF_DEVICE_MEMORY` (`-2`). Retrying with another compatible memory type did not resolve the allocation failure. In an earlier run, the subsequent whole-range heap-mirror allocation also failed with Vulkan result `-2`. The latest test was deliberately stopped by a safety guard after approximately 13 seconds, when available physical RAM fell to 2.31 GiB. This was a forced safety stop, not a spontaneous process exit. These results rule out the memory-type selection order as a sufficient fix for this case. They do not establish the complete root cause or demonstrate a working solution. No game files, executables, or log files are attached. The findings above are limited to the local diagnostic results.
oneandonlydean commented 2026-10-14 01:57:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T01:57:32Z.


Rebased onto main 52d134c02 and pushed here (maintainer edit), keeping your two commits, so this can go in. The conflicts were the bind joins (#4515, #4517): importAllocation keeps main's joined hit and passes end, evict through importRunAt, sameRange keeps both rules, HostImportFor still returns a joined import for a lookup across ranges, and in UploadFinish the per-region import is importAccess, which only returns an import that covers the region, so main's partial-cover check there is no longer needed. The two stamp flags #3874 removed are gone again.

With the joins on main, importJoinTests failed on this branch ("a buffer bound across two adjacent ranges larger than the import window was not imported as one"), so @AlxcBTW's 74e78fa5a is on top. agc_driver_graphics, the host import, budget, write-watch, buffer and BDA tests pass here (RTX 4090, NVIDIA Linux; 43 of 43).

The import set now settles at 8192 MiB in the 3D title from my earlier note: 146 imports in the run, 6 epoch rebuilds. Please check it still passes on Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159174297 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6159174297). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T01:57:32Z. --- Rebased onto main 52d134c02 and pushed here (maintainer edit), keeping your two commits, so this can go in. The conflicts were the bind joins (#4515, #4517): `importAllocation` keeps main's joined hit and passes `end, evict` through `importRunAt`, `sameRange` keeps both rules, `HostImportFor` still returns a joined import for a lookup across ranges, and in `UploadFinish` the per-region import is `importAccess`, which only returns an import that covers the region, so main's partial-cover check there is no longer needed. The two stamp flags #3874 removed are gone again. With the joins on main, `importJoinTests` failed on this branch ("a buffer bound across two adjacent ranges larger than the import window was not imported as one"), so @AlxcBTW's 74e78fa5a is on top. `agc_driver_graphics`, the host import, budget, write-watch, buffer and BDA tests pass here (RTX 4090, NVIDIA Linux; 43 of 43). The import set now settles at 8192 MiB in the 3D title from my earlier note: 146 imports in the run, 6 epoch rebuilds. Please check it still passes on Windows.
github-actions[bot] commented 2026-10-14 02:24:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T02:24:11Z.


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
#2434 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L174, L2102
#5390 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp L37
#5428 core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp L327, L1324-1325
#5482 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L712-713, L737-745
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159487175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/290#issuecomment-6159487175). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T02:24:11Z. --- <!-- 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 | |---|---|---|---| | #2434 | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L174](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L174), [L2102](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L2102) | | | | #5390 | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp` [L37](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp#L37) | | | | #5428 | `core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp` [L327](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp#L327), [L1324-1325](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp#L1324-L1325) | | | | #5482 | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L712-713](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L712-L713), [L737-745](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L737-L745) | | |
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!290
No description provided.