fix(agc): defer write tracking for fresh Windows shared imports #4535
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4535"
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 moong15 on 2026-10-12T14:56:42Z.
What
Windows shared direct-memory imports currently collect and arm every page, even when no consumer has collected it before. Unlike private
MEM_WRITE_WATCHallocations, section views are tracked by removing write access, so importing fresh memory introduces first-write faults on the guest's loading threads. This gives Windows shared mappings the deferred activation already used by the Linux path in #1960.Track collection history for each 4 KiB portion of a 16 KiB shared view, independently of its dirty generation and current protection. Import-time armed collection skips portions never collected. Before
MarkWrittenstamps a GPU write, fresh collection activates those portions across the containing 64 KiB tracking blocks and stamps them before the GPU generation. Later CPU writes remain visible. Protection still operates on whole views and their aliases; privateMEM_WRITE_WATCHcollection retains its existing behavior. Fresh collection skips unmapped neighbors and private allocations and preserves dirty pages that were already collected. The existing partial-output contract for ordinary collection is retained. The never-collected portions are also kept as address ranges, as the Linux tracker keeps_fresh, so a fresh collection returns after one lookup when none overlaps the request instead of walking every view of the written blocks on each GPU write.Seven files; no environment toggle, title-specific bypass, prefault worker or rendering changes. The prefault work from closed #4290 remains separate; it was closed to keep one open PR and will be resubmitted as a follow-up PR after this one, with evidence gathered on top of this change. This change alone does not reliably get Hades II through loading in the runs below; with the separate prefault patch on both sides it decides whether the title loads (0 of 5 without it, 5 of 5 with it).
Ready for review. The automated overlap comment currently lists #3874 in
GuestMemory.cppand #4661 inWindowsMappings.hpp. #3874 compares import-window bytes; this PR defers activation of fresh Windows shared pages. No ordering agreement or combined validation with either is claimed. The earlier overlap with #2802 was resolved by basing this branch on its merge inmain, preserving its unstamped-store notifications; the branch is now rebased ontomainc13dc7e6bwithout conflicts. There is no code dependency on an open PR. The separate prefault patch remains follow-up work.Tested
Windows 11 Pro 26200, Ryzen 7 9800X3D, 47 GB RAM, Radeon RX 9070 XT (driver 32.0.32015.2008), WinLibs GCC 15.2, Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON.Current head
dfc026af4(9694782e9 is the earlier commit rebased; dfc026af4 adds the fresh-range early return), based onmainc13dc7e6b: full build passed; all seven focused tests passed (1.40 s); all four alternate-mode tests passed (1.38 s). Fullctest --output-on-failure -j4: 1,019 passed, 10 skipped, 5 failed out of 1,034, in 125.47 s. Four failures are the shader tests listed below; the fifth,agc_driver_pooled_buffer_range, failed withvkMapMemory buffer slab: Vulkan result -5under-j4and passed 3 of 3 when rerun alone. A failure-only baseline run was not repeated onc13dc7e6b.git diff --checkandtools/check_conventions.py --base origin/mainpassed.October 13: prefault on both sides, requested in review.
mainc13dc7e6b+ 1ad61fec8 versus 9694782e9 + 1ad61fec8, Hades II PPSA36082 v01.006, same relinked executable. Every run restored the same warm shader-cache seed (184 files, 23,466,293 bytes, built for the new shader source version), cleared inheritedAPS5_*variables and set onlyAPS5_HOST_IMPORT_MIB=16384andAPS5_PREFAULT_MEMORY=1, with write tracking enabled. One warm-up per build was excluded before execution; five measured runs per build alternated main/PR over a 40-second window. No builds or tests ran concurrently.main + prefault: 0 of 5, each the same
LoadTaskSchedulernull write afterGUI.pkg; its warm-up crashed too. This PR + prefault: 5 of 5 opened both banks and survived; its warm-up survived. Outside the measured set, main + prefault survived once, on the first run from an empty shader cache, then crashed on two warm cache-priming runs and six further empty-cache runs. Times are from process creation to receipt of a flushed log line.Frame rate was read from the window title (no instrumentation) with no input. This PR + prefault held 119.85-119.91 FPS, the 120 cap, from 20 s to 170 s in one run, and median 119.88 FPS from 20 s to 60 s in five further runs (three with dfc026af4, two without, alternating; all five loaded). main + prefault never presented more than 15 frames, so no main frame time exists for this title, and the cap hides any difference between the two PR builds.
Per-call cost of a fresh
Collect, standalone program over 256 MiB of mapped shared views, before and after dfc026af4 (second of two rounds):No gameplay, cold-cache reliability, other-title, Linux or other-GPU claim is made. The prefault patch is not part of this branch.
Previous head
652cb0b87, based onmaind592d54e1: full build passed; all seven focused tests passed (1.78 s); all four alternate-mode tests passed (1.49 s). Fullctest --output-on-failure -j4: 968 passed, 8 skipped, 4 failed out of 980, in 87.29 s. The failures are the same four shader tests listed below and reproduced on the earlier untouched baseline; a separate failure-only baseline run was not repeated ond592d54e1.git diff --checkandtools/check_conventions.py --base origin/main --title ... --body ...passed. The overlap check at that time reported #3874; the current automated comment also lists #4661.The focused selection was
windows_write_watch,agc_write_watch_coverage,agc_write_tracking,agc_shared_write,agc_shared_write_partial_collect,agc_shared_write_partial_collect_two_pass, andguest_memory. The alternate-mode selection waswindows_write_watch,agc_write_tracking,agc_shared_write, andguest_memory.New backend coverage checks fresh/armed selection, 4 KiB history within a view, aliases, one-entry output buffers, remapping, pins, host writes, inaccessible-page failure, holes, private memory and concurrent writes. AGC integration coverage checks import-time deferral, activation before the first GPU stamp, CPU writes after GPU writes, adjacent fresh portions, repeated GPU writes, import-window stamps and an unaligned import beside an unmapped range.
Before the rebase, 840fcb475 on
main8fa5cc486built successfully. All seven focused tests passed (1.62 s); four tracking tests also passed withAPS5_NO_SINGLE_PASS_COLLECT=1(1.49 s). Full CTest: 966 passed, 8 skipped, 4 failed out of 978 (102.70 s). The four failures were reproduced serially on untouchedmain8fa5cc486:agc_driver_division_output_modifiers,agc_driver_division_result_modifiers,agc_driver_f64_conversions, andagc_driver_f64_transcendental, all SEGFAULT. This is a baseline comparison, not a claim that the full suite is green.Five isolated backend mutations were rejected by the new tests: armed collection consuming fresh pages, fresh collection returning nothing, not recording history, tracking history only per 16 KiB view, and fresh collection consuming existing dirty pages. Those mutation runs preceded the final partial-output compatibility adjustment; they were not rerun after it.
October 13: matched baseline comparison requested in review. Clean upstream
d592d54e1(this PR's exact parent) versus published head652cb0b87, on the Windows/GPU/toolchain above, Hades II PPSA36082 v01.006. This is a fixed-base comparison; newer upstream changes were not included. Every run restored the same warm shader-cache snapshot (2,396 files, 330,400,440 bytes), cleared inheritedAPS5_*variables and set onlyAPS5_HOST_IMPORT_MIB=16384, with write tracking enabled. No prefault, import bypass, loading throttle, backpressure or unrelated local patches. One warm-up per build was excluded before execution; the three measured runs per build alternated baseline/PR. No builds or tests ran concurrently with the game. OS file/driver caches were not reset.The uninstrumented loading comparison:
All six crashed before either audio-bank open with the same
LoadTaskSchedulernull-write signature. Baseline FATAL timestamps were 9.431/9.499/9.326 s; PR timestamps 9.222/9.401/9.024 s. Times are from process creation to receipt of a flushed log line, not completed asset loads or rendered frames; crash reporting added about ten seconds to process exit. Median Launch-to-GUI interval was 0.622 s in both arms. The predesignated baseline warm-up survived and opened both banks, while the PR warm-up crashed at 9.114 s; including them gives baseline 1/4 and PR 0/4. The sample does not establish a loading benefit or a regression.A separate diagnostic comparison applied identical local counter instrumentation to both source revisions and ran three alternating pairs to the same first
GUI.pkgopen:Each run reached four import windows. The baseline initially armed 434,176 shared views inside imports in every run; the PR armed zero there and initially armed 1,416 views outside imports. Median import-first write faults 2,104 -> 0; median all armed shared-write faults 2,124 -> 26 (98.78% fewer at this milestone). Ordinary write tracking remained active.
The counter tags a mapped 16 KiB virtual view when its first successful read-only protection occurs inside
ImportWatched, then counts a write access violation handled while that initial protection remains armed. Later re-arms do not count as fresh-import arms; aliases count separately and remapping resets the diagnostic history. These are shared-view write-protection exceptions, not hardware/soft page faults or unique physical pages. Atomic counters are read from a named shared-memory buffer; no per-fault printing or sampling thread is added to the game. The extra diagnostic variable names that buffer. Snapshots occur on log receipt and are not globally atomic across fields; instrumentation can affect timing.Counter validation passed against both headers: two import collections/writes of one view and a non-import collection/write of another produced exactly 2 import scopes, 1 initial import arm, 1 associated first-write fault, 3 total armed write faults and 1 other initial arm. Instrumented PR
windows_write_watchandagc_write_trackingpassed; baselineagc_write_trackingpassed. Full suites were not rerun for the diagnostic edits.The instrumented runs intentionally stopped immediately after the GUI counter snapshot and make no 40-second survival claim. The endpoint was set for both arms before their measured runs, after the baseline warm-up's crash left a temporary crash-snapshot child holding DLLs. Two PR staging attempts failed before starting a game. Both diagnostic warm-ups and all run outputs were retained. The source instrumentation was removed and the original game/cache restored afterward.
These measurements show removal of the observed import-induced first-write faults. They do not demonstrate faster/reliable loading or gameplay improvement. Diagnostic source, counter definitions and reproduction steps are in the review reply; none of the instrumentation is included in this branch.
Earlier title runs (October 12; before the rebase):
Hades II (PPSA36082 v01.006; bring-up #1965), warm existing shader caches, built from 840fcb475 before the rebase. Each run cleared inherited
APS5_*variables and setAPS5_HOST_IMPORT_MIB=16384. Write tracking stayed enabled. No experimental import bypass, loading throttle, backpressure or local gameplay patches were included.Music.bankandMasterBank.bank; two crashed with a null write onLoadTaskScheduler, consistent with the known upload-pool exhaustion failure.APS5_PREFAULT_MEMORY=1Surviving runs were terminated by the harness; their termination exit code is not a crash. The two crashing processes lasted 20.606 and 19.293 seconds including crash reporting. No drawn-menu, gameplay/FPS, cold-cache, other-title, Linux or other-GPU claim is made. The October 13 comparison above uses the published head; the combined-prefault runs were repeated on the rebased head in the prefault comparison above. The temporary prefault patch was removed from the branch, and the original game executable and libraries were restored and hash-checked. Full upstream CI requires a maintainer's manual workflow run.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T22:52:41Z.
Prepared author-preserved port of 652cb0b8780b7321c20ec4cfa952fdf4f353dc65 onto our runtime-table 007 stack: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-deferred-shared-tracking , head4135e2871 (production port31d46210c). Not built/staged yet; current separate game comparison is still running, so no concurrent build/test load.
Conflicts resolved by retaining the stack's 4 KiB per-subpage generations/protection/partial-output settlement, local shared-alias mapping, and #4661's newer host-write correction from1eb13fdf025bab9283bd6d18f6c55afdfcfd2646. Collection history is marked only for the settled output prefix. Fresh activation forces reporting of selected never-collected subpages; the existing host-write arming/untracked-page logic stays intact. The unrelated newer-main noteUnstampedStore API is absent from this runtime stack, so its existing unwatched fallback remains unchanged.
Your WindowsWriteWatch fixture came across. Two whole-view expectations need adaptation on this stack: collecting only page0 leaves page3 writable; writing page9 after activation reports page9 alone. Added an explicit check that page0 is protected and page3 remains writable. Will run the focused native suite and report failures/negative controls before attempting007; no FPS or crash-fix claim.
AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T22:59:21Z.
Windows/RTX5070Ti/GCC15.2 runtime-stack cross-test of652cb0b: final integration d26e52a8294bbc2e61b18a7f2f59e355da5a3c98 on codex/first-light-deferred-shared-tracking. Your production/fixtures preserved in31d46210c, 4KiB fixture expectation adaptation4135e2871, plus existing main9873fae1e's three-line reserved-view commitment dependency in d26e52a82 (original author preserved). The full lazy-backing libkernel change is not included.
Initial integration4135e2871 had5/7 pass; both new shared SEC_RESERVE fixtures failed before assertions with "protect shared guest page: Attempt to access invalid address". Our older Map lacked9873fae1e's query/commit. Importing exactly that existing Map hunk resolves setup:7/7 native PASS1.71s (windows_write_watch, agc_write_watch_coverage, agc_write_tracking, agc_shared_write, partial-collect single/two-pass, guest_memory). Alternate APS5_NO_SINGLE_PASS_COLLECT=1 on windows/coverage/tracking/guest4/4 PASS1.48s.
Production-only mutations, fixture unchanged:
Restored/touched/rebuilt positive:7/7 PASS1.67s, none skipped, source clean/diff-check pass. Not a current-main-only/full-suite validation.
Only patched graphics8745FDBD1E62CD423E9E5F0DFB79E4EE7D73149A36B02D98AFADAEEE406A0986 + libc08AB01A94E6A9D0D82DF51F1676B5D7392437CD8382DD7C36CC0801A5288C10A staged. Normal007 warm-cache/cache16 launched22:59:33.852UTC (initial helper invocation exited before starting the game; corrected its path quoting); no sampler/profile or concurrent builds/native tests. No rendering/crash/FPS claim yet. Preceding image-ordering comparison reached the incomplete slow scene (
0.19FPS) and ended intentionally after3min Resume; separate result on #2523.AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T23:11:47Z.
007 cross-test on d26e52a8294bbc2e61b18a7f2f59e355da5a3c98/graphics8745FDBD/libc08AB01A9/cache16 ended intentionally23:11:20.034UTC (~3m24 after Resume23:07:56.425), not a crash. Final frame1877/
0.17FPS, bright circles over black. Last private23.428GB/free5.356GB; five bounded working-set trims during the full run (one during startup), so no clean FPS benchmark. Runtime image-table write-backs remain unsupported. Startup/menu2FPS; no clear title rendering/FPS improvement established from deferred activation in this single run. Native7/7 plus two-pass4/4 and mutation results remain separate from game behavior.Next game comparison keeps these exact two libraries and changes only resource-cache capacity16→64, same warm cache/other settings/guards. Preparing combined #4646+#4683 native validation first, with no game concurrent. Still awaiting SleglJan's runtime-table-store/reference-texture head for cross-test; unsupported stores remain outside this change.
AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:21:08Z.
What does main do on the same three PPSA36082 runs? The description gives one of three runs surviving the 40 s window with this PR and no figure for main, and says the change doesn't get the title through loading on its own, so its effect isn't shown yet.
A count of first-write faults on fresh imports, or the time to a fixed point in loading, for main against main plus this PR alone would do.
Imported from boykopovar/AnyPS5. Originally posted by moong15 on 2026-10-13T02:09:33Z.
@oneandonlydean Collected both comparisons on the exact upstream parent
d592d54e1against published PR head652cb0b87, Hades II PPSA36082 v01.006, on Windows/RX 9070 XT/GCC 15.2 Release. Newer moving-main changes are not included.First-write fault counts at the first
/app0/Content/Packages/1080p/GUI.pkgopen, three alternating pairs with identical local instrumentation:All six reached four import windows. Main initially protected 434,176 shared views inside those windows each time; the PR protected none there, while initially protecting 1,416 views outside imports. The reduction is in the intended fault class, with ordinary write tracking still active.
The separate uninstrumented loading trials used the same two revisions and three alternating pairs:
All six failed with the same
LoadTaskSchedulernull write before either audio-bank open. Median Launch-to-GUI interval was 0.622 s for both. The excluded warm-ups were designated beforehand: main survived 40 s and opened both banks; PR crashed at 9.114 s. Including them gives main 1/4, PR 0/4; too small a sample to establish a regression. The result supports reduced import-induced first-write faults, but does not establish a standalone loading fix or a loading-time improvement.Every run restored the same warm shader-cache seed (2,396 files, 330,400,440 bytes), cleared inherited
APS5_*, and usedAPS5_HOST_IMPORT_MIB=16384. No prefault, bypass, throttle, backpressure or other local title changes; no concurrent builds/tests. The executable was identical; only libc and AGC driver differed in their executable-section hashes between the uninstrumented builds. OS file/driver caches were not reset.Counter definition: a fresh-import arm is a mapped 16 KiB virtual view's first observed successful read-only protection inside
ImportWatched. Its first-write counter increments when the real write access-violation handler sees it still armed from that activation. Later re-arms are excluded; aliases count separately, remapping starts a new history. Counts are protection exceptions, not 4 KiB hardware/soft page faults. The diagnostic history is independent of the productioncollectedfield.Atomic counters are in named shared memory; no per-fault printing or game sampling thread. The extra
APS5_FAULT_PROBEvariable names that buffer. Counts are sampled on receipt of the flushed GUI file-open line, then the instrumented process is intentionally stopped, so these runs do not assess 40-second survival. Snapshot fields are not read as a globally atomic group; instrumentation can perturb timing. Uninstrumented times remain separate.The deterministic probe fixture passed on both headers: 2 import scopes, 1 first import arm/fault, 3 armed write faults, 1 other first arm. Instrumented PR tracking/backend tests passed, as did baseline tracking. Before measured counter trials, the endpoint was changed for both arms from 40 s to GUI after the baseline diagnostic warm-up left a temporary crash snapshot holding DLLs. Two subsequent staging attempts launched no game. All warm-ups and raw outputs were retained; the temporary probe was removed and original game/cache restored.
The PR description now includes these results. Diagnostic sources and reproduction steps follow; local paths can be adjusted for another checkout. No probe code is committed to the PR.
Counter probe, identical instrumentation script, runner and validation fixture
FaultProbe.hpp
instrument.py
run_fault_comparison.py
ProbeValidation.cpp
validate_probe.py
Apply
instrument.py CHECKOUT_PATHto each clean revision separately, buildlibs, and save each patched library set asprobe-base/libsandprobe-pr/libsnext to the runner. Supplycache-seedfrom the common shader-cache snapshot. Runrun_fault_comparison.py probe-base RUN_NAME 40/probe-prin alternating order; this version stops at GUI even though 40 is the fallback timeout. Each JSON includes SHA-256 for libc, AGC and executable, milestone counters and intentional-stop reason;.timed.jsonlrecords log receipt timestamps. BuildProbeValidation.cppwith GCC C++20,-O2 -fasynchronous-unwind-tables, then runvalidate_probe.py base/prafter building it against the corresponding instrumented header. Keep the fixture's explicit ordinary collect on both: it tests the counters independently of the Armed/Fresh selector.AI-assisted: OpenAI Codex.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T02:28:38Z.
Thanks, that answers the question: first-write faults go from 2,104 to 0 by the first
GUI.pkgopen, the launch-to-GUI interval stays at 0.622 s, and PPSA36082 crashes at the same point either way. So the count moves, but no time or outcome does yet. Two things would show the need:MarkWrittennow collects on Windows as well, and a freshCollectvisits every shared view of the written blocks on each GPU write (WindowsMappings.hpp:229-235); the Linux side returns early when nothing is fresh (GuestWriteWatch.cpp:107-113). A frame time on a title that reaches rendering, main against this PR, would show whether that costs anything.Imported from boykopovar/AnyPS5. Originally posted by moong15 on 2026-10-13T03:38:43Z.
@oneandonlydean Ran both on PPSA36082, and changed
MarkWritten's collection as you pointed out.mainc13dc7e6b+ 1ad61fec8 against this change rebased onto it (9694782e9) + 1ad61fec8.APS5_PREFAULT_MEMORY=1,APS5_HOST_IMPORT_MIB=16384, write tracking on, same executable and warm shader-cache seed, one excluded warm-up each, five alternating pairs, 40 s window.main + prefault: 0 of 5, the same
LoadTaskSchedulernull write afterGUI.pkg; its warm-up crashed as well. This PR + prefault: 5 of 5, and its warm-up survived. Outside the measured set, main + prefault survived once, on the first run from an empty shader cache, then crashed on two warm priming runs and six more empty-cache runs. So with prefault on both sides and write tracking on, this change decides whether the title loads here._fresh, and a freshCollectreturns after one lookup when none overlaps. Per call, over 256 MiB of mapped views with nothing fresh: 64 KiB block 45 ns → 13 ns; 64 MiB range 22 µs → 13 ns; after CPU writes to every page, 64 KiB block 163 ns → 13 ns and 64 MiB range 140 µs → 13 ns. First activation of a block goes from 2.0 µs to 2.3 µs. I can't give a main-against-PR frame time on this title, because main + prefault never gets past its first 15 frames. With prefault, this PR holds 119.85–119.91 FPS (the 120 cap) at the title screens with no input, with and without dfc026af4, so the cap hides any difference there.Rebased onto
c13dc7e6b. Seven focused and four alternate-mode tests pass. Full suite: 5 failed out of 1,034 — the four shader segfaults already listed, andagc_driver_pooled_buffer_rangewith avkMapMemoryerror under-j4that passes 3 of 3 alone. The description has the details.AI-assisted: Claude Code.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T05:26:04Z.
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)core/libs/prx/libc/include/WindowsMappings.hppL493-494