fix(agc): copy a sparse descriptor heap only up to its last backed byte #2992
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2992"
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 CnRJay on 2026-10-10T20:03:31Z.
What
PPSA28416 (STAR WARS: Galactic Racer, UE5) binds a 4 GiB GPU heap of which 528 MiB is committed.
GuestBufferMemorycopies a sparse region whole, so every dispatch that binds it allocates 4 GiB and fails:A sparse region that is copied (not imported, not mirrored) is now copied only up to the later of its last committed byte and the start of its last descriptor view (plus 4 bytes), rounded up to 256 bytes:
Region::lastViewkeeps the greatest view start merged into the region;Region::bufferEndis the end of the shorter copy.Descriptorclamps a view's range to the copy and throws if the view starts past it.addressRangeends the BDA range at the copy, so an address past it faults, as an uncommitted page does.The cut is safe for descriptors: every descriptor access in the generated SPIR-V is bounded by
OpArrayLength(EmitMemoryElementInBounds), so the part past the copy reads 0 and drops stores, which is what uncommitted pages give.Tested
Windows 11, WinLibs GCC 15.2.0 r7, Release, RTX 4080.
agc_driver_graphics(sparseHeapTestsinBdaResources.cpp): a 64 MiB reservation with its first 64 KiB committed, with device memory limited to 4 MiB. A descriptor build binds it whole: the view is 64 KiB, the copy holds the committed bytes, and a GPU store is written back. An address-based build with a second view at +1 MiB: that view is bound and reads zeros, the copy ends 256 bytes past it, and the BDA range is clamped to the copy. Without the fix it fails withvkAllocateMemory buffer: Vulkan result -2.ctest -R "^agc_driver_graphics$|^agc_driver_bda|guest_agc": 4/4 pass. Full suite: 717/717 pass (6 VideoOut tests skipped, as onmain).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 (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-10T22:00:19Z.
Linux cross-test of ab6104be. Setup: CachyOS (kernel 7.2.9, GCC 16.2.1), RTX 3080 (NVIDIA 615.71.09), Release.
Merged onto
main262c0316, SPIRV-Tools onIt merges cleanly. Full suite: of 711 tests, 706 pass, 4 are skipped and 1 fails.
agc_driver_graphics(withsparseHeapTests),agc_driver_bda_deviceandagc_driver_bda_span_reads.video_out_flip_*tests, under ctest's offscreen SDL driver.agc_driver_dcc_keys_first_write, a known failure on this machine (#2767). Neither PR touches it.007 First Light (PPSA11386)
On
main, 007 stops earlier (#2523 row 4), so this was tested on the 007 stack from #2523: Scramblrrrr's 79dd488f with local commits, SPIRV-Tools off, default asynchronous draws, one 240 s run each.An earlier trace on the 75e319f5 stack from #2523, which has the same
GuestBufferMemorycode, showed draw builds copying one or both of two sparse 512 MiB regions whole into new host-visible buffers, about 1 GiB per build. On 79dd488f without this PR, available memory falls from 33.8 to 6.1 GiB within 7 s, and my watchdog stops the title.With ab6104be cherry-picked:
vkAllocateMemoryerrors orwhat(). The cold cache compiles 2,194 shader variants, and none logscould not be prepared.Combined with #2283 there's no jump either: the lowest available memory is 27.2 GiB. With both applied, #2283's
CopiedBytes()counts a copied region asregion.end - region.begin, so a region cut here atbufferEndis counted at its full size. The full table is in #2523.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-11T01:03:39Z.
Windows combined cross-test: #2992 ab6104be + #2283 55b09c0f + buffer-only entry checks 0280ac32, integration cf6de015 (parent ed73f788). The four selected Vulkan-required tests pass on RTX 5070 Ti: graphics including sparseHeapTests, recorded kept bytes, recorder budget, host-import unmap.
I reproduced the shortened-copy accounting interaction reported by @SleglJan and pushed a minimal follow-up:
github.com/Scramblrrrr/AnyPS5@cf6de015.CopiedBytes()usesbufferEndwhen present instead of the original end. Two assertions cover the first committed 64 KiB and the later descriptor extending the copy to 1 MiB + 256 bytes. Negative control without the accounting change failsa cut sparse heap is charged at its reserved size; positive all four selected tests pass. Conventions pass. Windows draw-snapshot subcase remains untested here; Slegl's independent Linux run covers it.Happy for either author to fold this tiny integration follow-up with authorship preserved, depending on merge order. No competing sparse/accounting PR. The next 007 run is using cf6de015; results pending. AI-assisted (Codex).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:21Z.
Conflicts with main in
GuestBufferMemory.cppandBdaResources.cpp; please push the rebased commit from #3167 here. With #2283 merged,CopiedBytes()still counts a cut region asregion.end - region.begin; it should stop atbufferEnd.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-11T01:20:53Z.
Merged current
maininto the branch (a fast-forward push, no force) and took the rebased cut from #3167 as the conflict resolution inGuestBufferMemory.cppandBdaResources.cpp.CopiedBytes()now stops atbufferEndfor a cut region.agc_driver_graphicspasses on Windows (MinGW, Release). This leaves a merge commit, so say if you would rather have it as a rebased branch and I will do that on your word.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-11T01:41:59Z.
Linux re-test of dda893dc merged onto
maind31b57a4, which already has #2283. Setup: CachyOS (kernel 7.2.9, GCC 16.2.1), RTX 3080 (NVIDIA 615.71.09), Release, SPIRV-Tools on.agc_driver_graphics,agc_driver_recorded_kept_bytes(with the draw-snapshot subcase running),agc_recorder_kept_bytes,agc_host_import_unmap,agc_driver_bda_deviceandagc_driver_bda_span_reads. Full suite: of 755 tests, 750 pass and 4 are skipped (video_out_flip_*, under the offscreen SDL driver). One fails:agc_driver_dcc_keys_first_write, which is known on this machine (#2767) and not touched by this PR.CopiedBytes()charge. With it set back toregion.end - region.beginon this head,agc_driver_graphicsstill passes. @Scramblrrrr's cf6de015 adds two assertions toBdaResources.cpp(a cut sparse heap is charged at its reserved size/... does not include its last view). Applied on top of this head, they pass 3/3 with the charge. With the charge set back, the test fails at the first one,a cut sparse heap is charged at its reserved size. @CnRJay, the charge came in with your merge resolution. Cherry-picking cf6de015's two test lines, as Scramblrrrr offered with his authorship kept, would put a test on it.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T02:03:58Z.
Windows run on two more GPUs: Windows 11, WinLibs GCC 15.2.0 r7, Release, head merged onto
maind31b57a4alone, RTX 5060 Laptop and the Arrow Lake iGPU (ANYPS5_GPU=Intel).agc_driver_bda_deviceandagc_driver_bda_span_reads(BdaResources.cpp) pass on both GPUs.agc_*tests: 339/339 on the RTX 5060. On the iGPU the only failures are the ones that also fail on plainmainthere (listed on #2114 and #3207).It doesn't merge together with #3167 (same files), so I ran it alone.
AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T05:05:41Z.
Yes, please rebase and force-push; the branch shouldn't carry a merge commit. While you're there, take the two assertions from Scramblrrrr's cf6de015: as SleglJan showed, nothing fails when the
CopiedBytes()charge is set back.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:14:53Z.
Checked on the PR merged onto current
main(which now has #2283): scoped build + ctest of libSceAgcDriver, 354/354 pass.agc_driver_graphics(sparseHeapTests) fails without the change, so it pins the cut.What I added, as one linear commit on top of
main(net diff of your branch, merge commit dropped; it conflicted withmainafter #2283):CopiedBytes()from @Scramblrrrr's cf6de015 (co-author credited). Setting the charge back toregion.end - region.beginpassedagc_driver_graphicsbefore; now it fails.Also confirmed by @SleglJan (Linux, RTX 3080) and @Scramblrrrr / @Silverash-i8 (Windows, RTX 5070 Ti / 5060 / Arrow Lake iGPU). The game itself (PPSA28416) is not verified here.
#3167 touches the same files and will need a rebase after this lands. Merging once CI is green.