fix(agc): keep CPU writes when a pending storage result is stored over untracked memory #5024
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5024"
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-13T08:49:02Z.
What
A storage image's results stay on the GPU until something reads their memory. If the CPU writes that memory first, the store has to leave the 64 KiB blocks it wrote alone. On write-watched memory the block stamps decide that. On memory outside the watch (direct host imports on Windows, imports on Linux when the driver resolves write protection, any range the tracker does not cover) the store compares guest memory with the bytes saved at the upload. On
mainthree things leave it with nothing to compare, and the layer is then stored whole over the CPU's bytes:originalValid), so every later store of the other units is whole.StorageTexture::FillClear) never saves the bytes under it.StorageTexture::CopyFrom) never saves them either.GTA V (PPSA04264) showed it on Windows, reported on #4410: an image over memory the title reuses as its JobManager pool stays pending, the pool is written, and after
the kernels read
ffffffffbuffer descriptors. #4410 did not introduce this. Results stay pending longer since it went in, so the store now lands after the CPU write more often. The new test fails onmainwith or without it.The change:
layerOriginal). A store, a drop or a stale eviction invalidates only the units it touched. A CPU-path store makes the units it stored valid again and reads guest memory only for the units without saved bytes.writeBackLayerscompares each run of selected units that has saved bytes, instead of the whole stored span or nothing.FillClearandCopyFromsave the bytes of the units they fill when the surface is not watched, as an upload already does.docs/dev/debt/libSceAgcDriver.md.On watched memory nothing is saved or compared, as before; the only additions there are one
GuestMemory::Watchedcall per fill and per copy, and per-unit flags where there was one.Tested
Linux, RTX 4090 (NVIDIA 610.57.04), Release, at
cac4e9688f.mainis the same tree withTexture.cppandTexture.hppfrommainand the new test kept.New test
agc_driver_store_over_untracked(0.3 s): a surface outside the watch, a CPU write while its result is pending, then a read through the flush hook and a store of everything. Five cases: another block read after the CPU write, another block read before it, a fill of the surface, an image copy into it, and a surface that leaves the watch while its result is pending (that one expects the throw and the CPU's bytes intact). 10 runs each:APS5_WRITE_WATCH_IMPORTS=unwatchmainOn
mainthe read/fill/copy cases lose bytes (32 or all 4096 of the 4096 written in the first, all 4096 in the others), and the surface that left the watch is stored whole. WithAPS5_WRITE_WATCH_IMPORTS=unwatchthe import already unwatches the surface at the upload, before anything is pending, so the last case does not apply there (the test prints that) and the bytes are saved as for any unwatched upload.ctest -R '^agc_' -E 'agc_driver_flat_|agc_driver_scalar_wide_loads|agc_driver_bda_span_reads|agc_driver_pixel_interlock', 441 tests, with this PR: all pass in both modes (agc_driver_stencil_ref_exportskips on this device). No existing test reaches the new throw. The excluded tests hang on this driver onmaintoo.Not tested: Windows (not built here), so the new throw has not been seen there and whether a Windows run reaches it is unknown. No lavapipe, no title. GTA V was not run, so whether its failure is one of these cases is not confirmed. No speed measurement; none is claimed.
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-13T08:53:26Z.
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)docs/dev/debt/libSceAgcDriver.mdL43-44core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppL4356Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-14T00:00:19Z.
@oneandonlydean confirmation from GTA V (PPSA04264), the title from #4410's regression report. Windows 11, RTX 4090.
On
main8d98e8851, with #4410 in and no local revert, plus the open PRs GTA needs to reach Story, the Story prologue ran for 150 s with none of the earlier failures. Before #5024 it died about 30 s in, after JobManager kernels 0x...1200 read all-0xFF V#s and 0x...7400 threwbuffer descriptor has reserved bits set. This run had neither. Thanks for tracking it down.AI-assisted (Claude Code).