feat(agc): trace ranges that leave the write watch #7604

Closed
spiff637 wants to merge 8 commits from upstream-pr/7604 into main
spiff637 commented 2026-10-18 16:40:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by spiff637 on 2026-10-18T16:40:31Z.


What

Adds APS5_TRACE_WATCH, a trace of every range that leaves the CPU write watch, and runs the store-over-untracked leave cases on Windows.

  • Each exclusion prints its site (Unwatch, ImportLeave, ImportStaysUncovered, ImportStaysWalkFailed, MarkWritten) and whether the unwatch hook saved pending storage results first.
  • saveBeforeUnwatch reports a failed collect and each unit it leaves unsaved, and forgetSavedOver reports clearing a pending unit's saved bytes.
  • At the unsavedOutsideWatch Require, up to 16 lines name each unit stored without saved bytes and the exclusion that left its blocks unwatched. That is recorded per 64 KiB block, and only while tracing.
  • APS5_TRACE_WATCH=unsaved prints only exits that left watched blocks without a save, skipped saves and unsaved stores. The full trace changes timing enough to hide a race.
  • With the switch unset, nothing is recorded or printed.
  • agc_driver_store_over_untracked_unimported runs agc_driver_store_over_untracked_tests with APS5_NO_HOST_IMPORT=1. On Windows the surface's host import is compared and unwatched, so agc_driver_store_over_untracked prints "not run, the surface is not write-watched" for every leave case, including #7505's partly unwatched import. The new registration runs them.

This branch is #7505's head merged with current main, plus 2 commits. Until #7505 (and #6308) are merged, the diff also shows their commits.

Tested

  • Windows 11 Enterprise 10.0.26200, NVIDIA GeForce RTX 3080, driver 617.42.
  • Marvel's Spider-Man 2 (PPSA08338), on main from before #6308/#7505, aborted about 27 s in at Texture.cpp's "storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented". APS5_TRACE_WATCH=unsaved named the cause:
    • exclude 0x11f1258000+0x21da8000 by ImportStaysUncovered hook none new-blocks 8666 generation 4633
    • unsaved image 0x1202ef3600+0x90000 … layerPendingGeneration 4497 … ImportStaysUncovered=10 … hooked none host-region 0
    • This is the exit #6308/#7505 fix. With the hook run before that import, the title ran 4 minutes without the abort.
  • The full trace (about 22,000 lines in 150 s) hid the abort, so the quiet mode exists.
  • ctest -R "^agc_": 712 of 713 pass, 3 skipped. agc_driver_bda_device fails with vkWaitForFences graphics: Vulkan result -4 on this machine, identically on main without this PR.
  • agc_driver_store_over_untracked_unimported: every leave case runs; only the two copy cases print "no host import".
  • tools/check_conventions.py --base origin/main and tools/check_test_registration.py build pass.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #7505
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3080, driver 617.42, Windows 11 Enterprise 10.0.26200
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01HAtTu2pw6GTkMNwsjBDatU

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4910873862 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7604). Originally posted by [spiff637](https://github.com/spiff637) on 2026-10-18T16:40:31Z. --- ### What Adds `APS5_TRACE_WATCH`, a trace of every range that leaves the CPU write watch, and runs the store-over-untracked leave cases on Windows. - Each exclusion prints its site (`Unwatch`, `ImportLeave`, `ImportStaysUncovered`, `ImportStaysWalkFailed`, `MarkWritten`) and whether the unwatch hook saved pending storage results first. - `saveBeforeUnwatch` reports a failed collect and each unit it leaves unsaved, and `forgetSavedOver` reports clearing a pending unit's saved bytes. - At the `unsavedOutsideWatch` Require, up to 16 lines name each unit stored without saved bytes and the exclusion that left its blocks unwatched. That is recorded per 64 KiB block, and only while tracing. - `APS5_TRACE_WATCH=unsaved` prints only exits that left watched blocks without a save, skipped saves and unsaved stores. The full trace changes timing enough to hide a race. - With the switch unset, nothing is recorded or printed. - `agc_driver_store_over_untracked_unimported` runs `agc_driver_store_over_untracked_tests` with `APS5_NO_HOST_IMPORT=1`. On Windows the surface's host import is compared and unwatched, so `agc_driver_store_over_untracked` prints "not run, the surface is not write-watched" for every leave case, including #7505's partly unwatched import. The new registration runs them. This branch is #7505's head merged with current `main`, plus 2 commits. Until #7505 (and #6308) are merged, the diff also shows their commits. ### Tested - Windows 11 Enterprise 10.0.26200, NVIDIA GeForce RTX 3080, driver 617.42. - Marvel's Spider-Man 2 (PPSA08338), on `main` from before #6308/#7505, aborted about 27 s in at `Texture.cpp`'s "storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented". `APS5_TRACE_WATCH=unsaved` named the cause: - `exclude 0x11f1258000+0x21da8000 by ImportStaysUncovered hook none new-blocks 8666 generation 4633` - `unsaved image 0x1202ef3600+0x90000 … layerPendingGeneration 4497 … ImportStaysUncovered=10 … hooked none host-region 0` - This is the exit #6308/#7505 fix. With the hook run before that import, the title ran 4 minutes without the abort. - The full trace (about 22,000 lines in 150 s) hid the abort, so the quiet mode exists. - `ctest -R "^agc_"`: 712 of 713 pass, 3 skipped. `agc_driver_bda_device` fails with `vkWaitForFences graphics: Vulkan result -4` on this machine, identically on `main` without this PR. - `agc_driver_store_over_untracked_unimported`: every leave case runs; only the two copy cases print "no host import". - `tools/check_conventions.py --base origin/main` and `tools/check_test_registration.py build` pass. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #7505 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3080, driver 617.42, Windows 11 Enterprise 10.0.26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01HAtTu2pw6GTkMNwsjBDatU
blawesom commented 2026-10-19 07:39:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T07:39:18Z.


Rebase handoff — rebased onto current main (all six commits, authorship unchanged). The conflicts: test calls unioned; the docs entries take main's fuller current text; and the unwatch-drop logic keeps main's dropped-generation tracking (the newer evolution of the erase-based exclusions this PR's older commits used) — your trace feature replays on top of it.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the four known main regressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/7604
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is f47ad5d57.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6262190121 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7604#issuecomment-6262190121). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-19T07:39:18Z. --- **Rebase handoff** — rebased onto current `main` (all six commits, authorship unchanged). The conflicts: test calls unioned; the docs entries take `main`'s fuller current text; and the unwatch-drop logic keeps `main`'s `dropped`-generation tracking (the newer evolution of the erase-based exclusions this PR's older commits used) — your trace feature replays on top of it. Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): builds; conventions pass; **full suite green apart from the four known `main` regressions** (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR. **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/7604 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `f47ad5d57`.
oneandonlydean commented 2026-10-20 14:25:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T14:25:14Z.


@spiff637 thanks for this. The branch sits on an old head of #7505, which carries #6308's commit. #6308 has since closed as superseded by #8172, and #8172 rewrote the staysWatched path of ImportWatched that your trace instruments. Main now splits a partly watched import into spans of covered 64 KiB blocks, and only gaps and spans whose walk fails leave the watch. The saveBytes sites your trace labels no longer exist, so the branch conflicts in GuestMemory.cpp.

Could you rebase c1c13def8 and 0e5269cce straight onto current main, without #7505 or #6308 underneath? Then map the trace sites to main's exits:

  • gaps that were never watched (not a watched-block exit);
  • a span dropped because its walk failed before the import;
  • a span whose window walk failed after the import;
  • the !staysWatched path, which already runs the hook first.

On main, the two span exits run without the unwatch hook, so APS5_TRACE_WATCH=unsaved should report them as unsaved. That makes the trace directly useful for the pending rework in #7505. If #7505's rework lands first, the same sites just report saved instead.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6293160113 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7604#issuecomment-6293160113). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T14:25:14Z. --- @spiff637 thanks for this. The branch sits on an old head of #7505, which carries #6308's commit. #6308 has since closed as superseded by #8172, and #8172 rewrote the `staysWatched` path of `ImportWatched` that your trace instruments. Main now splits a partly watched import into spans of covered 64 KiB blocks, and only gaps and spans whose walk fails leave the watch. The `saveBytes` sites your trace labels no longer exist, so the branch conflicts in `GuestMemory.cpp`. Could you rebase c1c13def8 and 0e5269cce straight onto current main, without #7505 or #6308 underneath? Then map the trace sites to main's exits: - gaps that were never watched (not a watched-block exit); - a span dropped because its walk failed before the import; - a span whose window walk failed after the import; - the `!staysWatched` path, which already runs the hook first. On main, the two span exits run without the unwatch hook, so `APS5_TRACE_WATCH=unsaved` should report them as unsaved. That makes the trace directly useful for the pending rework in #7505. If #7505's rework lands first, the same sites just report saved instead.
cookie42073-cmd commented 2026-10-20 15:47:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cookie42073-cmd on 2026-10-20T15:47:39Z.


Hey @spiff637, following the standalone-rebase request, I put together a port of your two diagnostic commits onto d073fe6a1, preserving your authorship and trailers. The attached ZIP has the patch, mbox and sanitized build/test logs. A third commit contains supporting provenance tests, kept separate for review.

The port maps the before/after walk failures onto main's span exits, keeps never-watched gaps out of the exit history, and labels hook invocation rather than claiming that bytes were saved. The storage safety refusal remains intact.

Both full Windows builds and the libs targets passed with #8310's ca55e46f9 fixture repair applied separately to both arms. On Windows 11 / NVIDIA RTX 4070 SUPER / driver 617.42, all 60 matched CTest executions passed on each side across tracing unset, full and quiet modes; three additional candidate registrations passed too. Khronos validation actually loaded, with no VUID errors or missing-layer messages.

This validates the pinned revision, not later main commits or the full registered test suite. NHL 26, Linux/macOS, and Texture's actual unsaved-unit report and 16-unit cap notice weren't exercised; timing neutrality isn't established.

The local candidate is 48fb82c6a52119c50e567eb8f36d924b0f27e215. The port and additional tests were AI-assisted and independently reviewed. No title-unblock claim here; this is a handoff to help get the next useful capture.

ZIP SHA-256: 6269c2aece40cc94663a1aac2688ec4164f613f58eaf1c9b40c3a948a954defd

AnyPS5-watch-trace-48fb82c6a-20261020.zip

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6294947048 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7604#issuecomment-6294947048). Originally posted by [cookie42073-cmd](https://github.com/cookie42073-cmd) on 2026-10-20T15:47:39Z. --- Hey @spiff637, following the standalone-rebase request, I put together a port of your two diagnostic commits onto `d073fe6a1`, preserving your authorship and trailers. The attached ZIP has the patch, mbox and sanitized build/test logs. A third commit contains supporting provenance tests, kept separate for review. The port maps the before/after walk failures onto main's span exits, keeps never-watched gaps out of the exit history, and labels hook invocation rather than claiming that bytes were saved. The storage safety refusal remains intact. Both full Windows builds and the libs targets passed with #8310's `ca55e46f9` fixture repair applied separately to both arms. On Windows 11 / NVIDIA RTX 4070 SUPER / driver 617.42, all 60 matched CTest executions passed on each side across tracing unset, full and quiet modes; three additional candidate registrations passed too. Khronos validation actually loaded, with no VUID errors or missing-layer messages. This validates the pinned revision, not later main commits or the full registered test suite. NHL 26, Linux/macOS, and Texture's actual unsaved-unit report and 16-unit cap notice weren't exercised; timing neutrality isn't established. The local candidate is `48fb82c6a52119c50e567eb8f36d924b0f27e215`. The port and additional tests were AI-assisted and independently reviewed. No title-unblock claim here; this is a handoff to help get the next useful capture. ZIP SHA-256: `6269c2aece40cc94663a1aac2688ec4164f613f58eaf1c9b40c3a948a954defd` [AnyPS5-watch-trace-48fb82c6a-20261020.zip](https://github.com/user-attachments/files/33726421/AnyPS5-watch-trace-48fb82c6a-20261020.zip)
cookie42073-cmd commented 2026-10-20 19:10:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cookie42073-cmd on 2026-10-20T19:10:23Z.


Quick follow-up on the coverage gap in my earlier handoff: the real unsaved-unit report and its 16-entry limit are now exercised by a synthetic Windows fixture.

The test uploads watched images without CPU snapshots, unwatches them while idle, completes a Vulkan clear and reads back a changed pixel, then marks the results pending. Each bounded flush has to hit the existing saved-byte safety refusal. Every attempt checks the entire 3 MiB guest allocation is unchanged, the results remain pending, and no comparison snapshot appeared.

Three fresh processes cover tracing unset, full and unsaved. Unset prints no watch reports. Full and quiet each print one detail for units 0–15, then exactly one suppression notice on attempt 17 using a second image. Retries on both images print neither. The detailed reports also check the actual 64 KiB unit ranges, exact generations, reason and exclusion provenance.

I also tested deliberately wrong caps of 15 and 17, and a removed safety guard. Each built and failed the intended assertion. Those temporary changes were restored byte for byte before the final passing build; the attached commit changes tests only.

The separate test commit is 063aec49b95b91e7ed23d98028192b5d044803e5, on top of the earlier 48fb82c6a diagnostic handoff. This supports @spiff637's trace contribution; it does not change their branch or open a duplicate feature PR. The ZIP contains the test patch/mbox, sanitized logs and negative-control evidence.

Final default Release build, libs, conventions, registration checks and all 11 focused CTest registrations passed, with no skips. Tested on Windows 11 / NVIDIA RTX 4070 SUPER / driver 617.42; Khronos validation loaded with no VUID or missing-layer messages. The same separate #8310 ca55e46f9 Windows fixture overlay was retained for the build and is excluded from this test commit.

This remains validation of the pinned diagnostic tree based on d073fe6a1, not newer main, the full suite, other platforms or GPUs, or a game run. It doesn't reproduce NHL 26 or Astro Bot's ordering, establish timing neutrality, or unblock a title. The actual title capture is still needed. AI-assisted with OpenAI Codex; source and results independently reviewed.

ZIP SHA-256: d3925c2fd467b476e60f271aaa1c5ecd19f424fba22a5f4c053aa624dc9193ce

AnyPS5-unsaved-report-063aec49b-20261020.zip

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6299035836 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7604#issuecomment-6299035836). Originally posted by [cookie42073-cmd](https://github.com/cookie42073-cmd) on 2026-10-20T19:10:23Z. --- Quick follow-up on the coverage gap in my earlier handoff: the real unsaved-unit report and its 16-entry limit are now exercised by a synthetic Windows fixture. The test uploads watched images without CPU snapshots, unwatches them while idle, completes a Vulkan clear and reads back a changed pixel, then marks the results pending. Each bounded flush has to hit the existing saved-byte safety refusal. Every attempt checks the entire 3 MiB guest allocation is unchanged, the results remain pending, and no comparison snapshot appeared. Three fresh processes cover tracing unset, full and `unsaved`. Unset prints no watch reports. Full and quiet each print one detail for units 0–15, then exactly one suppression notice on attempt 17 using a second image. Retries on both images print neither. The detailed reports also check the actual 64 KiB unit ranges, exact generations, reason and exclusion provenance. I also tested deliberately wrong caps of 15 and 17, and a removed safety guard. Each built and failed the intended assertion. Those temporary changes were restored byte for byte before the final passing build; the attached commit changes tests only. The separate test commit is `063aec49b95b91e7ed23d98028192b5d044803e5`, on top of the earlier `48fb82c6a` diagnostic handoff. This supports @spiff637's trace contribution; it does not change their branch or open a duplicate feature PR. The ZIP contains the test patch/mbox, sanitized logs and negative-control evidence. Final default Release build, `libs`, conventions, registration checks and all 11 focused CTest registrations passed, with no skips. Tested on Windows 11 / NVIDIA RTX 4070 SUPER / driver 617.42; Khronos validation loaded with no VUID or missing-layer messages. The same separate #8310 `ca55e46f9` Windows fixture overlay was retained for the build and is excluded from this test commit. This remains validation of the pinned diagnostic tree based on `d073fe6a1`, not newer main, the full suite, other platforms or GPUs, or a game run. It doesn't reproduce NHL 26 or Astro Bot's ordering, establish timing neutrality, or unblock a title. The actual title capture is still needed. AI-assisted with OpenAI Codex; source and results independently reviewed. ZIP SHA-256: `d3925c2fd467b476e60f271aaa1c5ecd19f424fba22a5f4c053aa624dc9193ce` [AnyPS5-unsaved-report-063aec49b-20261020.zip](https://github.com/user-attachments/files/33734164/AnyPS5-unsaved-report-063aec49b-20261020.zip)

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7604
No description provided.