fix(agc): place device memory in host memory when the driver refuses a device-local allocation #5987

Merged
GustavoGamarra95 merged 6 commits from upstream-pr/5987 into main 2026-10-18 20:02:03 +00:00
GustavoGamarra95 commented 2026-10-14 18:29:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-14T18:29:32Z.


What

DeviceMemoryType places a device-local allocation in host memory only when VK_EXT_memory_budget reports the heap as full. The report lags the driver. On a 4 GB RTX 3050 Laptop the heap was at 3684 of a 3685 MiB budget and the budget still showed room. The NVIDIA driver refused the allocation with VK_ERROR_OUT_OF_DEVICE_MEMORY, and the title stopped:

[videoout] presentation failed: AGC graphics: vkAllocateMemory device buffer: allocation=9437184 memoryType=1 reclaimed=604900608 initialResult=-2 attempts=2: Vulkan result -2

With device buffers covered, the next run stopped the same way at vkAllocateMemory depth target.

This is mostly a Linux/NVIDIA problem. On Windows, WDDM demotes allocations to system memory itself instead of refusing them, so these paths should rarely run there. I have not tested Windows.

Host placement is the last step of BufferPool::AllocateMemory, after the recovery that is already on main:

  1. trim the pool's idle tiers and retry device-local memory;
  2. release the sampled textures and clean storage images through the reclaim hook from #6174 and retry device-local memory;
  3. only if that retry is refused too, allocate in a host memory type the requirements allow.

A refusal the reclaim can satisfy never reaches host placement.

Changes:

  • fix: a device buffer still refused after steps 1 and 2 is allocated in host memory. It is marked host-placed, so the device pool does not keep it after release.

  • fix: every image allocation goes through the same path (AllocateImageMemory). This covers textures, storage textures, block, repacked, depth, depth plane and stencil copies, render, depth and multisampled targets, and attachment proxies. Several of these sites called vkAllocateMemory directly and stopped the title on the first refusal: the render, depth and multisampled targets, the attachment proxies, and the block, repacked, depth plane and stencil copies. The 1x1 denormal clear probe is left as it is.

  • Only VK_ERROR_OUT_OF_DEVICE_MEMORY from a device-local type falls back. Other results, and requirements that allow no host type, fail as before.

  • Each placement is logged with the bytes trimmed and released and the cumulative MiB, rate-limited to powers of two like the existing budget placement.

  • docs: docs/dev/debt/libSceAgcDriver.md records that a placed image keeps its placement until it is destroyed and is never moved back, so it is slower (PCIe) for its lifetime.

  • test: agc_buffer_pool_tests covers these cases:

    • RefusedDevicePlacement: a device buffer refused within the reported budget must land in host memory and leave the pool on release; a context with no host type must still fail.
    • AttachmentReclaim: an attachment refused once must reclaim the pool and stay device-local; refused twice, it must land in host memory.
    • ImageCacheReclaim: a texture refused once must release the texture caches and stay device-local; refused again, it must land in host memory.

    Each fails without its fix. agc_device_memory_fallback_tests covers the choice of fallback type: a refused device-local type, a refused host type, the type mask, and an unknown type.

Overlaps #4472 in Context.hpp and tests/BufferPool.cpp. That PR stops pooling released device buffers over the budget; this one handles a refusal the budget did not predict. Whichever merges second needs a manual merge there. pr_overlap also reports line overlaps with #7119 (tests/BufferPool.cpp) and #6764 and #7256 (DepthSurface.cpp). #6553 is stacked on this PR.

Tested

Rebased onto main 9f25d0bf5 (head 9f98c7c9b). Linux (CachyOS, kernel 7.2.9), Release build:

Test RTX 3050 Laptop 615.78.08 lavapipe (Mesa 26.2.4)
agc_buffer_pool, _small_device_shared, _small_device_no_staging pass pass
agc_device_memory_fallback pass pass
agc_driver_graphics pass pass
agc_driver_covered_centroid_state pass pass
agc_driver_tessellation pass skipped
agc_driver_depth_storage_reuse pass skipped
all 700 agc_* ctests pass –

Beast of Reincarnation (PPSA29343), RTX 3050 Laptop 4 GB, 900 s per run with the same scripted pad input. These runs used head 8bb3e07e0, which lacks only the repacked/stencil copy routing, the MiB counter and the DeviceBuffer cleanup:

Window this PR, warm cache: FPS / p50 main (bd5856170), two warm runs: FPS / p50
0–200 s 8.0 / 192 ms 9.0 / 173 ms, 8.0 / 147 ms
200–400 s 0.4 / 1430 ms 0.6 / 1518 ms, 0.7 / 1395 ms
400–600 s 0.5 / 1435 ms 0.7 / 1461 ms, 0.7 / 1376 ms
600–900 s 0.9 / 1020 ms – (600 s runs)

Both runs reached 900 s with no stop, no fault and no device lost. Peak VRAM was 3480 MiB, the same as main. The driver refused no allocation in these runs, so the host placement path did not run there: they show the rebase costs nothing, not what a placement costs. The run with a cold shader cache (2617 misses) is left out of the table.

Earlier data, before #6174 merged (head 4afec5739 and older):

  • New Game on main stopped at the device buffer refusal after about 15 minutes. With only the buffer fallback, the next run stopped at the depth target refusal. With this PR the runs stayed up for the full 15–24 minutes measured.
  • Per 600 s run, the textures that landed in host memory were 41–44 MiB and the storage textures 0–2 MiB, all on their first refusal, which this head no longer allows. No attachment reached host memory once the pool reclaim was in place.
  • 200–600 s ran at 1.11 and 1.18 FPS with the attachment reclaim, against 1.09 FPS without it. The title is CPU-bound here (one recording thread near 100%).

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 under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (#6174 is merged)
  • Fixes: none
  • Unblocks: PPSA29343 (Beast of Reincarnation) on GPUs with 4 GB of device memory; #6553 is stacked on it
  • GPUs tested: NVIDIA GeForce RTX 3050 Laptop 4 GB, driver 615.78.08, Linux (CachyOS 7.2.9); lavapipe (Mesa 26.2.4), Linux (CachyOS 7.2.9)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4862590696 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-14T18:29:32Z. --- ### What `DeviceMemoryType` places a device-local allocation in host memory only when `VK_EXT_memory_budget` reports the heap as full. The report lags the driver. On a 4 GB RTX 3050 Laptop the heap was at 3684 of a 3685 MiB budget and the budget still showed room. The NVIDIA driver refused the allocation with `VK_ERROR_OUT_OF_DEVICE_MEMORY`, and the title stopped: ``` [videoout] presentation failed: AGC graphics: vkAllocateMemory device buffer: allocation=9437184 memoryType=1 reclaimed=604900608 initialResult=-2 attempts=2: Vulkan result -2 ``` With device buffers covered, the next run stopped the same way at `vkAllocateMemory depth target`. This is mostly a Linux/NVIDIA problem. On Windows, WDDM demotes allocations to system memory itself instead of refusing them, so these paths should rarely run there. I have not tested Windows. Host placement is the last step of `BufferPool::AllocateMemory`, after the recovery that is already on `main`: 1. trim the pool's idle tiers and retry device-local memory; 2. release the sampled textures and clean storage images through the reclaim hook from #6174 and retry device-local memory; 3. only if that retry is refused too, allocate in a host memory type the requirements allow. A refusal the reclaim can satisfy never reaches host placement. Changes: - fix: a device buffer still refused after steps 1 and 2 is allocated in host memory. It is marked host-placed, so the device pool does not keep it after release. - fix: every image allocation goes through the same path (`AllocateImageMemory`). This covers textures, storage textures, block, repacked, depth, depth plane and stencil copies, render, depth and multisampled targets, and attachment proxies. Several of these sites called `vkAllocateMemory` directly and stopped the title on the first refusal: the render, depth and multisampled targets, the attachment proxies, and the block, repacked, depth plane and stencil copies. The 1x1 denormal clear probe is left as it is. - Only `VK_ERROR_OUT_OF_DEVICE_MEMORY` from a device-local type falls back. Other results, and requirements that allow no host type, fail as before. - Each placement is logged with the bytes trimmed and released and the cumulative MiB, rate-limited to powers of two like the existing budget placement. - docs: `docs/dev/debt/libSceAgcDriver.md` records that a placed image keeps its placement until it is destroyed and is never moved back, so it is slower (PCIe) for its lifetime. - test: `agc_buffer_pool_tests` covers these cases: - `RefusedDevicePlacement`: a device buffer refused within the reported budget must land in host memory and leave the pool on release; a context with no host type must still fail. - `AttachmentReclaim`: an attachment refused once must reclaim the pool and stay device-local; refused twice, it must land in host memory. - `ImageCacheReclaim`: a texture refused once must release the texture caches and stay device-local; refused again, it must land in host memory. Each fails without its fix. `agc_device_memory_fallback_tests` covers the choice of fallback type: a refused device-local type, a refused host type, the type mask, and an unknown type. Overlaps #4472 in `Context.hpp` and `tests/BufferPool.cpp`. That PR stops pooling released device buffers over the budget; this one handles a refusal the budget did not predict. Whichever merges second needs a manual merge there. `pr_overlap` also reports line overlaps with #7119 (`tests/BufferPool.cpp`) and #6764 and #7256 (`DepthSurface.cpp`). #6553 is stacked on this PR. ### Tested Rebased onto `main` 9f25d0bf5 (head 9f98c7c9b). Linux (CachyOS, kernel 7.2.9), Release build: | Test | RTX 3050 Laptop 615.78.08 | lavapipe (Mesa 26.2.4) | |---|---|---| | `agc_buffer_pool`, `_small_device_shared`, `_small_device_no_staging` | pass | pass | | `agc_device_memory_fallback` | pass | pass | | `agc_driver_graphics` | pass | pass | | `agc_driver_covered_centroid_state` | pass | pass | | `agc_driver_tessellation` | pass | skipped | | `agc_driver_depth_storage_reuse` | pass | skipped | | all 700 `agc_*` ctests | pass | – | Beast of Reincarnation (PPSA29343), RTX 3050 Laptop 4 GB, 900 s per run with the same scripted pad input. These runs used head 8bb3e07e0, which lacks only the repacked/stencil copy routing, the MiB counter and the `DeviceBuffer` cleanup: | Window | this PR, warm cache: FPS / p50 | `main` (bd5856170), two warm runs: FPS / p50 | |---|---|---| | 0–200 s | 8.0 / 192 ms | 9.0 / 173 ms, 8.0 / 147 ms | | 200–400 s | 0.4 / 1430 ms | 0.6 / 1518 ms, 0.7 / 1395 ms | | 400–600 s | 0.5 / 1435 ms | 0.7 / 1461 ms, 0.7 / 1376 ms | | 600–900 s | 0.9 / 1020 ms | – (600 s runs) | Both runs reached 900 s with no stop, no fault and no device lost. Peak VRAM was 3480 MiB, the same as `main`. The driver refused no allocation in these runs, so the host placement path did not run there: they show the rebase costs nothing, not what a placement costs. The run with a cold shader cache (2617 misses) is left out of the table. Earlier data, before #6174 merged (head 4afec5739 and older): - New Game on `main` stopped at the device buffer refusal after about 15 minutes. With only the buffer fallback, the next run stopped at the depth target refusal. With this PR the runs stayed up for the full 15–24 minutes measured. - Per 600 s run, the textures that landed in host memory were 41–44 MiB and the storage textures 0–2 MiB, all on their first refusal, which this head no longer allows. No attachment reached host memory once the pool reclaim was in place. - 200–600 s ran at 1.11 and 1.18 FPS with the attachment reclaim, against 1.09 FPS without it. The title is CPU-bound here (one recording thread near 100%). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none (#6174 is merged) - [x] Fixes: none - [x] Unblocks: PPSA29343 (Beast of Reincarnation) on GPUs with 4 GB of device memory; #6553 is stacked on it - [x] GPUs tested: NVIDIA GeForce RTX 3050 Laptop 4 GB, driver 615.78.08, Linux (CachyOS 7.2.9); lavapipe (Mesa 26.2.4), Linux (CachyOS 7.2.9) - [x] AI-assisted: yes
CnRJay commented 2026-10-14 19:16:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T19:16:52Z.

Review: COMMENTED


Falling back on VK_ERROR_OUT_OF_DEVICE_MEMORY instead of stopping is reasonable for buffers. They are pooled and short-lived, and a host-placed one leaves the pool on release, so the cost goes away with it.

For images it is different, because a host-placed image keeps its placement until it is destroyed. If a refusal hits during a short spike, a long-lived render target or depth target lands in system memory and stays there for the rest of the session. Every draw that writes or tests against it then goes over PCIe, at a fraction of VRAM bandwidth. On a 4 GB laptop part that is a large, permanent frame-time loss that no log line ties to the spike. Render targets, depth targets, multisampled targets and attachment proxies are the worst candidates for host memory. Sampled textures and block/depth copies are much more tolerable.

Some suggestions:

  • Reclaim before falling back for images too. The buffer path reclaims the pool and retries device-local first, but the image paths go straight to host memory. Evicting from the sampled and storage image caches (and the buffer pool) and retrying device-local once would avoid most of these placements, since the caches are usually what fills the heap.
  • Keep attachments device-local. For render, depth and multisampled targets, it may be better to keep the current failure, or to fall back only after a reclaim fails, and log that as the hard limit.
  • Show the cost. The PR says about 2 GB ended up in host memory in Beast of Reincarnation but gives no frame times. The summary lines for a stretch of that run with and without placements (or with the cache budgets reduced so main doesn't hit the refusal) would show what the title pays.

This is mostly a Linux/NVIDIA problem: on Windows, WDDM demotes allocations itself instead of refusing them. A sentence in the description saying so would help reviewers on the other platform.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5523371105 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#pullrequestreview-5523371105). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-14T19:16:52Z. **Review:** COMMENTED --- Falling back on `VK_ERROR_OUT_OF_DEVICE_MEMORY` instead of stopping is reasonable for buffers. They are pooled and short-lived, and a host-placed one leaves the pool on release, so the cost goes away with it. For images it is different, because a host-placed image keeps its placement until it is destroyed. If a refusal hits during a short spike, a long-lived render target or depth target lands in system memory and stays there for the rest of the session. Every draw that writes or tests against it then goes over PCIe, at a fraction of VRAM bandwidth. On a 4 GB laptop part that is a large, permanent frame-time loss that no log line ties to the spike. Render targets, depth targets, multisampled targets and attachment proxies are the worst candidates for host memory. Sampled textures and block/depth copies are much more tolerable. Some suggestions: - **Reclaim before falling back for images too.** The buffer path reclaims the pool and retries device-local first, but the image paths go straight to host memory. Evicting from the sampled and storage image caches (and the buffer pool) and retrying device-local once would avoid most of these placements, since the caches are usually what fills the heap. - **Keep attachments device-local.** For render, depth and multisampled targets, it may be better to keep the current failure, or to fall back only after a reclaim fails, and log that as the hard limit. - **Show the cost.** The PR says about 2 GB ended up in host memory in Beast of Reincarnation but gives no frame times. The summary lines for a stretch of that run with and without placements (or with the cache budgets reduced so `main` doesn't hit the refusal) would show what the title pays. This is mostly a Linux/NVIDIA problem: on Windows, WDDM demotes allocations itself instead of refusing them. A sentence in the description saying so would help reviewers on the other platform.
ee6aba54 commented 2026-10-15 01:01:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-15T01:01:00Z.


#6174 touches the same allocation sites (it releases the texture caches before the pool's retry). I will put it behind this one and route its texture and storage image allocations through Context::AllocateDeviceMemory once this is merged, so no change is needed here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6181938822 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6181938822). Originally posted by [ee6aba54](https://github.com/ee6aba54) on 2026-10-15T01:01:00Z. --- #6174 touches the same allocation sites (it releases the texture caches before the pool's retry). I will put it behind this one and route its texture and storage image allocations through `Context::AllocateDeviceMemory` once this is merged, so no change is needed here.
GustavoGamarra95 commented 2026-10-15 11:24:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-15T11:24:27Z.


Thanks @CnRJay and @ee6aba54 for the feedback! I really appreciate you both taking the time to look into this.

I'll spend some time today going through the points you raised and figuring out the best way to address them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6190908990 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6190908990). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-15T11:24:27Z. --- Thanks @CnRJay and @ee6aba54 for the feedback! I really appreciate you both taking the time to look into this. I'll spend some time today going through the points you raised and figuring out the best way to address them.
github-actions[bot] commented 2026-10-15 12:12:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:12:47Z.


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
PR 4472 core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp L308-313
core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp L169-179, L209, L790-791
PR 7119 core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp L177-179, L695
PR 7256 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L253-261

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1368 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 2434 docs/dev/debt/libSceAgcDriver.md
PR 4072 core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/debt/libSceAgcDriver.md
PR 4650 docs/dev/debt/libSceAgcDriver.md
PR 5058 docs/dev/debt/libSceAgcDriver.md
PR 5499 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
docs/dev/debt/libSceAgcDriver.md
PR 5609 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 5925 docs/dev/debt/libSceAgcDriver.md
PR 6177 core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6192 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6194 docs/dev/debt/libSceAgcDriver.md
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6223 docs/dev/debt/libSceAgcDriver.md
PR 6273 docs/dev/debt/libSceAgcDriver.md
PR 6280 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6292 core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6297 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 6300 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6320 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6412 docs/dev/debt/libSceAgcDriver.md
PR 6414 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6423 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6472 docs/dev/debt/libSceAgcDriver.md
PR 6481 core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6490 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6529 docs/dev/debt/libSceAgcDriver.md
PR 6539 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6548 docs/dev/debt/libSceAgcDriver.md
PR 6549 docs/dev/debt/libSceAgcDriver.md
PR 6563 docs/dev/debt/libSceAgcDriver.md
PR 6615 core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6741 docs/dev/debt/libSceAgcDriver.md
PR 6763 core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp
PR 6786 docs/dev/debt/libSceAgcDriver.md
PR 6808 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6867 docs/dev/debt/libSceAgcDriver.md
PR 6868 docs/dev/debt/libSceAgcDriver.md
PR 6941 docs/dev/debt/libSceAgcDriver.md
PR 6971 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6977 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7008 docs/dev/debt/libSceAgcDriver.md
PR 7201 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 7390 docs/dev/debt/libSceAgcDriver.md
PR 7426 docs/dev/debt/libSceAgcDriver.md
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/debt/libSceAgcDriver.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191760419 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6191760419). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:12:47Z. --- <!-- 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 | |---|---|---|---| | [PR 4472](https://www.github.com/boykopovar/AnyPS5/pull/4472) | `core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp` [L308-313](https://github.com/boykopovar/AnyPS5/blob/b8cd204a3fdf647976b77ddd19d32a6bda41856a/core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp#L308-L313)<br>`core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp` [L169-179](https://github.com/boykopovar/AnyPS5/blob/b8cd204a3fdf647976b77ddd19d32a6bda41856a/core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp#L169-L179), [L209](https://github.com/boykopovar/AnyPS5/blob/b8cd204a3fdf647976b77ddd19d32a6bda41856a/core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp#L209), [L790-791](https://github.com/boykopovar/AnyPS5/blob/b8cd204a3fdf647976b77ddd19d32a6bda41856a/core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp#L790-L791) | | | | [PR 7119](https://www.github.com/boykopovar/AnyPS5/pull/7119) | `core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp` [L177-179](https://github.com/boykopovar/AnyPS5/blob/b8cd204a3fdf647976b77ddd19d32a6bda41856a/core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp#L177-L179), [L695](https://github.com/boykopovar/AnyPS5/blob/b8cd204a3fdf647976b77ddd19d32a6bda41856a/core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp#L695) | | | | [PR 7256](https://www.github.com/boykopovar/AnyPS5/pull/7256) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L253-261](https://github.com/boykopovar/AnyPS5/blob/b8cd204a3fdf647976b77ddd19d32a6bda41856a/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L253-L261) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 1368](https://www.github.com/boykopovar/AnyPS5/pull/1368) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 1395](https://www.github.com/boykopovar/AnyPS5/pull/1395) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 2434](https://www.github.com/boykopovar/AnyPS5/pull/2434) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 4072](https://www.github.com/boykopovar/AnyPS5/pull/4072) | `core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp` | | [PR 4448](https://www.github.com/boykopovar/AnyPS5/pull/4448) | `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | [PR 4650](https://www.github.com/boykopovar/AnyPS5/pull/4650) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 5058](https://www.github.com/boykopovar/AnyPS5/pull/5058) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 5499](https://www.github.com/boykopovar/AnyPS5/pull/5499) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | [PR 5609](https://www.github.com/boykopovar/AnyPS5/pull/5609) | `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 5925](https://www.github.com/boykopovar/AnyPS5/pull/5925) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6177](https://www.github.com/boykopovar/AnyPS5/pull/6177) | `core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp` | | [PR 6188](https://www.github.com/boykopovar/AnyPS5/pull/6188) | `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 6192](https://www.github.com/boykopovar/AnyPS5/pull/6192) | `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 6194](https://www.github.com/boykopovar/AnyPS5/pull/6194) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6197](https://www.github.com/boykopovar/AnyPS5/pull/6197) | `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 6223](https://www.github.com/boykopovar/AnyPS5/pull/6223) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6273](https://www.github.com/boykopovar/AnyPS5/pull/6273) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6280](https://www.github.com/boykopovar/AnyPS5/pull/6280) | `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | [PR 6292](https://www.github.com/boykopovar/AnyPS5/pull/6292) | `core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 6297](https://www.github.com/boykopovar/AnyPS5/pull/6297) | `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp` | | [PR 6300](https://www.github.com/boykopovar/AnyPS5/pull/6300) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | [PR 6320](https://www.github.com/boykopovar/AnyPS5/pull/6320) | `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 6412](https://www.github.com/boykopovar/AnyPS5/pull/6412) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6414](https://www.github.com/boykopovar/AnyPS5/pull/6414) | `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 6423](https://www.github.com/boykopovar/AnyPS5/pull/6423) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 6472](https://www.github.com/boykopovar/AnyPS5/pull/6472) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6481](https://www.github.com/boykopovar/AnyPS5/pull/6481) | `core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | [PR 6490](https://www.github.com/boykopovar/AnyPS5/pull/6490) | `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 6529](https://www.github.com/boykopovar/AnyPS5/pull/6529) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6539](https://www.github.com/boykopovar/AnyPS5/pull/6539) | `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 6548](https://www.github.com/boykopovar/AnyPS5/pull/6548) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6549](https://www.github.com/boykopovar/AnyPS5/pull/6549) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6563](https://www.github.com/boykopovar/AnyPS5/pull/6563) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6615](https://www.github.com/boykopovar/AnyPS5/pull/6615) | `core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 6741](https://www.github.com/boykopovar/AnyPS5/pull/6741) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6763](https://www.github.com/boykopovar/AnyPS5/pull/6763) | `core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp` | | [PR 6786](https://www.github.com/boykopovar/AnyPS5/pull/6786) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6808](https://www.github.com/boykopovar/AnyPS5/pull/6808) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | [PR 6867](https://www.github.com/boykopovar/AnyPS5/pull/6867) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6868](https://www.github.com/boykopovar/AnyPS5/pull/6868) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6941](https://www.github.com/boykopovar/AnyPS5/pull/6941) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 6971](https://www.github.com/boykopovar/AnyPS5/pull/6971) | `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` | | [PR 7008](https://www.github.com/boykopovar/AnyPS5/pull/7008) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 7390](https://www.github.com/boykopovar/AnyPS5/pull/7390) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 7426](https://www.github.com/boykopovar/AnyPS5/pull/7426) | `docs/dev/debt/libSceAgcDriver.md` | | [PR 7642](https://www.github.com/boykopovar/AnyPS5/pull/7642) | `core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp`<br>`docs/dev/debt/libSceAgcDriver.md` |
GustavoGamarra95 commented 2026-10-15 12:32:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-15T12:32:49Z.


@CnRJay Thanks for the review. Updated:

  • Attachments: render, depth and multisampled targets and attachment proxies now go through the pool's recovery (release idle allocations, retry device-local); only a second refusal places them in host memory, logged with the bytes reclaimed. New AttachmentReclaim test.
  • Texture caches: #6174 releases the sampled and storage image caches before the retry and builds on this PR, so I left the texture and storage paths here as they are.
  • Cost: the description now has per-run placements and frame rates. No attachment reached host memory in these runs, and frame rate did not change (1.09 vs 1.11/1.18 FPS); the title is CPU-bound on this machine, so it can't show the per-draw PCIe cost. The earlier "about 2 GB" was mostly main's budget placement of device buffers, not this PR. I corrected it.
  • Windows: added a note that WDDM demotes instead of refusing (not tested there).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6192126961 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6192126961). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-15T12:32:49Z. --- @CnRJay Thanks for the review. Updated: - **Attachments:** render, depth and multisampled targets and attachment proxies now go through the pool's recovery (release idle allocations, retry device-local); only a second refusal places them in host memory, logged with the bytes reclaimed. New `AttachmentReclaim` test. - **Texture caches:** #6174 releases the sampled and storage image caches before the retry and builds on this PR, so I left the texture and storage paths here as they are. - **Cost:** the description now has per-run placements and frame rates. No attachment reached host memory in these runs, and frame rate did not change (1.09 vs 1.11/1.18 FPS); the title is CPU-bound on this machine, so it can't show the per-draw PCIe cost. The earlier "about 2 GB" was mostly `main`'s budget placement of device buffers, not this PR. I corrected it. - **Windows:** added a note that WDDM demotes instead of refusing (not tested there).
CnRJay commented 2026-10-15 18:20:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-15T18:20:59Z.


Thanks. Attachments now go through reclaim and a device-local retry first, and only a second refusal places them in host memory, with the bytes logged. That addresses the permanent-placement concern. The correction to the "about 2 GB" figure and the WDDM note help too. Leaving the texture-cache release to #6174 is fine as long as both land. Nothing more from me.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6199204325 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6199204325). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-15T18:20:59Z. --- Thanks. Attachments now go through reclaim and a device-local retry first, and only a second refusal places them in host memory, with the bytes logged. That addresses the permanent-placement concern. The correction to the "about 2 GB" figure and the WDDM note help too. Leaving the texture-cache release to #6174 is fine as long as both land. Nothing more from me.
SleglJan commented 2026-10-16 02:04:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-16T02:04:28Z.


Data from 007 First Light (PPSA11386) on Linux 7.2.10, RTX 3080 10 GB, driver 615.78.08, a second title and GPU for the attachment path. Shortly after its level entry the title stops on the refusal this PR handles. The stack is main 4186f06a9 plus open PRs and unpublished local fixes the title needs to get that far, plus local logging and scripted input, and the title's two feedback-wait limits widened in its executable as described in #6172 (local only). Three of the four runs below also carry #6174, and two of those also carry #6402 and #6364. 13 runs on these stacks stopped at a depth or render target; four are shown in detail.

  • Four runs, four stops: three at vkAllocateMemory depth target: Vulkan result -2 and one at vkAllocateMemory render target: Vulkan result -2. They came after presents 1186, 1236, 1245 and 1268, which is 21-31 presents after each run's level entry (presents 1155-1241).
  • In the last budget report before each stop, the device-local heap was 40 MiB under its budget in the first run (7982 of 8022 MiB) and at its budget in the other three (8714, 8698 and 8696 MiB). The last pool statistics showed 1191, 1683, 1324 and 1663 MiB in idle retained tiers (small/large/device: 14/482/695, 60/489/1134, 14/464/846 and 61/459/1143 MiB). The pool trims those tiers and retries when a device buffer is refused; with #6174 it does the same for a texture, storage texture or depth copy. Single trims reclaimed up to 1601 MiB, and the first run had 22 recoveries in its last 21 presents. In three runs a trim of 1300-1385 MiB ran during the final present, and the depth target allocation after it was still refused. The depth and render target sites allocate directly and throw on the first refusal. They do no trim or retry of their own.
  • #6174 alone does not reach these sites: the three runs that carried it still stopped on the depth target.
  • Same stack as the render-target run plus #6553 (head 56d44ed2c, which carries this PR's head 09c712d27), still without #6174. Cache budgets were at their defaults; that run had them forced to 1536 MiB. Level entry came at present 1270 and the first device-memory refusal at 1289. The run reached gameplay's first tutorial prompt and ended at present 1430 at its 3600 s time limit, with no fault and no stop. 943 staging shadows were refused, which the stager skips by design. This PR's attachment path recovered 43 depth targets (229 MiB requested, first at present 1314). Each recovery was a trim of the idle tiers (median 119 MiB, at most 1106 MiB) followed by a successful device-local retry. The pool's existing recovery also fired 495 times for device buffers (4916 MiB requested) and 34 times for staging buffers.
  • What it costs here: the budget-based placement printed nothing in this run, so every host placement followed a driver refusal. On this stack (without #6174), textures and storage textures go to host memory on their first refusal through Context::AllocateDeviceMemory. That counter reached 2048 allocations and 16,818 MiB placed by present 1403; 11 of its 14 printed lines were storage textures and 3 textures. Device buffers placed in host memory after the pool's trim (released with their use) reached 8192 by present 1391. All 16 printed lines of that counter are device buffers; none is an attachment. Both counts come from the last rate-limited line, are cumulative and are lower bounds, not resident memory. The frame rate fell over the same stretch: 0.12-0.13 at presents 1280-1296, 0.08 at 1330, 0.05 at 1360 and 0.03 from 1396 on. In that stretch the emulator created about 130 storage images (about 400 MiB) per present. This PR does not create these allocations; it decides where the refused ones go, and the run slows down instead of stopping.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6206385010 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6206385010). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-16T02:04:28Z. --- Data from 007 First Light (PPSA11386) on Linux 7.2.10, RTX 3080 10 GB, driver 615.78.08, a second title and GPU for the attachment path. Shortly after its level entry the title stops on the refusal this PR handles. The stack is main 4186f06a9 plus open PRs and unpublished local fixes the title needs to get that far, plus local logging and scripted input, and the title's two feedback-wait limits widened in its executable as described in #6172 (local only). Three of the four runs below also carry #6174, and two of those also carry #6402 and #6364. 13 runs on these stacks stopped at a depth or render target; four are shown in detail. - Four runs, four stops: three at `vkAllocateMemory depth target: Vulkan result -2` and one at `vkAllocateMemory render target: Vulkan result -2`. They came after presents 1186, 1236, 1245 and 1268, which is 21-31 presents after each run's level entry (presents 1155-1241). - In the last budget report before each stop, the device-local heap was 40 MiB under its budget in the first run (7982 of 8022 MiB) and at its budget in the other three (8714, 8698 and 8696 MiB). The last pool statistics showed 1191, 1683, 1324 and 1663 MiB in idle retained tiers (small/large/device: 14/482/695, 60/489/1134, 14/464/846 and 61/459/1143 MiB). The pool trims those tiers and retries when a device buffer is refused; with #6174 it does the same for a texture, storage texture or depth copy. Single trims reclaimed up to 1601 MiB, and the first run had 22 recoveries in its last 21 presents. In three runs a trim of 1300-1385 MiB ran during the final present, and the depth target allocation after it was still refused. The depth and render target sites allocate directly and throw on the first refusal. They do no trim or retry of their own. - #6174 alone does not reach these sites: the three runs that carried it still stopped on the depth target. - Same stack as the render-target run plus #6553 (head 56d44ed2c, which carries this PR's head 09c712d27), still without #6174. Cache budgets were at their defaults; that run had them forced to 1536 MiB. Level entry came at present 1270 and the first device-memory refusal at 1289. The run reached gameplay's first tutorial prompt and ended at present 1430 at its 3600 s time limit, with no fault and no stop. 943 staging shadows were refused, which the stager skips by design. This PR's attachment path recovered 43 depth targets (229 MiB requested, first at present 1314). Each recovery was a trim of the idle tiers (median 119 MiB, at most 1106 MiB) followed by a successful device-local retry. The pool's existing recovery also fired 495 times for device buffers (4916 MiB requested) and 34 times for staging buffers. - What it costs here: the budget-based placement printed nothing in this run, so every host placement followed a driver refusal. On this stack (without #6174), textures and storage textures go to host memory on their first refusal through `Context::AllocateDeviceMemory`. That counter reached 2048 allocations and 16,818 MiB placed by present 1403; 11 of its 14 printed lines were storage textures and 3 textures. Device buffers placed in host memory after the pool's trim (released with their use) reached 8192 by present 1391. All 16 printed lines of that counter are device buffers; none is an attachment. Both counts come from the last rate-limited line, are cumulative and are lower bounds, not resident memory. The frame rate fell over the same stretch: 0.12-0.13 at presents 1280-1296, 0.08 at 1330, 0.05 at 1360 and 0.03 from 1396 on. In that stretch the emulator created about 130 storage images (about 400 MiB) per present. This PR does not create these allocations; it decides where the refused ones go, and the run slows down instead of stopping. AI-assisted: yes (Claude Code)
GustavoGamarra95 commented 2026-10-16 10:28:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-16T10:28:24Z.


Thanks @SleglJan for putting together these detailed results.
The comparison is really useful, especially the fact that the attachment path successfully recovered from 43 depth-target allocation failures and allowed the game to continue without a fault or stop.

The performance degradation is also worth keeping in mind. While this PR addresses the immediate allocation failure, sustained memory pressure and allocation overhead can still make the game effectively unplayable.

I'll investigate how I can further improve the recovery path and reduce the performance overhead under sustained memory pressure. These results provide a valuable starting point for identifying potential improvements.

Thanks again for the detailed testing and analysis!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6213473339 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6213473339). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-16T10:28:24Z. --- Thanks @SleglJan for putting together these detailed results. The comparison is really useful, especially the fact that the attachment path successfully recovered from 43 depth-target allocation failures and allowed the game to continue without a fault or stop. The performance degradation is also worth keeping in mind. While this PR addresses the immediate allocation failure, sustained memory pressure and allocation overhead can still make the game effectively unplayable. I'll investigate how I can further improve the recovery path and reduce the performance overhead under sustained memory pressure. These results provide a valuable starting point for identifying potential improvements. Thanks again for the detailed testing and analysis!
parl0v commented 2026-10-16 15:39:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T15:39:00Z.


Windows data, since the description says it wasn't tested there: RTX 4060 8 GB (NVIDIA 617.42), 16 GB RAM, Windows 10, Minecraft Dungeons II world loads with an oversized cache budget. With this PR the load got past the point where main died, but the next abort was again VK_ERROR_OUT_OF_DEVICE_MEMORY on memory type 0, which on this driver is the host heap: vkAllocateMemory device buffer: allocation=134217728 memoryType=0 reclaimed=980363776 initialResult=-2 attempts=2. The buffer had already been placed in host memory by DeviceMemoryType and heap 1 was full, so the device-local retry here doesn't apply; in these rows no device-local allocation was ever refused, which fits WDDM demoting rather than refusing. Details and the heap 1 figures are on #6553: https://github.com/boykopovar/AnyPS5/pull/6553#issuecomment-6219031322

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6219031754 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6219031754). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-16T15:39:00Z. --- Windows data, since the description says it wasn't tested there: RTX 4060 8 GB (NVIDIA 617.42), 16 GB RAM, Windows 10, Minecraft Dungeons II world loads with an oversized cache budget. With this PR the load got past the point where `main` died, but the next abort was again `VK_ERROR_OUT_OF_DEVICE_MEMORY` on memory type 0, which on this driver is the host heap: `vkAllocateMemory device buffer: allocation=134217728 memoryType=0 reclaimed=980363776 initialResult=-2 attempts=2`. The buffer had already been placed in host memory by `DeviceMemoryType` and heap 1 was full, so the device-local retry here doesn't apply; in these rows no device-local allocation was ever refused, which fits WDDM demoting rather than refusing. Details and the heap 1 figures are on #6553: https://github.com/boykopovar/AnyPS5/pull/6553#issuecomment-6219031322 AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-16 20:33:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T20:33:17Z.

Review: CHANGES_REQUESTED


Thanks for the work and for the per-run numbers. The approach looks fine to me, but it can't merge as it is:

  • The PR conflicts with main: MultisampleTarget.cpp now allocates inside MultisampleTarget::allocate(), so the AllocateAttachmentMemory call has to move there. DepthSurfaceReuse.cpp also defines mapMemory/unmapMemory/destroyBuffer mocks that main already has, which breaks the build after the merge.
  • On the rebased tree, agc_driver_graphics, agc_driver_covered_centroid_state (DCC over a multisampled color target is unsupported) and agc_driver_tessellation (segfault) fail. Please rebase, run them with and without the PR, and say which also fail on main.
  • It overlaps with #6553 in Context.hpp (DeviceMemoryType/HostMemoryType); please agree the order with it and rebase on whichever lands first.
  • Textures and storage textures still fall to host memory on their first refusal and stay there. The 007 First Light run shows FPS going from 0.12 to 0.03 while ~16 GiB are placed; the storage-texture path should go through the pool reclaim and a device-local retry first, like attachments now do.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5553374625 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#pullrequestreview-5553374625). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T20:33:17Z. **Review:** CHANGES_REQUESTED --- Thanks for the work and for the per-run numbers. The approach looks fine to me, but it can't merge as it is: - The PR conflicts with `main`: `MultisampleTarget.cpp` now allocates inside `MultisampleTarget::allocate()`, so the `AllocateAttachmentMemory` call has to move there. `DepthSurfaceReuse.cpp` also defines `mapMemory`/`unmapMemory`/`destroyBuffer` mocks that `main` already has, which breaks the build after the merge. - On the rebased tree, `agc_driver_graphics`, `agc_driver_covered_centroid_state` (`DCC over a multisampled color target is unsupported`) and `agc_driver_tessellation` (segfault) fail. Please rebase, run them with and without the PR, and say which also fail on `main`. - It overlaps with #6553 in `Context.hpp` (`DeviceMemoryType`/`HostMemoryType`); please agree the order with it and rebase on whichever lands first. - Textures and storage textures still fall to host memory on their first refusal and stay there. The 007 First Light run shows FPS going from 0.12 to 0.03 while ~16 GiB are placed; the storage-texture path should go through the pool reclaim and a device-local retry first, like attachments now do.
SleglJan commented 2026-10-16 20:54:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-16T20:54:36Z.


@adriadam10 On the last point, a correction to my earlier comment. I listed the 0.12 → 0.03 FPS fall under what this PR costs, but that run did not carry #6465. The data I have since does not separate the cost of the host placements from the cost of the depth-surface list.

  • My data comment on #6465 has two runs on main 4186f06a9 with open PRs including #5987 and #6553, and the non-default switches listed there.
    • Without #6465, wall time grew from 8.3 s per present (10-19 presents into gameplay) to 28.6 s (133-141). Revalidate grew from 3.94 s to 18.2 s while its work per present stayed the same.
    • In a profile of a third run without #6465, DepthSurfaceTexture, which scans the depth-surface list on sampled-texture lookups, took 17.8% of the title process's samples.
  • With #6465, wall time stayed at 5.5-6.3 s per present from the fourth present of gameplay to the end of the run (85 presents into gameplay). That run made no host placement. The device-local heap's reported usage was 6,842-7,225 MiB per present in gameplay, against 7,402-8,245 MiB without it.
  • The run without #6465 also placed textures and device buffers in host memory from 15 presents into gameplay on. Its storage textures in host memory came to about 19,100 MiB cumulative; 1,129 MiB of them were live at present 1350.

The storage-texture path still falls back on its first refusal without a reclaim, as you say.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224511182 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6224511182). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-16T20:54:36Z. --- @adriadam10 On the last point, a correction to my earlier comment. I listed the 0.12 → 0.03 FPS fall under what this PR costs, but that run did not carry #6465. The data I have since does not separate the cost of the host placements from the cost of the depth-surface list. - My data comment on #6465 has two runs on `main` 4186f06a9 with open PRs including #5987 and #6553, and the non-default switches listed there. - Without #6465, wall time grew from 8.3 s per present (10-19 presents into gameplay) to 28.6 s (133-141). `Revalidate` grew from 3.94 s to 18.2 s while its work per present stayed the same. - In a profile of a third run without #6465, `DepthSurfaceTexture`, which scans the depth-surface list on sampled-texture lookups, took 17.8% of the title process's samples. - With #6465, wall time stayed at 5.5-6.3 s per present from the fourth present of gameplay to the end of the run (85 presents into gameplay). That run made no host placement. The device-local heap's reported usage was 6,842-7,225 MiB per present in gameplay, against 7,402-8,245 MiB without it. - The run without #6465 also placed textures and device buffers in host memory from 15 presents into gameplay on. Its storage textures in host memory came to about 19,100 MiB cumulative; 1,129 MiB of them were live at present 1350. The storage-texture path still falls back on its first refusal without a reclaim, as you say. AI-assisted: yes (Claude Code)
ee6aba54 commented 2026-10-16 23:40:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-16T23:40:30Z.


Point 4 (textures and storage textures going through the pool reclaim and a device-local retry first) is what #6174 does: texture, depth copy and storage texture allocate through BufferPool::AllocateMemory, which trims the pool's idle tiers, releases sampled textures and clean storage images through a reclaim hook, and retries before it reports the failure. Both PRs change the same three vkAllocateMemory lines in Texture.cpp, so one of them will have to rebase on the other.

A possible order: #6174 first (it merges cleanly with current main and does not need this PR), then this PR places memory in host memory only when the pool's reclaim and retry still fail, e.g. as the last step inside AllocateMemory or in an AllocateDeviceMemory called by it. That covers the 0.12 to 0.03 FPS case, because a refusal that the reclaim can satisfy never reaches host placement. Happy to rebase #6174 onto whatever order you and #6553 agree on.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6226742996 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6226742996). Originally posted by [ee6aba54](https://github.com/ee6aba54) on 2026-10-16T23:40:30Z. --- Point 4 (textures and storage textures going through the pool reclaim and a device-local retry first) is what #6174 does: `texture`, `depth copy` and `storage texture` allocate through `BufferPool::AllocateMemory`, which trims the pool's idle tiers, releases sampled textures and clean storage images through a reclaim hook, and retries before it reports the failure. Both PRs change the same three `vkAllocateMemory` lines in `Texture.cpp`, so one of them will have to rebase on the other. A possible order: #6174 first (it merges cleanly with current `main` and does not need this PR), then this PR places memory in host memory only when the pool's reclaim and retry still fail, e.g. as the last step inside `AllocateMemory` or in an `AllocateDeviceMemory` called by it. That covers the 0.12 to 0.03 FPS case, because a refusal that the reclaim can satisfy never reaches host placement. Happy to rebase #6174 onto whatever order you and #6553 agree on.
GustavoGamarra95 commented 2026-10-17 20:50:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-17T20:50:29Z.


Thanks @adriadam10 for the review, and @CnRJay, @ee6aba54, @SleglJan and @parl0v for the runs, data and corrections on this PR; they made the remaining work much clearer. Sorry for the delay in getting back to this.

Rebased onto main 922dc8999:

  • MultisampleTarget.cpp: the attachment call now lives in MultisampleTarget::allocate(), so both the plain and the storable target go through AllocateAttachmentMemory.

  • DepthSurfaceReuse.cpp: dropped this PR's mapMemory/unmapMemory/destroyBuffer mocks; main already defines them. The PR no longer touches that file.

  • Tests: agc_driver_graphics, agc_driver_covered_centroid_state and agc_driver_tessellation on main 922dc8999 and on this branch 4afec5739, same Release build, Linux 7.2.9:

    Test main, lavapipe main, RTX 3050 Laptop 615.78.08 PR, lavapipe PR, RTX 3050 Laptop 615.78.08
    agc_driver_graphics pass pass pass pass
    agc_driver_covered_centroid_state pass pass pass pass
    agc_driver_tessellation pass pass pass pass

    On the PR, agc_buffer_pool*, agc_device_memory_fallback and agc_driver_depth_storage_reuse also pass on lavapipe. I couldn't reproduce the three failures. They may come from the conflicted merge (the duplicate mocks, or the old MultisampleTarget allocation path). If they still fail for you on this head, which GPU and driver did you use?

  • Beast of Reincarnation (PPSA29343): a 300 s run on this head (RTX 3050 Laptop 4 GB) had no stop, no fault and no device-memory refusal. Peak VRAM was 3169 MiB.

  • Order with #6553: #6553 is stacked on this PR (it carries these three commits and says "Depends on #5987"), so it would rebase after this one lands. @fdfawef324, does that work for you?

  • Textures and storage textures: I'd follow @ee6aba54's order. #6174 lands first and routes texture, depth copy and storage texture through BufferPool::AllocateMemory (trim the idle tiers, release sampled and clean storage images, retry device-local). This PR then rebases on it, and its host placement becomes the last step after that retry is also refused. A refusal that the reclaim can satisfy never reaches host placement, which covers the case you raised. Until #6174 lands, those three lines still fall back on the first refusal here. I'd rather not duplicate #6174's reclaim hook in this PR, since both change the same lines in Texture.cpp.

  • On the 0.12 → 0.03 FPS run: per @SleglJan's correction, that run did not carry #6465, and its slowdown matches Revalidate/DepthSurfaceTexture growth more than the host placements.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6240838687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6240838687). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-17T20:50:29Z. --- Thanks @adriadam10 for the review, and @CnRJay, @ee6aba54, @SleglJan and @parl0v for the runs, data and corrections on this PR; they made the remaining work much clearer. Sorry for the delay in getting back to this. Rebased onto `main` 922dc8999: - **`MultisampleTarget.cpp`:** the attachment call now lives in `MultisampleTarget::allocate()`, so both the plain and the storable target go through `AllocateAttachmentMemory`. - **`DepthSurfaceReuse.cpp`:** dropped this PR's `mapMemory`/`unmapMemory`/`destroyBuffer` mocks; `main` already defines them. The PR no longer touches that file. - **Tests:** `agc_driver_graphics`, `agc_driver_covered_centroid_state` and `agc_driver_tessellation` on `main` 922dc8999 and on this branch 4afec5739, same Release build, Linux 7.2.9: | Test | `main`, lavapipe | `main`, RTX 3050 Laptop 615.78.08 | PR, lavapipe | PR, RTX 3050 Laptop 615.78.08 | |---|---|---|---|---| | `agc_driver_graphics` | pass | pass | pass | pass | | `agc_driver_covered_centroid_state` | pass | pass | pass | pass | | `agc_driver_tessellation` | pass | pass | pass | pass | On the PR, `agc_buffer_pool*`, `agc_device_memory_fallback` and `agc_driver_depth_storage_reuse` also pass on lavapipe. I couldn't reproduce the three failures. They may come from the conflicted merge (the duplicate mocks, or the old `MultisampleTarget` allocation path). If they still fail for you on this head, which GPU and driver did you use? - **Beast of Reincarnation (PPSA29343):** a 300 s run on this head (RTX 3050 Laptop 4 GB) had no stop, no fault and no device-memory refusal. Peak VRAM was 3169 MiB. - **Order with #6553:** #6553 is stacked on this PR (it carries these three commits and says "Depends on #5987"), so it would rebase after this one lands. @fdfawef324, does that work for you? - **Textures and storage textures:** I'd follow @ee6aba54's order. #6174 lands first and routes `texture`, `depth copy` and `storage texture` through `BufferPool::AllocateMemory` (trim the idle tiers, release sampled and clean storage images, retry device-local). This PR then rebases on it, and its host placement becomes the last step after that retry is also refused. A refusal that the reclaim can satisfy never reaches host placement, which covers the case you raised. Until #6174 lands, those three lines still fall back on the first refusal here. I'd rather not duplicate #6174's reclaim hook in this PR, since both change the same lines in `Texture.cpp`. - On the 0.12 → 0.03 FPS run: per @SleglJan's correction, that run did not carry #6465, and its slowdown matches `Revalidate`/`DepthSurfaceTexture` growth more than the host placements. AI-assisted: yes
GustavoGamarra95 commented 2026-10-18 04:12:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-18T04:12:48Z.


Rebased onto main 2626e5e, which carries #6174 (head b3187ec).

Host placement is now the last step of BufferPool::AllocateMemory, after the pool's own recovery and #6174's cache release:

  1. trim the pool's idle tiers and retry device-local memory;
  2. release the sampled textures and clean storage images through cacheReclaim and retry device-local memory;
  3. only if that retry is refused too, allocate in a host memory type the requirements allow. The log line now carries both the bytes trimmed and the bytes released.

A refusal that the reclaim can satisfy never reaches host placement, which covers the textures and storage textures point from @adriadam10's review.

The new commit also routes every image allocation through one helper, AllocateImageMemory (renamed from AllocateAttachmentMemory). That covers textures, storage textures, block, depth and depth plane copies, render, depth and multisampled targets, and attachment proxies. Block copies and depth plane copies were not covered by #6174 and still fell back on their first refusal. They now take the same path. Context::AllocateDeviceMemory is gone.

Tests, Release build, Linux 7.2.9:

Test RTX 3050 Laptop 615.78.08 lavapipe
agc_buffer_pool (+ small_device_shared, small_device_no_staging) pass pass
agc_device_memory_fallback pass pass
agc_driver_graphics pass pass
agc_driver_covered_centroid_state pass pass
agc_driver_tessellation pass skipped
agc_driver_depth_storage_reuse pass skipped
all agc_* ctests 696/696 pass –

New ImageCacheReclaim case in agc_buffer_pool_tests:

  • a texture refused device memory releases the texture caches and stays device-local when that makes room;
  • it lands in host memory only when the retry is refused again.

It fails when the cache release is skipped before host placement.

Correction to my earlier reply: the 007 First Light data came from @SleglJan, not @CnRJay. Sorry about the mix-up.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6245534747 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6245534747). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-18T04:12:48Z. --- Rebased onto main 2626e5e, which carries #6174 (head b3187ec). Host placement is now the last step of `BufferPool::AllocateMemory`, after the pool's own recovery and #6174's cache release: 1. trim the pool's idle tiers and retry device-local memory; 2. release the sampled textures and clean storage images through `cacheReclaim` and retry device-local memory; 3. only if that retry is refused too, allocate in a host memory type the requirements allow. The log line now carries both the bytes trimmed and the bytes released. A refusal that the reclaim can satisfy never reaches host placement, which covers the textures and storage textures point from @adriadam10's review. The new commit also routes every image allocation through one helper, `AllocateImageMemory` (renamed from `AllocateAttachmentMemory`). That covers textures, storage textures, block, depth and depth plane copies, render, depth and multisampled targets, and attachment proxies. Block copies and depth plane copies were not covered by #6174 and still fell back on their first refusal. They now take the same path. `Context::AllocateDeviceMemory` is gone. Tests, Release build, Linux 7.2.9: | Test | RTX 3050 Laptop 615.78.08 | lavapipe | |---|---|---| | agc_buffer_pool (+ small_device_shared, small_device_no_staging) | pass | pass | | agc_device_memory_fallback | pass | pass | | agc_driver_graphics | pass | pass | | agc_driver_covered_centroid_state | pass | pass | | agc_driver_tessellation | pass | skipped | | agc_driver_depth_storage_reuse | pass | skipped | | all agc_* ctests | 696/696 pass | – | New `ImageCacheReclaim` case in agc_buffer_pool_tests: - a texture refused device memory releases the texture caches and stays device-local when that makes room; - it lands in host memory only when the retry is refused again. It fails when the cache release is skipped before host placement. Correction to my earlier reply: the 007 First Light data came from @SleglJan, not @CnRJay. Sorry about the mix-up. AI-assisted: yes
GustavoGamarra95 commented 2026-10-18 11:19:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-18T11:19:39Z.


Rebased onto main 9f25d0bf5 (head 9f98c7c9b). A commit merged since the last rebase added a repacked copy in Texture.cpp that called vkAllocateMemory directly. It now goes through AllocateImageMemory, and so does the depth stencil copy in DepthSurface.cpp. The host placement log line now carries the cumulative MiB. The debt file records that a placed image stays in host memory for its lifetime. The description is updated: it no longer refers to Context::AllocateDeviceMemory or to #6174 as pending.

All 700 agc_* ctests pass on the RTX 3050 Laptop (615.78.08). On lavapipe, the buffer pool, fallback, graphics and covered-centroid tests pass, and tessellation and depth-storage-reuse are skipped.

Beast of Reincarnation ran 900 s on the previous head 8bb3e07e0 with no stop and no fault, at the same frame times as main. The driver refused no allocation there, so those runs show the rebase costs nothing; the numbers are in the description.

@adriadam10, the four points from your review should be covered now; could you take another look?

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249277010 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6249277010). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-18T11:19:39Z. --- Rebased onto main 9f25d0bf5 (head 9f98c7c9b). A commit merged since the last rebase added a repacked copy in `Texture.cpp` that called `vkAllocateMemory` directly. It now goes through `AllocateImageMemory`, and so does the depth stencil copy in `DepthSurface.cpp`. The host placement log line now carries the cumulative MiB. The debt file records that a placed image stays in host memory for its lifetime. The description is updated: it no longer refers to `Context::AllocateDeviceMemory` or to #6174 as pending. All 700 `agc_*` ctests pass on the RTX 3050 Laptop (615.78.08). On lavapipe, the buffer pool, fallback, graphics and covered-centroid tests pass, and tessellation and depth-storage-reuse are skipped. Beast of Reincarnation ran 900 s on the previous head 8bb3e07e0 with no stop and no fault, at the same frame times as `main`. The driver refused no allocation there, so those runs show the rebase costs nothing; the numbers are in the description. @adriadam10, the four points from your review should be covered now; could you take another look? AI-assisted: yes
GustavoGamarra95 commented 2026-10-18 11:37:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-18T11:37:16Z.


@adriadam10 when you have a moment, could you start the full build for this head (9f98c7c9b)? Only collaborators can run it:

gh workflow run build.yml --repo boykopovar/AnyPS5 --ref main --field pr=5987

Locally all 700 agc_* ctests pass on the RTX 3050 Laptop. I have not built it on Windows.

Thanks again to @SleglJan, @parl0v, @CnRJay and @ee6aba54 for the runs, data and reviews that shaped this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249449821 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5987#issuecomment-6249449821). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-18T11:37:16Z. --- @adriadam10 when you have a moment, could you start the full build for this head (9f98c7c9b)? Only collaborators can run it: ``` gh workflow run build.yml --repo boykopovar/AnyPS5 --ref main --field pr=5987 ``` Locally all 700 `agc_*` ctests pass on the RTX 3050 Laptop. I have not built it on Windows. Thanks again to @SleglJan, @parl0v, @CnRJay and @ee6aba54 for the runs, data and reviews that shaped this PR.
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!5987
No description provided.