fix(agc): keep a fast-clear copy where an import window can stamp watched memory #3372

Merged
alfalfa-star merged 2 commits from upstream-pr/3372 into main 2026-10-11 09:40:15 +00:00
alfalfa-star commented 2026-10-11 09:21:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-11T09:21:55Z.


Carried from @milescoviello's branch fix/fast-clear-snapshot-import-window (commits 4a085303 and 7ec9747b, kept under their name). The intake rule closes PRs opened from their account. The regression comes from my #2699, so I'm carrying the fix.

What

Fixes #3179. agc_driver_dcc_keys_first_write fails again on main on Linux with NVIDIA (an unchanged pending image was uploaded again). #2699 made the DCC fast-clear upload skip the guest-byte copy (originalValid = false) when the range is write-watched. #2984 then made Refresh turn a BlockMaybeWritten unit into BlockUnchanged only through compareUntracked, which needs that copy. Where a host import leaves its range watched and stamps the imported pages when it is made, the import window stamps the surface, so a pending fast-cleared image counted as changed again.

  1. fix(agc): keep a fast-clear copy where an import window can stamp watched memory
    • HostImports keeps whether making each kind of import (host pointer, dma-buf) stamped the probe's pages (writtenAtImport).
    • WatchedImportsStampPages(context) decides the device's import watch and reports whether an import that leaves its range watched can stamp it. The fast-clear path skips the copy only when none can. This is the approach @oneandonlydean proposed in #3179.
    • #2699's saving stays where no such stamp is possible: devices whose probe saw no pages written at the import, devices without host imports, and Windows. An unprobed watch (APS5_WRITE_WATCH_IMPORTS=watch) keeps the copy.
    • The fast-clear check in agc_driver_dcc_keys_first_write now expects the copy exactly when the range is unwatched or such a stamp is possible.
  2. test(agc): reproduce an import window over a pending storage image
    • RunImportWindow (Linux only) opens an import window itself over a pending storage image with GuestMemory::ImportWatched and stores the byte already there. That leaves the same stamp as the NVIDIA import without depending on the driver. A store of a new byte inside a window must still be seen. Devices whose imports are compared print that the window is not tested.
    • One TechnicalDebt entry: an identical-byte CPU store inside a window can't be told apart from the import, and images tracked by layer still upload again.

Not changed: the direct host-import upload path in StorageTexture::upload (uncompressed keys) also skips the copy when the range is watched. Whether an import window can reach an image uploaded there has not been checked.

Tested

By @milescoviello (Linux, RTX 5090 Laptop GPU 610.57.04, and Intel Arrow Lake ANV, Mesa 26.1.8), on main 4f602486:

agc_driver_dcc_keys_first_write Result
main, NVIDIA fails 3/3: an unchanged pending image was uploaded again
fix + test, NVIDIA passes 3/3
fix + test, Intel ANV (imports compared) passes 3/3

Full ctest on NVIDIA with both commits: 763/763. @oneandonlydean confirmed the failure on an RTX 4090 and that reverting #2699 makes the test pass.

By me, on this branch (main 90c152e8 + both commits, cherry-picked unchanged), Linux 7.2.9, GCC, Release, RX 9070 XT (RADV GFX1201):

  • Full ctest: 813/813 pass (4 video_out_flip_* skipped).
  • agc_driver_dcc_keys_first_write passes 3/3. RADV compares its imports (4 of 4 scratch pages written after a GPU read), so here neither the watched run nor the import window runs. This host doesn't test the fix itself.
  • With APS5_WRITE_WATCH_IMPORTS=watch forced on RADV, the import-window check fails (a pending image was uploaded again after an import that stored nothing new). The copy is present (GuestSnapshotValid() is true and WatchedImportsStampPages() is true), and the GPU changed none of the guest bytes. My reading is that RADV's own GPU reads of the import stamp the pages as written, which is why the probe compares imports there. If so, a forced watch on RADV doesn't test the NVIDIA case, but I haven't confirmed which stamp it is.
  • tools/check_conventions.py passes.

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 in TechnicalDebt
  • 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: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818023929 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3372). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-11T09:21:55Z. --- Carried from @milescoviello's branch [`fix/fast-clear-snapshot-import-window`](https://github.com/milescoviello/AnyPS5/tree/fix/fast-clear-snapshot-import-window) (commits `4a085303` and `7ec9747b`, kept under their name). The intake rule closes PRs opened from their account. The regression comes from my #2699, so I'm carrying the fix. ### What Fixes #3179. `agc_driver_dcc_keys_first_write` fails again on `main` on Linux with NVIDIA (`an unchanged pending image was uploaded again`). #2699 made the DCC fast-clear upload skip the guest-byte copy (`originalValid = false`) when the range is write-watched. #2984 then made `Refresh` turn a `BlockMaybeWritten` unit into `BlockUnchanged` only through `compareUntracked`, which needs that copy. Where a host import leaves its range watched and stamps the imported pages when it is made, the import window stamps the surface, so a pending fast-cleared image counted as changed again. 1. `fix(agc): keep a fast-clear copy where an import window can stamp watched memory` - `HostImports` keeps whether making each kind of import (host pointer, dma-buf) stamped the probe's pages (`writtenAtImport`). - `WatchedImportsStampPages(context)` decides the device's import watch and reports whether an import that leaves its range watched can stamp it. The fast-clear path skips the copy only when none can. This is the approach @oneandonlydean proposed in #3179. - #2699's saving stays where no such stamp is possible: devices whose probe saw no pages written at the import, devices without host imports, and Windows. An unprobed watch (`APS5_WRITE_WATCH_IMPORTS=watch`) keeps the copy. - The fast-clear check in `agc_driver_dcc_keys_first_write` now expects the copy exactly when the range is unwatched or such a stamp is possible. 2. `test(agc): reproduce an import window over a pending storage image` - `RunImportWindow` (Linux only) opens an import window itself over a pending storage image with `GuestMemory::ImportWatched` and stores the byte already there. That leaves the same stamp as the NVIDIA import without depending on the driver. A store of a new byte inside a window must still be seen. Devices whose imports are compared print that the window is not tested. - One TechnicalDebt entry: an identical-byte CPU store inside a window can't be told apart from the import, and images tracked by layer still upload again. Not changed: the direct host-import upload path in `StorageTexture::upload` (uncompressed keys) also skips the copy when the range is watched. Whether an import window can reach an image uploaded there has not been checked. ### Tested By @milescoviello (Linux, RTX 5090 Laptop GPU 610.57.04, and Intel Arrow Lake ANV, Mesa 26.1.8), on `main` 4f602486: | `agc_driver_dcc_keys_first_write` | Result | |---|---| | `main`, NVIDIA | fails 3/3: `an unchanged pending image was uploaded again` | | fix + test, NVIDIA | passes 3/3 | | fix + test, Intel ANV (imports compared) | passes 3/3 | Full `ctest` on NVIDIA with both commits: 763/763. @oneandonlydean confirmed the failure on an RTX 4090 and that reverting #2699 makes the test pass. By me, on this branch (`main` 90c152e8 + both commits, cherry-picked unchanged), Linux 7.2.9, GCC, Release, RX 9070 XT (RADV GFX1201): - Full `ctest`: 813/813 pass (4 `video_out_flip_*` skipped). - `agc_driver_dcc_keys_first_write` passes 3/3. RADV compares its imports (`4 of 4 scratch pages written after a GPU read`), so here neither the watched run nor the import window runs. This host doesn't test the fix itself. - With `APS5_WRITE_WATCH_IMPORTS=watch` forced on RADV, the import-window check fails (`a pending image was uploaded again after an import that stored nothing new`). The copy is present (`GuestSnapshotValid()` is true and `WatchedImportsStampPages()` is true), and the GPU changed none of the guest bytes. My reading is that RADV's own GPU reads of the import stamp the pages as written, which is why the probe compares imports there. If so, a forced watch on RADV doesn't test the NVIDIA case, but I haven't confirmed which stamp it is. - `tools/check_conventions.py` passes. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
milescoviello commented 2026-10-11 09:26:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T09:26:49Z.


Thanks @alfalfa-star for carrying this and keeping the commits as they are, and @oneandonlydean for the approach.

Since RADV compares its imports, I ran this PR's head (ee720ee0, on main 90c152e8) on the NVIDIA host (RTX 5090 Laptop GPU, 610.57.04, Linux):

  • agc_driver_dcc_keys_first_write: passes 3/3. It fails 3/3 on main 4f602486 without the change.
  • Full ctest: 813/816. The three failures are the guest_video_out_* tests, which time out here only because this laptop's displays are powered off right now. They don't touch this change.

The two commits are byte-identical to my branch (same git patch-id). The conventions check fails only on the PR template (Fill in the pull request template: fill Depends on with #N or none), so the description's Depends on line just needs none.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107576170 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3372#issuecomment-6107576170). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-11T09:26:49Z. --- Thanks @alfalfa-star for carrying this and keeping the commits as they are, and @oneandonlydean for the approach. Since RADV compares its imports, I ran this PR's head (`ee720ee0`, on `main` 90c152e8) on the NVIDIA host (RTX 5090 Laptop GPU, 610.57.04, Linux): - `agc_driver_dcc_keys_first_write`: passes 3/3. It fails 3/3 on `main` 4f602486 without the change. - Full `ctest`: 813/816. The three failures are the `guest_video_out_*` tests, which time out here only because this laptop's displays are powered off right now. They don't touch this change. The two commits are byte-identical to my branch (same `git patch-id`). The `conventions` check fails only on the PR template (`Fill in the pull request template: fill Depends on with #N or none`), so the description's Depends on line just needs `none`. AI-assisted: yes
adriadam10 commented 2026-10-11 09:40:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:40:12Z.


Checked the diff, build and libSceAgcDriver ctest on Linux (agc_driver_dcc_keys_first_write passes), plus the NVIDIA/ANV results from @milescoviello and the RTX 4090 confirmation in #3179. Filled the empty Depends on: line in the description (none) so the conventions check passes; merging once it is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107676014 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3372#issuecomment-6107676014). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T09:40:12Z. --- Checked the diff, build and `libSceAgcDriver` ctest on Linux (`agc_driver_dcc_keys_first_write` passes), plus the NVIDIA/ANV results from @milescoviello and the RTX 4090 confirmation in #3179. Filled the empty `Depends on:` line in the description (`none`) so the conventions check passes; merging once it is green.
milescoviello commented 2026-10-11 09:40:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T09:40:51Z.


Thanks @adriadam10 for reviewing and merging, @alfalfa-star for carrying it, and @oneandonlydean for the approach and the RTX 4090 check.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107680946 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3372#issuecomment-6107680946). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-11T09:40:51Z. --- Thanks @adriadam10 for reviewing and merging, @alfalfa-star for carrying it, and @oneandonlydean for the approach and the RTX 4090 check.
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!3372
No description provided.