fix(agc): wait for overlapping storage flushes #7757
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7757"
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 MarcZX10 on 2026-10-19T06:20:40Z.
What
When
FlushPendingfinds no pending image for a range, it now waits if an overlapping image is already being written back by another thread, then retries the pending lookup. The wait releases the pending-list mutex, and the GPU-lock holder avoids waiting, preventing a lock cycle. The flush completion path wakes readers after removing in-flight images. Adds a synchronized regression toagc_driver_storage_file_writefor a reader racing an overlapping flush. Fixes #7744.Tested
Linux x86_64, Debian 12.
cmake --build build-scalar --target agc_driver_storage_file_write_tests --parallel 4passed.ctest --test-dir build-scalar --output-on-failure --repeat until-fail:20 -R '^agc_driver_storage_file_write$'passed 20/20 using Mesa llvmpipe. This host lacks the emulator-required LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA features, so I temporarily bypassed only the host CPU startup guard in the local test build; the test itself ran against lavapipe, and the guard source was restored after the run. On the unmodified build, CTest exits at that guard before the test starts.python3 tools/check_conventions.py --base upstream/mainpassed. No game or homebrew run.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T06:27:16Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T06:35:41Z.
Manual follow-up to the overlap report: I reviewed the flagged
Texture.cpphunks. The reports are broad same-file comparisons because those PR heads conflict withmain; none changes the newFlushPendingin-flight wait/notification protocol. The closest interactions are #6615, which only changes therefreshingaccessor used inFlushPending; #7514, which adds range-index bookkeeping toPendingListwhile retaining its erase API (used here to remove a flushed texture); and #6960/#7048/#7604, whose relevant hunks concern guest-completion/write-back or unwatch/trace paths. The other reported hunks are in separate texture helpers. I found no direct overlap or required dependency for this change.Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T07:42:06Z.
Intel and AMD Windows data:
agc_driver_storage_file_writefails onmainand passes with this PR, 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 (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. This head346cc6ee4merged intomain6b8228b2b. "Without" means this PR's test files onmain6b8228b2b, with none of its other changes.agc_driver_storage_file_writefile write: concurrent guest read returned before an overlapping image was storedAI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T08:12:32Z.
Review: COMMENTED
Thanks for picking up #7744. I ran
346cc6ee4on Linux, and the host read path from the issue still reads the old bytes with this change.Machine: Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON, full build. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3) on the same host. PR merged ontomain6b8228b2b(clean).ANYPS5_NO_SHADER_CACHE=1,-j1 --timeout 30.The check is the repro from #7744 as a test: produce the pending surface, start a thread that takes the GPU mutex and calls
FlushAllPending("idle"), wait untilFindPendingon the surface returns null, thenGuestMemory::Readthe surface. 20 rounds per run; a round fails if the read sees zeros.mainagc_driver_storage_file_write, PRStorageFileWrite.cpp, onmainconcurrent guest read returned before an overlapping image was storedSo the new case does fail without the fix, but it only covers a reader that calls
FlushPendingitself beforeGuestMemory::Read. A plainGuestMemory::Readgoes through the flush hook (FlushForAccessinRecorder.cpp), and that path misses the wait twice:pending.texturesfor the range (images == 0, the defaultHookFlushCpuBlocks()off), the hook callsPublishShadowsOnlyand never reachesFlushPending. The image being written back is only inpending.flushingat that point, so this is the usual case for the race.APS5_HOOK_FLUSH_CPU_BLOCKS=0,FlushPendingstill returns false after the new wait (flushstays empty), so the hook skips itsSyncThroughand does not wait for the recorded store either.When I tried the same
FlushPending-only approach on #7744 it behaved the same way. It only passed afterFlushPendingreturned true after waiting and the hook'simages == 0branch waited onpending.flushingtoo: 0 stale reads in 200 on both devices. That change is open as #7769 (with theStorageReadDuringIdleStoretest that fails on this PR); happy to fold it into whichever lands.agc_driver_storage_file_writepasses onmaintoo here (30 of 30 on each device, idle host), so it doesn't show the race without load.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T08:53:31Z.
Thanks @jotitadev, you're right, and I missed the hook path when I looked at this. With
APS5_HOOK_FLUSH_CPU_BLOCKSunset,AccessKeptByCpuonly counts images still inpending.textures, so an image another thread is storing givesimages == 0and the hook never reaches the new wait. And on theFlushPendingbranch the wait returns false, so the hook skips itsSyncThrough.Reproduced on an RTX 4090 (Linux) with your
StorageReadDuringIdleStore:main20 of 20 reads stale in 3 of 3 runs, this PR the same, #7769 0 of 20 in 5 of 5. #7769 with this PR'sStorageFileWrite.cppalso passes 5 of 5, so it covers the directFlushPendingreader too. Folding that test into #7769, as you offered, sounds like the right way to keep both cases covered.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T16:00:28Z.
You’re right: this PR’s direct
FlushPendingwait does not cover the defaultFlushForAccesshook path whenAccessKeptByCpufinds no pending image. I checked #7769; its current head includes both that hook-path wait and theStorageFileWrite.cppconcurrent-flush regression from this PR. The hook-path regression is therefore represented in #7769, while this PR only covers readers that callFlushPendingdirectly. Thanks for identifying the gap and carrying the broader test into #7769.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T16:51:55Z.
Thanks @MarcZX10. Closing this as covered: #7769 has merged (
535587cf03), and it includes your concurrentFlushPendingtest from this PR inStorageFileWrite.cpp(ba72cb78f, co-authored by you), so the direct-reader case stays covered on main next to the flush-hook case fromagc_driver_storage_read_during_idle_store. Your report and test were what made that fix complete.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T16:53:12Z.
Thanks for confirming the direct-reader test is included in merged #7769 alongside the flush-hook coverage. I appreciate the clarification and the credit; that closes the remaining status question on this PR.
Pull request closed