feat(agc): import shared ranges above 64 MiB as sparse buffers over udmabuf chunks #5309
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5309"
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 hugodearaujo on 2026-10-13T16:52:34Z.
What
On Linux, a guest range with shared (memfd) backing is imported for the GPU through one udmabuf over the whole range, unless the resource fits inside one 64 MiB chunk. udmabuf refuses buffers above its
size_limit_mb(64 MiB by default), so every larger range fell back to copies:For ASTRO BOT (PPSA21567) that is the cause of its stall. A compute dispatch that reaches that 2.1 GiB range through addresses (BDA) gets an image mirror, and
acquireMirror→syncRangesyncs the whole range on every acquire. That stores back every pending storage image inside it (FlushForAccessover0x500000000+0x87c00000, about 15 images each time), synchronously, layer by layer. The compute queues wait for labels behind those stores (WAIT_REG_MEM_64 x52 10059msin 10 s on queue 0x48), and the GPU sits idle.Related: #5329 (the same limit in Dragon Quest III HD-2D Remake; not run here).
This PR imports such a range as one sparse buffer bound to the existing 64 MiB chunk imports (
ImportChunk, the same udmabuf objects the per-chunk import already shares). The range keeps one contiguous device address, so address-based dispatches use the import in place and no mirror is made.VulkanDeviceenablessparseBindingwhen dma-buf import is active and a queue family binds sparse memory. When the device has a second family that binds sparse memory (RADV has a sparse-only family), it creates one queue there for the binds, guarded by its own mutex. The import made at map time runs without the GPU mutex, and this queue lets it bind there too. Without a second family the bind uses the main queue and only runs under the GPU mutex.createSparseDmaBufImportruns after the single-chunk import does not fit and before the whole-range udmabuf. It binds every chunk the buffer covers, waits for the bind's fence, and keeps the chunks alive throughHostImport::chunk.dmaBufImportis already off there, so nothing changes for it. Windows does not change either.A TechnicalDebt entry records the fallback cases, and the
/dev/udmabufparagraph indocs/user/USAGE.mdsays when ranges abovesize_limit_mbare still copied.Results
ASTRO BOT (PPSA21567, dumped from my PS5), Linux, RX 9070 XT (RADV), 80 s runs with
APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1, per 10 s window (themaincolumn, except the first row, withsize_limit_mbat 1024):mainsize_limit_mb(64): 28, then 1, then 0 (the game stops submitting);size_limit_mb1024: 40–520x500000000+0x87c00000and0x10ca000000+0x120000000Hollow Knight: Silksong (PPSA12544) runs as before. Hades (PPSA03355) imports its 256 MiB and 3 GiB ranges now and gets further (1,533 file opens before the stop, 1,227 on
main). It still stops on its known null-destination copy, whichmainhits the same way.Tested
agc_driver_sparse_dma_buf_importmaps a memfd-backed range larger than the currentsize_limit_mb, imports it at map time (without the GPU mutex), and fills 64 KiB across the first chunk boundary through the import. It checks the backing memory and the bytes on both sides. Onmainit fails with "a range larger than udmabuf's size limit was not imported". It skips when/dev/udmabufis not accessible or when the device does not import a one-chunk range.agc_driver_tessellationsegfaults the same way on currentmain.agc_driver_sparse_dma_buf_importreports a skip there, since udmabuf imports are Linux only.size_limit_mbraised to 1024, then again with it back at the default of 64: ASTRO BOT still reaches its title screen (about 19 FPS against 21) with no "memory access" write-backs. Ranges above 64 MiB take the sparse import whatever the limit, so the limit only affects the fallback cases (two ranges whose offset is not 64 KiB aligned are copied in ASTRO BOT; #5390 imports them).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 simonbbby on 2026-10-13T17:28:17Z.
Independent RADV verification of exact head
00053abd5fdef4b83444b30a0156bc321a5a3f3awith udmabuf's defaultsize_limit_mb=64, left unchanged throughout:1002:13c0), RADV Mesa 25.2.8; Ubuntu 24.04 / Linux 7.0, GCC 13.3, Ninja Release, SPIRV-Tools ON.agc_driver_sparse_dma_buf_import,agc_driver_sparse_buffer_holesandagc_driver_bda_span_readseach pass three consecutive runs. No skips, failures or timeouts. The new fixture executes the at-map import without the GPU mutex, GPU fill across the first 64 MiB chunk boundary, backing-memory comparison and outside-range canaries.0214069e33ccfab4bd97ec973637299895f786d0, retained the PR's new fixture, and rebuilt. The new test fails on its 192 MiB range:UDMABUF_CREATE (-1000072003), thena range larger than udmabuf's size limit was not imported.Each run pins
radeon_icd.json,ANYPS5_GPU=RADV,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, serial CTest and a 30 s per-test bound. Logs identify the intended AMD device. Build used the existing private XRandR prefix; no system package or kernel-parameter changes.This adds default-limit coverage on another RADV GPU for #5329's failure shape. No title run, full-suite result, NVIDIA/Windows test or performance claim. Logs retained.
Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-13T20:15:00Z.
A second title takes this path: Hades (PPSA03355), RX 9070 XT (RADV), udmabuf
size_limit_mbat its default of 64.On
main(a0f5916a2) one of its shared ranges falls back to copies:On this PR's head (00053abd5), with
APS5_TRACE_HOST_IMPORT=1, the same 256 MiB range is imported:Both runs were 60 to 70 s from launch with no input. I did not measure a frame-rate change for Hades.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T20:31:09Z.
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/Execution/src/VulkanDevice.cppL1639Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T00:10:12Z.
Once the sparse path is chosen, a failure of
importChunk, the bind, the fence wait or the device address returns false and the range goes on to the whole-range udmabuf and then copies (GuestBufferMemory.cpp:513-536). Please decide the path before importing (size, sparse support, block alignment, memory type) and throw on any failure after that. Has PPSA20612 from #5329 been run with this at the defaultsize_limit_mb?Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-14T05:26:48Z.
Independent Linux check of revised head
4e136dd3230af4ac50ef1d20f37d959af32153b5. The default udmabufsize_limit_mb=64was left unchanged.Release, GCC 13.3, bundled dependencies, SPIRV-Tools ON.
agc_host_import_sparse,agc_driver_sparse_dma_buf_import,agc_driver_sparse_buffer_holesandagc_driver_bda_span_readseach pass 3/3 (12 passes, 1.53 s total). The three execution fixtures select gfx1036 (1002:13c0) / RADV Mesa 25.2.8, with the Radeon ICD pinned, Vulkan required and application shader caching disabled. Serial CTest, unchanged 30-second timeout; no internal skips printed.The new mock fixture checks the complete chunk-bind layout, declines an unaligned backing offset before importing chunks, and verifies selected-path chunk-import and sparse-bind failures throw and release the sparse buffer. Restoring only
GuestBufferMemory.cppfrom parent5894feff7e0e7074d67a50f39be341a9ce6ffa94, retaining the new fixture, makes its UDMABUF_CREATE and vkQueueBindSparse throw assertions fail. Restored the PR production source, rebuilt, and ran the matrix above.I also extended the mock fixture locally for the two other failure stages in the review:
vkWaitForFencesreturningVK_ERROR_DEVICE_LOST, and a zero device address for the sparse buffer only. Both throw with the intended stage and release the sparse buffer, three complete extended-fixture runs. With the parent's production file, all four throw assertions fail. These are mocked failures; neither real GPU was faulted.All temporary test/production edits were restored, rebuilt, and the checkout is clean at the stated PR head. No title run here, so this does not answer the PPSA20612 runtime question.
Test-only extension used for fence/address failure coverage
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T08:50:27Z.
Rebased onto main and added a commit on top. The sparse path is now chosen before anything is imported: sparse binding, a range above one chunk, the bind queue,
/dev/udmabufopen, the backing offset on the sparse block size, every memory type a chunk import can have accepted by the sparse buffer, and the backing file covering the last chunk. Once it is chosen, a failed chunk import, fence creation, bind, fence wait or device address throws instead of going on to the whole-range udmabuf and copies. The debt entry lists the cases that still take the single udmabuf.New test
agc_host_import_sparseruns the import against a mocked device and the real/dev/udmabufat the defaultsize_limit_mb: a 129 MiB range becomes one sparse buffer bound to one chunk import per 64 MiB, an unaligned backing offset imports no chunk, andUDMABUF_CREATEandvkQueueBindSparsefailures after the decision throw. On main all three import checks fail; with the earlier head of this PR the two throw checks fail.Linux, RTX 4090,
size_limit_mb64: the dma-buf path is off on the NVIDIA driver, so this was a regression check only. PPSA21564 reaches its first level on main and on this PR (level 29.1 / 28.9 fps on main, 28.6 / 29.4 and 32.8 / 27.7 here), and PPSA02929 passes on both. Full build is green.