fix(agc): compare host imports when device writes reach the write watch #1046
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1046"
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 aryanrawatispro-ship-it on 2026-10-07T04:15:47Z.
What
agc_driver_recorder_testsis built but never run in CI. On the Linux job's device (lavapipe) it fails onmainon every run, and the process then segfaults at exit:Cause. lavapipe runs command buffers on CPU threads, so its writes into a host import go through the page tables, and the write watch collects them as CPU stores. The probe that decides whether imports stay watched only checks a GPU read, which reports 0 of 4 pages on lavapipe, so imports stay watched. In
unitShadowTests, the whole publish's copy into the import is then collected as a CPU store over unit 3. After the unit is retiled again, the partial publish finds it written since the retile and drops the slab's newer bytes as stale:PublishShadowreturns 0 and the unit is no longer shadowed. Any write the driver records into a watched import on such a device reads the same way.Fixes #1429.
Five commits:
fix(agc): compare host imports when device writes reach the write watch:ProbeImportWriteProtectionalso fills the scratch import on the GPU and collects again (writtenAfterFill). When the read or the fill reports pages as written, imported ranges are compared, as on amdgpu. On lavapipe the startup line now reads:test(agc): run the recorder tests in ctest: registersagc_driver_recorderwith the other driver tests. It skips with 77 without a usable Vulkan device (the Windows job), unlessANYPS5_REQUIRE_VULKANis set (the Linux job). The draw snapshot reuse test (69a94208) assumed watched imports. With imports compared, a draw copies its input every time, as that commit intends, so the test now reports itself as not run there, like the unit shadow test. It also failed onmainwithAPS5_WRITE_WATCH_IMPORTS=unwatch, the amdgpu path.test(agc): gate the import window checks on the range's own writes:importWindowTeststook its write checks when the scratch import probe reported pages written at import time. That probe runs on a separate mapping. On NVIDIA it reports 4 of 4 pages while the test's range is unchanged, so the case failed (#1532). The case now branches on the range's ownUnchangedSinceafter the collect. Suggested by @MarcZX100 and measured by @Dextroid17 (RTX 3080 Ti: exit 1 before, 0 after).test(agc): report the dma-buf import probe as not run without /dev/udmabuf:importWatchTestsrequired the dma-buf import probe (#943) to succeed whenever the device supports dma-buf import. GitHub's Linux runner has no/dev/udmabuf, and many distributions create it asroot:kvm 0660(#1688), so the suite stopped in CI at(u) the dma-buf import probe failed at open /dev/udmabuf. When the probe fails at that step, the case now reports the dma-buf probe as not tested, as it does without dma-buf import. Any other probe failure still fails.test(agc): read storage results through the flush hook over unwatched memory: since #2096 (0e1d25a8), a refresh over an untracked import whose bytes still match the image's snapshot keeps the image's own results pending instead of storing them, as it already did over watched memory.storageRefreshTests(the unwatched case) andstaleGenerationTestsread the guest bytes directly and expected the refresh itself to store, so on currentmainthey stopped atthe refresh's store of the results did not reach guest memory(lavapipe and RADV, reported by @adriadam10) and then at(s) results pending when their memory left the watch did not reach it. Both now read the memory throughGuestMemory::Read, as the watched storage refresh case already did. Its flush hook stores the pending results first.No title needs this. It puts the suite that covers storage write-back, DCC keys, labels and unit shadows into CI, so every pull request that changes those paths runs it.
Tested
BUILD_TESTING=ON, lavapipe (Mesa 25.2.8).main, instrumented: the partial publish returns 0 and unit 3 is no longer shadowed. Right after the whole publish,UnchangedSinceCollected(unit3, unit, pre)is false: the publish's own copy was collected as a CPU write.5cb747c1, with CI's environment (VK_ICD_FILENAMESset to lavapipe,ANYPS5_REQUIRE_VULKAN=1,GALLIUM_OVERRIDE_CPU_CAPS=avx):agc_driver_recorderpasses (0.36 s), also underctest -R '^agc_driver_recorder$' --repeat until-fail:3and in 3 direct runs. WSL has no/dev/udmabuf, so the dma-buf probe reports itself as not tested, as on the CI runner. WithAPS5_WRITE_WATCH_IMPORTS=watch(the old lavapipe decision) it fails atthe partial publish did not copy exactly the partly covered unit. WithVK_ICD_FILENAMESpointing at no driver it skips (77); withANYPS5_REQUIRE_VULKAN=1as well it fails.cteston that head: 558 tests. The failures areguest_sce_netandnid_patcher_dynamic_strings(the resolver test; the local toolchain adds its own RUNPATH), as on earlier bases, andguest_video_out_resolution_status, whose window gets no Vulkan from this machine's SDL offscreen driver; the video-out flip tests skip here for the same reason.tools/check_test_registration.py buildpasses withKNOWN_UNRUNempty, andtools/check_conventions.pypasses.dc4b7104without the fifth commit. It is in the firststorageRefreshTestscall, whose block comes fromaligned_allocand is never watched, so this PR's import decision does not reach it; RADV compares imports with or without this PR. With only #2096's comparison switched off (compareUntrackedreturning false), the suite passes there without the fifth commit.the refresh's store of the results did not reach guest memory; with the earlier cases that catch it skipped, it fails at(s) results pending when their memory left the watch did not reach it. When results dead under new 0001 keys are kept, it fails atnew 0001 clear keys did not clear the image.APS5_WRITE_WATCH_IMPORTS=watch(the old lavapipe decision) differs only in the recorder suite. There, draw snapshot reuse, unit shadows and the watched storage refresh report themselves as not run on lavapipe.mainwith #1210): RX 7600 (RADV), UHD 730 (ANV) and llvmpipe pass.writtenAfterFillis 0). It passes with the third commit.agc_driver_*rule.main. That path is not touched here.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 orbz22 on 2026-10-07T13:10:16Z.
Tested the PR head (7857d689) on Windows with real GPUs.
Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7),
-DBUILD_TESTING=ON, targetagc_driver_recorder_tests:ctest -R '^agc_driver_recorder$' --repeat until-fail:3ANYPS5_REQUIRE_VULKAN=1VK_LOADER_DRIVERS_DISABLE=*VK_LOADER_DRIVERS_DISABLE=*,ANYPS5_REQUIRE_VULKAN=1VK_LOADER_DRIVERS_SELECT=nv-vk64.json(RTX 3060 Laptop, driver 32.0.16.1692), 3 direct runsVK_LOADER_DRIVERS_SELECT=igvk64.json(Intel UHD, driver 32.0.101.7085), 3 direct runsNo suite reported itself as not run on either driver. Tested with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-07T17:45:57Z.
Tested the PR head (7857d689) on AMD and Intel, since the description notes it was not run on AMD hardware.
Ubuntu 24.04.5, GCC 13.3, Release, Mesa 25.2.8; i3-12100 with RX 7600 (RADV) and UHD 730 (ANV).
ctest -R '^agc_driver_recorder$'withANYPS5_REQUIRE_VULKAN=1:yes (0 of 4 ... after a GPU read, 4 after a GPU write, 0 after the import)yes (4 of 4 ... after a GPU read, 4 after a GPU write, 4 after the import)(w) results pending over the import window did not reach guest memoryyes (4 of 4 ... after a GPU read, 4 after a GPU write, 0 after the import)importWindowTestspinsImportWatch::Watch, which the driver never picks on these GPUs; it fails the same way atd8c7c0cc. With it skipped when imports are compared, ANV then failsminLodTests: it takes the integer part of the fractional view minimum LOD, whichVK_EXT_image_view_min_lodallows.#1210 fixes both in the test file. With it on top of this PR, the suite passes 3/3 on all three devices.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T03:25:25Z.
Conflicts with main in
GuestBufferMemory.hpp/.cpp(#943 changed the import-watch decision),CMakeLists.txtandtests/Recorder.cpp; please rebase. #1210 goes in first, since the suite fails on RADV and ANV without it.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T11:24:19Z.
I resolved this onto current
main(084aeeb6) and ran it, because it is the fix for #1429 and it has been sittingCONFLICTING. It works — and the four conflicts are all "main moved into the same functions", not cosmetic:1.
core/libs/prx/libSceAgcDriver/CMakeLists.txt—mainaddedagc_spirv_module_testsandagc_driver_bda_device_teststo the sameforeach. Keep both and appendagc_driver_recorder_tests:2.
Graphics/include/GuestBufferMemory.hpp—mainadded its own field toImportProbe. Keep both (writtenByCpufrommain,writtenAfterFillfrom this PR).3.
Graphics/src/GuestBufferMemory.cpp— two conflicts:mainnow readsprobe.writtenAfterSubmit != 0, and the dma-buf line below it ismain's (keep the dma-buf block asmainhas it; this PR's line is about host imports, so it replaces the host-import line only).mainnow ends with a CPU store (*base = 2→collect(probe.writtenByCpu)), this PR adds a GPU fill. Keep both, with the fill step before the CPU store — the other order lets the fill's collect count the CPU store's pages, and thenwrittenAfterFill != 0would not mean what it claims.4.
tests/Recorder.cpp—mainexpanded the same import-probe block with a dma-buf probe section; keep that block and addwrittenAfterFillto the printed line.Verification on
084aeeb6+ that resolution:Lavapipe, CI environment (
VK_ICD_FILENAMES→ lavapipe,ANYPS5_REQUIRE_VULKAN=1,GALLIUM_OVERRIDE_CPU_CAPS=avx), three runs (CI's--repeat until-fail:3):That is the line the description predicts, and it is the failure from #1429 turning green.
Real GPU (RTX 3080 Ti, NVIDIA 615.71.09) — no behaviour change:
writtenAfterFillreads 0 there, so the decision staysstay watched. Diffing the whole log againstmain's run of the same binary, the only difference is the added diagnostic:So the added term is inert on a device where imports stay watched, which is what you want from a probe.
One thing worth knowing before this is registered. On the same GPU, on
main, this binary already fails — atRecorder.cpp:2130,(w) a cache over the pages the import reported sees no change, identically with and without this PR, becausewrittenAtImportis 4 there and that block is skipped on lavapipe. Filing it separately as #1532 so it does not get attached to this change; registering the test makes CI green on lavapipe and leaves that red on NVIDIA until it is answered.Verified against
084aeeb6;mainhas since moved (tob1c5f10d), so a rebase may hit fresh conflicts.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T16:08:56Z.
The conflict list for this branch is stale — it now conflicts in 4 files / 6 hunks on current
main(4b005b22), including amain()/openDevice()conflict inRecorder.cppand the newagc_driver_constant_store_testsskip inCMakeLists.txt. I resolved them and re-verified, because a resolution is worth little if it will not apply for you:Refreshed onto
4b005b22and verifiedThat
4 after a GPU writeis exactly what this PR is for — on unpatchedmainthe same line reads0 ... 0 ... 4and the cache check then fails (AGC graphics: (w) a cache over the pages the import reported sees no change), so the fill-based counter genuinely changes the verdict on the Linux CI device.Apply it without redoing the resolution:
git apply 1046-refreshed.patchon top of4b005b22, orgit amif you prefer it as a commit.1046-refreshed.patch(141 lines, applies to4b005b22)It is your call whether to fold this in or resolve it yourself — I am not opening a competing PR, since the work is yours. If you would rather I hand it over as a branch on my fork instead of a patch in a comment, say the word.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T20:22:43Z.
While reviewing #1532 against the current #1046 head, I found the same range mismatch in
importWindowTests:importWritescomes fromProbeImportWriteProtectionon a separate scratch mapping, then the test takes itscachedgeneration after constructing theStorageTextureand callsHostImportForon that existing import. The scratch probe does not establish that this range changed. The issue's instrumented result (cached=160,after=161,unchanged=1) also shows the generation increment alone is not evidence of a write.I made a local test-only patch that branches on the actual range's
UnchangedSince(address, surfaceBytes, cached)result after collecting it. If the range changed, it checks the changed-block and CPU-store invariants; otherwise it reports that this range had no writes and still runs the pending GPU-result checks. The test target builds and the binary passes on lavapipe here, but this environment reportsno write watching: the import window not tested, so that run does not validate the NVIDIA path. The issue's independent device measurements support the range-specific premise.Since #1046 already changes and registers this same test, I have not opened a duplicate PR. Please consider folding this correction into #1046, or let me know if the
importWritescondition is intended to prove a different property.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T22:00:48Z.
I read the test at the current head (
7857d689fa) and @MarcZX100's reading is accurate. Correcting my own first grep, which missed it: this PR does touch those lines, but only in the printout.ProbeImportWriteProtection(context)→probe.writtenAtImport. That establishes that the write-watch machinery engages after an import in a scratch mapping; it does not establish that the import range this test then exercises changed.Graphics/src/GuestBufferMemory.cpp(unwatchImports = probe.writtenAfterSubmit != 0 || probe.writtenAfterFill != 0); this PR's change totests/Recorder.cppis the addedwrittenAfterFillcounter in the printed line. So @MarcZX100's correction is additive to the test, not a rewrite of the fix.UnchangedSince(address, surfaceBytes, cached)taken after the write, which is what his test-only patch uses.no write watching: the import window not testedwhen the host cannot watch writes.The question stands for @aryanrawatispro-ship-it: if
writtenAtImportis meant to prove a different property (that the watch mechanism engages at all), the test's message should say so; otherwise the gate should be that range's ownUnchangedSince.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T22:14:42Z.
Third arm, measured on hardware — @MarcZX100's reading holds, and here is what it costs.
Setup: a local branch = this PR's four files applied to current
main(ae91d978), plus a test-only edit that replaces the scratch-probe gate with the range's own state:build/tests/agc_driver_recorder_tests,ANYPS5_REQUIRE_VULKAN=1, exit codes:AGC graphics: (w) a cache over the pages the import reported sees no changethe import reports no pages here: only the pending results of the import window checkedGraphics/src/GuestBufferMemory.cppback atmainAGC graphics: the partial publish did not copy exactly the partly covered unitThree things this settles:
4 after the importwhile the range the case then asserts about reads unchanged, so without the correction the case fails on a condition that range never met.host imports are compared, not watched: the import window not tested). So the gate becomes honest but, on this hardware, toothless for the import window — a RADV/AMD datapoint is what would show the branch actually running.The negative control does still bite, elsewhere: with
writtenAfterFillreverted, lavapipe fails atthe partial publish did not copy exactly the partly covered unit, so the fill half of this PR is load-bearing for that case — and NVIDIA is blind to it.One more thing for the reviewer: this PR also registers
agc_driver_recorder_testsinto ctest (EXCLUDE_FROM_ALL OFF+add_test), so whichever gate lands becomes part of the suite. On this evidence, the range-specific gate is the one to register.No PR from me — the change belongs in this one. Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-08T23:42:20Z.
RADV/ANV datapoint for the question at the end of @Dextroid17's last comment. Setup: this PR's head
7857d689merged ontomainf1451396, with the conflicts resolved as in his refreshed patch (fill step before the CPU store). Machine: Ubuntu 24.04.5, Mesa 25.2.8.agc_driver_recorder_testswithANYPS5_REQUIRE_VULKAN=1passes (exit 0) on all three devices here:So the import-window branch can't be reached on AMD (or Intel): a GPU read through a host import already dirties the pages, imports are compared, and the case returns before either gate is evaluated. Forcing
APS5_WRITE_WATCH_IMPORTS=watchdoesn't help. It fails earlier on all three withthe partial publish did not copy exactly the partly covered unit, which is the miss this PR's fill counter exists to catch, and RADV/ANV also lose the device. On these devices only NVIDIA keeps imports watched, so the gate question can only be settled there. The llvmpipe row (0 after a read, 4 after a write) is this PR's change doing its job.Imported from boykopovar/AnyPS5. Originally posted by aryanrawatispro-ship-it on 2026-10-09T01:32:49Z.
Rebased onto
f1451396. I resolved the conflicts the way @Dextroid17 laid out:writtenByCpufrom main,writtenAfterFillfrom this PR).writtenAfterFilldoes not count the store's pages.agc_driver_recorder_testsis added to main's ctest list. main'smain(int argc, char** argv)is kept, together withopenDevice().On the gate question from @MarcZX100 and @Dextroid17:
writtenAtImportwas not meant to prove anything about the range the test uses. It was a proxy, and on NVIDIA it was the wrong one. A new commit,08939059test(agc): gate the import window checks on the range's own writes, branches onUnchangedSince(address, surfaceBytes, cached)after the collect. This is the same test-only change Dextroid17 measured: NVIDIA 1 → 0, lavapipe stays 0. Thanks to @johnmaia for the RADV/ANV run. It shows that only NVIDIA keeps imports watched, so only NVIDIA reaches that branch.Local results on the rebased head (WSL2, GCC 13.2, Release, lavapipe from Mesa 25.2.8):
[write-watch] host imports resolve write protection: yes (0 of 4 scratch pages written after a GPU read, 4 after a GPU write, 0 after the import); imported ranges are compared(u) the dma-buf import probe failed at open /dev/udmabuf. WSL has no/dev/udmabuf, and that check comes from main's dma-buf probe, not from this PR. With that one check skipped in a local-only build, it passes 3/3.APS5_WRITE_WATCH_IMPORTS=watchit fails atthe partial publish did not copy exactly the partly covered unit.ANYPS5_REQUIRE_VULKAN=1as well it fails.ctest: 495 tests. Apart from the dma-buf stop above, the only failures areguest_sce_netandnid_patcher_dynamic_strings, which also fail on main in this toolchain.I have no NVIDIA, AMD or Intel hardware here, so the NVIDIA result for the new gate is Dextroid17's, not mine.
Written with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T11:18:26Z.
Verified your head (
f2124645) on the device CI actually runs — lavapipe extracted locally, Mesa 26.2.4 / LLVM 23.1.1:Both green, so the registration and the gating both hold on the CI device.
One gotcha worth knowing, because I hit it myself: if a newly registered test fails in 0.00 s with no output at all, its binary was not built —
agc_recorder_kept_bytesdid exactly that to me until I built the target explicitly. That was my error, not your branch's, and I mention it only because the same thing will bite anyone who runsctestwithout a full build.I have not re-derived your
NVIDIA 1 → 0, lavapipe stays 0numbers, so this confirms the CI device only. The part I did measure earlier — that the check should branch onUnchangedSince(address, surfaceBytes, cached)rather than onwrittenAtImport— is what your08939059does, and it reads correctly.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T13:43:12Z.
I checked the current PR head against upstream
main(d70b8998).git merge-treeconfirms real content conflicts incore/libs/prx/libSceAgcDriver/CMakeLists.txtandtools/check_test_registration.py. CONTRIBUTING asks PR branches to stay current withmain; please rebase/resolve these two files, then rerun the checks on the new head. The existing green Linux/Windows results are for the previous headf2124645.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:15:30Z.
Review: CHANGES_REQUESTED
Thanks for the work and for keeping this current. It conflicts with
mainincore/libs/prx/libSceAgcDriver/CMakeLists.txtandtools/check_test_registration.py; please rebase.I rebased it locally onto
bfef67f36(the two conflicts are mechanical: keepmain's list plusagc_driver_recorder_tests, and drop it fromKNOWN_UNRUN). After thatagc_driver_recorderfails, with CI's setup (lavapipe from Mesa 25.2.8,ANYPS5_REQUIRE_VULKAN=1,GALLIUM_OVERRIDE_CPU_CAPS=avx) and on RADV:It comes from
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp:1764(memoryHolds).mainhas changedRecorder.cppandGraphics/sincef2124645(#2176, #1441, #2299, #856), so please check which of them this case now depends on, fix it, and rerunagc_driver_recorderon the new head. Registering the test in ctest means the Linux job goes red until it passes.Imported from boykopovar/AnyPS5. Originally posted by aryanrawatispro-ship-it on 2026-10-09T23:15:35Z.
@adriadam10 Rebased onto
5cb747c1. I resolved the two conflicts as you described:main's list plusagc_driver_recorder_tests, and the test dropped fromKNOWN_UNRUN. #1225 has since removedvideo_out_flip_testsfrom that set as well, so it is nowset().The failure comes from #2096 (
0e1d25a8), not from #2176, #1441, #2299 or #856. It is in the firststorageRefreshTestscall. That call's block comes fromaligned_allocand is never watched, so the import decision in this PR does not reach it. This is also why RADV fails: it compares imports with or without this PR. Since #2096, a refresh over an untracked import compares its bytes with the image's snapshot. When they still match, the refresh keeps the image's own results pending instead of storing them, as it already did over watched memory. The test readtexelsdirectly, so it expected the refresh itself to store them. Ondc4b7104with onlycompareUntrackedswitched off, the suite passed without any test change.New commit
9579e622reads that memory throughGuestMemory::Read, as the watched case already did. Its flush hook stores the pending results first.staleGenerationTestsread its bytes the same way and stopped next, at(s) results pending when their memory left the watch did not reach it, so it gets the same change. Both checks still fail when the results never reach memory: I tried a write-back that counts every untracked block as written by the CPU.On the new head, with CI's environment (lavapipe from Mesa 25.2.8,
ANYPS5_REQUIRE_VULKAN=1,GALLIUM_OVERRIDE_CPU_CAPS=avx):agc_driver_recorderpasses, also under--repeat until-fail:3.APS5_WRITE_WATCH_IMPORTS=watch(the old lavapipe decision) it still fails atthe partial publish did not copy exactly the partly covered unit.ctest: 558 tests. The only failures are local:guest_sce_net,nid_patcher_dynamic_strings, andguest_video_out_resolution_status, whose window gets no Vulkan from this machine's SDL offscreen driver.I have no RADV device. The two changed checks take the same unwatched path on every device, but I have not run the rest of the suite on RADV on this head.
Written with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T23:28:58Z.
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/CMakeLists.txtL673core/libs/prx/libSceAgcDriver/tests/Recorder.cppL2971core/libs/prx/libSceAgcDriver/CMakeLists.txtL673core/libs/prx/libSceAgcDriver/CMakeLists.txtL673core/libs/prx/libSceAgcDriver/CMakeLists.txtL673core/libs/prx/libSceAgcDriver/CMakeLists.txtL673Pull request closed