fix(agc): run the unwatch hook when a watched import leaves the write watch #6308
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6308"
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 LeandroLP23 on 2026-10-15T10:44:36Z.
What
Fixes #6301. Since #6060, ProsperoPuzzles (PPSA99006) stops 5 s in on Windows:
GuestMemory::ImportWatchedwithstaysWatchedstill drops the range from the write watch when the range was only partly watched (beforeis false) or the import window can't be resolved. That fallback calledunwatchLockedwithoutbeforeUnwatch, so the storage-image hook (StorageTexture::SaveBeforeUnwatch) never saved the guest bytes of results pending there. The!staysWatchedpath always runs the hook first.Before #6060, Windows direct imports never took this path. Now settled private imports do. In ProsperoPuzzles an 8 MiB import at
0x21f800000took the fallback with the range only partly watched, and unwatched the storage image at0x21fc00000with results pending.The fallback now releases the tracker lock, runs the hook over the page range, takes the lock again and unwatches. The hook takes the pending-texture mutex and
GpuMutex(and, with #5671, the tracker lock), so it can't run under the tracker lock.agc_write_trackinggetsCheckImportWindowOverUnwatchedPart. It unwatches the middle block of three, imports all three withstaysWatched, and requires the hook to have covered the range.This complements #5671, which widens the span the hook gets to whole 64 KiB blocks. The two touch different lines.
Tested
Windows 11 (26300), Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), WinLibs GCC 15.2.0, Release, on
maine49ec591d.--windows --trap-sdk-syscall-stubs, new run folder, 60 s, no input): 3 of 3 alive at 60 s, 19.0–19.2 FPS. Onmain, every run stops at 5–7 s (data in #6301). Before #6060 it ran at 9.5–13.7 FPS.agc_write_trackingpasses. With theGuestMemory.cppchange reverted, the new check fails:an import that left the write watch did not run the unwatch hook over its range.ctest -R '^agc_|guest_memory|write_watch' -j 1from an emptytests/shader_cache: 583 of 585 pass. The two failures fail onmainhere too:agc_driver_quad_pixel_mask(#6255) andagc_driver_layered_volume_vertex_no_gpl(#4768).tools/check_conventions.py --base origin/mainpasses;git diff --checkis clean.Fork CI (run): Windows 1264 of 1265 and Linux 1241 of 1242, the one failure in each being the fork-only
conventions_ci_gate. The first Linux attempt also failedagc_driver_preparation_scope_settle(the link did not wait for the vertex shader's registration preparation), a shader-registration timing test that uses no imports. It passed on the job rerun and 10 of 10 locally.Not tested: NVIDIA, Intel, other titles.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-15T11:49:10Z.
NVIDIA run, for the "Not tested: NVIDIA, Intel, Linux, other titles." line. Windows 11 (26200), RTX 3060 Laptop GPU (NVIDIA 617.42), WinLibs GCC 15.2.0 r7 (UCRT), Release,
BUILD_TESTING=ON. Head93df5c42amerged ontomain8856f180c(clean);ANYPS5_GPU=3060, and a verbose test log shows the RTX 3060 selected.agc_write_tracking: passes.GuestMemory.cppfrommainand the PR's test (2 of 2 runs),agc_write_trackingfails:an import that left the write watch did not run the unwatch hook over its range.ctest -R "agc|shader|guest_memory|write_watch" -j4: 591/591 pass with the PR, and 591/591 onmain. Both skip the same 3 tests (agc_host_import_sparse,agc_driver_sparse_dma_buf_import,agc_driver_stencil_ref_export).agc_driver_quad_pixel_maskandagc_driver_layered_volume_vertex_no_gplpass here, with the PR and onmain.Not run: ProsperoPuzzles or any other title, Intel, Linux.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:18:24Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppImported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-15T12:26:19Z.
Independent Linux CPU write-tracking control at exact head
93df5c42a1b3ddd9362d7fc8541f811eac730248: Ubuntu 24.04, kernel 7.0.0-38, GCC 13.3, Ryzen 9 9950X.Compiled the unchanged
WriteTracking.cpptest with the productionGuestMemory.cpp,GuestAllocations.cpp,GuestArena.cppandGuestWriteWatch.cppdirectly (-std=c++20 -O2 -pthread -msse4.2, function/data sections and link-time garbage collection). This avoids the unrelated SDL/XRandR configuration blocker; no watch implementation or tracker was mocked.write tracking tests passed(exit 0, not the exit-77 no-write-watch skip).GuestMemory.cppwithHEAD^: 5/5 fail atan import that left the write watch did not run the unwatch hook over its range. The preceding import and unwatched-block assertions succeed, isolating the missing callback rather than a failed import or range-unwatch operation.Watchedon the first and last blocks and requires both still watched. 5/5 pass with the PR. This checks that the hook runs before unwatching and can re-enter the real tracker. Removing only the surroundinglock.unlock()/lock.lock()in a scratch production copy makes this control time out at 5 s, consistent with the mutex-order requirement in the description.A traced pass also shows successful
UFFDIO_REGISTER,UFFDIO_WRITEPROTECTandPAGEMAP_SCANcalls through the real Linux write watch. The exact-head worktree is unchanged. Scope: standalone production CPU tracker/write-watch test and callback re-entry; no full runtime/renderer build, GPU execution, or ProsperoPuzzles/title replay.Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T12:39:48Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), MinGW GCC 15.2, PR head
93df5c42amerged on main8856f180c:ProsperoPuzzles (PPSA99006), catalog 01.000.010, relinked with
--windows(same launch as our catalog run 7), new run folder each run, 90 s limit, no input. Runs alternated before/after.main8856f180c0xC0000409main8856f180c0xC0000409On
mainboth runs end with:right after
[gpu] storage image 0x21fc00000: guest memory changed while GPU results were pending; keeping the CPU's blocksindownload0/prosperopuzzles/app.log, as in #6301. With the PR, the title gets past that line in all three runs and keeps rendering the menu. Frame dumps at presents 30-360 have the same mean brightness (about 105) as in our earlier run onmaind92a8dad3, before #6060 (984 frames in 60 s). FPS at the end was 2-11. This host was heavily loaded by other builds and tests, so FPS is not comparable with the 19 FPS in the PR.Tests (merged tree):
agc_write_tracking: 3/3 pass. With theGuestMemory.cpphunk reverted, it fails withan import that left the write watch did not run the unwatch hook over its range.-E '^agc_driver_|^video_out_flip',-j8): 797/816, then 809/816 after serial reruns. The 7 left are timeouts (conventions_function_bodies,hardware_oracle_compare,guest_raise_exception,guest_file_lock_process,guest_none_relocations,tls_function_coverage_register_address_loads,windows_diagnostic_fixture_isolation) that also time out serially onmain8856f180con this host under the same load.-R '^agc_driver_',-j1), one full pass: 435 passed, 2 skipped, 1 failed. The failure isagc_driver_preparation_scope_settle("the link did not wait for the vertex shader's registration preparation"), which is flaky onmaintoo: 3 of 7 runs pass on each build. The storage, import and watch tests (host_import_*,storage_*,store_over_untracked,untracked_snapshot_hint,depth_storage*,resource_cache_*storage*, 17 run + 1 skipped) pass 3/3.tools/check_conventions.py --base origin/mainpasses;git diff origin/main --checkis clean.Notes, none blocking:
!staysWatchedpath the hook runs before the import; in the new fallback it runs after it. That makes no difference for host-pointer imports, which don't write guest bytes. For the partly-watched case (!covered), the fallback is already known before the import, so the hook could also run before it, as in the other path.walkWriteswindow-resolution failure branch.docs/dev/debt/libSceAgcDriver.md("Pending storage-image results over memory outside the write watch") says the bytes are saved atUnwatch"or a host import that does not stay watched". An import that should stay watched but falls back to leaving the watch now saves them too, so that sentence could mention it.Written with Claude Code assistance.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-15T21:46:24Z.
A second title that stops with this text and that this PR moves on: Minecraft Dungeons II (PPSA16064, Unreal Engine 5), Windows 11, RTX 5070 Laptop (NVIDIA 617.42). On a build of
mainthat contains #5671 it stops while loading its first world (2 of 2 runs):The refused image is the 2564x1444 scene colour target (DCC, 252 units of 64 KiB, all with results pending, none with saved guest bytes, none of its memory write-watched). With this PR's change (a lab build with the same hunk, the hook run in the fallback after the import) the title loads the world and plays. Five of five rows of that build loaded the world and played (one fresh world load from the main menu, four from a save inside the world; each walking 180 s with the HUD up), 2.6 FPS mean on the fresh load and 4.0-4.5 FPS warm, with no refusal; the hook ran 32 times per row. Without the change 2 of 2 world loads stopped. One earlier row that combined the hunk with a second, unrelated lab change aborted later on a different check (
a heap mirror's range is no longer write-watched); the hunk cannot change which ranges are watched, and #6546 addresses that path.The first 16 fallback events of that run (the build's report stops at 16), all 8 MiB import windows, had
beforefalse because the range was not wholly watched before the import (covered before 0, the first walk was not made); none came from a failing walk. The same holds for the other rows of the job. So the title takes the branch thatCheckImportWindowOverUnwatchedPartcovers.Two notes, not blocking, in the direction of the third note of the cross-validation above:
!before), so the hook collects the pages the import itself marked written (4096 of 4096 scratch pages reported written at the importin the probe line) as CPU writes, andsaveBeforeUnwatchkeeps the blocks they cover for the CPU unlessunchangedSinceBaselineproves their bytes unchanged; an image over 1 MiB has nogenerationBaseline(GenerationBaselineBytes), so it cannot. Read from the code, not shown on a title.MarkWrittenexcluding a block after a failed fresh collect, when the caller holds the GPU mutex), a unit test per exit and the debt entry sentence.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-16T00:34:21Z.
@AlxcBTW thanks, a second title (and a UE5 one) is good to have, and your trace matches the
covered before 0branch the test covers.Agreed on both notes. Running the hook before the import in that branch avoids counting the import's own written pages as CPU writes, and the
MarkWrittenexit is the same gap. I'd keep this PR to the minimal fix that the three verifications ran on, so your follow-up after merge sounds right to me.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-16T08:22:08Z.
Rerun on current main
5d9dcc42d(which includes #5671), Windows 11 Pro 26220, NVIDIA GeForce RTX 4070 (596.21), WinLibs MinGW-w64 GCC 15.2, PR head93df5c42amerged clean. ProsperoPuzzles PPSA99006, 150 s limit, no input:5d9dcc42d0xC0000409The stop on main is still the same line, right after
[gpu] storage image 0x21fc00000: guest memory changed while GPU results were pending; keeping the CPU's blocks(0x220800000in the other run):So #5671 did not change this stop here, and this PR still removes it. Frame dumps with the PR have a mean of 105.3 to 105.5, as in my earlier runs. The host was loaded by parallel builds, so I did not compare frame rates.
Not rerun today: the PR's tests and the suite (see my earlier comment), Linux.
Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-16T08:52:34Z.
Tested on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON,mainat5d9dcc42d2ec5401aebd089028b8d4d7410a77b4.This PR and #6169 do not compile together. Each one builds
GuestMemory.cppalone onmain. Merged together, in either order, it fails (2 of 2 for each order):Cause: #6169 turns
lockTrackerinto aTrackerLockclass (GuestMemory.cpp:1018on its head). It hasUnlock()and no way to take the mutex again, and itslockmember is private. The new fallback in this PR (GuestMemory.cpp:1349and:1351) callslock.unlock(); beforeUnwatch(...); lock.lock();.Whichever of the two lands second has to adapt. A fix would be a
Lock()method onTrackerLockthat takes the mutex again, andlock.Unlock()/lock.Lock()in this fallback.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-16T08:59:02Z.
@nicolasfalesy thanks, that's a real conflict. If #6169 lands first, I'll rebase this onto it with a
Lock()onTrackerLockandlock.Unlock()/lock.Lock()aroundbeforeUnwatchin the fallback, as you suggest. If this lands first, #6169 needs the sameLock()for this call site. @screamm thanks for the rerun on currentmain; it confirms #5671 alone doesn't reach this path.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T15:40:16Z.
A second Windows machine for this: RTX 4060 8 GB (NVIDIA 617.42), i5-14400F, Windows 10 19045, Minecraft Dungeons II (PPSA16064 01.100.100). Every world load I ran today had this PR in it (
main5d9dcc42d+ this PR + other open PRs, scripted from boot to the first world): 151 first-world loads, 136 reached the HUD. None stopped with thestoring storage image results pending over memory outside the write watchabort the world load hits onmain.What did stop the others, for completeness: two out-of-memory aborts with an oversized
APS5_TEXTURE_CACHE_MIB(host heap full, see #6553), seven aborts by Unreal itself at the start of the world load (LowLevelFatalError, five of themFMallocBinned3 Attempt to free an unrecognized pointer 3c00000000000000, also seen on a second machine and under investigation on AlxcBTW/AnyPS5#56; nothing ties them to this PR), and rows I stopped myself.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T08:14:41Z.
Still needed on current
main1c523bdb4, after #6455 merged. ProsperoPuzzles (PPSA99006 01.000.010), Radeon 860M (driver 32.0.13058.8001, Windows 11 26300), WinLibs GCC 15.2.0, Release, two 60 s runs each (first with empty AnyPS5 shader cache, second warm),tools/title_run.pyfrom #7264:main1c523bdb4main1c523bdb4+ this PR (48a1d3453)Both
mainruns stop onAGC graphics: storing storage image results pending over memory outside the write watch without the guest bytes. The merge of this PR ontomainis clean.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-19T03:26:28Z.
Marvel's Wolverine (PPSA03671) stops on this
Requireon currentmain, and every run with this PR got past it.Setup: Windows 11 Pro 26300, RTX 4080 SUPER 16 GB (NVIDIA 617.42), Ryzen 7 5800X3D, 32 GB RAM, WinLibs GCC 15.2.0 r7, Release. Content 01.001.005;
eboot.binand its three modules unwrapped withtools/unwrap_self.pyand converted withrelinker --windows --module-dir .. Base:mainf3059421f+ #6901 (8cd400aa4), which the title needs to load. Every run is the same scene, the "Sony Interactive Entertainment presents" card, with no input, a shader cache from earlier runs andAPS5_PROFILE_DRAW=1.[textures] sampled texture ... keeps the snapshot path: AGC graphics: storing storage image results pending over memory outside the write watch ...lines.48a1d3453) merged on the same base: 5 of 5 runs reached the 900 s limit without the abort and printed none of those lines. That is this PR alone (1 run), with #7432 (1), with #7048 (1) and with both (2).Not checked: anything past the splash card, Linux.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T07:07:43Z.
Thanks for this and for the title reports. #8172 (the fix for #8103) has now merged and rewrites the
staysWatchedpath ofImportWatched: a range that is only partly watched is now split into runs of covered 64 KiB blocks, those blocks stay watched, and only the gaps plus any span whose walk fails are unwatched. That removes the most common way this fallback was reached (a partly watched range used to unwatch the whole range), so the stop you saw may already be gone on #8172. Could you rerun the titles you reported on current main (which has #8172) without this PR and say whether theRequirestill triggers?Either way, the hook is still missing on the path that remains: on #8172, a covered span whose CPU walk fails before the import (dropped before
runImport) or whose window walk fails after it is unwatched byunwatchLockedwithoutbeforeUnwatch, so pending storage-image results over it aren't saved. Could you rebase onto main and reduce this PR to that:beforeUnwatchon them beforerunImport(with the tracker lock released, as you do now). #7505's "save early" idea fits here: the bytes are saved before the import can change them.beforeUnwatchon them before they're unwatched (same lock release).#7505 (@AlxcBTW) contains this PR plus the save-early change, so it'd be simplest to land one combined PR. Please agree between you which branch carries it.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-20T07:18:40Z.
Rechecked on current
maine9cc4a8ef. That tree includes #7432, which fixes another path to the same refusal. This branch (48a1d3453) still merges cleanly.ProsperoPuzzles (PPSA99006):
mainmain+ this PRmain+ #7048 still stops at 3 s (0 of 3), so this path isn't covered elsewhere. Same setup as the description: AMD Radeon 860M, Windows 11, Release, new run folder each time, 60 s, no input.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-20T11:52:51Z.
Superseded by #8172, so I'm closing this. Data is in #6301: ProsperoPuzzles stops at 4 s on #8172's parent (
e9cc4a8ef, 0 of 2 alive at 60 s), and runs with #8172 (2 of 2) and on currentmaind50ec76da(3 of 3).With #8172, a stays-watched import keeps the spans that were watched before it. A span leaves the watch only when the walk after the import fails (
walkWriteswith the window), and thatunwatchLockedstill runs withoutbeforeUnwatch. That's the same kind of gap this PR closed, but I have no title or test that reaches an incomplete collection there. If you'd like the hook on that path anyway, say so and I'll rebase this onto #8172's structure: collect the spans to unwatch, run the hook outside the tracker lock, then unwatch them, asMarkWrittendoes.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-20T14:21:15Z.
ProsperoPuzzles (PPSA99006) on
main1d4164552(includes #8172,d9df34d08), without this PR: Windows 11 Pro 26220, RTX 4070 (596.21), WinLibs GCC 15.2.0 r7, Release,--windows, new run folder each run, no input. 3 of 3 runs were still alive at the 150 s kill (7581, 8281 and 7575 frames, about 50-55 fps at the end), and none logged the write-watchRequirerefusal orterminate called. On the earliermainc9e6c45dethe same title stopped at about 7 s with 0xC0000409 on that refusal (reported above on93df5c42a). So on currentmaintheRequireno longer triggers for this title here.Written with Claude Code assistance.
Pull request closed