fix(agc): destroy settle aliases before their imports are freed #7629
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7629"
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 EagleBearerYS on 2026-10-18T18:00:07Z.
What
A regression from our #6678. On Windows,
agc_driver_host_import_lifetime(from #7339) fails on unchangedmainon an AMD Radeon 860M: "host import Vulkan objects were destroyed out of order or more than once", at its first partial unmap. @LeandroLP23 reported it in #7601 and traced it there: the buffer the test tracks isn't the import's own but an alias bound to the import's memory, and two routes free that memory before the alias is destroyed. The second commit is LeandroLP23's own fix for one of them, as they posted it in #7601, with their authorship.How it happens (
main889cee5f9f,GuestBufferMemory.cpp, Windows only):VulkanDevice.cpp~1473-1499), as on AMD's Windows driver. A device with spare graphics queues settles in the same family and makes no alias.retiredlist, and the reap destroys the aliases before it drops that list. Two routes skip that order:forgetSettle(~256) hands the batch back only while the GPU is still running it. For a batch that has finished but hasn't been reaped yet,retireImportreleases the import at once: its buffer is destroyed and its memory freed, and the alias goes at the next reap. LeandroLP23 found this route.releaseSettleRetired, ~376-395) waits for the batch, then releases the import with the alias still bound.vkBindBufferMemoryhook keeps the last buffer bound to an import's memory, which is the alias. SopartialUnmapsees the memory freed before that buffer is destroyed: #7601'sdestroyed=0 outOfOrder=1 frees=1.As @MarcZX10 points out in #7601, Vulkan permits freeing memory while resources are still bound to it, once the commands that use them have completed. Both routes run after the batch has finished and nothing uses the alias afterwards, so this isn't a GPU hazard. LeandroLP23's trace there shows the sequence: the import's own buffer is destroyed, the memory is freed while the fixture tracks the alias (a new buffer reusing an earlier handle value), and the alias is destroyed right after, at the reap.
A fixture that tracked only the import's own buffer would pass as well, but it would no longer check the order for the alias. This change keeps the test as it is and makes both routes keep the order the reap and drain paths already keep. Which of the two to take is the maintainers' call.
The change, in three commits:
releaseSettleRetireddestroys a finished batch's aliases before it releases the imports the batch held.forgetSettlehands back any busy batch, not only a running one. An import retired after its read finished then stays with its batch until the batch is reaped or an unmap releases it, and both destroy the aliases first.agc_driver_host_import_lifetime_other_familyruns the lifetime tests with the settles forced onto another queue family (settleOnOtherFamily, asagc_import_settle_deferred_other_familydoes), so a GPU with spare graphics queues takes the alias path too. It's registered on Windows and skips where the device has no other queue family.Side effects:
[buffers]host imports line (APS5_PROFILE_DRAW), "retired during their read" now also counts imports retired after their read finished but before its batch was reaped. "unmaps waited for it" still counts only reads that were running.What stays as it is: devices that settle in the import's own family, which make no alias, and Linux, which has no settle batches.
Fixes #7601
Tested
main6efb7261bwith this branch's tree: thehost_importtests pass 5 runs of 5. With only the first commit, both lifetime tests fail 3 of 3; with only the second,agc_driver_host_import_lifetimefails 3 of 3. Their fullagc_*run passes 715 of 717; the 2 failures fail on unchangedmainthere too (#6255, #5271).agc_driver_host_import_lifetimeandagc_driver_host_import_lifetime_other_familypass 3 of 3 each. The forced-family test ran on the device every time, with nothing skipped.main'sGuestBufferMemory.cppand the same tests, the forced-family test fails on its first run with #7601's message. The plain test passes there, since this device settles in the import's own family.agc_driver_host_import_lifetimepasses 3 of 3.main'sGuestBufferMemory.cppit fails with #7601's message, as on the 860M.main. libc'sprecise_waitfails on Linux withmain's code too.Checklist
main889cee5f9f, and merges cleanly into currentmain; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T18:10:26Z.
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/tests/Recorder.cppL9965core/libs/prx/libSceAgcDriver/tests/Recorder.cppL9965Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T18:22:33Z.
Review: APPROVED
Reviewed the lifetime paths and the diff. Keeping any busy settle batch with its retired imports covers the completed-but-not-yet-reaped case, and releasing the aliases before dropping overlapping retired imports covers partial unmap. The other-family Windows test exercises the alias path on devices that otherwise settle on the graphics family. I did not run the Windows GPU tests locally; the reported 860M and RTX 3070 results provide the hardware validation for this review.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T18:28:32Z.
Rechecked the PR head
8a1e73718on the 860M. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release,BUILD_TESTING=ON. Build:mainc3591adf9with #7629, #7630 and #7627 merged together (each merge clean, built once).The 11
host_importtests, among themagc_driver_host_import_lifetimeandagc_driver_host_import_lifetime_other_family, andagc_import_settle_deferred_other_familypass 3 runs of 3.agc_host_import_sparseskips itself as before.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T17:59:03Z.
Re-checked against current
main: the merge is clean, and the recent merges only add unrelated test registrations to the AgcDriverCMakeLists.txt; the settle-batch paths this changes (forgetSettle,releaseSettleRetired, batch aliases) are untouched. Aliases are destroyed before the imports of a finished batch are released, the same order reap and drain keep; the forced-family test covers the alias path, and the hardware results in the thread (860M, RTX 3070, 5900HS, UHD 770, RX 9070 XT) agree; merged.