fix(agc): keep small storage images current outside the write watch #23790
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23790"
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 birdmarty on 2026-11-19T16:54:45Z.
What
A storage image of up to 1 MiB keeps an upload copy (
generationBaseline) to prove, outside the write watch, that its memory still holds what the image was made from. Two defects let that copy go stale, so results stored over a unit outside the watch were refused although nothing went wrong:Lies of P (PPSA10621) aborts with this after 3.5 to 10 minutes on Windows, always on a 512x512 storage image (format 7, tile mode 4, 0x80000 bytes, 8 units) whose memory sits in host imports under 1 MiB, which are compared rather than watched.
1. The unwatch hook renewed the copy before the unit's results landed (
StorageTexture::rebaseBeforeUnwatch). It read the unit at once unlessPendingWriteOverlapsnamed a batch writing it, and results that reached guest memory without such a note were read before they landed: a diagnostic build that also performed the old read counted 2-13 renewals per run where it differed from the bytes after all recorded work completed. It also skipped units whose results were still in their unit shadow, and a skipped unit clearedanyBaselineDuefor the whole image, dropping it from later hooks.PublishShadow,PublishScope::Whole); a unit still shadowed afterwards stays due.Recorder::OnComplete; batches complete in order); an idle recorder reads at once.awaitRebasealready syncs a renewal still due when results become pending.anyBaselineDueis derived frombaselineDue.2. A dispatch was recorded with a storage image that changed after its bindings were made.
VulkanDevice::dispatchbuilds the resources (cachedStorageTexture→Refresh);VulkanDevice::recordDispatchrecords the dispatch later and ends inMarkGpuWrites. A CPU store into watched memory traps and the flush hook drains the queue first; a CPU store into memory outside the watch does not, so the dispatch was recorded with the image's old content and the copy no longer matched at its store.StorageTexture::ChangedOutsideWatch: a unit outside the watch with no results pending and no save or renewal in flight changed when its bytes differ fromoriginal(when held) or from its upload copy, or when its copy was not renewed as its range left the watch.recordDispatchcallsShaderResources::RefreshStorageChangedOutsideWatchbefore recording anything for the dispatch; each of the dispatch's storage images (and storage sources of its sampled views) with such a unit is refreshed, so the upload lands in the batch before the dispatch.refreshre-uploads such units and does not take its epoch proof while one exists.uploaddropped the whole copy when any part of the image had a live unit shadow, pending results or a recorded write in flight (guestBytesSettled); a refresh of one unit outside the watch while other units were shadowed would have left every unit without a copy. Each uploaded unit now reads its own slice when its own range is settled (unitSettled); an unsettled unit is marked due, so its copy is renewed when its range leaves the watch or the unit is uploaded again at its next refresh.Not covered (debt fragment): draws (an upload cannot be recorded inside a render pass), and images above 1 MiB that hold no
original(no upload copy to detect against).What stays the same:
original.refreshbefore taking its epoch proof.How the causes were found
Diagnostic builds kept a per-image event history (uploads, write-backs, unwatch decisions, renewals, refreshes, the caller that made results pending) and printed it at the refusal. What was tried and ruled out:
context.recorder)Recorder::Active()is a global, not per thread; no effect, the next run still renewed a unit with stale bytesGuestMemory::FlushGpuWrites)refreshImportsre-unwatches an import under the host imports mutex and the flush takes it again (ExistingHostImportFor); replaced by waiting withOnCompletefastRevalidaterejects ranges outside the watch (UnchangedSince), and its other paths callRefresh; every exit ofrefreshwas logged: none ran between the unwatch and the refused dispatchResolvedDispatchcarries no storage imagesagc_storage_pending_after_unwatch, which requires the results to land in a unit they coverrefreshalready re-uploads a unit outside the watch when it runs (its blocks are untracked); it does not run between the build and the recordThe history then showed the remaining case directly: units 0-1 carried CPU stores the watch had seen, unit 2 changed after its copy was renewed correctly, no
refreshran, and the refusing dispatch came throughMarkGpuWritesfromrecordDispatch.settleFloorByteslowered to 512 KiB also avoids the abort in the title, by keeping these imports watched; this PR leaves it at 1 MiB.Tested
Windows 11 Pro build 26300, Intel Core i9-9900K, AMD Radeon RX 6800 (AMD proprietary driver 26.10.1, Vulkan 1.4.315), WinLibs GCC 15.3.0, Release.
Tests,
main(d7be67833e) and this change, same machine and GPU. The set has 75 test programs:agc_driver_recorder_tests(the storage-image, unit shadow and unwatch tests, and the new one);agc_driver_store_over_untracked_testsandagc_driver_host_write_shadowed_unit_tests;agc_driver_own_refresh_view_alias_tests(#21699) andagc_driver_resident_heap_mirror_tests(#17796);mainANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(1.4.363),VK_LOADER_DEBUG=layer,ctest -VInsert instance layer "VK_LAYER_KHRONOS_validation"was not found but was requested by env var VK_INSTANCE_LAYERSVUID-linespublic_headersThe same tests fail on both sides:
agc_driver_store_over_untracked: the known Windows failure #22670. Run alone 10 times it failed 9 of 10 onmainand 8 of 10 with this change, both witha pending storage result was stored over bytes the CPU wrote to untracked memory.agc_storage_write_back_host_retile: failed in the parallel run on both sides ("the linear write-back went through its scratch instead of retiling into the import") and passed in the validation run on both. Run alone 10 times with this change it passed 10 of 10.The five skips are the same on both sides:
agc_driver_host_write_shadowed_unitandagc_host_import_sparse(Linux imports only),agc_driver_copied_writer_label_order,agc_driver_copied_writer_label_order_drainandagc_driver_partially_committed_volume_page_samples.agc_shader_memory_testsdoes not link with this toolchain on either side (ld: .rsrc merge failure: multiple non-default manifests), so its tests are not counted.tools/check_conventions.py --base origin/mainandtools/debt_fold.py --check: passed.tools/pr_overlap.py: three open pull requests change lines next to this change's, not the same logic. Whichever lands second resolves the adjacent lines.RequireGuestBufferscall inrecordDispatch, after which this change adds its refresh.RefreshStorageChangedOutsideWatch.Recorder.cpp'smain. It drops pending results over unmapped memory and does not touch the upload copy.86 pull requests that conflict with
mainshare files and could not be compared.New test
agc_storage_refresh_after_unwatched_cpu_write:kR64KBXimage is written back while watched, and its last unit leaves the watch through the hook.ChangedOutsideWatchmust report it, and the refresh must clear it.With the detection switched off (
unitChangedOutsideWatchreturning false) it fails with(c) a CPU write into the unit outside the watch is not seen; with it, it passes. TherecordDispatchcall needs the full dispatch pipeline and is covered by the title runs below.Lies of P (PPSA10621, 01.012.000), #22009, on an earlier
main(d31916ed37) with #23789 and with #16053 reverted (#20827 does this onmainnow), plus this change and its diagnostics. The title only gets past its first loading screen and into gameplay with #23789, so that one goes first; this change does not need its code. A cold shader cache (shaders compiled at first use) reproduced the abort within minutes before the fix.UploadCopyDiffers)UploadCopyDiffers)UploadCopyDiffers) on the image whose refresh was skipped just beforeThe before-fix route crashed reliably at three places (leaving the train, the way to the first miniboss, the door to the first Stargazer); every clean run crossed all three. In the clean runs the record-time refresh fired 5, 26 and 8 times, every time on a 0x80000 storage image, and the hook's renewal waited for in-flight writes that the old read would have missed 5, 5 and 2 times. With the record-time refresh switched off, the six refreshes it would have made were logged as skipped, and the store was refused on the image of the last one.
Lies of P (PPSA10261, 01.005.001, another release of the game; see #5983), same build and stack: a cold run from no save data through a New Game and about 16 minutes of gameplay ran 1154 s and exited cleanly. The record-time refresh fired 12 times, again every time on a 0x80000 storage image, and the hook's renewal waited for in-flight writes 5 times.
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)mainand this change, no new VUIDs🤖 Generated with Claude Code