fix(agc): heap-mirror ranges whose import windows left the write watch #5688
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5688"
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 EagleBearerYS on 2026-10-14T06:46:08Z.
What
Since #5596, singly mapped direct memory on Windows is private
MEM_WRITE_WATCHmemory instead of section views. That breaks heap mirrors for a direct-memory heap that a buffer access has partly imported. Resident Evil Village (PPSA01556) stops early in boot, 19 s in on the run under Tested:How it happens, on
main:importAccess→importAllocation,GuestBufferMemory.cpp).MEM_PRIVATE, so the import takes the direct path instead ofMapAlias. On Windows such a host import leaves the write watch (ImportWatched(..., staysWatched=false)→unwatchLocked→coverage.Exclude,GuestMemory.cpp). Before #5596 the alias import stayed watched.AcquireRegistered), and the import is refused.acquireMirror'sCollectWritesreturns 0 as soon as one 64 KiB block of the range is outside the watch.This change lets a heap mirror cover a range in the guest arena whose blocks are partly outside the watch:
CollectWatchedWritescollects the blocks still watched, andChangedWatchedBlocksreports the others asBlockUnwatched.The commits:
feat(agc): the two tracker calls, withCheckWatchedPartsinagc_write_tracking.fix(agc): heap mirrors use them, withagc_heap_mirror_unwatched_window.docs(agc): the debt entry. The compares' cost in a title isn't measured, and a sparse heap mirror still needs its whole range watched.chore(agc): moves the test's registration and the debt entry off lines that other open PRs change.Related: #5596, and #5169 (the Village bring-up discussion).
Tested
On GitHub's runners from my fork, on
mainat0b6d033b8:-DANYPS5_ENABLE_SPIRV_TOOLS=ON.agc_heap_mirror_unwatched_windowruns on the mock Vulkan device, so no GPU is needed. It replays the title's sequence: singly mapped direct memory on Windows (an arena range on Linux), a window import out of the watch, and the whole import refused by the budget.main'sGuestBufferMemory.cpp, it fails on Linux and Windows with "a heap whose window import left the write watch was not heap mirrored when its whole import was refused" (run).Also:
ctest -R "agc_driver|agc_masked|agc_shader"has no failures on either (396 tests each, with the same skips asmainon each GPU).ctest -R "agc|shader|video_out"(516 tests) passes on the RTX 5070. On the AMD GPU only the three tests of #5271 fail, and they fail the same way onmainthere.tools/check_conventions.py --base origin/mainpasses for all four commits.Resident Evil Village (PPSA01556, 01.210.000) on Windows 11 Home 10.0.26300, RTX 3070 Laptop (driver 617.42), Ryzen 9 5900HS, 15.4 GB RAM:
maincan't boot the title on this PC. Preparing every shader at registration gave a black screen for 10 minutes here, with private memory at 21.9 GB and heading for the commit limit, before the first frame.mainat0b6d033b8plus two local, experimental commits and a one-line adaptation that prepare each shader at its first draw, run withAPS5_RE8_LAZY_PREPARE=1 APS5_NO_GPL=1. They change onlyShaderRegistry.cpp, not the import or mirror paths.APS5_TRACE_HOST_IMPORT=1, the trace first shows a 64 MiB window of the heap imported (0x260400000+0x4000000), then later the whole heap (0x260400000+0x1a300000), after the heap mirror has served the first builds. The run goes on to an unrelated stop at 37 s (mprotect of uncommitted memory outside the guest arena; #5703 is its fix).APS5_PROFILE_DRAW=1: the[address]line's mirror compares took 1.3 ms per address-based build in the first 10 s window (36 builds, 131 blocks compared and about 74 copied per build), and nothing in the 23 windows after it. That field counts every mirror compare, so it's an upper bound for this change's.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 tibzejoker on 2026-10-14T08:29:55Z.
Runs for this PR at head
92a12d93a. Windows 11, MinGW-w64 GCC 15.2.0 Release, two GPUs in one machine: Intel UHD Graphics 770 (driver 32.0.101.6129, picked withANYPS5_GPU=Intel) and RTX 4090 (NVIDIA 616.92).agc_compute_descriptor_layout_flags,agc_descriptor_pool_reset_failure,agc_driver_address_space_teardown,agc_driver_covered_centroid_state,agc_driver_graphics,agc_heap_mirror_unwatched_window,agc_sparse_buffer_holes,agc_write_tracking) pass on both GPUs.ctest -R "agc_driver|agc_masked|agc_shader" -j4: no failures on either GPU. Intel: 396 tests, 28 skipped. NVIDIA: 396 tests, 1 skipped (agc_driver_stencil_ref_export). The skips are the same as onmainwith each GPU. On the UHD 770 they are features it doesn't support: f64, 64-bit and float atomics, mesh shaders, fp16 interpolation and dot, shader clock.No difference between the two GPUs.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-14T08:35:20Z.
Thanks for running it on both GPUs. The Intel result is especially useful, since my runs were on lavapipe, GitHub's runners and an RTX 3070. I've added it to the description's Tested section.
The compare cost the debt entry mentions is now measured for boot: on a 5-minute Village boot to the title with
APS5_PROFILE_DRAW=1, the mirror compares took 1.3 ms per address-based build in the first 10 s window and nothing after it. Gameplay isn't measured yet.Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T08:59:26Z.
AMD and NVIDIA runs for this PR at head
92a12d93a. Windows 11 Pro 26200, WinLibs GCC 15.2.0 (MinGW-w64), Release, one machine with two GPUs, each picked withANYPS5_GPU:1002:13c0, RDNA 2), driver 32.0.21036.18ctest -R "agc|shader|video_out" -j 8(516 tests, including the ones this PR adds or changes):agc_driver_lds_mixed_width_atomics,agc_driver_pixel_interlockandagc_driver_layered_volume_vertex_no_gpl. These three fail the same way on currentmain(872f52320) on this GPU and pass there on the RTX 5070; they are the three of #5271, so not caused by this PR.No title run. AI-assisted: yes (Claude Code ran the builds and tests).
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-14T09:01:42Z.
Thanks for the AMD and RTX 5070 runs. The RDNA 2 result fills the gap in this PR's testing; I've added it to the description.
Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-14T13:46:30Z.
@EagleBearerYS We hit the same #5596 effect from another side: Ghost of Yōtei's intro ran at half its frame rate because every import of singly mapped direct memory left the write watch and was compared on the CPU each frame. #5851 fixes it at the import: a range that holds resident direct memory goes through
MapAlias, which moves the resident runs into the section, so the import stays watched.If you have a moment, could you try Village with #5851 and without this PR? I expect the 64 MiB window import of the 419 MiB heap to stay watched there, so the heap mirror would not refuse it. The two changes don't conflict, and I'm not suggesting either should wait for the other.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-14T14:48:45Z.
Ran it: with #5851 and without this PR, Village boots past the 419 MiB abort, and its title runs about 6.6 times as many frames. Numbers on #5851: https://github.com/boykopovar/AnyPS5/pull/5851#issuecomment-6171130227
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-14T15:25:40Z.
Closing in favour of #5851, which keeps these imports write-tracked at the source. On Village it removes the abort this PR fixed and the per-frame compares with it (numbers on #5851).
Pull request closed