fix(agc): keep another device's host imports until its teardown #3976
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3976"
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 pipe1os on 2026-10-11T20:20:24Z.
What
Fixes #3503.
HostImportsis one process-wide state bound to oneVkDevice. When another device reconciles it,refreshImportsdestroyed every import of the previous device at once withvkDestroyBuffer/vkFreeMemory, even though that device's submitted batches could still read them.agc_driver_depth_fast_clear_submituses two live devices: the test's ownVulkanDevicefor draws and the driver's device for the DCB submissions.AgcDriverWaitIdlewaits for packet processing, not for the GPU, so the driver'sDMA_DATAfill (avkCmdFillBufferinto the HTILE block's import) can still be queued when the test device's next draw reachesUploadFinish→refreshImports. lavapipe then executes the fill on a destroyed buffer:(Mesa 25.2.8-0ubuntu0.24.04.4, symbolized with
mesa-vulkan-drivers-dbgsym.) The Khronos validation layer reports it on the same runs:with the destroy coming from
GuestBufferMemory::UploadFinish→refreshImportson the test device'sDraw.The previous device's imports are now kept as
RetiredImports per device and destroyed byClearHostImportsof that device, which itsVulkanDeviceteardown calls aftervkDeviceWaitIdleand beforevkDestroyDevice. With one device per process nothing changes: the switch happens on device replacement, and the old device's teardown frees the parked imports as before.RetiredImportis forward-declared and held throughshared_ptr, soHostImportsandImports()stay where they are; with #2434 the file merges without conflicts.The other device-keyed caches (
Chunks,Mirrors, BDATables) only dropshared_ptr/weak_ptrreferences on a switch, so batches that keep their objects are unaffected;HostImportswas the one holding raw handles.Tested
Linux, Docker
ubuntu:24.04mirroring the CIlinuxjob (GCC 13.3.0, Mesa 25.2.8 lavapipe,GALLIUM_OVERRIDE_CPU_CAPS=avx,ANYPS5_REQUIRE_VULKAN=1, Release,-DANYPS5_ENABLE_SPIRV_TOOLS=ON),seccomp=unconfinedso the userfaultfd write watch is active as in CI, 4 CPUs. Tree:maina11c8f7f7(this file is unchanged up to currentmain).ctest --parallel 4runs did not reproduce it. The test alone, 300 runs, cleared shader cache each run, with 8 busy-loop processes on the 4 CPUs:VUID-vkDestroyBuffer-buffer-00922appears in the crashing runs;00922(or any other VUID besides the old layer's unknownpNextstructure at device creation).ctest --parallel 4with the change: 838 tests, the same 4 failures as without it (agc_driver_emulated_color_compare#3526,agc_driver_image_plane_address_on_line_implicit_lod#3630,guest_kernel_stack_protect#3459,guest_truncate, which also fails on unchangedmainin this container).python3 tools/check_conventions.py --base origin/mainpasses.Windows not tested (the change is platform-independent;
RetiredImportkeeps the Windows alias unmap it already had).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 Kikoarl on 2026-10-11T21:02:57Z.
Tested on Linux (CachyOS x86_64) on real hardware with an NVIDIA GeForce RTX 5060 Ti (driver 615.78.08, Vulkan 1.4):
agc_driver_depth_fast_clear_submit: ran 10 consecutive stress runs (--repeat until-fail:10) on physical NVIDIA hardware — 10/10 passed with zero crashes or validation warnings.agc_driver_depth_*) pass 100%.tools/pr_overlap.py: no merge conflicts with open PRs.tools/check_conventions.pypasses clean.Validates the fix on physical NVIDIA hardware beyond lavapipe. LGTM!