fix(agc): keep at most 4 GiB of the host heap from the host import budget #7844
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7844"
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 Mouhand-Kaddo on 2026-10-19T10:24:16Z.
What
Demon's Souls (PPSA01342) stops on
mainwhile loading into the tutorial level, right after the intro cinematic, on a 32 GiB Linux machine (RX 6900 XT, RADV):#6472 keeps the larger of 2 GiB and half the largest host heap out of the import budget. That fixed the 16 GiB machine it was measured on (heap 8128 MiB, about 4 GiB kept back). The same half also applies to larger heaps, so a 32 GiB machine (RADV heap 15911 MiB) went from 13863 MiB to 7955 MiB. With
APS5_TRACE_HOST_IMPORT, this title holds up to 10466 MiB of live imports at once while it loads the level, so the address-based build's imports are refused and the copy limit aborts.The reserve is now half the heap kept between 2 and 4 GiB:
mainHeaps up to 8 GiB keep
main's budget.APS5_HOST_IMPORT_MIBstill overrides it, and #6479 (lowering the budget aftervkAllocateMemoryfailures) composes with this: it caps the effective budget, this sets the default it starts from. #7808 rewrites theAPS5_HOST_IMPORT_MIBrow ofENVIRONMENT.md; I left that row alone to avoid the conflict. The debt entry is updated.Risk: two-way door, one constant. A machine with a host heap above 8 GiB pins more host memory for imports before the least-recently-used ones are retired. On the run below, total GTT use peaked at 12.6 of 15.9 GiB.
Tested
Linux 7.2.11 (EndeavourOS), i7-13700K, 32 GiB, RX 6900 XT with Mesa 26.2.5 RADV, GCC 16.2.1, Release,
BUILD_TESTING=ON,main36f60df9e; rebased ontomain98db77922on 2026-10-20 (only the debt entry conflicted:mainhad extended the same paragraph, so its text is kept with this PR's reserve sentence applied). Rebased again ontomain3a2c51afdon 2026-10-25: the debt entry conflicted again, becausemaindropped its sentence on address-based builds evicting (now its own "Piece-split ranges" entry), somain's text is kept with this PR's reserve sentence applied. On Windows 11 (WinLibs GCC 15.2.0, RX 6900 XT, driver 32.0.21045.16010),ctest -R agc -j 8on the rebased branch passes 1037 of 1040;agc_host_import_cut_lifetime,agc_driver_depth_plane_partial_storeandagc_driver_sample_order_grid_referencefail the same way onmain3a2c51afdthere.agc_driver_graphics(hostImportBudgetTests): with only the test change onmainit fails witha 32 GiB machine does not keep 4 GiB of its 16 GiB host heap from imports; with the change it passes. The 8128 MiB and 3 GiB cases are unchanged and still pass. Rerun on98db77922:agc_driver_graphics_testswithmain'sGuestBufferMemory.cppexits 1 with the same message, and with this PR it printsGraphics validation tests passed.agc_host_import_unmap,agc_host_import_retirement,agc_host_import_retire,agc_host_import_sparse,agc_driver_bda_anchor_reads,agc_driver_bda_span_readspass.agc_driver_bda_devicefails the same way onmainand on this branch on this GPU (an anchored BDA read differs from the same read through the lookups at anchor ...); it does not use the budget.python3 tools/check_conventions.py --base upstream/mainpasses.--to-intel, continuing a saved character (main menu → Continue → Continue Offline), 1080p (+r_Wants4K = WantsPerfin a copy of therenderconfig_ps5_*.txtfiles), no environment overrides:maine12c91357(sameHostImportBudget): the stop above while loading the level, exit 134 (one run).mainwithAPS5_HOST_IMPORT_MIB=13862(the old default): reaches the level in both runs, peak 10466 MiB live imports, no refusal.mainrun withAPS5_HOST_IMPORT_MIB=11815(this PR's value) crashed in title code while loading: a guest heap pointer had been overwritten with RGBA16F texel data. No import was refused in it, so it is a separate bug, which I'm investigating.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 LeandroLP23 on 2026-10-19T10:44:06Z.
Windows and AMD's own driver. AMD Radeon 860M (RDNA 3.5,
1002:1114), driver 32.0.13058.8001, Windows 11, WinLibs GCC 15.2.0, Release,ANYPS5_NO_SHADER_CACHE=1. Head merged intomain118266aec(clean merge). "Main's sources" means this PR's test files overmain's other files.main's sourcesagc_driver_graphicsa 32 GiB machine does not keep 4 GiB of its 16 GiB host heap from importsagc_host_import_unmap,agc_host_import_retirement,agc_host_import_retireagc_host_import_sparseAI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-19T12:10:54Z.
Review: APPROVED
Reviewed the change:
std::min<std::uint64_t>(hostHeap / 2, 4096ull << 20u)) prevents 32 GiB hosts with 16 GiB host heaps from clamping the import budget below the 10,466 MiB working set required by memory-intensive titles (PPSA24191), while preserving the 2 GiB minimum floor for smaller 16 GiB configurations.Graphics.cppexplicitly guard both 16 GiB, 32 GiB, and 15,911 MiB heap scenarios against regression.docs/dev/debt/libSceAgcDriver.mdupdated accurately.@LeandroLP23(AMD Radeon 860M) verifyingagc_driver_graphicspasses 3/3 on this head.Ready to merge.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T14:32:27Z.
AMD and Intel Windows data: with this PR's test changes,
agc_driver_graphicsfails onmainand passes with the PR, on an AMD RX 9070 XT and an Intel UHD 770.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. This head096de7f53merged intomain85029a00f. "Without" means only this PR's diff totests/Graphics.cpp, applied tomain85029a00f.tests/Graphics.cppagc_driver_graphicsfails:a 32 GiB machine does not keep 4 GiB of its 16 GiB host heap from imports; the other 28 passAI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-19T20:12:42Z.
I ran into the same thing with Ghost of Yōtei (PPSA26344) on a 32 GiB Windows laptop with an NVIDIA GPU, so here's a second data point from another title and vendor. With #6472's rule the budget there comes out at 8,117 MiB. In a warm run from a save into the open world, imports started being refused as soon as the world began loading, 171,828 of them by the end of the run, and the environment only appeared in the frame dump at 492 s. The same build with the old 2 GiB reserve put back (about 14 GiB here) refused no import in a 1,408 s run, and the same frame showed the environment at 412 s.
I haven't run Yōtei with this PR's 4 GiB cap yet; it would give about 12 GiB on this machine. Our older notes put Yōtei's import working set at around 13 GiB, so it may still refuse some here, though far fewer than at 8 GiB. If it's useful, I can run your branch and post the refusal count.
One caveat: these runs are from our local tree (a
mainfrom this morning plus our Yōtei changes), not plainmain. The two runs differ only in the reserve.Details
host import budget/refused for the host heaplines in 1,408 s; frame 88 (environment complete) at 411.6 s.Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-19T20:47:00Z.
Performance data from another title: on a 32 GiB Linux machine, #6472's budget makes ASTRO BOT about 2.5× slower, and this PR brings it back.
Setup: ASTRO BOT PPSA21567 01.019.000,
-lvl hub_crashsite, no input. Linux 7.2.10 (CachyOS), Ryzen 7 7800X3D, 31 GiB RAM, RX 9070 XT, Mesa 26.2.4 RADV (host heap 16304 MiB). Headless gamescope at 3840×2160.APS5_NO_SNAPSHOT_CHECK=1, official traceAPS5_TRACE_SECONDS=90:50, 180 s runs. Each build got a warm-up run first, and the main and override runs were interleaved.main12ee57a39, run 1main12ee57a39, run 2main+APS5_HOST_IMPORT_MIB=11815, run 1main+APS5_HOST_IMPORT_MIB=11815, run 2main+ this PR (ac03b41d4, clean merge), run 1main+ this PR, run 2What happens on
main: the scene keeps about 10.4 GiB of live imports, and the budget is 7807 MiB. Onmainthe log ends with7797 MiB live of 7807 MiB; 32 imports (51260 MiB) refused. The refused ranges then take device-local memory. VRAM use climbs to ~12.2 GiB of the 14.4 GiB budget, and the sampled texture cache drops to its 2048 MiB floor while the level holds ~2.5 GiB of sampled textures. So textures are evicted and recreated continuously, the same thrash @mrfelek measured in Sky Garden on #357. With this PR, VRAM use stays around 9.7 GiB, and the texture cache keeps 4.2 GiB under a 5.6 GiB budget.How I found it: Crash Site went from p50 124 ms on
aff725bf6(2026-10-16) to 251 ms on1e774a3b2. Rerunning the old build today still gives 126 ms, so the host is not the cause. A first-parent bisect narrowed it to the 25 merges betweenfd2ef7e28(114 ms) and8687da6c0(249 ms), which include #6472. I stopped the bisect there because of the override result above: the budget alone accounts for the whole slowdown.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-20T19:59:12Z.
Follow-up on the first level, Sky Garden (
-lvl underwater_aerial_garden), same machine and builds as my comment above (Linux, RX 9070 XT 16 GB / RADV Mesa 26.2.4, 31 GiB RAM, ASTRO BOT PPSA21567 01.019.000). Headless, no input, level start, official traceAPS5_TRACE_SECONDS=90:50, warm caches.main12ee57a39main+ this PR, run 1main+ this PR, run 2main+ this PR +APS5_TEXTURE_CACHE_MIB=4096(2 runs)main+ this PR +APS5_HOST_IMPORT_MIB=15000mainis about 3.3× slower than with this PR (~1.2 FPS against ~3.9 FPS).main, two for the PR.Tested and written by Claude (AI assistant) on a contributor's machine.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T04:47:34Z.
Windows data point for
2af7b9bfbmerged ontomain9f4ddf7cf(clean,git merge-treerc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release.ctest -N -R '^agc_driver_graphics$'lists exactly that one test;ctest --no-tests=error -R '^agc_driver_graphics$'was run three times per tree.core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpprestored tomain(the new test cases kept): fails 3 of 3 (ordinary test failure, not a crash).Not tested: other platforms, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-22T10:20:37Z.
Sky Garden on today's
main, same machine as above (RX 9070 XT 16 GB, RADV Mesa 26.2.4, 31 GiB, now CachyOS kernel 7.3.0), same setup (-lvl underwater_aerial_garden, headless, no input,APS5_TRACE_SECONDS=90:50, warm caches).At the default budget (7807 MiB here), Sky Garden lands at random in one of two states, on the same build:
main3aa35dc01tod6eafa54dmaind6eafa54d+ this PR (incl. + #9514)306bb17a2gave 808 ms and then 5466 ms. Its child6bd669e40gave 726 ms and 692 ms. So this is not a regression of a merge, and a bisect over this range follows the noise. (My own one pointed at a Bluetooth exports PR, which ASTRO BOT never imports.)0x10ca000000+0x120000000), and both leave the sampled texture cache at its 2048 MiB floor, with device-local usage around 13.0–13.6 of 15.3 GiB. What differs is the GPU time per present, ×4 in the slow state. That is consistent with the copied ranges and the floored texture cache sometimes pushing the device-local heap past what the kernel keeps resident, but I haven't proven that.So my 829 ms for
mainon 2026-10-20 was one sample of the fast state. In the runs above, the default budget costs ASTRO BOT 2.5× in the fast state and up to ×20 in the slow state.Tested and written by Claude (AI assistant) on a contributor's machine.
AI-assisted: yes