perf(libc,agc): re-land skipping never-written guest pages in Windows heap mirror zero scans #18144
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18144"
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 sktharunbalaji13-cmd on 2026-11-10T16:21:46Z.
What
Re-lands #15967, which #18129 reverted because it hid a guest store of zero over a never-written page from the write tracker. Main failed
agc_driver_msaa_dcc_clear_2/4/8andagc_driver_native_depth_publicationon real Windows GPUs (#18113, #18114); the Windows CI job has no GPU and skipped them.Commits:
possiblyNonzero,GuestBytesZero) skip them instead of reading every page of a large, mostly empty heap. Review of the rebase:MarkPossiblyWritten(address, bytes, order)was the one overload withoutForgetKnownZero; it now has it.harvestZero,resetWrites) may drop a watched page that still reads as zero.watchWritestakesdropZero, default off, socollectOwnedWrites, which feedsCollect,CollectFreshandCollectArmed, reports every watched page and clears its known-zero bit. A first read of a never-written page also sets its write-watch bit, so such a page is reported as a write again; that is the behaviour before #15967.Why in the collector and not in each consumer: every residency check (
StoredOver,UnchangedSince*,CpuWroteSince,UnchangedCommittedSince, the MSAA DCC clear and the native depth publication) compares against a generation thatcollectWindowsWritesorwalkHintsstamps from these collects, so they see a zero store without a per-callerGuestMemory::ForgetKnownZero. Survey of the paths that still filter:harvestZero(insideKnownZero): a flagged page that still reads as zero keeps its known-zero bit. Its bytes are zero, so the heap mirror skipping it is correct; the flag is not reset.resetWrites: only settles pages of aCollection::Freshrun, whichCollectalready reports as fresh (report = fresh), so consumers treat them as changed regardless of the watch.ForgetKnownZerois a no-op there).@angrysandhill's
2bf167c210takes the other route,ForgetKnownZerocalls inMultisampleTarget::initialDccClearandprepareDepthSampling/prepareUniformPlaneSampling. It passes the same tests; I went with the collector because it also covers any consumer not listed. Thank you for the quick reproduction and the bisect.Generic behaviour: nothing depends on a title, address or size.
Tested
Windows 11 26200, RTX 4060 Laptop GPU (8 GB), NVIDIA driver 617.42, MinGW GCC (winlibs) Release,
BUILD_TESTING=ON, onmainc5488026abplus the commits of this PR,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:agc_driver_msaa_dcc_clear_2/_4/_8agc_driver_native_depth_publicationwindows_write_watchwindows_write_watch_verify_direct,agc_driver_resident_heap_mirrorCheckKnownZeroFirstReadsincore/libs/tests/WindowsWriteWatch.cppis the test that needs no GPU: it stores zero into a never-written page and requiresCollectto report it, and requires a real store to be reported too. It failed on the pre-fix code, so GitHub's GPU-less Windows job would have caught this regression.Wider run, 90 tests with
-R "host_import|guest_memory|guest_owned_memory|committed_read_mapping|copied_writer|linear_target|private_collect|write_watch|storage_write_back|read_only_lease_writer|partially_resident_snapshot|copy_guest_bytes|direct_write_completion|write_tracking|heap_mirror|msaa_dcc|native_depth_publication": 90 of 90 pass, 4 are skipped by design (agc_driver_msaa_dcc_compared_import_2/4/8"Linux comparison mode only",agc_host_import_sparse). NoVUID-in the log and nowas not found but was requested by env var VK_INSTANCE_LAYERS.Performance capture,
mainagainst this head, same title, scene and machine (Ghost of Tsushima Director's Cut PPSA02225, boot to the PlayStation Studios intro, RTX 4060 Laptop, driver 617.42, Windows 11 26200, 16 GB RAM, freshly restarted,APS5_TRACE_SECONDS=0:40 APS5_SKIP_REFUSED_DRAWS=1 APS5_PROFILE_DRAW=1 APS5_SOFT_DEPTH_CHECKS=1).mainisc5488026ab(after the revert), the head isd372128ba1, each built as a full library set from the same tree, three runs each alternating, 80 to 100 s per run. Frame and GPU numbers are the 40 stools/trace_digest.pywindow starting at present 0:A first
mainrun froze after 160 presents (the trace window never closed, so it has no summary line) and was repeated; it is not in the table. The blue PlayStation logo appeared in every run of both builds except head 1.Result: no speed or memory difference in this scene at 10 to 12 GB free RAM; the run-to-run spread (111 to 688 presents) is larger than any difference between the two builds. #15967 measured its gain at about 5 GB free RAM, where the old scans exhausted memory, and I did not reproduce a gain here. This PR therefore claims correctness only: the zero-scan skip returns, now without hiding zero stores.
Traces and
aps5-summary.jsonllines for all six runs:mainsummaries, head summaries, and the six traces next to them in that folder. The older #15967 captures at about 5 GB free are here. The zero-scan skipping that saves the RAM is unchanged from #15967, whose measurements are in that PR; only which write reports reach the tracker changed.python3 tools/check_conventions.py --base origin/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)agc_driver_resident_heap_mirrorand the wider run)🤖 Generated with Claude Code