Skip to content

fix(agc): keep half the host heap out of the host import budget - #6472

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
ahir061:fix/agc-host-import-budget-half-heap
Oct 19, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
ahir061:fix/agc-host-import-budget-half-heap

Conversation

@ahir061

@ahir061 ahir061 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Imports, type-3 mirrors and the buffers and textures placed in host memory share the driver's system memory heap. On Windows that heap is half the physical memory, so on a 16 GiB machine (heap 8128 MiB, VK_EXT_memory_budget 7465 MiB on the RX 6600 XT below) the import budget, the heap less 2 GiB, let live imports hold 6080 MiB and left about 1.4 GiB for everything else. Host buffer allocations then fell back to the 256 MiB device-local host-visible heap (no Resizable BAR) and failed:

[gpu] driver failure: compute shader 0x11d032b100: AGC graphics: vkAllocateMemory buffer slab: allocation=2097152 memoryType=2 reclaimed=0 released=0 initialResult=-2 attempts=1: Vulkan result -2

The budget now keeps the larger of 2 GiB and half the largest host heap out of it. HostImportBudget holds the arithmetic so agc_driver_graphics can check it: 16 GiB machine 4064 MiB (6080 before), 32 GiB 8 GiB (14 before), 64 GiB 16 GiB (30 before); heaps of 4 GiB and less keep the 2 GiB reserve. APS5_HOST_IMPORT_MIB still overrides it. Imports past the budget retire the least recently used ones as before; in the runs below no import was refused.

Tested

  • agc_driver_graphics (Windows 11 26200, GCC 15.2.0 UCRT, Release, BUILD_TESTING=ON): passes. With the old 2 GiB reserve put back, hostImportBudgetTests fails with "imports on a 16 GiB machine take more than half its 8128 MiB host heap".

  • python tools/check_conventions.py --base upstream/main: passes.

  • Marvel's Wolverine PPSA03671 01.001.005, Windows 11, Ryzen 7 5800X3D, 16 GiB RAM, RX 6600 XT 8 GB (AMD 26.9.2), --windows. main alone aborts earlier on this card (device memory, Marvel's Wolverine (PPSA03671) on an 8 GB card: storage images cycle ~5.4 GB through the 2 GB storage cache, and evicted images stay alive until device memory runs out #5961), so the runs use a local branch: main a5e2a80 + fix(agc): include retained storage images in recorder budget #5998, perf(agc): reuse eligible image table entries independently #6340, fix(agc): place device memory in host memory when the driver refuses a device-local allocation #5987, fix(agc): release the texture caches when a device allocation runs out of memory #6174, plus a local storage-cache budget of 4 GiB (APS5_STORAGE_CACHE_MIB=4096). The 464 s run and the 600 and 1500 s runs predate a commit that makes two texture creation logs debug-only (a separate PR); every other run has it. Only the import budget differs:

    import budget runs result
    default before this PR, 6080 MiB 2 aborted after 464 s (the error above) and after 84 s, before the first frame, in the host heap itself: vkAllocateMemory buffer: allocation=196083712 memoryType=3 reclaimed=0 released=1048576 initialResult=-2 attempts=2
    default with this PR, 4064 MiB (the branch plus this commit, no override) 1 no abort in 904 s (stopped at the time limit), 40 frames, about 13 s per frame
    APS5_HOST_IMPORT_MIB=4096 4 no abort in 600, 1500 and 900 s; the fourth, of 60 minutes, aborted after 3052 s (below)

    The 3052 s abort took the same path: heap 1 full, then a 187 MiB buffer sent to the BAR heap.

    [gpu] driver failure: compute shader 0x11d0323c00: AGC graphics: vkAllocateMemory buffer: allocation=196083712 memoryType=2 reclaimed=0 released=0 initialResult=-2 attempts=1: Vulkan result -2
    

    The imports stayed within the budget then, and none was refused. Heap 1 had filled with storage textures that the full device-local heap placed in host memory: [gpu] storage texture: device-local heap 0 uses 6583 of its 6583 MiB budget, 3670016 bytes placed in host memory type 1; 524288 such allocations, 1507919 MiB. That placement has no host-heap budget of its own; it is a separate topic, not in this PR.

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
  • Unblocks: none on its own; on PPSA03671 Marvel's Wolverine (PPSA03671) #5516 (16 GiB machines, with fix(agc): include retained storage images in recorder budget #5998) it removes the early abort above, not the later one under Tested
  • GPUs tested: AMD Radeon RX 6600 XT, AMD proprietary driver 26.9.2, Windows 11 26200
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

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 6646 docs/dev/debt/libSceAgcDriver.md L181
PR 6647 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp L5831
PR 6958 docs/dev/debt/libSceAgcDriver.md L181
PR 7292 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp L79

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 1191 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 1324 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 1395 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 2434 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 4040 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 4650 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 5021 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 5058 docs/dev/debt/libSceAgcDriver.md
PR 5372 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 5441 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5499 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 5500 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5925 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6177 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6185 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6186 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6188 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6194 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6223 docs/dev/debt/libSceAgcDriver.md
PR 6235 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6273 docs/dev/debt/libSceAgcDriver.md
PR 6280 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6292 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6300 docs/dev/debt/libSceAgcDriver.md
PR 6412 docs/dev/debt/libSceAgcDriver.md
PR 6457 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6479 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6481 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6498 docs/dev/debt/libSceAgcDriver.md
PR 6523 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6529 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6535 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6543 docs/dev/debt/libSceAgcDriver.md
PR 6548 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6549 docs/dev/debt/libSceAgcDriver.md
PR 6563 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6567 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6571 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6615 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6636 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6639 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6683 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6727 docs/dev/debt/libSceAgcDriver.md
PR 6730 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6762 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6786 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6808 core/libs/prx/libSceAgcDriver/tests/Graphics.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 6946 docs/dev/debt/libSceAgcDriver.md
PR 6947 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6966 docs/dev/debt/libSceAgcDriver.md
PR 6970 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6972 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6977 docs/dev/debt/libSceAgcDriver.md
PR 7008 docs/dev/debt/libSceAgcDriver.md
PR 7085 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7201 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7233 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7254 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7256 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7258 docs/dev/debt/libSceAgcDriver.md
PR 7332 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7371 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7390 docs/dev/debt/libSceAgcDriver.md
PR 7432 docs/dev/debt/libSceAgcDriver.md
PR 7505 docs/dev/debt/libSceAgcDriver.md
PR 7514 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7604 docs/dev/debt/libSceAgcDriver.md
PR 7618 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7650 docs/dev/debt/libSceAgcDriver.md

@EagleBearerYS

Copy link
Copy Markdown
Contributor

Data point from Resident Evil Village (PPSA01556) on Windows 11, RTX 3070 Laptop GPU, 16 GB: main's default import budget here is 5,840 MiB. Village fills it by its title screen and keeps refusing imports (21,138 refusals in one boot), each one falling back to a CPU copy. With this rule the budget on this machine would be about 3,944 MiB. At 6,864 MiB we did see vkAllocateMemory return -2 here; at 6,400 MiB and below we haven't.

@coltken95

Copy link
Copy Markdown

Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with d46210a merged into main 44df216:

  • With the PR: all 8 tests built from Graphics.cpp pass, including the new HostImportBudget checks in agc_driver_graphics.
  • No comparison against main: HostImportBudget is new in this PR, so the test doesn't link without it (undefined symbol: AgcDriver::Graphics::HostImportBudget).

AI-assisted: yes (Claude Code)

Imports, type-3 mirrors and the buffers and textures placed in host memory share the driver's system memory heap. On Windows that heap is half the physical memory, so on a 16 GiB machine the old budget (the heap less 2 GiB) let imports hold about 6 of its 8 GiB, and host buffer allocations then overflowed into the 256 MiB device-local host-visible heap and failed. The budget now reserves the larger of 2 GiB and half the largest host heap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the fix/agc-host-import-budget-half-heap branch from d46210a to f970620 Compare October 19, 2026 02:24
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 19, 2026
@adriadam10
adriadam10 merged commit d23ed99 into boykopovar:main Oct 19, 2026
10 checks passed
EagleBearerYS added a commit to EagleBearerYS/AnyPS5 that referenced this pull request Oct 19, 2026
The host-import debt entry takes boykopovar#6472's budget sentence and keeps this branch's sentence on remembered refusals.
EagleBearerYS added a commit to EagleBearerYS/AnyPS5 that referenced this pull request Oct 19, 2026
The host-import debt entry takes boykopovar#6472's budget sentence and keeps this branch's sentence on remembered refusals.
@SoRadGaming

Copy link
Copy Markdown
Contributor

ASTRO BOT no longer boots on a 32 GiB host after this change

Windows 11, Ryzen 7 5800X3D, 32 GiB RAM, RX 9070 XT (16 GiB, Adrenalin 26.8.1). The driver's host heap is 16,345.5 MiB. ASTRO BOT (PPSA21564), on main 676d423 plus the open PRs #6188 #6273 #6292 #6503 #6566 #6609 #6615 #6617 and some local experiments, none of which change the import budget.

The budget used to be the heap less 2 GiB, 14,297 MiB here; it is now half the heap, 8,172 MiB. During the boot, the title's large registered ranges then stop fitting:

[gpu] host import budget: 8125 MiB live of 8172 MiB (APS5_HOST_IMPORT_MIB); 5 imports (9858 MiB) refused so far, last 0x33d024000+0x3c7dc000
FATAL: an address-based build copies 966 MiB of 1 registered ranges, past 64 MiB (APS5_ADDRESS_COPY_MAX_MIB); the largest: 0x33d19c000+0x3c664000 (966.4 MiB committed, outside the write-watched arena)

The refused range falls back to a copy, and AddressCopyOverflow makes that fatal, so the game aborts during the boot (here an empty-shader-cache boot, about 9 minutes in and before its first frame; I have not tried a warm-cache boot with the new budget). With APS5_HOST_IMPORT_MIB=14297 (the old budget), the same build boots without the abort and reaches the Crash Site hub, as it did before this merged.

So on hosts where half the heap is well above the 2 GiB floor, the reservation costs titles with large imports more than the 16 GiB case needed. A few options, in case they help:

  • cap the reservation (for example the 2 GiB floor plus a fixed share, not half the heap);
  • reserve half only when the heap is small;
  • or let a refused import that would exceed APS5_ADDRESS_COPY_MAX_MIB retry after the budget is trimmed instead of aborting.

Happy to test a change on this machine.

Written with AI assistance (Claude); measured on the machine above.

@Sevthered

Copy link
Copy Markdown
Contributor

A data point from a 32 GB machine where the new budget is too small for a title: ASTRO BOT PPSA21567 v01.019.000 on main 5eba12d6b, Windows 11, Ryzen 7 5800X, 32 GB, RTX 3080 Ti, NVIDIA 616.56, WinLibs GCC 15.2.0 r7. The copy is my own, from a repack folder. Relinked with that commit's relinker, libraries from the same commit, no switches, no input, 160 s from start.

With this PR the budget here is 8172 MiB, which puts the host heap at about 16.0 GiB. The title imports 2172 MiB at 0x500000000, 4608 MiB at 0x10ca000000, 1434 MiB at 0x324618000 and 3232 MiB at 0x1000000000 before its first frame (17 s in), and not enough of that is evictable yet, so the refusals start at the third one (lines from run r-M1):

[gpu] host import budget: 7737 MiB live of 8172 MiB (APS5_HOST_IMPORT_MIB); 1 imports (1433 MiB) refused so far, last 0x324618000+0x599e8000
[gpu] host import budget: 8022 MiB live of 8172 MiB (APS5_HOST_IMPORT_MIB); 5 imports (10227 MiB) refused so far, last 0x3360d8000+0x47f28000
[gpu] host import budget: 8025 MiB live of 8172 MiB (APS5_HOST_IMPORT_MIB); 19 imports (40891 MiB) refused so far, last 0x336424000+0x47bdc000

That is 3 of 3 runs on main (19 and 17 refusals by 160 s in two of them, 5 by the abort in the third). In that third run, the one with a cold shader cache, an address-based build then hit the refused range and the title aborted at 146 s, 54 s after its first frame and still in the PlayStation logo sequence:

FATAL: an address-based build copies 1148 MiB of 1 registered ranges, past 64 MiB (APS5_ADDRESS_COPY_MAX_MIB); the largest: 0x3363ac000+0x47c54000 (1148.3 MiB committed, outside the write-watched arena)
FATAL: abort() (SIGABRT) on thread 10284

With #6499 reverted on top of the same main (a local build, since #6499 merged four hours after this PR) the same abort is 2 of 2: the frames stop at 33 s, 16 s after the first frame and still in the logo, and the process exits at 50 s. So between the two merges the title did not get past the logos on this machine. With APS5_HOST_IMPORT_MIB=14336, about the 14 GiB the old formula gave on 32 GB, there is no refusal and no abort in 7 runs (5 on main, 2 on the reverted build), and every run reaches the title screen; live imports peak at 12.4 GiB. On main 82f0c9aec of 2026-10-17 the same runs never printed a budget line.

So on 32 GB the half-heap reserve takes the budget from 14 GiB to 8 GiB, and this title holds about 12.4 GiB of imports live at its title screen. Is the reserve meant to keep growing with the heap, or should it stop near the 4 GiB the 16 GB machine in this PR needed? A reserve capped there would give about 12 GiB here, which is marginal for this title, so maybe the answer is elsewhere; I can run whatever formula you have in mind on this machine.

AI-assisted: yes (Claude Code)

oneandonlydean pushed a commit that referenced this pull request Oct 19, 2026
importBudget keeps this branch's configuredBudget split and takes #6472's HostImportBudget for the default; the host-import debt entry takes #6472's budget sentence next to this branch's report and refusal sentences.
TheBlenDed pushed a commit to TheBlenDed/AnyPS5 that referenced this pull request Oct 25, 2026
…5_HOST_IMPORT_HALF_HEAP_RESERVE=1

Main's boykopovar#6472 reserves half the host heap: on this 32 GiB machine the budget drops from
14 to 8 GiB (8117 MiB), Yotei's imports reach it as the world loads (w20m-long: 9,654
imports, 1.2 GiB refused by frame 084) and the world arrives late. The half-heap
reserve (meant for 16 GiB machines) is now opt-in; HostImportBudget keeps it as its
default argument for its tests.

AI-assisted: yes
Pipodi pushed a commit to Pipodi/AnyPS5 that referenced this pull request Nov 14, 2026
…5_HOST_IMPORT_HALF_HEAP_RESERVE=1

Main's boykopovar#6472 reserves half the host heap: on this 32 GiB machine the budget drops from
14 to 8 GiB (8117 MiB), Yotei's imports reach it as the world loads (w20m-long: 9,654
imports, 1.2 GiB refused by frame 084) and the world arrives late. The half-heap
reserve (meant for 16 GiB machines) is now opt-in; HostImportBudget keeps it as its
default argument for its tests.

AI-assisted: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants