fix(agc): save the guest bytes of pending storage results when their range leaves the write watch #5657
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5657"
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 oneandonlydean on 2026-10-14T04:43:44Z.
What
Fixes the regression reported in #361 for Disney Epic Mickey: Rebrushed (PPSA15657). @johnmaia bisected it to #5596: on Windows
mainthe title stops during the level load or before the main menu's Continue withand the same build with #5596 reverted stays in the level for 10 minutes (comment).
Since #5596, singly mapped direct memory on Windows is private memory.
importAllocationfinds it writable and imports it directly (GuestBufferMemory.cpp:894), anddecideImportWatchmakes every direct import on Windows leave the watch (:542,:933→GuestMemory::ImportWatched(..., false)→unwatchLocked,GuestMemory.cpp:1223). Before #5596 the same memory was a shared view, imported throughMapAlias, and stayed watched. A storage image uploaded while the range was watched saves no guest bytes (Texture.cpp:2163,:2212,:3835,:3970). If its results were still pending when the range was imported, its next store found the range neither watched nor saved, which is the throw #5024 left (Texture.cpp:4339,:4486).This saves the bytes at the moment the range leaves the watch:
GuestMemory::SetUnwatchHook: called beforeUnwatchand before anImportWatchedthat does not stay watched, while the range's write stamps are still current.StorageTexture::SaveBeforeUnwatch: every image with results pending over the range reads the guest bytes of its pending units that have none, then collects the range. It records the pieces that the keep rule ofwriteBackLayersleaves to the CPU for the writes the watch saw, with the unit's generation.Refreshcounts them as CPU-written.ImportMappedRanges) is deferred to its locked retry when pending results overlap the run, as it already is when it would retire an import. Without the lock, the hook throws.What still throws is in the debt entry: units without a write generation, and ranges that leave the watch through a failed collect.
Tested
Linux (CachyOS, GCC 16.2.1, RTX 4090), Release,
BUILD_TESTING=ON, onmaine33258a64:agc_driver_store_over_untrackedhas three new cases: the range leaves the watch throughUnwatchand through anImportWatchedthat does not stay watched, with the CPU write after the transition, and with the CPU write before it. Onmainit throws the message above. With this PR it passes in 3 of 3 runs. Without the recorded pieces, the write-before case loses all 4096 CPU-written bytes.ctest -R "guest_memory|agc_driver_graphics|storage|write_watch": 18 of 18 pass.ctest -R "agc_|guest_": 854 of 855 pass.agc_driver_bc_block_copyfails the same way on unmodifiedmain.tools/check_conventions.py --base origin/mainpasses.Not run on Windows or with PPSA15657. @johnmaia, could you run the title with the same input sequence?
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-14T04:54:19Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppL194docs/dev/debt/libSceAgcDriver.mdL52-53docs/dev/debt/libSceAgcDriver.mdL51-52Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-14T05:30:37Z.
@oneandonlydean ran PPSA15657 on this PR as asked: Windows 11, RTX 4080, head
db4fd5f29merged intomainac35f596c, the game relinked with that build's relinker, the same steps (title, Continue into Dark Beauty Castle). It still stops on the same throw, about 2 minutes after Continue, during or just after the level load:maina31043146mainac35f596c+ this PRmaina31043146with #5596 revertedOne run only, so I can't say whether it comes later than without the PR. The log is available if useful.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T05:46:18Z.
@johnmaia thanks for running it. The fix in #5657 only covers ranges that leave the write watch through a host import or
Unwatch, so the title is taking another path to that throw. Could you run it once more on the same build withand attach the last ~300 lines of the log before the throw? We need the
[flush] image 0x...line that fails, plus the[gpu] host import ...and[memory] ...lines for the same address range. The output is large, so a compressed log is fine.Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-14T06:50:31Z.
@oneandonlydean ran it again with
APS5_TRACE_FLUSH=1 APS5_TRACE_HOST_IMPORT=1 APS5_TRACE_MEMORY=1onmaind8888df9b(#5657 included). Same steps: Windows 11, RTX 4080, game relinked with that build. The throw came 17 s after Continue, from the present path:The flush trace has no line for the image that throws: the last
[flush] imagelines (about 20 lines earlier) are for other images (0x20816c0000, 0x2081750000, 0x2081870000, 0x207eec0000, 0x204ddb0000, each "keeps N CPU-written 64 KiB blocks ... generation 0"). Right before the throw, the log only shows a run of[memory] remap fixed ... prot=0xf2+[gpu] host import ... okpairs for 64 KiB to 9.4 MiB ranges. The last 300 lines before the throw:log (300 lines)
The full log is 1.4 MB (150 KB gzip). I can send it however suits you.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T07:35:29Z.
Thanks, the trace helps. Every image it stores is at generation 0, so their memory was already outside the write watch when their results were written: this isn't a range leaving the watch with results pending, which is all #5657 and #5671 handle. The remaps and retired imports before the throw don't drop the watch either.
What does leave pending results on such memory without saved bytes is an image copy or fill into memory another image overlaps: it dropped the saved bytes of every unit of that other image, including units it never touched that still had results pending, and the next store of those throws. #5707 limits that to the units the copy or fill covers. Could you try a build of
mainwith #5707 and #5671 both applied? If it still throws, please attach the full log (a gist is fine).Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T10:06:17Z.
@johnmaia #5761 is
mainwith #5671, #5679, #5707 and #5760 applied (branchoneandonlydean:test/storage-writeback-1014, full build green). #5760 covers what your trace and #5711 point to: a write-back done on the GPU over memory outside the write watch left no saved bytes, so the next store threw. Could you build it and rerun Epic Mickey? If it still throws, please attach the log with the same traces.