AGC: agc_driver_host_import_lifetime fails on Windows (Radeon 860M) in partialUnmap: the import's memory is freed before its buffer is seen destroyed #7601
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 LeandroLP23 on 2026-10-18T16:35:26Z.
agc_driver_host_import_lifetime, added by #7339, fails on every run here on unchangedmain. #7339 ran it on Linux with an RTX 4090 and lists Windows as not run, so this may be the first Windows run.Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release,
main6efb7261b.3 runs of 3, and the same on a build with 14 unrelated open AGC PRs merged.
Which case
I printed the three conditions of
requireFreed's secondRequirewith a local line I have since removed:The first six
requireFreedcalls pass:descriptorFirstImport,idleUnmapand the fourpendingReadcases. The seventh fails, the first check ofpartialUnmap, inside theUnmapcallback of the middle third. So the import'svkFreeMemoryran while the test'svkDestroyBufferhook had not yet seen the import's buffer, which is what setsoutOfOrder.freesis 1, so the memory is not freed twice.Two readings fit, and I haven't separated them:
state->buffer == buffer), for example a Windows alias of the import, sodestroyednever becomes true.I can't tell Windows from AMD here, since I have only this combination.
AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T16:40:12Z.
I checked the fixture's
requireFreedandfreeMemoryhook against the Vulkan memory-lifetime rule. The Vulkan memory chapter says memory may be freed while still bound to resources; the submitted commands that use it must have completed, and those resources must not be used afterward.Here
requireFreedtreats!destroyedatvkFreeMemoryentry as out-of-order, and the destroy hook stops tracking a later buffer destruction oncefreedis true. Sodestroyed=0, outOfOrder=1by itself appears consistent with a permitted memory/resource lifetime. The accessibility checks before and after the realvkFreeMemorycall are separate and still meaningful for the imported host pointer.Could you check whether a command uses the buffer after the memory is freed, or whether the relevant Vulkan rule for
VK_EXT_external_memory_hostimposes a stricter order? Without that, I think the failure may be an overstrict lifetime assertion rather than a Windows-only production defect.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T16:51:46Z.
@MarcZX100 I checked, and I agree it is the fixture, not the production order. I added two local prints, since removed: every
vkDestroyBufferthat reaches the fixture's hook, and, in thevkFreeMemoryhook, the buffer the fixture tracks for that memory. The end of the failing run:vkFreeMemorycomes right after avkDestroyBuffer, and every path I read frees in that order (destroyImport,~RetiredImport, thebindImportfailure path).ImportStateholds buffer…ac630. That handle was destroyed earlier in the run (thependingReadcases, against memory…0d6e7710) and shows up again right after, as a new buffer. Memory handles are reused too:…0d6e7710and…0d7b7fd0each back several imports in one run.destroyednever becomes true for it, and the check fires although the import's own buffer (…acf30) was destroyed just before. AMD's Windows driver recyclesVkBufferandVkDeviceMemoryvalues quickly, which may be why the RTX 4090 run never hit it.I have not traced which hook leaves the stale
bufferin that state: an earlier entry for the same memory value surviving, or a bind the fixture doesn't see. Clearing a state's entry once its memory is freed, or keying states by import rather than by handle value, would avoid it.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-18T16:52:10Z.
@LeandroLP23 thanks for the detailed report. Your second reading is the right one: the buffer the hook tracks isn't the import's own but an alias that our #6678 binds to the import's memory for its settle read on Windows.
releaseSettleRetired) waits for the batch, then releases the import, destroying its buffer and freeing its memory. The alias stays bound to that memory until the next reap. The test'svkBindBufferMemoryhook keeps the last buffer bound to the memory, which is the alias, sopartialUnmapsees the memory freed before "its" buffer is destroyed: yourdestroyed=0 outOfOrder=1 frees=1.The fix is on
fix/agc-settle-alias-before-import-free(d6335722ce). It adds a variant of the test that forces the settles onto another queue family, so GPUs with spare graphics queues take the same path. We'll open it once it's been checked on a Windows GPU. If you have time, runningagc_driver_host_import_lifetimeon the 860M with that branch would confirm it there.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-18T17:08:47Z.
@LeandroLP23 thanks, that trace pins it down, and it fits the settle alias from my comment above.
…ac630isn't a stale entry. It's a new buffer that reuses an earlier handle value: the alias #6678 binds to the import's memory for its settle read when the settle queue is in another queue family.…acf30is the import's own buffer, bound to…7fd0first. The fixture's bind hook then sees the alias'svkBindBufferMemoryto the same memory, so the state ends up naming…ac630.…acf30and frees…7fd0while the alias is still bound. The alias goes at the settle batch's next reap, which is thedestroyBuffer …ac630right after the failing free.vkBindBufferMemoryto…7fd0, with…ac630, after the one with…acf30.So the import's own buffer is destroyed before its memory, as you found, but one more buffer is bound to that memory. A fixture that tracks only the import's own buffer would pass too, though it would no longer check that order for the alias. d6335722ce keeps the test as it is and has the unmap path destroy the aliases first, as the reap and drain paths already do. Which way to go is the maintainers' call, since the test is from #7339.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-18T17:14:47Z.
@LeandroLP23 a correction to my two comments above: d6335722ce doesn't make the test pass on our Windows GPUs.
agc_driver_host_import_lifetime_other_familystill fails on an RTX 3070, and the plain test on an AMD iGPU, with the same message as before the change. So please don't spend a build on that branch. The alias reading needs another look before we say more, and we'll report back here.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T17:19:43Z.
@EagleBearerYS thanks for the explanation. I ran your branch on the 860M, and both tests still fail there.
Build: your
fix/agc-settle-alias-before-import-freeatd6335722c(newer than thefa2f320eebin your comment) merged ontomain6efb7261b, clean merge. Radeon 860M, driver 32.0.13058.8001, Windows 11 26300, WinLibs GCC 15.2.0 r7, Release.agc_driver_host_import_lifetimeagc_driver_host_import_lifetime_other_familyhost_importtests (9)agc_host_import_sparseskippedBoth fail with
host import Vulkan objects were destroyed out of order or more than once, still at the seventhrequireFreedcheck (partialUnmap). The same local prints as before, since removed, show the end of each run:The buffer the hook tracks, the alias by your reading, is still destroyed right after the import's memory is freed. So on this path the alias outlives the free with the fix too.
partialUnmapgoes throughMutation::Unmapon part of the allocation, so maybe it releases the import by a route other than the reap and drain paths your change orders.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T17:26:54Z.
@EagleBearerYS I think I found the missing piece. With it added to
d6335722c, both lifetime tests pass on the 860M.Why
d6335722calone isn't enough.releaseSettleRetiredonly reaches imports that a batch holds inretired.retireImportputs an import there only whenforgetSettlereturns its batch, andforgetSettledoes that only whilesettleBatchRunning, that is while the fence is still unsignaled. A batch the GPU has finished but that has not been reaped yet is stillbusyand still holds its aliases. For that batchforgetSettlereturnsnullptr. TheRetiredImportis then dropped at the end ofretireImport, which destroys the import's buffer and frees its memory, and the alias goes later, at the next reap. That is thedestroyBuffer <import> / freeMemory / destroyBuffer <alias>sequence in my trace.The change, on top of
d6335722c:The import then stays with its batch until the batch is reaped or released. Both
reapSettleBatchesand yourreleaseSettleRetireddestroy the aliases before they dropretired.Results, Radeon 860M, driver 32.0.13058.8001, Windows 11 26300,
main6efb7261b+d6335722c+ the change above:host_importtests (11)main+d6335722cagc_driver_host_import_lifetimeand_other_familyfail, 3/3main+ the change aloneagc_driver_host_import_lifetimefails, 3/3main+d6335722c+ the changeagc_host_import_sparseskipped)The full
agc_*run on the last build: 715 of 717 pass. The 2 failures,agc_driver_quad_pixel_maskandagc_driver_layered_volume_vertex_no_gpl, also fail on unchangedmainhere (#6255, #5271).The cost is that a finished batch keeps its imports' Vulkan objects until it is reaped, instead of releasing them at once. I haven't measured that. Feel free to take the change into your branch.
AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-18T17:30:27Z.
@LeandroLP23 thank you, and sorry for the build it cost you; our holding note crossed with your run. Your result matches ours on an RTX 3070 (the forced-family test) and an AMD iGPU (the plain test). Your prints also show that on the
partialUnmappath the alias still outlives the import's free with that change, so it doesn't cover every route that releases the import. A corrected change for that route is being checked on our AMD iGPU first, and we'll post here when it passes.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-18T17:44:53Z.
@LeandroLP23 thank you, that's the missing piece, and sorry that my last comment crossed with yours. We've taken your change into the branch as your own commit (
e22b41c56c, authored by you), between the unmap-path change and the forced-family test:fix/agc-settle-alias-before-import-freeat8a1e737182. We're checking it on our RTX 3070 and AMD iGPU before opening the PR.Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-18T21:53:19Z.
Windows data from two more GPUs:
agc_driver_host_import_lifetimepasses on an Intel UHD 770 and an AMD RX 9070 XT.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (RDNA 4,1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. Unchangedmainf3059421f.agc_driver_host_import_lifetime, ×5mainf3059421fSo on this machine the out-of-order free in
partialUnmapdoesn't show up, either on a discrete RDNA 4 card or on an Intel iGPU. Thismainis later than your6efb7261band includes #6097 (a7730cb9e), which changes import probes inGuestBufferMemory.cpp. I haven't checked whether that alone changes the Radeon 860M result.AI-assisted: yes (Claude Code)