fix(agc): keep Windows host imports watched while late driver marks settle #1847
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1847"
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 JAB-dev on 2026-10-08T21:45:50Z.
What
#1441 dropped PPSA22520 (Animal Well) on Windows from about 59 to 7.5 FPS. This restores the frame rate and keeps #1434 fixed.
Since #1441, Windows compares every host import instead of write-watching it, because the NVIDIA driver marks imported pages written again about 1.2-2 ms after the import window, and those marks dropped GPU results (#1434). The comparisons make every resource revalidation over an import a full walk. In PPSA22520 (Animal Well) that is 6.8 s of every 10 s and the frame rate falls from about 59 to 7.5 FPS.
Imports stay watched again, and the late marks are told apart from CPU stores by their bytes:
GuestMemory::ImportWatchedkeeps a copy of the import's bytes for a settle period after the import (1 s,APS5_IMPORT_SETTLE_MS). The late marks arrive about 2 ms after the import; the period only needs to outlast them, and a longer one only keeps the copy longer.ImportWindow(maybe written), as the import window's own marks already are. Write-back keeps the GPU results over such a block.StoreOwnBytesand the otherstoreOwnpaths) refresh the copy, so a late mark over GPU results it wrote back still reads maybe written.APS5_IMPORT_SETTLE_MS=0. Its import entry records that, so a refresh keeps it compared. Unwatching a range or giving it fresh private backing drops its copy.APS5_WRITE_WATCH_IMPORTSis now read on Windows too:unwatchcompares every import, as #1441 does;watchkeeps imports watched without settling, the behaviour before #1441.TechnicalDebt records the settle period, that it assumes a driver finishes marking within it, that a CPU store of identical bytes in the period reads as maybe written, and that a GPU write straight into a settling import (
MarkWritten) cannot refresh the copy, as its bytes land later, so a late mark over it reads as a CPU store, as without settling. Treating those pages as maybe written instead makesagc_driver_recorder_testslose a CPU store made after a GPU write ("a CPU store into a unit with results pending was not seen by the refresh"). Settling an import on an event instead (a GPU read of it and its fence, as #1434 suggests) would remove the timing assumption, but it can't be checked on a driver that doesn't mark late, and the import sites hold the host import and tracker locks.A settle period that only reclassified marks by time was not enough:
agc_driver_recorder_teststhen publishes a stale unit shadow over a real CPU store ("a stale unit was published"), becausePublishShadowonly dropsBlockWrittenunits. The byte check is what keeps that test passing.Tested
Windows 11, RTX 4070 SUPER (driver 610.88), WinLibs GCC 15.2.0 r7, Release.
#1434, deterministically: this driver does not show the late marking on its own (
agc_driver_dcc_keys_first_writeandagc_driver_srgb8_color_targetpass 30 of 30 with plain watching). On Windows, the write-watched run ofagc_driver_dcc_keys_first_writenow rewrites every page of the imported block with its own bytes between the import and the write-back, as the driver does, and pins a long settle period so a slow runner cannot race it. WithAPS5_WRITE_WATCH_IMPORTS=watchit fails in every run with #1434's message (the first write: the write-back stored 0 written and 0 cleared bytes of 65536, expected 128 written); by default and withAPS5_WRITE_WATCH_IMPORTS=unwatchit passes.Frame rate, PPSA22520,
APS5_PROFILE_DRAW=1, 10 s windows:[present]per 10 s[rescache] revalidatemain4b6ab6bbfe9beae0(before #1441)agc_write_tracking: a new Windows case (with its settle period pinned to 100 ms) imports two blocks, then checks that a page rewritten with its own bytes in the settle period reads maybe written, that a changed page and a store next to the import read written, that the closing walk applies the same rule, that a mark after the period reads written, that an import watched without settling trusts its marks, that a late mark over the driver's own store reads maybe written, that a CPU store after a GPU write into a settling import reads written, and that unwatching a settling import leaves it unwatched.agc_driver_recorder_tests(not registered in ctest) passes, including the unit-shadow stale publish case and the Windows import-watch default.8 mutations each fail a test: unchanged pages trusted as CPU stores, changed pages not trusted, no closing walk, imports not registered, the driver's stores not refreshing the copy, a settle period that never ends, Windows comparing by default, and Windows not settling by default.
Full ctest on this branch alone, on top of
main: 479/479.Linux and macOS: the change is Windows-only (
#ifdef _WIN32), not built there.Related: #1599 keeps GPU results over write-back blocks whose bytes the CPU left unchanged (images up to 1 MiB); it is compatible with this and does not restore watching. #1310 and #1361 speed up write tracking and import lookups on Linux.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T22:09:36Z.
A second title for this, with a different workload: ccleste (PPSA59322), a homebrew port that renders through RADV (Mesa's Vulkan driver on the PS5) and writes its frames through storage images. #1441 halved its frame rate here, and this PR restores it.
Windows 11 Pro (26200), RTX 5070 Ti (driver 610.88), WinLibs GCC 15.2.0 r7, Release,
APS5_PROFILE_DRAW=1, 35 s runs on the title screen, 10 s windows. ccleste only renders on AnyPS5 with my open RADV PRs (#1732, #1733-#1736, #1819, #1825 and others), so both builds aremainaa277b38merged into the same local branch carrying them, with and without this PR:[present]per 10 sGraphics::Drawper draw[storage]uploads per 10 suntracked)Without it, every draw re-uploads ccleste's storage images in full (reason
untracked;[buffers] image mirrorsreports 804 unwatched heaps), and draws hold the GPU mutex for about 10 ms each. With it, the uploads and unwatched heaps are gone and the log readshost imports stay watched; pages marked written while an import settles are compared, not trusted. The title screen renders the same in both.To isolate the cause beforehand, I set only
unwatchImportsback tofalseindecideImportWatchon the slow build: 26.8 FPS. #1472 and #1474 made no difference.I only measured the frame-rate side; I did not test the #1434 side here.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T01:05:01Z.
A possible gap in the byte check that I'd like to confirm with you. I found it by reading the code and can't run the Windows path here (Linux only), so it may not show up in practice.
Only
Cpuwalks refresh the settle copy.settlingKindreturns early forStampKind::Driver(GuestMemory.cpp:1054), so afterstoreOwnwrites GPU results into a settling import (Cpu walk, store, Driver walk at 1340-1342), the copy still has the pre-import bytes. #1434 says the late mark can come more than 150 ms after the import. If it lands after that store, the next collect compares the written-back bytes with the old copy, sees a difference and stamps the pageCpu.ChangedBlocksthen reports the 64 KiB block asBlockWritten, and the next write-back over it skips the block (Texture.cpp:3423). That's the #1434 symptom again.I ran a standalone copy of
settlingKind: a late mark with unchanged bytes givesImportWindow, and the same page after astoreOwngivesCpu.Minimal fix: let the Driver walk refresh the copy.
Could you run this on Windows? It's a test in the style of
CheckImportSettle. If the gap is real it fails with the message below; if it passes, ignore the rest of this comment.GPU writes that go straight into the import (
MarkWritten, no walk) have the same problem. Refreshing the copy there would capture bytes before the GPU writes them, so I don't have a small fix for that case.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-09T05:02:17Z.
@fisherjoey thanks, good catch, the
storeOwncase was real. Without a fix your test fails here on Windows.9a4b70f4refreshes the copy for the stored range instoreOwn's stamping, so it also covers the store paths that don't walk, and your test is now part ofCheckImportSettle.For
MarkWrittenI left it as is: treating those pages as maybe written makesagc_driver_recorder_testslose a CPU store made right after a GPU write, so it's noted in TechnicalDebt instead.Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T08:22:26Z.
Ran this on the driver that shows #1434's late marking, as asked in #1434.
Setup: Windows 10 (19045), RTX 3060 Laptop GPU, NVIDIA 616.92, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. This PR's head
9a4b70f4merged ontomain6cc0503d, plus #2093, whichmaincurrently needs to build. The earlier headec961ed8onmainf1451396gave the same numbers.agc_driver_dcc_keys_first_writeagc_driver_srgb8_color_targetmain(compares every import, #1441)APS5_WRITE_WATCH_IMPORTS=watchAPS5_WRITE_WATCH_IMPORTS=unwatchsrgb8_color_targetfails 11 of 20 runs without any rewrite from the test, for examplea multiply blend into an 8_SRGB target beside a linear target: byte 1 inside the scissor is 7, expected 2 from 7. By default the settle period absorbs those marks.dcc_keys_first_writewithwatch: it fails every run with the expected message (the write-back stored 0 written and 0 cleared bytes of 65536, expected 128 written).agc_driver_recorder_tests: built explicitly, since it'sEXCLUDE_FROM_ALL.watch.unwatchit stops at its check of the Windows default (Windows host imports were compared by default). That's expected when the default is overridden.No title was run.
🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Rohan03x on 2026-10-09T11:38:07Z.
Tested on Windows with another title and GPU.
Setup: Windows 11 22621, Ryzen 7 5700X, RTX 3070, Dreaming Sarah (PPSA02929), GCC 15.2.0 UCRT Release. PR merged onto main
f1451396; ctest 488/488.f1451396APS5_WRITE_WATCH_IMPORTS=watchOn main,
APS5_PROFILE_GPUshows storage-upload 2200 ms and storage-writeback 1378 ms of about 3715 ms timed per 10 s; the two 3840x2160 display buffers are re-uploaded on every draw and present. Average recorded draw: 1019 µs on main, 19 µs with this PR.Limits: runs were under a minute and stayed on the title screen and main menu, not gameplay. No crash and no visible difference in that time.
agc_driver_recorder_testsis not registered in ctest, so it was not run.AI-assisted: yes (build, log analysis and this write-up).
Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-09T15:22:30Z.
Closing this, #2096 fixed the same regression on main a different way (shared aliases keep their write tracking, direct imports compare against a texture snapshot). On main
d70b8998Animal Well now runs at 587–588 presents/10 s with 0 full rescache walks, the same as with this PR, so there's nothing left for it to do.Thanks @popcoder565 and @Rohan03x for testing on the 616.92 driver and Dreaming Sarah, and @fisherjoey for the review.
Pull request closed