AGC on MoltenVK: a GPU label becomes visible to the CPU before earlier GPU writes to the same host import #20118
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 XIIYAZ on 2026-11-14T16:29:09Z.
What happens
On MoltenVK (Apple M4), a label that
WriteLabelOnGpurecords after a GPU copy can be seen by the CPU while some cache lines of that copy still hold their old bytes.agc_driver_label_after_import_copyfails withround 6: a CPU read after the label that followed the copy found 64 of 262144 destination bytes not yet copied.Title, test or build step
Three ctest cases rest on the same ordering:
agc_driver_label_after_import_copy:a CPU read after the label that followed the copy found 64 of 262144 destination bytes not yet copied(the round and the count vary).agc_driver_label_ordered_flush_unimported:label ordered flush: the label was visible before the image store it follows.agc_driver_label_ordered_flush:label ordered flush: no label store took the GPU-ordered flush over the host import.AnyPS5 commit
main290ee1aa0fwith the open macOS build fixes merged locally (#17425, #11049, #11437), host report commit3f3a8df38aae. The three tests fail the same way with and without my other open MoltenVK PRs applied.System
Apple M4, macOS 26.7.3, MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1), Apple clang 21.0.0, Release build with
-DCMAKE_OSX_ARCHITECTURES=x86_64, run under Rosetta.Host report
Steps to reproduce
agc_driver_label_after_import_copystops within its 32 rounds on most runs; the other two fail on every run.Log
What was checked
To find which bytes are stale and whether they arrive later, I instrumented
LabelAfterImportCopy.cpplocally (not part of any PR). When the check fails, it records the stale range, callsWaitIdle(), and counts again:after idle 0). No write is lost; the GPU's label store becomes CPU-visible before part of the transfer recorded ahead of it in the same batch.APS5_DRAIN_COMPLETION_LABELS=1andAPS5_LABEL_GATE_ALL=1do not change the result. In this test no copied writer is listed and no completion store is pending, so the label still goes to the GPU (reason 0).Vulkan makes device writes visible to the host only through a device-to-host dependency: a fence or event wait plus
VK_ACCESS_HOST_READ_BIT. Polling a value the GPU wrote earlier in the same batch is not such a dependency. AMD and NVIDIA happen to land the writes of one queue in order, which is what the console's labels guarantee and what these tests check. Apple's GPU through MoltenVK does not, for writes to a host-imported (VK_EXT_external_memory_host) range.A fix I can see, and did not want to make without agreement because it changes label timing on macOS: on MoltenVK, store the labels that guest code polls behind the batch's completion. The CPU would write them when the batch is reaped, the way
Recorder::AfterCompletionsalready handles a small label while a copied writer is listed (reason 5). That orders them after every write of the batch. The cost is that a label lands only once its batch is reaped, so a title spinning on a label depends on the reap happening promptly. Is that acceptable on macOS, or is there a preferred way to get the ordering there?Related, but a different cause: #17937 (two stores of one label run with no barrier between them).