fix(agc): release host imports before the device is destroyed #1239
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1239"
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 awake-devel on 2026-10-07T19:06:43Z.
What
Closes #1236.
VulkanDevice::State::~Statereleases the device's caches beforevkDestroyDevicebut never emptied the host import registry (Imports()inGuestBufferMemory.cpp, a function-local static). Every import still registered at teardown kept itsVkBufferandVkDeviceMemorypastvkDestroyDevice, which the validation layer reports asVUID-vkDestroyDevice-device-05137. The next device then freed them through the destroyed device's handle inrefreshImports, and that crashes: a second device importing the same block after the first was destroyed ends the process withSIGILLin the NVIDIA driver (SIGABRTunder the validation layer). In the app the device is only destroyed inDriver::Shutdown, and the replacement at the first flip keeps the old device alive (#59), so no title reaches the crash today; tests and any later device recreation do.ClearHostImports(VkDevice), besideClearImageMirrors: under the registry lock, when the registry belongs to the device, destroys each import's buffer and memory (and unmaps its alias on Windows) as the device-change path ofrefreshImportsdoes, then clearsimportsandfailed, resetsdeviceandrefreshedGenerationand bumpsepoch.~Statecalls it right afterClearImageMirrors, once the recorder (with its retired imports), the resource cache andcopiedWritersare gone.agc_driver_host_import_teardown: a device fills part of a registered guest block throughVulkanDevice::FillBuffer, which imports it; the test checks that the fill reached guest memory and that the import exists, destroys the device and checks that the registry no longer holds an import for it. A second device then does the same with the same block, the sequence that crashed. It is skipped on devices without host imports.tests/Recorder.cppbuilds its ownVkDeviceand would need the same call before itsvkDestroyDevice; it is not registered in ctest, and #1046 and #1210 rework that harness, so it is left alone here.Tested
Linux (Arch, GCC 16.2.1), GeForce GTX 1050 Ti Max-Q, NVIDIA 580.178.04.
ctest: 400/400 pass (the 399 tests ofmainand the new one).ctestunderVK_LAYER_KHRONOS_validation1.4.363.0 (core validation): 400/400 pass with no validation message. Onmainthe 23 execution tests listed in #1236 reportVUID-vkDestroyDevice-device-05137.ClearHostImportscall removed, the new test fails withthe guest block's import outlived the first deviceand the layer reports 2 leaked objects; with it, the test passes.SIGILL(exit 132), orSIGABRT(exit 134) under the layer; with it, both devices import, fill and release the block with no validation message._WIN32alias unmapping followsrefreshImportsand was not built here.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
https://claude.ai/code/session_018RNrNcixatky8U4LfC7Ew5
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T09:27:37Z.
Checked on Linux (main + PR): full ctest 431/431;
agc_driver_host_import_teardownpasses, and fails with theClearHostImportscall reverted.ClearHostImportsmirrors the device-change path ofrefreshImports(destroy buffer/memory, unmap alias on Windows, clearimports/failed, bumpepoch). Linux, Windows and conventions CI are green on this head; merging.