agc: a host read on another thread does not wait for an image the queue-idle store is writing back #7744
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 jotitadev on 2026-10-19T05:42:38Z.
StorageTexture::FlushPendingtakes the overlapping images out ofpending.texturesintopending.flushing, then writes them back under the GPU mutex. A secondFlushPendingfor the same range on another thread (the flush hook ofGuestMemory::Read, a file write since #6234) scans onlypending.textures. It finds nothing and returns false without waiting, so the caller reads guest memory before the first write-back lands.The queue-idle store (
VulkanDevice::StoreIdleResults: GPU mutex, thenFlushAllPending("idle")) is the usual other flusher. Any host read that overlaps it can see the old bytes.Repro (a temporary variant of
StorageFileWrite.cpp, patch below): produce the pending surface, start a thread that takes the GPU mutex and callsFlushAllPending, wait untilFindPendingon the surface returns null, thenGuestMemory::Readthe surface.agc_driver_storage_file_writeonmainshows the same thing under load asthe GPU producer wrote only zeros(3 of 100 runs on lavapipe and 5 of 50 on the RTX 3070 withSIGSTOP70 ms every 20 ms).Possible fix: in
FlushPending, when nothing is found intexturesbut an overlapping image is influshingand this thread does not hold the GPU mutex, take the GPU mutex and check again until no overlapping image is left influshing.flushingis empty almost always, so the hot path only pays one more scan of an empty list. When this thread already holds the mutex, no other thread can be in the middle of a write-back.Repro patch (test-only, not for merging)
Machine: Intel i7-8700, Ubuntu 26.04, main
3904ce6cf.GPUs tested: NVIDIA RTX 3070 (Linux), lavapipe.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.