Repository navigation
feat(agc): import shared ranges above 64 MiB as sparse buffers over udmabuf chunks - #5309
Conversation
|
Independent RADV verification of exact head
Each run pins 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. |
|
A second title takes this path: Hades (PPSA03355), RX 9070 XT (RADV), udmabuf On On this PR's head (00053ab), with Both runs were 60 to 70 s from launch with no input. I did not measure a frame-rate change for Hades. |
|
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.
|
|
Once the sparse path is chosen, a failure of |
…dmabuf chunks On Linux a shared-backed guest range is imported through one udmabuf covering the whole range, and udmabuf refuses buffers above its size_limit_mb (64 MiB by default). Larger ranges fell back to copies; an address-based dispatch then synced its whole mirror, storing back every pending storage image inside it each time. Such a range is now one sparse buffer bound to the existing 64 MiB chunk imports. The bind runs on a sparse binding queue of its own when the device has one, so imports made at map time (without the GPU mutex) can use it; otherwise only under the GPU mutex on the main queue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… after A shared range larger than one chunk now takes the sparse path only when the device binds sparse memory, udmabuf is open, the range's backing offset is on the sparse block size, the sparse buffer accepts every memory type a chunk import can have and the backing file covers the last chunk. All of that is known before a chunk is imported. Once the path 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. agc_host_import_sparse checks the import against a mocked device with the real udmabuf: a range above size_limit_mb becomes one sparse buffer bound to one chunk import per 64 MiB, an unaligned backing offset imports no chunk, and failures of UDMABUF_CREATE and vkQueueBindSparse after the decision throw.
00053ab to
4e136dd
Compare
|
Independent Linux check of revised head Release, GCC 13.3, bundled dependencies, SPIRV-Tools ON. 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 I also extended the mock fixture locally for the two other failure stages in the review: 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 coveragediff --git a/core/libs/prx/libSceAgcDriver/tests/HostImportSparseDmaBuf.cpp b/core/libs/prx/libSceAgcDriver/tests/HostImportSparseDmaBuf.cpp
index a6d05d4dc..6430669ed 100644
--- a/core/libs/prx/libSceAgcDriver/tests/HostImportSparseDmaBuf.cpp
+++ b/core/libs/prx/libSceAgcDriver/tests/HostImportSparseDmaBuf.cpp
@@ -56,6 +56,8 @@ struct MockDevice {
std::map<VkDeviceMemory, VkDeviceSize> memories;
std::vector<Bind> binds;
VkResult bindResult = VK_SUCCESS;
+ VkResult waitResult = VK_SUCCESS;
+ bool zeroSparseAddress = false;
std::uint64_t nextAddress = 0x500000000ull;
};
@@ -69,7 +71,7 @@ VKAPI_ATTR VkResult VKAPI_CALL mockCreateFence(VkDevice, const VkFenceCreateInfo
VKAPI_ATTR void VKAPI_CALL mockDestroyFence(VkDevice, VkFence, const VkAllocationCallbacks*) {}
VKAPI_ATTR VkResult VKAPI_CALL mockWaitForFences(VkDevice, std::uint32_t, const VkFence*, VkBool32, std::uint64_t) {
- return VK_SUCCESS;
+ return mock.waitResult;
}
VKAPI_ATTR VkResult VKAPI_CALL mockGetMemoryHostPointerProperties(VkDevice, VkExternalMemoryHandleTypeFlagBits, const void*, VkMemoryHostPointerPropertiesEXT*) {
@@ -125,6 +127,7 @@ VKAPI_ATTR VkResult VKAPI_CALL mockQueueBindSparse(VkQueue, std::uint32_t count,
}
VKAPI_ATTR VkDeviceAddress VKAPI_CALL mockGetBufferDeviceAddress(VkDevice, const VkBufferDeviceAddressInfo* info) {
+ if (mock.zeroSparseAddress && mock.sparse.contains(info->buffer)) return 0;
const auto address = mock.nextAddress;
mock.nextAddress += (mock.sizes.at(info->buffer) + Alignment - 1) / Alignment * Alignment;
return address;
@@ -293,6 +296,12 @@ int main() {
UnalignedOffsetIsDecidedBeforeImporting();
FailureAfterTheDecisionThrows(false, VK_SUCCESS, "UDMABUF_CREATE");
FailureAfterTheDecisionThrows(true, VK_ERROR_DEVICE_LOST, "vkQueueBindSparse");
+ mock.waitResult = VK_ERROR_DEVICE_LOST;
+ FailureAfterTheDecisionThrows(true, VK_SUCCESS, "vkWaitForFences");
+ mock.waitResult = VK_SUCCESS;
+ mock.zeroSparseAddress = true;
+ FailureAfterTheDecisionThrows(true, VK_SUCCESS, "vkGetBufferDeviceAddressKHR");
+ mock.zeroSparseAddress = false;
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1; |
|
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, New test Linux, RTX 4090, |
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; feat(agc): import shared ranges whose backing offset is not 64 KiB aligned #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