fix(agc): select coherent buffer heaps using available budget #4446
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4446"
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 Scramblrrrr on 2026-10-12T11:51:40Z.
What
Coherent host buffers prefer a cached memory type even when its heap's reported available budget cannot cover the allocation. Select a compatible type on another heap before allocating, using VK_EXT_memory_budget; keep every required property and memoryTypeBits restriction.
The check uses the full slab allocation size for pooled buffers. It keeps the preferred type when budget information is unavailable, when it has room, or when no suitable alternate heap has room. Explicit HOST_CACHED and DEVICE_LOCAL requirements remain required. The existing upstream BufferPool allocation/error behavior is preserved; this revision adds no allocation retry after an error. An alternate CPU-visible device heap can make CPU reads slower, so it is selected only when the preferred heap has insufficient reported budget.
This replaces the earlier post-failure fallback, following maintainer review. Rebased base: main
88107b7de6. Head: 9528749cde0fa295a1280516024b2c5a89721523 (0a3f392c2 selection change plus allocation-level regression tests).Tested
Validation on Windows / RTX 5070 Ti / Release GCC / SPIRV-Tools OFF:
510a2188c: removing only the production budget selection while retaining tests makes both selection and real Buffer allocation cases fail; buffer-pool control passes. Restored production passes all three.5d50886ee: five native controls pass; parent compile mismatch is not counted as a production negative.The older 007 integration's allocation failure motivated the investigation, but it is not current-main evidence. Independent Windows title evidence by EagleBearerYS: Resident Evil Village on main
18c438b10plus its required open patches, same save/inputs and warm cache, one run per side. Without this PR, one 8 MiB allocation first failed with -2 and succeeded after existing pool reclamation; with it, no allocation failed and compatible type 5 allocations were used. Heap 1 at title screen was 7,485 vs 7,236 MiB (reported budget 7,237 MiB); title-screen time 138 vs 131 s. This is integration-stack, single-run evidence, not a clean-main A/B or an established FPS improvement. Details: https://github.com/boykopovar/AnyPS5/pull/4446#issuecomment-6152703302 . Game OOM recovery is not established. This remains a draft pending maintainer assessment of the generic change and relevant title evidence. No integration stack, title code, assets, or captures included.Related: #4108 (image budget selection), #290 (host import/pool allocation behavior).
Checklist
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T12:49:19Z.
First observed runtime use of the alternate-heap path, on the older 007 integration artifact f8956bece/SHA61BF39CB (same production code as diagnostic027090d37; standalone PR4446 itself has not been staged): after original type3 allocations fail with -2, logs show recovery for58720256bytes and75497472bytes on memoryType4/originalType3, reclaimed0, attempts2. This is the compatible device-local host-visible/coherent heap on this RTX5070Ti. Same run separately recovers18MiB/16MiB allocations after trimming/retrying on original type3. Uses existing APS5_HOST_IMPORT_WINDOW_MIB=16, host-import budget6144; no other executable change. This supports the recovery mechanism on real allocations, not an FPS/playability claim or a proof that all OOMs are fixed. Current run still has known unsupported runtime-table operations and high retained memory. No title data uploaded. AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T13:11:10Z.
Acknowledged #4472 overlap. Its production change reads the VRAM budget and changes Put's retention of released device-tier buffers; #4446 changes allocation failure retries for ordinary coherent host-visible buffers. They are separate mechanisms and neither requires the other. The reported conflict is the shared BufferPool mock fields/test registration; it should be resolved by retaining both test sets, not dropping either. I have reviewed #4472's mock diff but have not built the combined heads yet, so this is source-level compatibility only. My next game cross-test is the collaborator's merged-hull/sparse-index stack; I will keep any VRAM-budget performance experiment separate. AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T14:29:00Z.
Source-level compatibility branch prepared for #4446 head55e666483 and #4472 head2d90e03e3: https://github.com/Scramblrrrr/AnyPS5/tree/codex/buffer-fallback-vram-budget-cross-test head89329b39b26b1b50550a694e9773768a0d51acaa. The two conflicts were only the mock fields and test registrations in tests/BufferPool.cpp; both sets are retained. Production merges cleanly. Conventions pass. Not built/staged yet, while the separate007 ordering test runs; will report combined native checks afterwards. This remains separate from the game shader/mapping integration, with no FPS claim. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T14:45:45Z.
Combined native validation is now complete for head89329b39b26b1b50550a694e9773768a0d51acaa: #4446 head55e666483 + credited #4472 head2d90e03e3. Both conflicting mock-field groups and both test registrations are retained. Fresh build of the pool, graphics and draw-cache fixture targets; agc_buffer_pool, agc_driver_graphics, agc_driver_draw_cache_reuse and _off pass4/4 in5.50s on Windows11/RTX5070Ti. Conventions pass, worktree clean. No game staging or FPS/memory-gain claim from this combination. Branch: https://github.com/Scramblrrrr/AnyPS5/tree/codex/buffer-fallback-vram-budget-cross-test . This confirms the shared test-file overlap can be resolved without dropping either mechanism's checks. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:20:18Z.
BufferPool::AllocateMemoryallocates again, with a memory type on another heap, aftervkAllocateMemoryhas failed (core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp:60-73). Retrying after an error isn't allowed here: choose the memory type before allocating, from the heap'sVK_EXT_memory_budgetbudget and usage as #4108 now does for images, and keep the throw.Which title fails this allocation on main? The 2359296000-byte failure in the description is from an older integration stack.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T01:00:00Z.
Agreed: the current post-failure retry does not follow the requested allocation policy. I will revise it to select an eligible coherent heap from its budget/usage before allocating, retaining the allocation error rather than retrying it, following #4108's approach.
The quoted2359296000-byte failure is from the older007 integration described in this PR; I do not have a demonstrated title failure on current main. I will keep those claims separate and have moved this PR back to draft while preparing the revision and focused selection tests. The earlier native retry tests do not validate the requested budget-selection policy. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T01:16:08Z.
Source-only requested budget-selection revision is prepared on current main510a2188cf4ea505dd58b3d5fc80ae3af2680c38: https://github.com/Scramblrrrr/AnyPS5/tree/codex/buffer-budget-selection-current-main head1590dbe5c95438cbed9ceea5abad72240502ee3f. Unbuilt/untested yet; waiting for the separate007 comparison to end, so no build/tests compete with it. Conventions/diff checks pass.
Context::BufferMemoryType keeps the existing cached coherent preference when it fits or budget information is unavailable. When the preferred heap's reported headroom cannot fit the allocation, it selects another allowed heap/type satisfying all required flags and with enough reported headroom. Default cached preference can yield to an eligible uncached coherent type; explicitly required cached/device-local flags remain mandatory. Slab placement uses the full slab block size, and its key is created for the selected type. BufferPool::AllocateMemory is unchanged from main; none of this revision contains the additional post-failure alternate-heap retry. The existing allocation error handling remains.
Twelve selection cases added to the existing device-memory-placement fixture cover exact fit, budget overflow, allowed masks, same-heap types, noncoherent alternatives, explicit device-local/cached constraints, unreported/insufficient budgets and unavailable queries/devices. Native and production-negative validation still pending. No current-main title failure demonstrated; original older-stack evidence stays historical. Keeping #4446 draft and its old branch unchanged until this revision is validated. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T01:40:51Z.
Revised this draft to pre-allocation budget selection as requested. New head 4c291ba4c, base main
510a2188c. The earlier post-error alternate-heap retry is gone; required flags/memoryTypeBits remain enforced, slab selection budgets for the full slab, and unavailable budget data preserves the original preference. Existing upstream BufferPool behavior is unchanged.Selection, buffer-pool control, and full mocked graphics tests pass (3/3, 5.69 s). Removing only production selection makes the helper and allocation-level regressions fail; restoring it passes. The real Buffer cases verify a single request to the selected type for both a 2 MiB slab backing a 512-byte buffer and a direct 3 MiB allocation, including allocation failures. Conventions pass.
Still no current-main title failure established. I rewrote the title/body around the final change and kept it draft rather than presenting the older integration failure as current-main evidence.
AI-assisted (Codex).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T05:21:17Z.
Conflicts with main in
core/libs/prx/libSceAgcDriver/tests/Graphics.cppafter today's merges there (#2121, #2132, #3471, #3633, #4206); please rebase before marking it ready.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T05:41:58Z.
Acknowledged, thanks. I have resolved the current-main conflicts locally on base
88107b7de: the sparse-buffer-holes CLI mode and our independent buffer-budget-placement mode are both retained. Local rebased head is 9528749cd; production budget-selection behavior is unchanged. Scoped conventions/diff checks pass. I am holding the PR branch update until the rebased native checks finish; they will run after the current isolated 007 test, to avoid concurrent build/test load. It remains draft, and the lack of a demonstrated current-main title allocation failure still applies. AI-assisted (Codex).Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T06:01:37Z.
Rebase now validated and pushed: 9528749cde0fa295a1280516024b2c5a89721523 on main
88107b7de6. Preserved both CLI modes in the Graphics.cpp conflict. Windows/GCC15.2/Release: selection, buffer pool, full mocked graphics 3/3 PASS 5.67s; focused real-allocation placement and sparse-buffer-holes control PASS. Scoped conventions/diff checks pass, source clean. Earlier negative controls remain tied to their original base in the updated description. Production selection behavior is unchanged; still draft, with no established current-main title failure or 007 FPS/OOM claim. No current-main build library staged into the game. AI-assisted (Codex).Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T12:05:25Z.
Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with 9528749cd cherry-picked onto main
5d50886ee:agc_device_memory_fallback,agc_driver_graphics,agc_sparse_buffer_holes,agc_descriptor_pool_reset_failureandagc_compute_descriptor_layout_flagsall pass.Context.hpp/Resources.cpp, the new test doesn't compile:'struct AgcDriver::Graphics::Context' has no member named 'BufferMemoryType'Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T15:23:45Z.
Thanks for the Linux cross-test of9528749cd and the five passing controls. The compile failure with main production restored confirms the new fixture depends on the added API, but is not a runtime behavioral negative; retaining that distinction in the validation evidence. Current head remains mergeable. AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T18:46:17Z.
A title that hits this: Resident Evil Village (PPSA01556, 01.210.000), on Windows 11 with an RTX 3070 Laptop GPU (8 GB) and 16 GB of RAM (WinLibs GCC 15.2.0 r7, Release). With 16 GB, heap 1 (host-visible system memory) is 7,888 MiB, with a
VK_EXT_memory_budgetbudget of 7,237 MiB, and about 6 GiB of it are host imports atmain's default import budget.On plain
main, Village stops at its first frame (#4949). These runs are onmain18c438b10with the open pull requests it needs to get further (listed in #5169, among them #4517 and #5249) and a few local changes. They used the same save and inputs and a warm shader cache, single runs, up to the title screen after the first scene load:DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT, resizable BAR)On an older build, before #4515, #4517 and #5249 cut the per-build copies of descriptor views, the reclaim ran dry and the load stopped:
Heap 1 was then at 7,483 MiB: 6,143 MiB of imports, 1,076 MiB of dedicated buffers in type 4 (most of them per-build copies of descriptor views) and 84 MiB of slabs. I haven't run that build with this PR. With it, an allocation made while heap 1 is past its budget goes to heap 0, as in the runs above.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T19:25:16Z.
Thanks for the Windows title cross-test and exact heap/type measurements. This provides relevant title evidence that my original 007 motivation did not: same-stack Resident Evil Village runs select compatible alternate heap types without weakening required properties. I will add the result to the description as your single-run integration evidence, keeping the current-main stop and lack of a clean-main A/B explicit. No allocation retry or OOM recovery is added by this PR.
Also thanks @coltken95 for the Linux native controls. The parent compile failure is an API mismatch, rather than a production-negative result; the meaningful budget-selection/allocation negatives in the description remain the Windows controls with unchanged fixtures and only production selection disabled. AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T21:05:07Z.
Our points are met here: the heap is chosen from the budget before allocating, and the allocation failure is gone in the title run. Please mark it ready for review when you are happy with it, and it gets a full build.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:51:34Z.
Rebased onto main to resolve the conflict in
tests/Graphics.cppafter #290; no other change. Mark it ready when you want it reviewed.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:57:26Z.
Marked this ready, since both points are met and it's rebased onto main; it goes through the full build now.