feat(agc): host import windows, least-recent eviction under the budget #290
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/290"
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 MichonGoddijn231849 on 2026-10-01T21:57:56Z.
What
Split out of #167. GTA V's Story Mode load stopped at 30% with
VK_ERROR_OUT_OF_DEVICE_MEMORY, and its large heaps took the whole import budget.AcquireRegistered) imports a registered range whole. A window over its first byte does not serve it; the build replaces it.APS5_HOST_IMPORT_MIB, else the larger of 6 GiB and half the physical memory, at most the largest host heap less 2 GiB (imports and type-3 mirrors share that heap; #167's rule).main.#167 derived the budget from the system memory heap (heap minus 2 GiB). With a fixed 6 GiB, GTA V's address-based draws (after #411) needed more than the budget, and every one of them re-imported guest memory (about 25 ms per build, 6.9 instead of 10 fps).
Tested
Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.
agc_driver_graphics, each failing without its change:agc_driver_host_import_windows(windows follow their range;ClearHostImportsdrops them),agc_driver_host_import_at_map,_teardown,agc_host_import_unmap,agc_driver_bda_device,agc_buffer_pool,agc_driver_pooled_buffer_rangeandtools/check_conventions.pypass, onmain82b1b2e7a.main0214069e3(2026-10-13): the wholeagc_*suite passes on Windows (484 tests), the host import tests above included. The debt entry moved todocs/dev/debt/libSceAgcDriver.md(tools/debt_split.py resolve).main.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T00:24:43Z.
A note on host imports on Linux with NVIDIA, since this PR reworks
importAllocationand adds the out-of-memory path.On NVIDIA (RTX 4090, driver 610.57.04, Linux), a host import that the driver refuses and that is 64 KiB or smaller poisons the
VkDevice. Every later device-localvkAllocateMemoryreturns -2 (VK_ERROR_OUT_OF_DEVICE_MEMORY) while VRAM is nearly empty, and imports of good anonymous memory fail too. Host-visible allocations still succeed. A refused import of 68 KiB or more fails cleanly and leaves the device usable.A standalone probe (plain Vulkan, no AnyPS5 code) imports a read-only private file mapping and then allocates device-local memory:
VkDevicein the process, 64 MiBHow main reaches this on Linux:
importAllocationchecks pages only on Windows (theVirtualQueryloop from #186).Three parts of this PR meet that case:
retryAfterand is offered again 4096 uses later. A small import refused this way poisons the device each time it is offered.RelieveGpuMemory: after poisoning there is nothing to free. Retiring imports, trimming the pool and rerunning the draw still gets -2.What avoided it for me: on Linux, read
/proc/self/mapsfor the range before attempting an import.That is about 85 lines plus tests, and it would sit in the same place this PR changes. I can send it as a follow-up once this lands, or it can be folded in here, whichever you prefer.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-02T08:05:21Z.
Thanks for the detailed probe, that's a nasty one. I changed the two parts of this PR that made it worse:
retryAfterpath is gone; a refused import goes to the copy path for good, as onmain. Only an import of 16 MiB or more refused for memory retires imports and is tried once more, which is above the 64 KiB your table shows poisoning the device.The
/proc/self/mapscheck is Linux-only and I can't test it here, so a follow-up from you would be great once this lands.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T10:01:59Z.
Thanks, both changes look right to me. With
retryAftergone and no short tail windows, a refused small import is no longer offered again. The first refusal of an import of 64 KiB or less still poisons the device on NVIDIA, as it does on main today, so I'll send the/proc/self/mapscheck as a follow-up once this lands.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-02T16:16:17Z.
Pushed e558b8e0, a fix for a bug in this PR that I found while debugging GTA V.
A window made while a smaller import of the same allocation was still held, or a window spanning other cells than an existing one, left two live imports over the same bytes.
UnitShadow's lookups assume imports never overlap, so a write-back shadowed in one import stayed hidden from reads through the other. A cube map then read stale bytes although its faces had just been written back.A new import now takes in every import it would overlap and replaces them, and is not made while a build still holds one of them. This is the same rule this PR already applied to an import at the same base. With that invariant,
findImportis back tomain's single-predecessor lookup, and theuniqueflag is gone.Tested: GTA V with this change reaches the world and renders as before.
ctestpasses. I haven't re-run Dreaming Sarah on this commit yet.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T22:24:55Z.
A note for after this lands, so the two out-of-memory paths do not stack.
My integration branch replaces the fixed 2048 MiB budgets of the texture and storage image caches with limits from
VK_EXT_memory_budget: a soft limit per cache from the heap budget, and a hard limit from the budget's free space minus headroom. It evicts by age and never evicts a texture used in the current frame. OnVK_ERROR_OUT_OF_DEVICE_MEMORYat texture or storage image creation, it evicts every entry not used this frame and retries once. In PPSA21564 this cut texture rebuilds in a long intro run from about 52k to 3k, and took one level from 0.4 to about 2 FPS.Once this PR is merged, I plan to rebase that change so that:
AllocateGpuMemory's recovery, after the buffer pool trim, instead of a retry of its own. A texture allocation then retries with both the pool and the caches trimmed;If you would rather keep
AllocateGpuMemoryto the pool trim only, I can keep the texture retry at its call sites instead. Nothing is needed in this PR either way.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T22:32:15Z.
The Linux CI failure on d3e1f345 is in
configuredBudget(): the lambda's two returns deduceunsigned long long(strtoull(...) << 20u) andstd::uint64_t(std::max<std::uint64_t>), which are different types with GCC on Linux, soGuestBufferMemory.cppdoes not compile. Declaring the return type fixes it:static const std::uint64_t budget = []() -> std::uint64_t {.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-03T02:47:43Z.
Thanks for the build fix. I suspect the remaining Linux failure is not from this PR:
agc_driver_vopc_comparefails withthread 1 compare 39 is 0, expected 1, and compare 39 is the f16 NLE case (!(ha <= hb)) that #399 changed. The same failure shows up on unrelated PRs (#312, run 37071265405, and #407, run 37065871874), whilemainpassed at7d40a57dwith #399 in, so it looks intermittent on llvmpipe. A rerun of the linux job would likely pass.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-03T08:26:04Z.
Thanks for tracing the vopc_compare failure; I can't rerun jobs here, so I rebased onto
d3ec1f15and CI runs again. On your memory-budget plan: making the cache eviction one more step inAllocateGpuMemoryafter the buffer pool trim sounds right to me, with the draw and dispatch level recovery kept as the last resort. Go ahead once this lands.Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-03T20:34:35Z.
Test note, Linux (GCC 16.2), RTX 3070 8 GiB, 46 GiB RAM, PPSA21567. Base:
maind3ec1f15+ #285, plus a local experiment that lets one compute shader get past an unrelated record-time failure (#479). The run is not on cleanmain.vkAllocateMemory(-2) (one 3232 MiB import refused under the 6144 MiB default budget), thenvkAllocateMemory texture-2 was fatal. VRAM use was about 1.1 GiB at the time.APS5_HOST_IMPORT_MIB=2048did not help.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-03T20:43:04Z.
Thanks for testing this on Linux with an 8 GiB card; that's exactly the case the fallback is for. The refused 3232 MiB import falling back to copies instead of a fatal
vkAllocateMemorymatches what I see on Windows.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:49:50Z.
This conflicts with main after today's merges; once it's rebased I'm happy to see it in.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T08:24:30Z.
Rebased onto
main(9f9a8f5a). The only conflict was inrefreshImports:mainnow frees the old device's import buffers there, and this PR's memory-count decrement goes next to that. All 4 commits applied otherwise unchanged.ctest on Windows (RTX 5080): the same failures as on
mainhere.agc_driver_flip, and onceagc_driver, sometimes end with a heap-corruption exit (0xc0000374) underctest -j 8, and pass when run alone.mainhits the same exit inagc_driver_flipon every-j 8run I tried, so I don't think it comes from this PR.linux_entry_argvandwindows_iconfail onmainlocally too.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:51:34Z.
Thanks for the rebase. The resolution in
refreshImportslooks right to me: the old device's imports are destroyed once there, each one'sCountGpuMemorydecrement sits next to that, andliveBytesis reset with the map, so nothing is counted twice. Merged with current main it builds and passes the full ctest here. It's ready to merge from my side; since it changes how guest memory is imported for every draw, I'll run it on PPSA21564 on my integration branch first.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T10:10:25Z.
Rebased again after today's merges. #401 changed the buffer pool's free slots to keyed lists, so this PR's
BufferPool::Trimnow walks the keyed slots (a separate small commit on top). Build and ctest are clean apart from the failuresmainhas locally.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:37:47Z.
Thanks for the second rebase. The
BufferPool::Trimchange is right for #401's keyed slots: it walks every list under each key, counts evictions from the tier'sslotscounter and resets it along withretainedBytes, so the counters stay consistent withfree. The other four commits are unchanged apart from context. It's in my next PPSA21564 test batch; I'll merge after that if it passes.Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-05T01:04:20Z.
@MichonGoddijn231849 a suggestion for the relief step, from Astro Bot (PPSA21567) on an 8 GB RTX 3070. That's on oneandonlydean's
astrobotbranch, which has a sampled-texture and storage-image residency cache thatmaindoesn't.There, 3 of the 5 fatal out-of-memory stops I hit today were device-buffer allocations in dispatches (
vkAllocateMemory device buffer: Vulkan result -2, in compute shaders0x5007d2800twice and0x500797d00). The other 2 were image allocations (a storage texture in0x5005a5400, a texture in0x50740a700). On that branch, an image made through one of the caches can at most evict that one cache before retrying. At the same time, the two texture caches were holding about 4.3 GB: sampled textures 2.7 GB, sitting at their soft target of 3/8 of the memory budget, and storage images 1.55 GB. That's from a local counter onvkAllocateMemory/vkFreeMemoryby call site, with the same breakdown in two runs. Device-local memory was about 6.1 GB of 8 at that point.On that branch,
DeviceMemoryExhaustedis only caught inside texture and storage-image creation, which evict their own cache and retry. So a buffer that can't be allocated fails while idle textures stay resident, and an image allocation can only free its own cache. YourRelieveGpuMemorywould be the natural place to also evict idle entries from those caches: theirRunEvictionPasswith the exhausted policy only evicts entries not used since the current frame started, and in-flight users keep theirshared_ptr. Freeing both caches and the buffer pool together, before the retry, would cover both kinds of failure.I also checked the obvious alternative, a smaller cache instead of recovery. Lowering the sampled cache's soft target to 1.5 GB (
APS5_TEXTURE_CACHE_MIB=1536) made it worse: 2 of 2 runs stopped out of memory at the intro's texture burst around minute 6, against 0 of 2 baseline runs, and their lowest 10-second frame rate dropped from about 7.0 to 5.5-6.3 fps. The likely reason (not measured): below the scene's working set, the cache keeps evicting textures that are soon re-created, while the evicted copies are still alive. So the memory has to come back when an allocation fails, rather than by keeping the cache small. The sync and release wait your relief already does matter here: about 40-50 batches are in flight at that point, and an evicted texture's memory only returns after the batches that use it finish (the release queue itself was never backed up: 0 pending at every 10-second report).One question before anyone writes it: the relief takes
GpuMutexand would then take each cache's mutex. Do you know whether any path holds a texture cache's mutex and then waits forGpuMutex? If one does, the order would need to be the other way round, or the eviction moved outside the lock.This only matters once #290 and that cache meet, on
astrobotor if the residency cache goes upstream.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-05T15:40:58Z.
@ThisIsAkill thanks, the numbers are convincing, especially the 1.5 GB run being worse. I agree the relief is the place to free idle cache entries, and both caches plus the buffer pool together before the retry makes sense.
On the lock order, for
mainat least:GpuMutexis only taken in the driver's packet, draw and dispatch paths (Execution/src/Driver), never insideGraphics/, where the texture and storage-image caches live. So onmaina cache's mutex is always taken with the GPU lock already held, which is the same order the relief would use (GpuMutex, then each cache). The relief also only runs once the failing packet has unwound.relieveMemoryis called from the packet loop after the exception, andRelieveGpuMemoryreturns at once if the thread still holdsGpuMutex. So no cache lock is held at that point.I can't check the residency cache on
astrobot, since it isn't onmain. If any of its paths takes the cache mutex and then the GPU lock (an eviction that syncs the recorder, for example), the eviction would have to move outside the cache lock. I'd do this as a follow-up once #290 and that cache meet, rather than in this PR.Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-05T16:12:01Z.
@MichonGoddijn231849 thanks. Agreed on both points: the relief is the place to free idle cache entries, and it's a follow-up once #290 and the residency cache meet, not part of this PR.
Your concern holds on
astrobot. There, the sampled-texture lookup holds the cache's mutex while it compares guest memory, and that goes throughFlushForAccess(Recorder.cpp), which takesGpuMutex. That's cache → GPU, the opposite of the relief's order. In my local prototype I matched the branch's order: the relief evicts each cache under its own mutex while not holdingGpuMutex(it requires that it isn't held), and only then takesGpuMutexfor the sync and the release wait.What the prototype showed (PPSA21567, RTX 3070 8 GB, details and numbers on #357: measurement, fallback A/B):
So on 8 GB cards in heavy levels, eviction alone won't save the run. The working set itself is the problem. I'm measuring next how much of the sampled cache is duplicate copies of one guest surface (the cache key is the whole T#) and how much is top mips.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-06T15:48:12Z.
@ThisIsAkill thanks, that's a clear result. On 8 GB in heavy levels the working set doesn't fit, so eviction only buys time, and the system-memory fallback trades the crash for 0.1 fps. Agreed that it's beyond this PR. The duplicate measurement sounds like the right next step: if T#s that differ only in swizzle, format view or mip clamps each get their own image, one image with several views could save a lot. I'm happy to adapt the relief to whatever the residency cache ends up with once you have numbers.
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-07T13:24:14Z.
A data point from Linux for the new default budget, in case it helps.
Demon's Souls (PPSA01341 v1.07) registers just over 6 GiB of host imports by its attract movie (956 imports, 6178 MiB live). Under the current 6144 MiB default, the allocation that falls off the budget depends on registration order. In two runs it was the title's 64 MiB render target (
0x3e2300000+0x3fc0000in one of them). That range was refused again on every lookup (474 refusals, 30217 MiB, by the end of the run), and its storage image was written back through the CPU path on every queue 0x30 dispatch that hooked it, under the GPU mutex.Attract movie, per 10 s:
maindefault)APS5_HOST_IMPORT_MIB=16384write-changed)The last column is the same formula as this PR, applied locally as a one-line change to
main'simportAllocation. I have not run this PR itself. The gap between 28 and 40 fps in the last two columns is not the budget. Both runs had no refusals and no CPU write-backs, and the difference comes from indirect-dispatch recipe rebuilds that some runs show and others don't (I'll open a separate issue for that).One forced-exhaustion run (
APS5_HOST_IMPORT_MIB=6000) refused a 120 MiB allocation instead. It was asked for 173,749 times in about 130 s and the attract movie ran at 9.4-12.9 fps.A Linux-only aside on the copy path, for when eviction cannot keep a range imported: when the texels changed, most of the cost of a 64 MiB CPU write-back is userfaultfd write-protect faults. In 30 s,
GuestMemory::WriteChangedran 228 times, and 36 of those calls took 128-512 ms (about 7.3 s in total). Every one of the 568,866 page faults inside the write-back was insideWriteChanged, about one per 4 KiB page. Windows'GetWriteWatchdoesn't fault per page.Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti (595.91.07), Ryzen 5 7600X, 32 GB.
mainatc1241ad0with #157, #861, #864 and #1051, plus the path fix from #1047.I can run this PR on the title if that's useful.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T13:34:48Z.
@oneandonlydean you said on Oct 4 you'd merge this after your PPSA21564 batch; did it pass?
From our side, merged onto current
main(e79c971f9): build and full ctest pass (396/396, RADV gfx1035), CI green, no conflicts. fisherjoey's Demon's Souls numbers above back the RAM/2 default on Linux too.One nit for @MichonGoddijn231849, not blocking:
BufferPool::Trimcatches(...); catchingstd::bad_allocandstd::system_error(whatreserveand the lock can throw) keeps it from hiding anything else.Note: nothing in ctest reaches the import windows (>64 MiB ranges) or the out-of-memory retry, so those rest on the game runs.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T17:38:41Z.
@adriadam10 done in 25bc2098:
BufferPool::Trimnow catches onlystd::bad_allocandstd::system_error. Build and ctest pass.@fisherjoey thanks for the Demon's Souls numbers. The 64 MiB render target falling off a 6 GiB budget is the case the RAM / 2 default is meant for, and it's good to see it hold on Linux too.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-07T20:47:30Z.
Not yet, sorry. #290 is still in the queue for the regression run, and I haven't got a result for it. I'll post it here when I have one, and merge if it passes. Thanks for the full ctest on current main, and thanks to fisherjoey for the Linux numbers; they back the RAM / 2 default.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T07:13:15Z.
Sorry for the delay on this one. It now conflicts with main in
GuestBufferMemory.{hpp,cpp}since #943 (udmabuf import), so please rebase. Also, the out-of-memory path retries the draw/dispatch and the ≥16 MiB import once afterVK_ERROR_OUT_OF_DEVICE_MEMORY; retries after an error aren't allowed here (#182), so please throw there instead. Once it's rebased it goes to the front of the test queue.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-08T09:11:38Z.
Since you're about to rebase, here's how this PR (25bc20986) did in an hour of Ghost of Yōtei (PPSA26344 v1.008) today, plus one thing from our own merge with main's #1235 that might save you some debugging.
The run was stable: no FATAL, no
vkAllocateMemoryfailure, and no refused heap mirror in 3,600 s, so the out-of-memory retry that oneandonlydean asked about never ran. The import windows stayed at the budget the whole time (5,961 of 6,144 MiB live at the end), and 7.1 M imports were refused along the way, against 5.6 M in a 3,000 s run before. Two caveats on those numbers: we setAPS5_HOST_IMPORT_MIB=6144, and our tree carries a local patch that also counts mirrors and host buffers against the host-visible heap, so this isn't your default budget.On #1235: main's
leasedRangeOwnerandsameRangematch the registered range that starts at the import's base. A window further inside a larger range doesn't start there, so after a straight mergerefreshImportsretires all such windows on every refresh, andimportAllocationnever reuses them. What worked for us was to make both look up the readable range that contains [base, base + bytes) instead (ashared_ptrform of yourcontainingRange), and to store that inentry.range. Also, main's auto-merged "retired: the range was mapped again" trace line right after that hunk reads arangevariable, so the merge doesn't compile untilrefreshImportsdeclares it. I'm happy to share our resolution if it helps, though you'll know better how it should look.Details
Windows 11, RTX 3080 Laptop (16 GB), 32 GB RAM. Our integration tree on main
c8a2f0632+ this PR at 25bc20986, resolved against #943 and #1235, + our open PRs (including #1085) + a local host-heap accounting patch. Private bytes peaked at 37,218 MiB.Previous run (3,000 s, same budget):
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-08T16:08:54Z.
Rebased onto main. Main has since added import ownership (an import is reused only while the same registered Range still owns it) and dma-buf imports, which touched the same code, so I folded the PR into one commit on top of them:
sameRangeover the import's whole extent), so an unrelated registration no longer drops it and a remapped range's window is retired. dma-buf imports keep their own unwatch flag; the budget, least-recent eviction and the out-of-memory retry sit on top unchanged.ClearHostImports(from main) destroyed imports without uncounting them from the GPU memory totals; it does now.agc_driver_host_import_windowsreaches imports throughFillBufferand checks window reuse after an unrelated registration, retirement after a remap, and the counter. Reverting to main's exact-base refresh rule, to containment-only, or dropping the uncount each fails it.agc_driver_bda_device_testsneeded aHostImportLimitstub beside its existing stubs (it does not linkGuestBufferMemory.cpp).All 225
agc_tests pass on Windows (RTX 5080).Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:32:47Z.
Parked as a draft to keep my rebase load sane after #639. I'll rebase it when someone wants to review it.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:21:46Z.
When you rebase: the out-of-memory retry needs to go. It should throw on
VK_ERROR_OUT_OF_DEVICE_MEMORYinstead of trying again (#182):PacketExecution.cpp:62retryOutOfMemoryruns the dispatch packet a second time afterrelieveMemory;Resources.cpp:82callsvkAllocateMemoryagain afterBufferPool::Trim;GuestBufferMemory.cpp:500creates the import again after trimming and retiring.Evicting under the budget before an import is fine. The 24 new code comments need to go too;
conventionsfails on them.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T14:39:38Z.
Thanks, noted. Before this comes out of draft I will drop the retry paths (the second dispatch run in
retryOutOfMemory, the secondvkAllocateMemoryafterBufferPool::Trim, and the import retry), soVK_ERROR_OUT_OF_DEVICE_MEMORYthrows as #182 asks, keep the eviction under the budget before an import, and remove the new code comments.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T14:48:36Z.
Done in 39b87412: VK_ERROR_OUT_OF_DEVICE_MEMORY now throws everywhere (no second dispatch run, no second vkAllocateMemory after trimming the pool, no second import). After a failure the driver still relieves memory for the packets that follow, and imports are still retired under the budget before an import. The new code comments are gone, and
check_conventions.pypasses. Title and description updated to match.Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-09T16:39:01Z.
Tested on Linux with Sonic Origins (PPSA05324), merged onto the testing branch from #2021:
PacketExecution.cpp.agc_driver_host_import_windowspasses.Speed: the auto-save notice runs at about 60 fps instead of about 23, and the boot reaches it at 78 s instead of 116 s. The same settings without this PR are the baseline.
Windows over udmabuf's limit: several 128 MiB windows (
+0x8000000) failed atUDMABUF_CREATEand were copied. udmabuf's defaultsize_limit_mbis 64. With the default 64 MiB window, a window that spans two cells, or the last cell with its remainder, goes over that limit. Capping the window at the udmabuf limit on Linux may be worth it.Separate from this PR, the title screen still loses the device here. About 10 s after the notice closes:
UDMABUF_CREATEand are copied: 5000 MiB, 1126 + 873 MiB (one 2000 MB allocator) and 256 MiB. They look like the whole-allocation imports of address-based builds.Not enough memory for command submission, thenVK_ERROR_DEVICE_LOST.APS5_HOST_IMPORT_WINDOW_MIB=16doesn't change it, because these imports are not windowed.I'll add a result with a raised
size_limit_mb.Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-09T16:51:02Z.
I re-ran the same test with udmabuf's
size_limit_mbraised to 8192. Every import now succeeds, including the 128 MiB windows and the whole-heap imports. The device is still lost, though, and this time it is about the import budget.APS5_TRACE_HOST_IMPORT=1): the 5000 MiB heap, 1126 + 873 MiB, 256 MiB and a few small ranges. The nextvkQueueSubmitfails withradv/amdgpu: Not enough memory for command submission, thenVulkan result -4. That happens about 10 s after the auto-save notice closes.max(6 GiB, RAM / 2)comes to 7611 MiB. RADV's GTT heap is 7.43 GiB (also 7611 MiB), and RADV's own GTT allocations need room too. So the GTT heap runs out before the budget ever refuses an import.APS5_HOST_IMPORT_MIB=6144(the old default) refuses the 5000 MiB range, so that range goes to the copy path instead. The submit fails at the same point.A default capped by the GTT heap's
VK_EXT_memory_budgetbudget, minus some headroom, would keep the budget below what the driver can actually hold. It won't get this title to its title screen on this host, though. The address-based ranges alone need about 7.3 GB in GTT, whether they are imported or copied, so I'll try a larger GTT next (ttm.pages_limit).The failed submit returns
VK_ERROR_DEVICE_LOST(-4) here, notVK_ERROR_OUT_OF_DEVICE_MEMORY, so the out-of-memory handling from 39b87412 doesn't get a chance to run.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:14:21Z.
When you rebase: the out-of-memory retry needs to go. It should throw on
VK_ERROR_OUT_OF_DEVICE_MEMORYinstead of trying again (#182):PacketExecution.cpp:62retryOutOfMemoryruns the dispatch packet a second time afterrelieveMemory;Resources.cpp:82callsvkAllocateMemoryagain afterBufferPool::Trim;GuestBufferMemory.cpp:500creates the import again after trimming and retiring.Evicting under the budget before an import is fine. The 24 new code comments need to go too;
conventionsfails on them.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T22:09:59Z.
These are already gone on the current head (39b87412, pushed at 14:47):
PacketExecution.cpp:retryOutOfMemoryis removed; a failed dispatch or draw callsrelieveMemory(eviction under the budget) and rethrows, so the packet never runs a second time.Resources.cpp: the secondvkAllocateMemoryafterBufferPool::Trimis removed;VK_ERROR_OUT_OF_DEVICE_MEMORYthrows.GuestBufferMemory.cpp: the second import after trimming and retiring is removed.The
conventionsjob passes on that head. Did you look at an older head? It stays a draft for now. I'm keeping the number of ready PRs down until some of the current ones merge.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:16:21Z.
Yes, that was the older head, sorry; 39b87412 is right. It conflicts with main in
BufferPool.cppandResources.cppnow, so when you rebase and mark it ready it goes first in the test queue.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-10T08:23:45Z.
Thanks. The rebase is more than conflict resolution now. Since this PR's base,
maingot Celegans12's host heap budget (#1085), shared dma-buf import chunks (b7443c44) and in-place draw-buffer reads from host imports (c903d1ad), about 480 changed lines inGuestBufferMemory.cppalone. The import windows and least-recent eviction have to be rebuilt on #1085's budget instead of a second one next to it. I'm doing that today; I'll mark it ready once it builds and passes here, with GTA V checked on it.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-10T08:55:42Z.
Rebased onto
main(af1a8edf) as one commit,87091dc4, and marked ready.#1085's budget turned out to be the heap-mirror one (
APS5_HEAP_MIRROR_MIB), so the import budget doesn't duplicate it after all. What had to change for main:retireImport: takes the device now (main's signature). A retired import is still held by the active recorder while batches are in flight, so a draw that bound itsVkBufferin place (c903d1ad) keeps it until that batch completes.HostImportFor(main's in-place vertex/index path) now counts as a use. Otherwise the least-recently-used eviction would pick imports the draws read every frame.Tested on Windows, RTX 5080:
agc_*suite passes (306 of 306), includingagc_driver_host_import_windows,agc_driver_host_import_teardown, the BDA tests andagc_driver_sampled_cache_budget(_memory);check_conventions.pypasses.GTA V can't confirm it on
mainalone yet, because it stops at #1184's bindless table before gameplay. The same windows code runs on our integration branch.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T09:56:04Z.
Could you rebase this on main? It conflicts in
PacketExecution.cpp. Astro Bot on current main stops on "guest snapshot differs from registered memory", and the 6 GiB budget was part of that stop before, so this is next in line once #374/#425 are done.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-10T10:06:29Z.
Rebased onto
main(be403084), head2ab78478. ThePacketExecution.cppconflict was main's merged dispatch branch (pending waits, group look-ahead). Itsdispatch/dispatchIndirectcalls now go throughrelievingMemory(evict under the budget, then rethrow), as the two branches did before. A second commit adapts the new test to main'sMutation::Addgpuflag. The fullagc_*suite passes here (319 of 319, Windows, RTX 5080), and so doescheck_conventions.py.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T18:08:34Z.
Conflicts with main again in
BufferPool.hppandResources.cppafter765619a00b(small host buffers sub-allocated from shared blocks); please rebase. It goes to the front of the test queue after that.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-10T22:26:40Z.
@oneandonlydean rebased onto main
b65d6b71(with #1190):58ea21db+1f418944. The two conflicts were additive: main's slab path for small host buffers (765619a00b) stays first inBuffer's allocation, and the PR's countedAllocateGpuMemorytakes over the dedicated allocation after it;BufferPool.hppkeeps both the slab members and the PR'sTrim/RetainedBytes. The 324 agc tests pass on Windows (RTX 5080).Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:09Z.
Conflicts with main again in
GuestBufferMemory.cpp(#1961 now imports GPU-mapped memory when it is mapped) andResources.cpp(#2233); please rebase. It's first in the test queue once it's clean.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T07:59:36Z.
@oneandonlydean will do, later today once main has been quiet for a while (it is merging every minute or two this morning; the last rebase was stale within an hour).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T08:02:38Z.
Thank you!
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:39:30Z.
Review: DISMISSED
This conflicts with current
mainin three files, and the conflicts are not mechanical:GuestBufferMemory.cpp: #1961 (GPU-mapped memory imports) overlaps the import path this PR reworks (windows,retireImport, eviction); 9 conflicting hunks.Resources.cpp: #2233 and the shared small-buffer blocks overlap the countedAllocateGpuMemory; 3 hunks.Texture.cpp: 1 large hunk.Please rebase on
mainand re-runagc_driver_host_import_windowsand the otheragc_*tests on the rebased tree. The out-of-memory retries are gone in the current head (it throws, as #182 asks), which is what Dean asked for, and the reports on Linux (RADV) and Windows in this thread back the budget and windows. After the rebase it only needs a clean merge to go through.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T12:14:58Z.
@adriadam10 thanks, tonight once main is quiet: rebased on
mainwith #1961's GPU-mapped imports and #2233's shared small-buffer blocks merged into the windows/eviction path, thenagc_driver_host_import_windowsand the rest of theagc_*tests rerun on the rebased tree.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T14:07:52Z.
@adriadam10 rebased on
maina11c8f7f7(6dff2c5f8). TheGuestBufferMemory.cppmerge keeps main's import runs (#1961, #3425) and puts this PR on top of them:APS5_HOST_IMPORT_WINDOW_MIB(64 MiB by default) is imported in the windows the access touches. Main's window joins small adjacent ranges into runs; this window splits a big range, so the two compose. A window of an unchanged range counts as the same import when the registry is reconciled.Resources.cppkeeps main's class allocation and exact-size buffer binding next to the countedAllocateGpuMemory. Main's new depth-copy texture now allocates through it too, so live counts stay balanced.On the rebased tree (Windows, RTX 5080):
agc_driver_host_import_windowsandagc_driver_host_import_at_mappass, and 374/375agc_*tests pass. The one failure isagc_driver_emulated_color_compare, where the recompiler refuses an sRGB format this device cannot sample ("samples or gathers an sRGB image the device cannot sample"). This PR doesn't touch the recompiler or that test.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T14:12:35Z.
Correction to my comment above:
6dff2c5f8was missing three fixes from the merge (a closing brace inResources.cpp, a name clash with main'simportWindowvariable, and main's exact-startleasedRangeOwneroverload), so it did not build. The current headf7a2b5e1dhas them, and passes the conventions check (I dropped the merge's explanatory comments).On
f7a2b5e1ditself:agc_driver_host_import_windowspasses. 373/375agc_*tests pass withctest -j 4. One failure isagc_driver_emulated_color_compare, the sRGB refusal I mentioned above. The other,agc_driver_prepared_shaders_deferred, crashed once with heap corruption (0xc0000374) under the parallel run, then passed 10 of 10 runs on its own.Imported from boykopovar/AnyPS5. Originally posted by ponhei9502 on 2026-10-11T20:43:19Z.
Test report from a Linux setup with Demon's Souls (PPSA01341 v1.07), head f7a2b5e1. Caveat first: this is from a mixed tree (
maina11c8f7f+ this PR + local work: #757, #425 and others), not frommain+ this PR alone, so please treat the failure below as a lead until someone reproduces it on a clean tree. Host: CachyOS, kernel 7.3-rc, Ryzen 5 7600, RTX 3080 10 GB (driver 615.78), 32 GB RAM, title rendering 1920x1080.1. With the default 64 MiB windows the title dies in the first minute
The owner region spans about 1.5 GiB and has a direct import, and the view lies inside the region. The check that throws compares the view against
region.direct->base + region.direct->bytes. My reading (not verified with a debugger): the region's direct import is one window fromwindowRun, chosen for an earlier use, and a later view elsewhere in the same region is checked against that window's end instead of the region's. One run, reproducible on every start here.2. With
APS5_HOST_IMPORT_WINDOW_MIB=0it runs, and it is a large gainSame build, windows off, budget left at the default (15.5 GiB on this machine), retail route from launch through logos and intro to the title, 6-minute runs, title frames counted as
GetOutputStatuscalls per minute (minutes 2-5):Before, the log showed the 6144 MiB budget full within minutes and hundreds to thousands of refused imports per run. Memory charged to the process peaked at 15.2 GB and 22.2 GB in the two runs (26 GB cap, no swap), with no stall.
Not tested: a clean
main+ this PR, any other title, Windows, and long sessions.AI-assisted: yes (runs and log reading by Claude Code on the machine above).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:22:42Z.
Review: DISMISSED
Rebased head
f7a2b5e1dbuilds and passes here: libSceAgcDriver scope 387/387 on RADV, includingagc_driver_host_import_windows(it fails to compile without the change). The out-of-memory retries are gone as asked.One blocker, from @ponhei9502's Demon's Souls report above (default 64 MiB windows, dies in the first minute with
guest buffer view ... rounded up to its view range exceeds its GPU owner ... direct 1; fine withAPS5_HOST_IMPORT_WINDOW_MIB=0). Reading the code, a likely cause:AcquireRegisteredimports a whole registered range withimportAllocation(context, state, range->address, lease, 0, false)(GuestBufferMemory.cpp:2284).end == 0the early lookup isfindImport(state, address, address + 1)(:697), so any existing window that contains the first byte is returned, although the region is the whole range (region.end= range end).region.directis then shorter than the region, andDescriptorlimits the view todirect->base + direct->bytes(:3431), which throws for a view later in the range.Fix direction: when no end is given, the early hit has to cover the whole run (or the whole-range request must not be served by a window), and the retire/replace logic below it then handles the window already there.
Please also add a test that covers it: a registered range larger than the window, a window made by an earlier access, then
AcquireRegistered(address-based) and aDescriptorview in the last window.HostImportWindows.cpponly exercisesFillBuffer. Nothing in ctest reachesrelieveMemory/RelieveGpuMemoryeither; a test that forces the failure path would pin it.Smaller points:
Driver::relieveMemorydecides by parsing"Vulkan result -"out ofwhat()(PacketExecution.cpp:36-40); a typed exception or a flag set byAllocateGpuMemorywould not break if the message changes.protectedUses = 256(GuestBufferMemory.cpp:629) and the 1 s relief interval are unmeasured choices; add them under "Unknown function info"/choices in TechnicalDebt, with the numbers if you have them.docs/dev/ARCHITECTURE.mdhas no word on host imports; a short paragraph (windows, LRU eviction, relief) under the memory/import diagram would keep it true.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T22:10:05Z.
@adriadam10 @ponhei9502 thanks, the reading was right. Rebased on current
main(acc5d2949), head32a35a00f.The blocker:
importAllocationwithout an end (the whole-range import ofAcquireRegistered) now takes an early hit only from an import of the whole run. A window over the first byte no longer serves it; the retire logic below replaces that window. Requests with an end (the windowed path) keep the one-lookup fast path.Tests, both in
agc_driver_graphics(BdaResources.cpp):importWholeRangeOverWindowTests: a 128 MiB registered range, its first 64 MiB window imported by an access, thenAcquireRegisteredand aDescriptorview in the last window. It must bind in an import of the whole range. Without the fix it fails with the reported message (guest buffer view ... rounded up to its view range exceeds its GPU owner ... direct 1).importReliefTests:RelieveGpuMemoryretires an import unused for 300 lookups and keeps one used in the last 256. It fails if the protection window does not match.Smaller points:
relieveMemoryno longer parseswhat().AllocateGpuMemoryalready counts every out-of-memory result on its thread (OutOfMemoryFailures), and that count is now the only check.Rebase note:
main'sBufferPool::AllocateMemory(trim and retry once when out of memory) now owns the buffer allocations this PR counted. It now allocates throughAllocateGpuMemory, so pooled buffers and slab blocks are counted as GPU memory and out-of-memory results are counted for the relief. Slab blocks count down when freed.main's retry is unchanged.Run here (Windows, RTX 5080):
agc_driver_graphics,agc_driver_host_import_windows,agc_host_import_unmap,agc_driver_host_import_at_map,agc_driver_host_import_teardown,agc_buffer_poolandagc_driver_pooled_buffer_rangepass;check_conventions.pypasses. Currentmaindoesn't buildlibkernelon Windows (HostPollinSocket.cpp), so I applied #4021 locally for the run, not on this branch.@ponhei9502 if you can, a Demon's Souls run with the default 64 MiB windows on this head would confirm it on the title.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T05:25:18Z.
The whole-range path is fixed by reading and the points of the last review are in. A few things before this can go in:
GuestBufferMemory.cpp:2094: the map observer reachesimportAllocationwithevict = trueand without the GPU lock (Lifecycle.cpp:68). Past the budget it retires imports there:RetireShadowdrops their shadowed units (UnitShadow.cpp:773-779) andrecorder->Keepruns unlocked. Pass0, false, asAcquireRegistereddoes at:2294.GuestBufferMemory.cpp:713-727run before the refusals at:729-744. An address-based build whose whole-range import is refused (budget, orfailed) still retires the range's windows, at every build: withAPS5_HOST_IMPORT_MIB=100, a 128 MiB range and one window, 3 builds retired the window 3 times and the next access imported it again each time. Decide the refusal first and retire nothing when it refuses.windowRun(:676-693): a use that crosses a cell edge replaces the windows it overlaps. Two uses across neighbouring edges of one range retire each other's window at every use (10 rounds of both: 20 imports of 128 MiB), and the second is copied when both are in one build (:715-721). Grow to the union of the overlapped windows instead.relieveMemory(PacketExecution.cpp:35-57) runs before a rethrow that fails the driver (QueueWorker.cpp:166-169,Lifecycle.cpp:96), and VideoOut then terminates (VideoOutDriver.cpp:622). Which packet runs after it onmain? If none, please drop it withRelieveGpuMemory, the limit,BufferPool::Trim,WaitForReleases,importReliefTestsand the GPU memory counters. The counters also miss every retirement (retireImport,:216-226, never uncounts): with one 128 MiB import live they read 2816 MiB after 21 retirements.APS5_HOST_IMPORT_WINDOW_MIB: #3425 removed a variable of this name. Please make the 64 MiB a constant with a setter for the tests, likeSetHostImportWindow.APS5_TRACE_GPU_MEMORYgoes with the counters.:794-800: thecreatelambda is called once; inline it. It is also the only conflict with #2434 and one of the two with #3874.:733-744is tried at every lookup, as onmain.A test for each of the first three would fail on this head: an import at map time over the budget, an address-based build over the budget after a window, and two uses across neighbouring cell edges.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T10:09:55Z.
Preparing a Windows/RTX 5070 Ti 007 cross-test of #290 current head 32a35a00f, preserving your three commits/authorship: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-host-window-cross-test head 4e4083057. This is source-only, not built or staged yet; an unrelated quiet FPS test is still running.
Base is our older public-perf/cache-preserving sparse stack plus AlxcBTW's #4385 port a5c0c9a36. One include conflict and an architecture-text conflict resolved; omitted unrelated newer MSAA documentation not represented by this older stack. Tiny local integration commit adapts import accounting to #4385's extracted-node holder and our old immediate device-change path. No new upstream PR or duplicate implementation.
For the first game comparison I will explicitly keep APS5_HOST_IMPORT_MIB=6144 (our current budget), rather than raising it to the new physical-RAM default: the 32 GB host already hits the free-physical-RAM guard during campaign loading while GPU dedicated memory is only ~8 GB/16 GB. Native window/retirement and existing sparse/copy checks come first. No game improvement claim yet. AI-assisted: Codex. No title data uploaded.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T10:17:23Z.
Host-window cross-test 4e4083057 is built/staged on Windows/RTX 5070 Ti: graphics SHA256 605581D6247E0DC376D7BB0364ECD1F2A24454E26E056093A9D856DCA74B949D. Native six-test set passed 6.86 s, no skips: host_import_windows, host_import_retire, graphics (includes split-heap written/copied-read/owner replacement/growth/gap and #3248 overlap cases), bda_device, draw_cache_reuse ON/OFF. Source-only preparation/port details in prior comment remain applicable; not full current-main/full suite.
Quiet 007 run now started with APS5_HOST_IMPORT_MIB=6144 explicitly and APS5_TRACE_GPU_MEMORY=1 (one category report per 10 seconds, not broad profiling), same other modules/cache/bounds. This branch is a5c0c9a36 + #290, and does NOT carry the separate #4410 delay experiment. Next will record rendered FPS and campaign memory/stop; no improvement claim yet. AI-assisted: Codex. No title data uploaded.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T10:24:08Z.
Host-window stack 4e4083057 / SHA605581D6 reached fully rendered title frame858 ~1.61 FPS, ~20.08 decimal GB private, one bounded trim. Prior cc495 control title ~1.57; #4410 experiment ~1.61. One sample each/different camera/timing, so no demonstrated meaningful speed or resident-memory gain from #290 yet.
New coarse category trace at this stage is roughly: host imports 5575 MiB (~579 imports), host buffers 0.6 GiB, sampled textures and storage images each ~2 GiB, depth surfaces levelled near624 MiB/130 allocations, shadow slabs ~404 MiB. GPU dedicated use is ~7.7–8.1 GB of16.3 GB. Depth retention is unbounded in this older source, but the observed startup levelled off; I am not calling it this campaign's leak/cause. Moving through offline menu; will inspect available game graphics settings, record changes if any, and check campaign loading. Lazy snapshot #3991 is prepared separately a33e1e5fc, not built/staged. AI-assisted: Codex. No title data uploaded.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T11:12:33Z.
007 Windows cross-test on older #290 port efcd89969 hit a terminal buffer OOM: allocation2359296000, memoryType3, reclaimed627897488, initialResult=-2, attempts2. GPU sample~7585MiB of16303MiB. A read-only physical-device query confirms type3 is host-visible/coherent/cached on system heap1, while type4 is host-visible/coherent/device-local on heap0. maxMemoryAllocationSize is UINT64_MAX. Thus VRAM-use alone does not diagnose the failing heap.
I found #2809 and #4108; this is a different direction from #4108's texture fallback. Preparing a source-only buffer fallback on https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-buffer-allocation-fallback . After existing trim/retry, ordinary coherent host buffers may try ONE allowed memory type on a different heap, preserving pNext/device-address flags and required properties. No same-heap retry, no fallback on device loss, no explicit cached-property relaxation, no slab/device-buffer change. Mock tests prepared for success, exhausted fallback, incompatible types/coherence, same heap, device loss, flags/mapping and cleanup. NOT built/tested/staged yet; ongoing game remains isolated IR probe7a91759e4. No competing upstream PR. Will offer the tested commit after the quiet run, if it passes. AI-assisted: Codex. No title data uploaded.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T11:22:30Z.
IR probe7a91759e4/SHA70E13C rendered title at frame872
1.68FPS/private19.26 decimalGB (later verified frame8921.76). Cold cache due recompiler source fingerprint: no valid warm-start speed comparison. Campaign Resume proceeded to2896 misses/2895 writes, then terminated withAGC driver: registered program refers to an incompatible shader binary type. Final private21.91GB, WS0.26GB/free5.44GB after four bounded trims. GPU sample8014MiB/16303MiB. Runtime table unsupported faults still occur at pc0x54 and0x80. Earlier 2.36GB allocation failure did not recur before this different stop; that is not proof it is fixed. No visible gameplay; black loading screen. Exact rejected/expected types missing from this diagnostic, so added a rejection-only message in fork codex/first-light-shader-kind-diagnostic f8956bece (no admission change).Also carries source buffer fallback f06d93ce2: after trim/retry, ordinary coherent host buffers may try one compatible different heap, preserving required properties and device-address flags. Six native tests pass11.61s/no skips: buffer_pool, driver, graphics, sampled_cache_budget, draw_cache_reuse ON/OFF. Disabling the constructor fallback makes the new regression checks fail (CTest exit8); restored implementation passes. WIP tested on older integration, not current-main/full-suite. Staging f8956bece/SHA61BF39CB795089AD8D94DA1BD8D31C06E01ABA468F521426763ECF903A054027 for next guarded run. Coordination offered on #290; no duplicate upstream PR. AI-assisted: Codex. No title data uploaded.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T11:52:07Z.
Latest warm-cache combined run (artifact f8956bece, SHA61BF39CB; diagnostic branch is now027090d37 after subject-only correction, source code identical) exited during campaign loading without a normal fatal log. Windows Application Error/WER confirms native heap corruption0xc0000374 at08:32:29 local, PID15216, ntdll detection point. Final private19.47 decimalGB/WS10.30/free5.09; GPU7993MiB/16303; only one bounded trim. Cache2625 hits/0 misses/0 writes. No logged fallback recovery or deferred-table failure before this earlier exit, so no evidence that the new fallback was exercised or caused it. Earlier cold IR run ended later with the registered-type rejection. Keeping dump local; investigating actual stack/objects, not blaming ntdll or claiming a cache bug from this alone.
Standalone buffer fallback on current main is now PR #4446, head55e666483/base3d8ffeb27. Four native tests pass5.29s/no skips; constructor fallback disabled gives failing regressions (CTest exit8), restored passes. Conventions including PR template pass. This is independently buildable and carries no 007 stack. No game/FPS fix claim. Offered integration to #290 author earlier. AI-assisted: Codex. No title data uploaded.
Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-12T15:14:43Z.
A 16 GiB data point for the budget part. ASTRO BOT (PPSA21564, 01.007.000) on Windows 11, RTX 4070 Laptop (8 GiB VRAM, NVIDIA 616.92), 16 GiB RAM, unmodified
main33ae282e(after #4281), WinLibs GCC 15.2.0 r7. The driver reportsMemory heap 1 size=7808.4 MiB(host, memory types 0/2/3), i.e. half of RAM.APS5_HOST_IMPORT_MIB(6144): after about 150 s of loading,host import budget: 4483 MiB live of 6144 MiB; 2 imports (7808 MiB) refused so far, last 0x1000000000+0xc8000000. The fallback then fails:heap mirror of 0x1000000000+0xc8000000: vkAllocateMemory buffer: allocation=3355443200 memoryType=3 ... initialResult=-2 attempts=2. Earlier it had also refused0x10c8000000+0x120000000(4608 MiB).APS5_HOST_IMPORT_MIB=16384: the large imports go through, and then imports themselves start failing in the driver:host import of 0x3018dc000+0x11ca4000 failed at vkAllocateMemory (-2); falling back to copies. Even a 298 MB mirror of that range then fails the same way.So on this machine neither setting fits. The limit is the host heap of about 7.8 GiB, which imports and type-3 mirrors share. Two things that seem to matter for the windows and eviction here:
I can rerun Astro Bot against a rebased head of this PR on this laptop when there is one.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-12T16:27:14Z.
@oneandonlydean thanks, all of it was right. Rebased on
main82b1b2e7a, head5857f9eb5:importAllocationdecides every refusal before it retires anything: alignment, a failed run, a held import, and the budget counting what may be evicted. The test makes 3 address-based builds over the budget after a window; the window stays the same import.windowRungrows the cells a use touches to the union of the range's imports it overlaps. The test does 10 rounds of two uses across neighbouring edges, each in its own build, and both share one import.mainruns after it, so it is gone, withRelieveGpuMemory, the limit, theBufferPool::Trim/WaitForReleasesadditions, the relief test and the GPU memory counters (andAPS5_TRACE_GPU_MEMORYwith them). The counters' missing uncount on retirement goes with them.SetHostImportRangeWindow(andSetHostImportBudget) for the tests.createlambda is inlined.@AchrafReyani thanks for the 16 GiB data point. The default budget is now capped at the largest host heap less 2 GiB (#167's rule), so on your laptop it comes to about 5.8 GiB instead of 8. That leaves room in the shared heap for type-3 mirrors. Windowing the mirrors too is a good idea, but it's a separate change from this PR. A rerun of Astro Bot on this head would show whether the cap is enough there.
@ponhei9502 the default 64 MiB windows should work on this head; a Demon's Souls run with them would confirm it.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T03:47:05Z.
Thanks, the three fixes hold here: each new test fails when its fix is reverted, and the relief, the counters, the two variables and the lambda are gone. Still open on 5857f9eb5:
mainindocs/dev/ARCHITECTURE.mdanddocs/dev/TechnicalDebt.md. The debt entry now goes indocs/dev/debt/libSceAgcDriver.md. The code merges with #4385 without a conflict, and the merged tree passes theagc_*tests here (460 of 460).evictable(GuestBufferMemory.cpp:654-656) protects the last 256 lookups and a frame makes thousands, so windows that are all used in every frame retire each other every frame. A 3D title we test with holds 12.3 GiB of imports; the same tree with and without this PR, level parts in ms per frame over the same frames:At 8192 MiB two windows replace each other for the rest of the level (
0x101c000000+0x4000000and0x10a0000000+0x4000000in turn, about 20 imports a second, 8188.6 MiB live), and each one moves the import epoch:Four windows do the same for the first 30 s of the title (1,200 imports). Without the PR the import is refused and the set stays as it is. At 5760 MiB, which is what the new cap gives the 16 GiB laptop above, it settles: 77 imports, 42 refusals, every build from the cached space, same speed as without. An import that is used in every frame shouldn't be evicted for another one; refuse the new import there, as
maindoes.:801removed, or withevictablereturning false, every test passes. One that would also pin the point above: three ranges under a budget for two, the third looked up 300 times between alternating uses of the other two. On this head 10 rounds make 19 imports.:779because the first one's window is held, and it is copied at every build (10 of 10). The new test puts each use in a build of its own.:703: with a host heap of 2 GiB or less the cap is skipped and the budget is 6 GiB or more.A 2D title we test with passes on
main+ this head, also withAPS5_HOST_IMPORT_MIB=128.Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T12:04:03Z.
Test note, Windows, Demon's Souls (PPSA01342), the loading screen after the opening cinematic.
Setup. Windows Server 2025, RTX 3060 12 GB (driver 32.0.15.9186), Ryzen 9 5900X, 32 GB, MinGW-w64 GCC 15.2. Base: an integration branch on
mainfc1f063f5plus local merges, not cleanmain. This PR's two commits (5857f9eb5) were cherry-picked onto it. NoAPS5_HOST_IMPORT_MIB, so the new default applies. Here it is 14286 MiB: half of physical memory is 16335 MiB, and the cap is the 16335 MiB host heap less 2 GiB.Rebase. Applying the two commits onto current
main(c8eb1f52d) conflicts in three files, and one technical-debt entry has to move. The integration branch hit the same, and I resolved them like this:GuestBufferMemory.cpp,struct HostImports: #3874 removedimportsStampPagesanddmaBufImportsStampPages. Keep them removed and adduseCounterandbuildFloor.GuestBufferMemory.cpp,ImportMappedRanges: #4017 addedif (!GpuMutex().HeldByThisThread() && wouldRetireImport(...)) return false;before the import. Keep that line, then this PR'simportAllocation(context, state, range->address, current, 0, false). The map observer then neither replaces nor evicts without the GPU lock.docs/dev/ARCHITECTURE.md: #425 added the depth-plane bullet at the same place. Keep both bullets.docs/dev/TechnicalDebt.md: #4411 moved library entries todocs/dev/debt/. The "Host import windows and budget" entry goes after the "Host imports" entry indocs/dev/debt/libSceAgcDriver.md, with links one level deeper (../../../core/...). Left inTechnicalDebt.md, the entry failscheck_conventions.py'sdebt-filerule.With those resolutions,
check_conventions.pypasses. These tests pass:agc_driver_graphics, which includes this PR's four newBdaResourcescases;agc_driver_host_import_windows, which ran here (it was not skipped);agc_driver_host_import_at_map,agc_driver_host_import_teardown,agc_host_import_unmap,agc_parked_import_unmap,agc_host_import_retirement,agc_host_import_retire,agc_unit_shadow;agc_driver_bda_device,agc_buffer_pool,agc_driver_pooled_buffer_range;agc_driver_sampled_cache_budget(also_memory),agc_driver_storage_cache_budget,agc_driver_unimported_label_order,guest_buffer_reuse.Run. Three runs on the same base and input script:
APS5_HOST_IMPORT_MIB=12288host import budgetlines0x383700000+0x7800000again and againThe "at least 180 s" comes from the 19 budget lines, which are printed at most once per 10 s.
APS5_PROFILE_DRAW=1was set for this run only. Presents per 10 s after the cinematic: 59, 33, 11, 3, 7, 2, 11, 11. The two runs without the PR had no draw profile, and the 12 GiB run shared the machine with a build. The frame rates are therefore not an exact A/B.BPE JobWorkerThreadstack. That looks like #361, not this PR. None of them got past the black loading screen.So on this title the PR does what the larger budget does: no refusals, and the loading screen at about 1 FPS instead of 0.1. The eviction path itself was not exercised here.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T13:41:06Z.
A data point from a 16 GB machine, in case it helps size the default: Resident Evil Village (PPSA01556, 01.210.000) on Windows 11 with an RTX 3070 Laptop GPU (8 GB) and 16 GB of RAM. Windows exposes 7,888 MiB of system memory as the host-visible heap (memory type 4, heap 1).
The title stops loading its first scene, on a local branch past its earlier stops:
Same scene, the same build otherwise:
main's default)APS5_HOST_IMPORT_MIB)So on 16 GB, this PR's budget and eviction are not enough for this scene. The imports and the copies of what is not imported compete for the same 7,888 MiB. The GPU process used 6.3-7.5 GB of shared memory and 1.6-2.0 GB of its 8 GB of dedicated memory at those points. A 32 GB machine would have about twice the heap. I have not tested one.
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T16:22:05Z.
A follow-up with GTA V (PPSA04264) Story Mode, the case in this PR's description. Same machine as my note above. The base is an integration branch with the open tessellation and image-table PRs GTA V needs to reach its menu. I cherry-picked this PR's two commits onto it.
APS5_HOST_IMPORT_MIB=12288host import budgetlines during the Story Mode loadAGC graphics: sample masks are unsupportedon the first gameplay framesSo for this title the PR's default budget does what raising the budget by hand does, and the load no longer runs out of imports. As in the Demon's Souls runs, I can't tell whether eviction ran or the larger default was simply enough. No budget line was printed.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-13T16:25:27Z.
Rebased onto current
main(0214069e3). The conflicts weremain's new retire guard before the import inAcquireRegistered, which is kept with this PR's call, and the debt split; the entry is now indocs/dev/debt/libSceAgcDriver.md. Theagc_*suite passes on Windows (484 tests), including the host import tests.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T18:00:05Z.
A heads-up for anyone combining this PR with the bind join (#4515, now on main, and #4517). The budget-first replace loop in
importRunAtrefuses a join whose new import would replace imports that the build in flight already holds. The join then fails silently, and the joined run is CPU-copied for the rest of that build. The join PRs' own tests don't see it, because they run without this PR's loop.Minimal scenario (
importJoinTestsintests/BdaResources.cpp):HostImportFor; both import fine.AcquireRegistered(), thenAddReadable(second - 16, 32), thenUpload(true). The join pre-pass runs before any region confirms an import and wants to replace both imports.pointerHeld(...)for them and returnsnullptr. The check "a buffer bound across two adjacent ranges larger than the import window was not imported as one" fails.A retired import stays alive through the retire-hold, and
UploadFinishre-resolves every pointer after the pre-pass. So refusing a join for held overlaps isn't needed.Fix (5 lines): a join no longer counts a held overlap as a reason to refuse.
github.com/AlxcBTW/AnyPS5@74e78fa5aSeen in practice:
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T18:46:27Z.
An update to my data point above: with #4517 and #5249 cutting the per-build copies, the scene now loads at
main's default 6 GiB import budget. Heap 1 still ends about 250 MiB past its budget, and #4446 moves that overflow to video memory (numbers: https://github.com/boykopovar/AnyPS5/pull/4446#issuecomment-6152703302).Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T20:37:29Z.
Windows legacy-integration cross-test of the budget-first import replacement in canonical #290 head7f3fed864e77d0ec84e48d499bc08b39f206d2fd: author-preserved adaptation163c10711, final fixture/control corrections75c85dd5 andcd70602fafcdf27af41825b2ac9d7f6dc6fa0740. Public branch: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-import-budget-preservation . Our olderc990 adaptation retired overlaps before deciding whether a whole-range replacement fit; this port retains the existing adaptive cap and already-carried joined-held rule equivalent to AlxcBTW74e78fa5a. It does not duplicate the whole PR or claim current-main coverage.
Restored final8/8 controls PASS7.26s, Windows Release/GCC15.2/RTX5070Ti, Vulkan required: mocked graphics including the refused-whole-range window preservation fixture; BDA device; unmap/retirement; imported/copied sparse runs; alias handover/memory. Production-only negative restores only importRunAt from9ac345d4f, retains identical fixture plus budget/range-window controls: graphics FAILS exactly "an address-based build refused its whole-range import and retired the range's window (build0)"; BDA control PASSES. Positive restored/rebuilt, source/conventions clean.
Two fixture-adaptation attempts are not counted as negatives: first confused join-window and range-window controls and never created the intended window; second omitted the binding path's GPU mutex and cleanup masked the expected assertion with a deferred-import pin. Corrected fixture holds that mutex, matches the canonical range-window control, and produces the exact assertion above with old production. No skipped tests/full-suite/Linux claim.
Starting matched patched graphics/Agc/VideoOut atcd70602fa with existing3864 libc, same1GiB budget and bounded memory guard as previous title trial. No title RAM/FPS improvement claimed yet. AI-assisted: yes (Codex); synthetic code/aggregate results only, no title data attached.
Imported from boykopovar/AnyPS5. Originally posted by ultraacademy657-dot on 2026-10-13T20:39:13Z.
Windows/NVIDIA: large host-memory import fails with both compatible memory types
I tested a local experimental AnyPS5 build based on commit
488d08f20on Windows, using an NVIDIA RTX 3080 and 16 GiB of system RAM.The diagnostic trace showed that two smaller host imports succeeded before a larger registered allocation of approximately 6544 MiB failed:
compatibleTypes=0x00000018 memoryType=3 result=-2
compatibleTypes=0x00000018 memoryType=4 result=-2
Both compatible memory types returned
VK_ERROR_OUT_OF_DEVICE_MEMORY(-2). Retrying with another compatible memory type did not resolve the allocation failure.In an earlier run, the subsequent whole-range heap-mirror allocation also failed with Vulkan result
-2.The latest test was deliberately stopped by a safety guard after approximately 13 seconds, when available physical RAM fell to 2.31 GiB. This was a forced safety stop, not a spontaneous process exit.
These results rule out the memory-type selection order as a sufficient fix for this case. They do not establish the complete root cause or demonstrate a working solution.
No game files, executables, or log files are attached. The findings above are limited to the local diagnostic results.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T01:57:32Z.
Rebased onto main
52d134c02and pushed here (maintainer edit), keeping your two commits, so this can go in. The conflicts were the bind joins (#4515, #4517):importAllocationkeeps main's joined hit and passesend, evictthroughimportRunAt,sameRangekeeps both rules,HostImportForstill returns a joined import for a lookup across ranges, and inUploadFinishthe per-region import isimportAccess, which only returns an import that covers the region, so main's partial-cover check there is no longer needed. The two stamp flags #3874 removed are gone again.With the joins on main,
importJoinTestsfailed on this branch ("a buffer bound across two adjacent ranges larger than the import window was not imported as one"), so @AlxcBTW's 74e78fa5a is on top.agc_driver_graphics, the host import, budget, write-watch, buffer and BDA tests pass here (RTX 4090, NVIDIA Linux; 43 of 43).The import set now settles at 8192 MiB in the 3D title from my earlier note: 146 imports in the run, 6 epoch rebuilds. Please check it still passes on Windows.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T02:24:11Z.
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)core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL174, L2102core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppL37core/libs/prx/libSceAgcDriver/tests/BdaResources.cppL327, L1324-1325core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL712-713, L737-745