AGC: on Windows (NVIDIA) a new host import's pages are marked written after ImportWatched's window, so write-backs drop GPU results #1434
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 popcoder565 on 2026-10-08T06:18:03Z.
Summary
On Windows with an NVIDIA GPU,
agc_driver_dcc_keys_first_writefails in about one run in three onmain(5850a6cd):It always fails in the second
Run, on the write-watched block (0x200000000, from the guest arena). WithAPS5_TRACE_FLUSH=1, the first write-back of that surface keeps its only block for the CPU:Nothing on the CPU writes the texels between the upload and that write-back.
What happens
I added a print to
collectWritesfor walks over the block, and one tocreateImport. A failing run and a passing run then take the same steps in the same order:In the failing run, the walks after the import find both the texel and the key pages written (the first value). In the passing run they find nothing. The texel block is then stamped at 11, after its layer generation of 3, so
ChangedBlocksreports it written andwriteBackLayerskeeps it for the CPU.GuestMemory::ImportWatchedalready walks the range right aftercreateImportand stamps what it finds asImportWindow. Here the pages are marked written after that walk. As an experiment, not a fix, I addedSleep(50)aftercreateImportinside theImportWatchedcallback. In the same session the test then passed 30 of 30 runs, against 21 of 30 without it.So something marks the imported pages written in the write watch shortly after
vkAllocateMemoryreturns, outside the window. Most likely it is the driver pinning them; the driver here is 616.92. On Windows,decideImportWatchkeeps imports watched without a probe:ProbeImportWriteProtectionreturns "the Linux write watch".Impact
This can happen to any write-watched range that is imported on Windows after a storage image over it was uploaded and before that image's write-back. The image's GPU results are lost the same way: the write-back keeps the guest bytes, and the image is uploaded again from them at its next use. In a title this would look like GPU-written textures falling back to older contents.
Possible directions
ImportWatched's second walk, for example with a GPU read of it (submit and wait). The import sites hold only the host import mutex, andImportWatchedholds the tracker lock, so this needs care with the GPU lock.ProbeImportWriteProtectionon a scratch arena range that looks for pages marked written some time after the import, and compares imported ranges (unwatchImports) when it finds them. The timing varies between runs, so a single probe could miss it.Windows 10 (19045), NVIDIA GeForce RTX 3060 Laptop GPU (driver 616.92), Intel Core i7-12700H, MinGW-w64 GCC 15.2.0, Release.
Investigated with AI assistance.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-08T06:35:45Z.
Two more findings.
The new
agc_driver_srgb8_color_target(94cf99e3) fails the same way, and more often. Onmain7a178e22it fails in 7 of 10 runs here, with messages such asa draw over a fast-cleared 8_SRGB target: byte 0 inside the scissor is 0, expected 200 from 93.APS5_TRACE_FLUSH=1showskeeps 2 CPU-written 64 KiB blocks (... 0 ranges stored ...). With the 50 ms sleep insideImportWatched's callback it passed 20 of 20 runs, against 3 of 20 without it.The driver marks every imported page twice. I polled
GuestArenaCollectWriteswithout resetting it:createImportreturns, all 32 of the import's 32 pages already read as written. The window'sImportWindowwalk absorbs these, as intended.ImportWatchedthen, so no GPU work had been submitted.That second, whole-range marking is what the next collect stamps as a CPU write.
A contained fix, Windows only, in
GuestMemory.cpp, which I can send as a PR unless you'd rather go another way:ImportWatchedremembers the imported range as awaiting its pin.StampKind::ImportWindowand forgotten. Those blocks then read as maybe-written, as the import window's own stamps do, sowriteBackLayersstores the GPU results.The risk is the one the import window already takes: a CPU store to every page of a freshly imported range, before the driver's second marking, would be taken for that marking.
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T16:37:05Z.
Linux NVIDIA data for scoping the fix to Windows.
RTX 5070 Ti, NVIDIA 595.91.07, Nobara 44 (Linux 7.2), GCC 16.2.1, Release.
agc_driver_dcc_keys_first_writepassed in 13 of 13ctest -R agc_driver -j1runs, each onmaindf16c4c2+ #1329 + a different PR under test (none of them touch the write watch). At one failure in three, 13 passes in a row would happen about 0.5% of the time.agc_driver_srgb8_color_targetonly ran once here and passed.On this driver the startup probe reads
no (0 of 4 scratch pages written after a GPU read, 4 after the import); imported ranges stay watched, so Linux NVIDIA also marks the pages at the import, andImportWatched's window absorbs that. I haven't polled for a second marking after the window the way you did, but the test results suggest it doesn't happen on Linux, which fits a Windows-only fix.Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-08T21:46:09Z.
#1847 replaces the always-compare approach from #1441, which drops PPSA22520 from about 59 to 7.5 FPS on Windows. Imports stay watched, and a page marked in the second after an import only counts as a CPU store if its bytes changed.
On Windows,
agc_driver_dcc_keys_first_writenow reproduces this issue on every driver: it rewrites the imported block with its own bytes between the import and the write-back. It fails in every run with plain watching (APS5_WRITE_WATCH_IMPORTS=watch) and passes with #1847.My driver (610.88) doesn't show the late marking by itself. @popcoder565, could you run #1847 on 616.92, for example
agc_driver_dcc_keys_first_writeandagc_driver_srgb8_color_targeta few times each? That would confirm it against the real late marks.Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T08:22:27Z.
@JAB-dev ran #1847 on 616.92: both tests pass 30/30 by default, and with plain watching
srgb8_color_targetstill fails 11 of 20 runs from the driver's own late marks. Details: https://github.com/boykopovar/AnyPS5/pull/1847#issuecomment-6077240672🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:49:47Z.
Status on
maind70b8998, after #1441 and #2096, on the same machine (Windows 10 19045, RTX 3060 Laptop, NVIDIA 616.92):agc_driver_dcc_keys_first_write: 30 of 30agc_driver_srgb8_color_target: 30 of 30Direct host imports on Windows are now compared rather than watched, and #2096 keeps write tracking on the separate shared aliases. So the driver's late marks no longer drop GPU results here. #1847 was closed for the same reason.
Closing. I'll reopen if it shows up again.
🤖 Addressed by Claude Code