fix(agc): bound a strided buffer's rounded-up last record by its allocation #2912
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2912"
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 TheAggie on 2026-10-10T18:24:40Z.
What
RADV rounds a strided buffer descriptor's record count up, so
stride * recordscan run up to one stride past the end of the buffer's allocation. That range then no longer fits inside the allocation's host import, andGuestBufferMemorycopies it on the CPU, whole, on every draw that binds it.RetroArch's Dolphin core (PPSA99169) does this on every draw:
0x4009200000+0x3000000, with stride 20 andrecords = 0x266667;0x300000c, 12 bytes past the allocation;host import of 0x4009200000+0x3000000 ok), but the descriptor's range isn't contained in it;APS5_PROFILE_DRAWshows14000 copied regions on the CPU: ... 14000 outside imports (672000 MiB)after about 60 s, all of them this one range;copyRegion→GuestMemory::Read→memmove.The fix: when a strided descriptor ends less than one stride past the end of the readable registered allocation that contains its base, the range is bound up to the allocation's end.
RegisteredReadableEndsits next toRegisteredReadableCoversinGuestBufferMemory.Tested
agc_driver_graphics(BdaResources.cpp,stridedOverhangTests) binds a stride-20 descriptor over a registered 32 KiB allocation with the record count rounded up. It checks that the bound range ends at the allocation, and that a descriptor inside its allocation keeps its length. With theShaderResources.cppchange reverted, the test fails witha strided buffer's rounded-up last record was bound past its allocation.agc|shader|recompiler|guest|bda: 553 passed, 1 skipped, 1 failed. The failure isguest_memory, which fails the same way onmainhere (CheckGuestModuleImageProtection'sdlopen).mainalone yet. This measurement is from my integration branch: amainfrom 2026-10-07 plus my open PRs, #423 and local changes, with this commit cherry-picked unchanged.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T22:09:56Z.
Ran 9a469b0e on Linux (GCC 16.2.1), merged onto main
dc105f8ain a branch with eight other open PRs;agc_driver_graphicspasses on an RTX 5080 and on RADV (Radeon 610M).One case where the clamp cuts bytes that are backed: in
stridedOverhangTestsI registered a second readable allocation of 0x8000 bytes directly after the first one (mutation.Add(block + allocation, allocation, true, false, true)) and bound the same descriptor again (stride 20, 1639 records, 32780 bytes). The bound range is still 32768 on both GPUs, so the last record's 12 bytes in the second allocation are left out.RegisteredReadableEndonly looks up the allocation that holds the base address.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:22:06Z.
Review: CHANGES_REQUESTED
Thanks, the approach is sound and
stridedOverhangTestsfails without the change here too. One thing to fix, already reproduced by @fma-rc:core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp:2671clamps toRegisteredReadableEnd(address), which only looks at the allocation holding the base. When another readable registered allocation starts right at that end, the last record's bytes are backed but get cut. Clamp only when the bytes past the allocation end are not covered, e.g.!RegisteredReadableCovers(allocationEnd, end - allocationEnd), and add fma-rc's adjacent-allocation case (second0x8000allocation right after the first; the bound range must stay 32780) tostridedOverhangTests.Please also fill in the FPS numbers' setup in Tested once this is rebased on current
mainif you can re-measure; the current ones come from an integration branch.Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-10T23:28:00Z.
Thanks @fma-rc, good catch, and it's deliberate. I tried exactly that change: clamp only when no readable allocation starts at the end of the first one. It breaks the case this PR is for.
In RetroArch's Dolphin core, the 48 MiB stream buffer at
0x4009200000is followed directly by another registered, readable allocation at0x400c200000. The descriptor's overhang (+0x300000c) even merges with a descriptor region there (0x400c200008+0x10). With the extra check, the clamp no longer applies, and Dolphin is back at 0.74 FPS (27-29 FPS with the PR as it is).So being backed by a neighbour doesn't separate your case from that one. What does separate them is that the bytes past the allocation aren't part of the buffer the records describe:
num_recordsup so that an attribute fetch inside the last vertex works.I've pushed f6e16ceb, which pins that in
stridedOverhangTests: with a second readable allocation right after the first, the bound range still ends at the first allocation.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:39:59Z.
Review: APPROVED
Checked on the PR rebased onto current
main: build + ctest of libSceAgcDriver green, andagc_driver_graphicsfails without theShaderResources.cppchange.num_recordsof the last record, andstridedOverhangTestsnow pins it.Merging once CI is green.