fix(agc): drop pending storage-image results when the guest unmaps their memory #8932
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8932"
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 BunnyFl on 2026-10-21T06:39:44Z.
What
Pending storage-image results are stored when something reads their memory, or by the queue 0 worker once every queue has been idle for 50 ms. An unmap left them pending: since
e3ce9bac0the idle store waits for the unmap's mutation and drops the results only when it then finds the range unregistered. A title that maps new memory over the same addresses before the idle store runs gets the stale results written into its new data.Heavenly Bodies (PPSA04246, Unity) does this at its first mission load. With
APS5_TRACE_MEMORY=1 APS5_TRACE_FLUSH=1, run trace-7 onmain:The 16 MiB block mapped at line 10203 is Unity's heap; the idle store at line 10297 writes the image of the unmapped range over it, and the allocator reads the overwritten words (
0x27219a960lies in that image). The other crashes are access violations on other threads (AssetGarbageCollectorHelper,UnityGfxDeviceWorker,Gfx Task Executor, unnamed ones) after the same kind of idle store.This PR:
retireUnmapped, also called for allocation removals) drops the results pending in images lying wholly inside the removed range throughStorageTexture::DiscardPendingInside, the path a fill over a whole image already takes. For block-unit images it drops the pending units inside the range.StorageTexture::AnyCreated), next to the multisample and depth guards that already share it.IdleStoreOverUnmapmaps the surface again at the same address inside the unmap's mutation and checks that the idle store andFlushAllPendingdo not write the old results into it. Its previous check that the results are still pending while the mutation is held no longer applies, as they are dropped at the unmap; when the address cannot be mapped again it keeps the previous settle check.Lock order: the observer runs under the registry mutation and takes
Pending().mutex, which is a leaf (no path takes the registry lock while holding it; seeblocksKept). A store that holds a lease finishes beforeRequireUnpinnedlets the unmap proceed.Still not covered (debt entry): an image only partly inside an unmapped range, and memory reused without an unmap.
Overlap (
tools/pr_overlap.py): #7600 also extendsretireUnmappedand the observer condition inMultisampleTarget.cppfor its multisampled clear records; whichever merges second keeps both calls and both conditions. #6926 and #8707 edit the same #1970 debt entry for other cases (host writes over pending results, DCC images with several mips); only the text needs merging.Tested
Windows 11 Pro 10.0.26200, AMD Radeon RX 9070 XT (AMD proprietary driver 26.10.1, LLPC), WinLibs GCC 15.2.0 r7.
Heavenly Bodies (PPSA04246, 01.006.004), converted from the dump on
main53a0a27bb, with this PR rebased onto that commit for the second row. 45 s runs from start into the first mission (cross pressed every 2 s throughAPS5_PAD_INPUT_FILE),APS5_PROFILE_DRAW=1 APS5_LOG_TIMESTAMPS=1 APS5_TRACE_FLUSH=1 APS5_TRACE_MEMORY=1, after one warm-up run:main53a0a27bbEvery crashed run had 61 or more such stores. The crashes are access violations on
Loading.PreloadManager,Gfx Task Executorand unnamed threads, and onceunsupported PM4 packet type: header 0x00000000in an overwritten command buffer. With this PR the idle store still runs (37-42 stores per run instead of 88-145); only the stores into unmapped ranges are gone. Earlier, onmain7ab4b2e56with the same settings,maincrashed in 6 of 15 runs and this PR in 0 of 15; withoutAPS5_TRACE_FLUSH/APS5_TRACE_MEMORY,maincrashed in 2 of 15. One of three played runs on7ab4b2e56also crashed there (AssetGarbageCollectorHelper).GPU tests on
main0aa55ef29and on this PR rebased onto it,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R "idle_store|multisample_retirement|native_multisample_depth|cached_image_multisample|host_import|guest_memory_lifetime|flip_stores|pipelined_fill|pattern_buffer_fill|fill_cover|depth_storage_reuse|memory_value_fill|pending_exact|clamped_global_fill|constant_dword_fill" -V:mainwith this PR'sIdleStoreOverUnmap.cpp: 30 of 31 passed,agc_driver_idle_store_over_unmapfailed withidle store over unmap: results of the unmapped surface were stored into the memory mapped over it.agc_host_import_sparseskipped (udmabuf imports are Linux only); the validation layer loaded (nowas not found but was requested by env var VK_INSTANCE_LAYERS) and neither log has aVUID-error.Rebased onto
main3e91c8edfafter #7600 merged. #7600 also extendsretireUnmappedand the unmap observer condition inMultisampleTarget.cpp; the rebase keeps both calls (forgetSingleClearsandDiscardPendingInside) and both conditions (anySingleClears()andStorageTexture::AnyCreated()), and changes nothing else. The GPU tests above were run again there, withagc_driver_graphicsandagc_driver_msaa_dcc_clear_2/4/8(where #7600's tests are) added:mainwith this PR's test 34 of 35 passed (agc_driver_idle_store_over_unmapfailed with the same message), this PR 35 of 35,agc_host_import_sparseskipped, the validation layer loaded and noVUID-error.tools/check_conventions.py --base upstream/mainpasses.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)The investigation, the change and this description were prepared with AI assistance (Claude Code); the in-game observations were made by me.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by simnJS on 2026-10-21T15:51:28Z.
NVIDIA, Windows. GeForce RTX 4080 SUPER, driver 616.92 (32.0.16.1692), Windows 11 Pro 26200, Ryzen 9 7950X3D, WinLibs GCC 15.2.0 r7, Release.
This PR
470938394merged intomaincecb540a6(clean merge), and the same tree with the three non-test files (Texture.hpp,MultisampleTarget.cpp,Texture.cpp) put back tomain.ANYPS5_GPU=NVIDIA ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest --test-dir build -R "^(agc_driver_idle_store_over_unmap|agc_driver_storage_read_during_idle_store|agc_driver_multisample_retirement|agc_driver_native_multisample_depth|agc_driver_msaa_dcc_clear_2|agc_driver_msaa_dcc_clear_4|agc_driver_msaa_dcc_clear_8|agc_driver_graphics)$" --timeout 120 --repeat until-fail:3 -V. Every Vulkan test loggedSelected GPU name=NVIDIA GeForce RTX 4080 SUPER vendor=0x10de device=0x2702; none skipped.maincode with this PR's testidle store over unmap: results of the unmapped surface were stored into the memory mapped over itWith this PR the idle store test did not print
skipped the remap check, so the remap check ran. Onmaincode,--repeat until-failstopped at the first failure; two more runs of that test alone failed the same way.agc_driver_graphicsuses a mocked Vulkan device and does not run on the GPU.Not run with
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: the Vulkan SDK (Khronos validation layer) is not installed on this machine.AI-assisted: yes
Pull request closed