fix(agc): place the presentation source in host memory when device memory runs out #10807

Merged
milescoviello merged 1 commit from upstream-pr/10807 into main 2026-10-26 00:34:03 +00:00
milescoviello commented 2026-10-25 02:09:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-25T02:09:56Z.


What

Forspoken (PPSA03984) on main stopped once at 118 s with:

[gpu] driver failure: AGC graphics: vkAllocateMemory presentation source: Vulkan result -2
[videoout] presentation failed: AGC graphics: vkAllocateMemory presentation source: Vulkan result -2
terminate called after throwing an instance of 'std::runtime_error'

That run was on Linux, RTX 4070 Ti (12 GB), NVIDIA 615.71.09, with about 2.3 GB of the card held by other processes on the machine. The title fills the device-local heap (on that card it already reports device-local heap 0 uses 9164 of its 9164 MiB budget for textures), so when the presentation source image was recreated, its vkAllocateMemory returned VK_ERROR_OUT_OF_DEVICE_MEMORY. PresentationScaler::EnsureSourceImage asked for device-local memory only and threw, and the presentation failure terminated the title. Any card whose device-local heap the title fills can hit this.

How

  • PresentationScaler::EnsureSourceImage picks the source's memory type with Context::DeviceMemoryType, as textures do: a device-local type while the heap's budget has room, else a host type. It takes the memory from the buffer pool's image path (AllocateImageMemory). On a refused device-local allocation that path reclaims cached pool memory first, then falls back to host memory through RefusedDeviceMemoryFallback.
  • release() gives the memory back with ReleaseImageMemory instead of vkFreeMemory. The scaler keeps the allocation's size and memory type for that.
  • Nothing else changes: the black image, the blits and the uploads are as before.

Overlap (tools/pr_overlap.py and git merge-tree of each head with this one):

  • tests/PresentationPass.cpp: #9508 adds its GpuHeapEnabled() block right after residentPresentTests(device->GetContext()) in main, where this PR adds sourceImageOutsideDeviceMemoryTests(device->GetContext()). #7642 and #10193 carry that block through #9508. #10507 adds its own test call there, and #10043 adds helpers just before main, where this PR adds its allocation-refusing wrappers. Each resolves by keeping both sides, with this PR's call above the heap block.
  • PresentationScaler.cpp: #10194 changes the same two lines (the source's allocate and free) to MemoryAccounting::Allocate / Free. With #10194, BufferPool::AllocateMemory, TakeImageMemory, PutImageMemory and ReleaseImageMemory record the accounting themselves, so the merge keeps this PR's AllocateImageMemory / ReleaseImageMemory and drops #10194's two calls; proposed on #10194.

Tested

Linux (Ubuntu 26.04.1, GCC 15.2, Release, RTX 4070 Ti, NVIDIA 615.71.09) unless noted.

  • Red/green: agc_driver_presentation_pass gains a case that gives the scaler a context whose vkAllocateMemory refuses every device-local memory type. It requires the source image to be created, at least one device-local refusal, and the image's memory to come from a host heap. With the test alone on main (7d24e61d28) it fails 3 of 3 with the title's message, AGC graphics: vkAllocateMemory presentation source: Vulkan result -2. With this change it passes 3 of 3, and the pool logs vkAllocateMemory presentation source: memory type 1 is out of device memory for 16384 bytes ...; placed in host memory type 0. The case skips on a device with no host memory type for the image.
  • Focused tests: the 8 tests matching presentation|buffer_pool|^agc_driver_graphics$|display pass 3 of 3. On the Windows 11 VM (GT 1030, driver 582.78, WinLibs GCC 15.2.0 r7) the same 8 pass 3 of 3 on the merge base and on this head. The new case runs there too (memory type 7 refused, placed in host memory type 1).
  • Khronos validation 1.4.363 over the same 8, each arm run as VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R "$R" -V -j4: 8 of 8 on main bd8e13428a and on this head, no layer-missing line, no VUID- message on either.
  • Forspoken (PPSA03984 01.020.000), warm, 16 GB cap, 250 s runs:
    • main 2e22b67032 plus a local diagnostic that only records VK_EXT_device_address_binding_report events: 2 of 15 runs stopped as quoted above (at 118 s and 115 s).
    • This PR: 6 runs. 4 ran to the limit; 2 were stopped by my 16 GB host-memory cap at 218 s and 86 s (the second while a backup of the VM was writing). None stopped on the presentation source. The fallback also didn't trigger in these runs (no presentation source line), so they show nothing regressed, not the fallback in the title.

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. Merge order only: this PR goes before #7642 and #10043 (agreed by EagleBearerYS) and #10507 (agreed by orezraey). I proposed the same order on #9508, #10193 and #10194, whose authors have not answered yet. Whichever goes second keeps both sides, as Overlap describes
  • Fixes: none
  • Unblocks: none (the stop above, Forspoken PPSA03984, when the device-local heap is full)
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 615.71.09, Ubuntu 26.04.1; NVIDIA GeForce GT 1030, driver 582.78, Windows 11 VM
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5001032376 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10807). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-25T02:09:56Z. --- ### What Forspoken (PPSA03984) on `main` stopped once at 118 s with: ``` [gpu] driver failure: AGC graphics: vkAllocateMemory presentation source: Vulkan result -2 [videoout] presentation failed: AGC graphics: vkAllocateMemory presentation source: Vulkan result -2 terminate called after throwing an instance of 'std::runtime_error' ``` That run was on Linux, RTX 4070 Ti (12 GB), NVIDIA 615.71.09, with about 2.3 GB of the card held by other processes on the machine. The title fills the device-local heap (on that card it already reports `device-local heap 0 uses 9164 of its 9164 MiB budget` for textures), so when the presentation source image was recreated, its `vkAllocateMemory` returned `VK_ERROR_OUT_OF_DEVICE_MEMORY`. `PresentationScaler::EnsureSourceImage` asked for device-local memory only and threw, and the presentation failure terminated the title. Any card whose device-local heap the title fills can hit this. ### How - `PresentationScaler::EnsureSourceImage` picks the source's memory type with `Context::DeviceMemoryType`, as textures do: a device-local type while the heap's budget has room, else a host type. It takes the memory from the buffer pool's image path (`AllocateImageMemory`). On a refused device-local allocation that path reclaims cached pool memory first, then falls back to host memory through `RefusedDeviceMemoryFallback`. - `release()` gives the memory back with `ReleaseImageMemory` instead of `vkFreeMemory`. The scaler keeps the allocation's size and memory type for that. - Nothing else changes: the black image, the blits and the uploads are as before. **Overlap** (`tools/pr_overlap.py` and `git merge-tree` of each head with this one): - `tests/PresentationPass.cpp`: #9508 adds its `GpuHeapEnabled()` block right after `residentPresentTests(device->GetContext())` in `main`, where this PR adds `sourceImageOutsideDeviceMemoryTests(device->GetContext())`. #7642 and #10193 carry that block through #9508. #10507 adds its own test call there, and #10043 adds helpers just before `main`, where this PR adds its allocation-refusing wrappers. Each resolves by keeping both sides, with this PR's call above the heap block. - `PresentationScaler.cpp`: #10194 changes the same two lines (the source's allocate and free) to `MemoryAccounting::Allocate` / `Free`. With #10194, `BufferPool::AllocateMemory`, `TakeImageMemory`, `PutImageMemory` and `ReleaseImageMemory` record the accounting themselves, so the merge keeps this PR's `AllocateImageMemory` / `ReleaseImageMemory` and drops #10194's two calls; proposed on #10194. ### Tested Linux (Ubuntu 26.04.1, GCC 15.2, Release, RTX 4070 Ti, NVIDIA 615.71.09) unless noted. - **Red/green:** `agc_driver_presentation_pass` gains a case that gives the scaler a context whose `vkAllocateMemory` refuses every device-local memory type. It requires the source image to be created, at least one device-local refusal, and the image's memory to come from a host heap. With the test alone on `main` (`7d24e61d28`) it fails 3 of 3 with the title's message, `AGC graphics: vkAllocateMemory presentation source: Vulkan result -2`. With this change it passes 3 of 3, and the pool logs `vkAllocateMemory presentation source: memory type 1 is out of device memory for 16384 bytes ...; placed in host memory type 0`. The case skips on a device with no host memory type for the image. - **Focused tests:** the 8 tests matching `presentation|buffer_pool|^agc_driver_graphics$|display` pass 3 of 3. On the Windows 11 VM (GT 1030, driver 582.78, WinLibs GCC 15.2.0 r7) the same 8 pass 3 of 3 on the merge base and on this head. The new case runs there too (memory type 7 refused, placed in host memory type 1). - **Khronos validation** 1.4.363 over the same 8, each arm run as `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R "$R" -V -j4`: 8 of 8 on `main` bd8e13428a and on this head, no layer-missing line, no `VUID-` message on either. - **Forspoken (PPSA03984 01.020.000), warm, 16 GB cap, 250 s runs:** - `main` 2e22b67032 plus a local diagnostic that only records `VK_EXT_device_address_binding_report` events: 2 of 15 runs stopped as quoted above (at 118 s and 115 s). - This PR: 6 runs. 4 ran to the limit; 2 were stopped by my 16 GB host-memory cap at 218 s and 86 s (the second while a backup of the VM was writing). None stopped on the presentation source. The fallback also didn't trigger in these runs (no `presentation source` line), so they show nothing regressed, not the fallback in the title. ### 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. Merge order only: this PR goes before #7642 and #10043 (agreed by EagleBearerYS) and #10507 (agreed by orezraey). I proposed the same order on #9508, #10193 and #10194, whose authors have not answered yet. Whichever goes second keeps both sides, as Overlap describes - [x] Fixes: none - [x] Unblocks: none (the stop above, Forspoken PPSA03984, when the device-local heap is full) - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 615.71.09, Ubuntu 26.04.1; NVIDIA GeForce GT 1030, driver 582.78, Windows 11 VM - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 02:13:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T02:13:42Z.

Review: COMMENTED


I reviewed the fallback path and test. The host-memory fallback is exercised by injecting a device-local allocation refusal, and the test verifies both the refusal and resulting heap class. I did not find an additional correctness blocker in the changed ownership path: the source allocation records its size/type and returns through ReleaseImageMemory. The hosted workflow has conventions/intake/report green; platform product jobs are skipped. No separate local Vulkan rerun was available here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5641111977 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10807#pullrequestreview-5641111977). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T02:13:42Z. **Review:** COMMENTED --- I reviewed the fallback path and test. The host-memory fallback is exercised by injecting a device-local allocation refusal, and the test verifies both the refusal and resulting heap class. I did not find an additional correctness blocker in the changed ownership path: the source allocation records its size/type and returns through `ReleaseImageMemory`. The hosted workflow has conventions/intake/report green; platform product jobs are skipped. No separate local Vulkan rerun was available here.
MarcZX10 commented 2026-10-25 03:03:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T03:03:27Z.

Review: CHANGES_REQUESTED


Thanks for confirming that #7642 and #10193 add the same GpuHeapEnabled() / OpenVulkanTestDevice() fixture block. Both PRs are still open, while this PR checklist remains Depends on: none. CONTRIBUTING.md requires the authors to agree which overlapping PR goes first and declare it with Depends on. Please coordinate with #7642 and #10193 and update the checklist (and have the other affected checklist(s) reflect the agreed order). I have not modified or rebased any branch. The hosted policy checks currently pass; product jobs are skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5641271197 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10807#pullrequestreview-5641271197). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T03:03:27Z. **Review:** CHANGES_REQUESTED --- Thanks for confirming that #7642 and #10193 add the same `GpuHeapEnabled()` / `OpenVulkanTestDevice()` fixture block. Both PRs are still open, while this PR checklist remains `Depends on: none`. CONTRIBUTING.md requires the authors to agree which overlapping PR goes first and declare it with `Depends on`. Please coordinate with #7642 and #10193 and update the checklist (and have the other affected checklist(s) reflect the agreed order). I have not modified or rebased any branch. The hosted policy checks currently pass; product jobs are skipped.
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!10807
No description provided.