fix(agc): keep half the host heap out of the host import budget #6472
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6472"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ahir061 on 2026-10-15T16:35:00Z.
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_budget7465 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:The budget now keeps the larger of 2 GiB and half the largest host heap out of it.
HostImportBudgetholds the arithmetic soagc_driver_graphicscan 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_MIBstill 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,hostImportBudgetTestsfails 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.mainalone aborts earlier on this card (device memory, #5961), so the runs use a local branch:maina5e2a80c6+ #5998, #6340, #5987, #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:vkAllocateMemory buffer: allocation=196083712 memoryType=3 reclaimed=0 released=1048576 initialResult=-2 attempts=2APS5_HOST_IMPORT_MIB=4096The 3052 s abort took the same path: heap 1 full, then a 187 MiB buffer sent to the BAR heap.
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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T16:44:44Z.
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.
main)docs/dev/debt/libSceAgcDriver.mdL181core/libs/prx/libSceAgcDriver/tests/Graphics.cppL5831docs/dev/debt/libSceAgcDriver.mdL181core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppL79Some 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.
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-15T16:52:12Z.
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
vkAllocateMemoryreturn -2 here; at 6,400 MiB and below we haven't.Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T20:26:24Z.
Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with d46210a6e merged into main
44df21632:Graphics.cpppass, including the newHostImportBudgetchecks inagc_driver_graphics.HostImportBudgetis new in this PR, so the test doesn't link without it (undefined symbol: AgcDriver::Graphics::HostImportBudget).AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by SoRadGaming on 2026-10-19T04:54:43Z.
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
676d42396plus 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:
The refused range falls back to a copy, and
AddressCopyOverflowmakes 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). WithAPS5_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:
APS5_ADDRESS_COPY_MAX_MIBretry 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.
Imported from boykopovar/AnyPS5. Originally posted by Sevthered on 2026-10-19T14:40:35Z.
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
main5eba12d6b, 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 at0x10ca000000, 1434 MiB at0x324618000and 3232 MiB at0x1000000000before its first frame (17 s in), and not enough of that is evictable yet, so the refusals start at the third one (lines from runr-M1):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: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. WithAPS5_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 onmain, 2 on the reverted build), and every run reaches the title screen; live imports peak at 12.4 GiB. Onmain82f0c9aecof 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)