fix(agc): compare Windows host imports after late driver writes #1441
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1441"
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 ToyuAU on 2026-10-08T06:42:35Z.
What
Addresses #1434: Windows drivers can mark imported pages dirty after the synchronous import window. Treating those marks as CPU stores makes storage-image write-back discard newer GPU results. Windows host-pointer imports use the existing byte-comparison paths instead.
GuestMemory::Unwatchexcludes overlapping 64 KiB tracker blocks and invalidates collection memos. A new private allocation that fully replaces an excluded block restores tracking, stamps a new generation, removes old driver-store pieces and invalidates collection memos. Protection-only commits, shared remappings and partly replaced blocks retain the exclusion. A later import excludes the replacement again.WindowsMappings::Commitreports only the private allocations it creates from placeholders, coalescing adjacent fresh spans.GuestArenanotifies the tracker after the mapping mutex is released, avoiding the inverse lock order of write collection. Commit generations are recorded with exclusions so a delayed notification cannot re-enable tracking for an import made after that commit. Generation records are stored sparsely for excluded blocks. The VirtualAlloc2 documentation distinguishes placeholder replacement with a private allocation from committing already committed memory.This addresses the address-reuse failure reported in the recorder executable without weakening
AllocateWatched's assertion. The fresh-backing observer and Windows integration test still need a Windows build and hardware retest; this remains a draft.The test target now links
libc, configures Windows unwind and supplies the Windows runtime library path, correcting the reported MinGW__gxx_personality_v0link failure.Related: #1046 changes the Linux probe and includes the same recorder snapshot-reuse guard. #1310 overlaps the write-tracking tests. Neither is a dependency. The Linux probe is unchanged here. The alternative linked in the Windows report keeps imports watched and classifies an all-pages dirty sweep; this PR continues using byte comparisons instead of that heuristic.
TechnicalDebt records that snapshot reuse and unit shadows remain unavailable on excluded backing, that only complete private-backing replacement restores coverage, and that restoration on import retirement and comparison performance remain future work.
Tested
macOS arm64, AppleClang 17, C++20, rebased onto main
6b573862:agc_write_watch_coveragepasses with-Wall -Wextra -Werrorand AddressSanitizer/UndefinedBehaviorSanitizer. It covers exclusions, fresh-backing restoration, partial replacements, clipping, adjacent blocks, repeated imports and stale/same-generation mapping notifications.python3 tools/check_conventions.py --base origin/mainandgit diff origin/main...HEAD --checkpass.tools/tests/test_progress.pypassed. These are not full Windows build results.A new Windows-only
agc_write_trackingcase uses the real arena and tracker: a protection-only commit retains the exclusion; resetting/releasing and allocating the same address with fresh private backing restores it, invalidates old stamps, detects a subsequent CPU edit and excludes a second import again. This case was not run locally.Windows results reported by popcoder565, for main
bc1fbe81merged with the originalbab05aafand the suggested two linker lines: Windows 10 (19045), RTX 3060 Laptop, driver 616.92, MinGW-w64 GCC 15.2.0, Release.agc_driver_dcc_keys_first_writeandagc_driver_srgb8_color_target: 20/20 each, versus approximately one-third and three-quarters failures on main.agc_write_watch_coverageandagc_write_tracking: pass.agc_driver_recorder_testsexecutable failed 3/3 atAllocateWatched; main passed 10/10. Those observations predate this PR's fresh-backing follow-up and do not establish that the latest revision fixes the hardware regression.Draft pending a supported Windows rebuild and reruns of
agc_write_tracking, the two original GPU regressions, full CTest and the separately builtagc_driver_recorder_testsexecutable. No full Linux build or title run is claimed locally.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 repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T06:52:05Z.
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/libSceAgcDriver/tests/WriteTracking.cppL119, L129Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-08T06:53:49Z.
Ran this on Windows, which the description says couldn't be run: Windows 10 (19045), RTX 3060 Laptop (driver 616.92), MinGW-w64 GCC 15.2.0, Release,
mainbc1fbe81merged with bab05aaf.agc_write_watch_coverage_tests:undefined reference to __gxx_personality_v0. The target needs what the other test targets have:agc_driver_dcc_keys_first_writeandagc_driver_srgb8_color_targetpass 20 of 20 runs each. Onmainthey fail in about one run in three and three in four.agc_write_watch_coverageandagc_write_trackingpass.agc_driver_recorder_tests, which is not in ctest but which #1046 registers, fails in 3 of 3 runs withthe watched block is not watched. Onmainit passes 10 of 10. The check isAllocateWatched(tests/Recorder.cpp:62). A new arena block at an address an earlier import excluded stays unwatched, which is the trade-off this PR's TechnicalDebt entry describes.For comparison, I tried keeping imports watched instead: popcoder565/AnyPS5@fix/agc-import-pin-marking. The driver's second marking covers every page of the import about 1-2 ms after the window, so
ImportWatchedremembers the range. The first walk that finds all of its pages written stamps them asImportWindowand forgets it, re-probing for up to 4 ms when it sees a marking in progress.agc_driver_recorder_testskeeps passing.agc_write_trackinggets a GPU-free check of the rule.I haven't opened it as a PR, since this one already targets #1434. Whichever approach the maintainers prefer is fine.
Imported from boykopovar/AnyPS5. Originally posted by gunerky on 2026-10-08T09:15:09Z.
Independent Windows retest of the fresh-private-backing follow-up.
Tested PR head
2b2636a0e75b9cbc217639d5d2727995b0d8fe2f, with matching main6b57386237a652f11ecdd2c420f43376adb972e6in separate, unmodified detached worktrees.These results cover the two pinned revisions above. Newer main, rebased revisions and the eventual merged tree have not been tested.
Windows 11 Pro (26300), desktop RTX 3060, driver 617.42; WinLibs MinGW-w64 GCC 15.2.0 UCRT/posix/SEH, Ninja Release, BUILD_TESTING=ON, SPIRV-Tools=OFF. Vulkan was required, the physical RTX 3060 was selected, and shader caching was disabled. No import-policy override, artificial delay, game input or driver change.
Normal Windows host results, with workspace-local TEMP/TMP:
The PR's default build, patched libs target, local conventions check and diff whitespace check passed without a local source correction. The Windows private-address-reuse case executed in all 30 write-tracking runs, including protection-only exclusion, fresh-backing restoration, stale-generation invalidation, a later CPU edit and re-import.
The recorder is still unregistered in CTest, so it was explicitly built and run. No
the watched block is not watchedassertion occurred. Draw snapshot reuse and unit shadows are explicitly not tested under the comparison policy; watched storage refresh runs through its unwatched path. The import-policy assertion passed. The range-leaving-watch and import-window cases remain Linux-only.Main's intermittent GPU failure did not reproduce here. These results therefore corroborate the latest Windows build, fresh-backing integration and recorder follow-up, but do not establish a before/after driver fix on this configuration. A rerun on the original Windows 10 / RTX 3060 Laptop / 616.92 configuration remains useful. No performance or game-compatibility conclusion is claimed.
The initial restricted AppContainer full run had 16 failures; its disk-cache write failure also occurred on main and disappeared with workspace TEMP/TMP. All 420 passed in the normal host run. Initial restricted failures are retained locally and are not claimed as PR regressions.
AI-assisted: OpenAI Codex assisted with preparation, execution and analysis of this validation and report. No production code change was authored.
Imported from boykopovar/AnyPS5. Originally posted by ArjenS-LA on 2026-10-08T09:34:35Z.
<html>
Independent Windows retest of the fresh-private-backing follow-up.
Tested PR head
2b2636a0e75b9cbc217639d5d2727995b0d8fe2fin an isolated detached worktree, with main7fccb7ff5ff7043c044b7c820cbb63a4bd4c48f6as the baseline. Both source checkouts were unmodified. The baseline is newer than the PR’s base,6b57386237a652f11ecdd2c420f43376adb972e6, so this is not an exact parent-versus-PR comparison.These results cover those pinned revisions. Newer revisions and the eventual merged tree have not been tested.
Windows 11 Enterprise (10.0.26200), NVIDIA GeForce RTX 3050 Ti Laptop GPU, driver 591.55; WinLibs MinGW-w64 GCC 15.2.0 UCRT/posix/SEH r2, Ninja Release,
BUILD_TESTING=ON,SPIRV-Tools=OFF. The project documents WinLibs r7; this run used the installed r2 toolchain.The targeted execution tests selected NVIDIA, required Vulkan, and disabled shader caching. No import-policy override, artificial delay, game input, or driver change was used.
Dedicated validation-harness results, excluding additional CTest runs:
The PR’s full build, patched
libstarget, conventions check, and diff whitespace check passed without a local source correction. Both tracking tests also passed in a separate targeted CTest run and in the full suite. The Windows private-address-reuse case passed, covering protection-only exclusion, fresh-backing restoration, old-generation invalidation, a subsequent CPU edit, and re-import.The recorder remains unregistered in CTest, so it was explicitly built and run. No
the watched block is not watchedassertion occurred. Draw snapshot reuse and unit shadows are explicitly not tested under the comparison policy; watched storage refresh runs through its unwatched path. The Windows import-policy assertion passed.Main’s intermittent GPU failure did not reproduce here. These results therefore support the latest Windows build, fresh-backing integration, and recorder follow-up, but do not establish a before/after driver fix on this configuration. A rerun on the original Windows 10 / RTX 3060 Laptop / 616.92 configuration remains useful. No performance or game-compatibility conclusion is claimed.
Initial sandbox build attempts encountered Git ownership/dependency-check problems and a stalled Ninja process. The build completed after resuming outside the sandbox, and the full CTest run passed in the normal Windows host environment. Those build-environment problems are not claimed as PR regressions.
AI-assisted: OpenAI Codex assisted with preparation, execution, and analysis of this validation and report. No production code change was authored.
</html>Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T13:48:46Z.
Checked on Linux: build and full ctest (459/459) on top of current
main;agc_write_trackingandagc_write_watch_coveragepass. The Windows-only reuse case can't run here, so I'm relying on the Windows runs above (popcoder565, gunerky, ArjenS-LA: both GPU regressions,agc_write_tracking, the separately built recorder and full ctest pass on the current head).Added one commit of ours:
Notes, not blocking:
tests/Recorder.cpp:1175: the newWatched()guard also skips the snapshot-reuse test on Linux when imports end up unwatched, where it used to fail. Fine while the recorder isn't in ctest, worth remembering when #1046 registers it.Merging once CI is green.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-08T20:52:52Z.
I ran Ghost of Yōtei (PPSA26344 v1.008) on plain
mainwith this PR to check a start-up abort we hit in our own tree. Plainmaindoesn't abort, but both what it shows and our abort come from the gap your TechnicalDebt line already mentions: once a host import is created on Windows, its 64 KiB blocks leave write tracking for the rest of the process.Yōtei creates its Vulkan device twice. On
main4b005b22the 3.3 GiB range at 0x5000000000 is imported on the first device, and when the device is recreated at swapchain creation (27 s)mainimports it again in one piece, so imports go from 4,932 MiB back to 4,935 MiB and nothing needs a mirror. Our tree carries #290's 64 MiB import windows and a heap-mirror change of ours that serves such a range from a heap mirror until it can be imported whole. There the range wasn't imported again after the recreation (imports fell from 4,933 MiB to 206 MiB), no heap mirror could be made because the range was no longer watched, and the next address-based build fell back to copying all 3,380 MiB and stopped at the 64 MiBAPS5_ADDRESS_COPY_MAX_MIBlimit. So that abort is ours to deal with, though I'd expect the same onmainwhenever a large range that was imported once later has its import refused and needs a mirror.What plain
maindoes show is the cost of the comparison. Storage images inside imported ranges get no write stamps, so every refresh uploads them again: about 20 GiB of "untracked" uploads per 10 s, and 42 presents in 240 s. With only the Windows part reverted (unwatchLockeda no-op,unwatchImports = false), the same build had no untracked uploads and 188 presents. Do you have a plan for putting the watch back when an import is retired, or for keeping stamps on imported storage images? I'm happy to test a change against this case.Details
Windows 11, RTX 3080 Laptop, the same post-gamma save,
APS5_HOST_IMPORT_MIB=6144. Plainmain4b005b22(which has this PR) stops at its first present on a descriptor read that an open PR fixes, so these runs add one local env-gated probe that skips a dispatch that throws (APS5_FMT_PROBE_TOLERATE=2); 240 s each, no FATAL.With the revert: 284 direct storage uploads (2,594 MiB) per 10 s on average against 1,659 (19,676 MiB), and 0.98 against 0.21 fps over the last 100 s. The revert run came second and started with the 104 shader cache entries the first run wrote (27 for the first); both created 21 pipelines.
Our tree (integration on main
4b005b22):The run before this PR mirrored the same range and later released the mirror for an import. With the revert, a 1,200 s capture pass and a 3,600 s run in our tree had no FATAL and 0 unwatched heaps.
Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-08T21:46:07Z.
On Windows this change costs PPSA22520 (Animal Well) most of its frame rate: about 59 FPS before it, 7.5 FPS after (Windows 11, RTX 4070 SUPER). A
git bisect --first-parentnames this merge (7a047bc1) as the first bad commit; its parentfe9beae0is good. With every import compared,[rescache] revalidategoes from 0 to 10,725 full walks per 10 s, 6.8 s of every 10 s.#1847 keeps imports watched and tells the late driver marks apart from CPU stores by comparing a copy of each import's bytes for a settle period, so #1434 stays fixed. @ToyuAU @adriadam10, a review would be welcome.
Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-08T22:32:37Z.
Regression report for PPSA12544 (Hollow Knight: Silksong) on Windows after this change landed (
838d02a8), with a measurement of what it costs.Setup: Windows 11, MinGW GCC 15.2 Release, NVIDIA RTX 3080 (driver reports Vulkan 1.4),
origin/main4b6ab6bbplus #846 for the bring-up of this title. Same converted game, same build, only the import-watch decision differs.Before (host imports stay write-watched): the title reaches its main menu at 59.94 FPS (window-title counter, 2848 frames at the 60 s mark). The player also played past the menu into gameplay on the pre-#1441 code at well over 30 FPS (reported by the user; I only measured the menu).
After (host imports compared, as merged): the same menu runs at 9.9 to 10.3 FPS (655 frames at 66 s, 733 at 75 s, warm shader cache).
APS5_PROFILE_DRAW=1over a 10 s window shows:[storage] uploads by path: direct 6929 to 8191 uploads, 25.4 to 25.9 GiB; by reasonuntracked7214 to 8461 uploads, 27 to 28 GiB. Every refresh of a resident target counts as untracked and re-uploads it.[dcc]: 49871 scans / 1017 MiB scanned per 10 s, key proofs 42514 of 42515 unstable.[resources]: image preparation 8034 ms of 8000 builds,[recorder]3452 syncs waited 12.1 s for the GPU.Experiment: I locally restored the previous behaviour on Windows with an environment switch in
decideImportWatch(state.unwatchImports = falsewhen set), nothing else changed. Same title, same machine: 59.94 FPS,[storage] uploads by pathdrops toclear 1154 / 5.4 GiB, direct 0.So the compare path is correct for the late-driver-write case in #1434, but on this GPU it makes every Silksong frame re-upload its render targets. Two questions for the author and maintainers:
decideImportWatchprobes it (ProbeImportWriteProtection) and compares only when the probe says writes arrive after the import. A Windows probe, or an opt-out, would keep the fix where it is needed and the speed where it is not.I can test any change on this title and report the numbers. I have not changed upstream code for this.
AI assistance: this report was prepared with Claude Code; all numbers above are from my own runs.
Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-08T22:45:41Z.
@ps54all @Celegans12 my PR #1847 does what you're both describing: imports stay write-watched on Windows, and only the driver's late marks right after an import are checked against a copy of the import's bytes, so #1434 stays fixed.
APS5_WRITE_WATCH_IMPORTS=unwatchkeeps today's comparisons and=watchplain watching. On Animal Well it brings back 59 FPS, and TheAggie measured ccleste going from 15.5 back to 29.2 FPS. Since you both offered, it'd be great to see how Silksong and Ghost of Yōtei do with it.Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-10T09:14:23Z.
Follow-up: #1847 was closed, and #2096 (merged 10-09) fixes this for PPSA12544. Same machine (Windows 11, RTX 3080),
main6cc33583plus a local integration branch, no import-watch override: the main menu holds 59.94 FPS again (4176 frames at 90 s), against 9.9-10.3 FPS before. Thanks for the quick turnaround.Written with AI assistance.