fix(agc): ignore unchanged imported texture blocks #2984

Merged
MarcZX10 merged 1 commit from upstream-pr/2984 into main 2026-10-10 23:43:28 +00:00
MarcZX10 commented 2026-10-10 19:37:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T19:37:29Z.


What

Fixes #2767. When write tracking reports a 64 KiB texture block as possibly written, compare the block with the image snapshot before treating it as changed. If the bytes are identical, keep the pending GPU image and clear the false CPU-write stamp. This avoids redundant uploads when a host import remains write-watched but did not change guest bytes.

The issue reports the current failure on three NVIDIA setups and confirms the patch on those systems; an Intel report also reproduces the failure with import watching forced. No open PR overlaps this change.

Tested

  • Linux Release: built agc_driver_dcc_keys_first_write_tests
  • CTest agc_driver_dcc_keys_first_write, repeated 5 times: passed 5/5
  • tools/check_conventions.py --base upstream/main passed
  • git diff --check passed
  • Open PR overlap scan: no overlap

The local llvmpipe run reports that write-watch is unavailable, so the import-watch portion of this execution test was skipped locally. The hardware-specific reproduction and patched results are documented by the reporters in #2767.

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; silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813913423 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2984). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T19:37:29Z. --- ### What Fixes #2767. When write tracking reports a 64 KiB texture block as possibly written, compare the block with the image snapshot before treating it as changed. If the bytes are identical, keep the pending GPU image and clear the false CPU-write stamp. This avoids redundant uploads when a host import remains write-watched but did not change guest bytes. The issue reports the current failure on three NVIDIA setups and confirms the patch on those systems; an Intel report also reproduces the failure with import watching forced. No open PR overlaps this change. ### Tested - Linux Release: built `agc_driver_dcc_keys_first_write_tests` - CTest `agc_driver_dcc_keys_first_write`, repeated 5 times: passed 5/5 - `tools/check_conventions.py --base upstream/main` passed - `git diff --check` passed - Open PR overlap scan: no overlap The local llvmpipe run reports that write-watch is unavailable, so the import-watch portion of this execution test was skipped locally. The hardware-specific reproduction and patched results are documented by the reporters in #2767. ### 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 - [x] Unimplemented paths throw; silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [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
fma-rc commented 2026-10-10 21:40:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T21:40:45Z.


Tested this head (c0610950, merged cleanly onto main 262c0316) on the hardware the linked issue is about, since the description says the watched path was skipped on llvmpipe.

Arch Linux (kernel 7.2.9), GCC 16.2.1, Release, ANYPS5_REQUIRE_VULKAN=1. RTX 5080 (NVIDIA 615.78.08), where host imports stay write-watched, and a Radeon 610M on RADV, where they are compared.

RTX 5080 RADV, Radeon 610M
main 262c0316, agc_driver_dcc_keys_first_write fails (an unchanged pending image was uploaded again) passes
this PR, agc_driver_dcc_keys_first_write passes 10 of 10 passes
this PR, full ctest 708 of 708 708 of 708

ctest reports 4 video_out_flip_* tests as skipped in the RTX 5080 run, and those plus 3 guest_video_out_* tests in the RADV run; they are counted in the 708.

The diff is the patch from the issue unchanged, so this is the change the three NVIDIA reports there were made with. Not tested: Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102465932 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2984#issuecomment-6102465932). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-10T21:40:45Z. --- Tested this head (c0610950, merged cleanly onto `main` 262c0316) on the hardware the linked issue is about, since the description says the watched path was skipped on llvmpipe. Arch Linux (kernel 7.2.9), GCC 16.2.1, Release, `ANYPS5_REQUIRE_VULKAN=1`. RTX 5080 (NVIDIA 615.78.08), where host imports stay write-watched, and a Radeon 610M on RADV, where they are compared. | | RTX 5080 | RADV, Radeon 610M | | --- | --- | --- | | `main` 262c0316, `agc_driver_dcc_keys_first_write` | fails (`an unchanged pending image was uploaded again`) | passes | | this PR, `agc_driver_dcc_keys_first_write` | passes 10 of 10 | passes | | this PR, full `ctest` | 708 of 708 | 708 of 708 | ctest reports 4 `video_out_flip_*` tests as skipped in the RTX 5080 run, and those plus 3 `guest_video_out_*` tests in the RADV run; they are counted in the 708. The diff is the patch from the issue unchanged, so this is the change the three NVIDIA reports there were made with. Not tested: Windows.
milescoviello commented 2026-10-10 23:05:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-10T23:05:31Z.


The description notes that the import-watch part of agc_driver_dcc_keys_first_write was skipped on llvmpipe. It only runs where the device's own host import resolves the write protection, which CI's devices don't do, so this fix has no test there. Here is one that doesn't depend on the driver, as a single commit on top of this PR's head (c0610950):

milescoviello/AnyPS5:test/2984-import-window, commit a086c534.

  • RunImportWindow (in DccKeysFirstWrite.cpp, 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 BlockMaybeWritten stamp the NVIDIA import leaves, so the image must stay pending and unchanged. A store of a new byte inside a window must still be seen by the next Refresh. Devices whose imports are compared print that the window is not tested, as the recorder's (w) test does.
  • One TechnicalDebt.md entry: an identical-byte CPU store inside a window can't be told apart from the import, and images tracked by layer (not by 64 KiB unit) still upload again.

Tested (Linux, RTX 5090 Laptop GPU 610.57.04 and Intel Arrow Lake ANV, Mesa 26.1.8):

agc_driver_dcc_keys_first_write
this PR + test, NVIDIA passes 3 of 3 (0.5 s)
this PR + test, Intel (imports compared) passes; prints that the import window is not tested
without the fix, new test only, NVIDIA fails at the new check: import window: a pending image was uploaded again after an import that stored nothing new

tools/check_conventions.py passes. Feel free to fold it into this PR or leave it.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103143684 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2984#issuecomment-6103143684). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-10T23:05:31Z. --- The description notes that the import-watch part of `agc_driver_dcc_keys_first_write` was skipped on llvmpipe. It only runs where the device's own host import resolves the write protection, which CI's devices don't do, so this fix has no test there. Here is one that doesn't depend on the driver, as a single commit on top of this PR's head (`c0610950`): [`milescoviello/AnyPS5:test/2984-import-window`](https://github.com/milescoviello/AnyPS5/tree/test/2984-import-window), commit `a086c534`. - `RunImportWindow` (in `DccKeysFirstWrite.cpp`, 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 `BlockMaybeWritten` stamp the NVIDIA import leaves, so the image must stay pending and unchanged. A store of a new byte inside a window must still be seen by the next `Refresh`. Devices whose imports are compared print that the window is not tested, as the recorder's `(w)` test does. - One `TechnicalDebt.md` entry: an identical-byte CPU store inside a window can't be told apart from the import, and images tracked by layer (not by 64 KiB unit) still upload again. **Tested** (Linux, RTX 5090 Laptop GPU 610.57.04 and Intel Arrow Lake ANV, Mesa 26.1.8): | | `agc_driver_dcc_keys_first_write` | |---|---| | this PR + test, NVIDIA | passes 3 of 3 (0.5 s) | | this PR + test, Intel (imports compared) | passes; prints that the import window is not tested | | without the fix, new test only, NVIDIA | fails at the new check: `import window: a pending image was uploaded again after an import that stored nothing new` | `tools/check_conventions.py` passes. Feel free to fold it into this PR or leave it. AI-assisted: yes
adriadam10 commented 2026-10-10 23:43:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:43:25Z.


Checked the diff: the block is only reused when compareUntracked finds it byte-identical to the snapshot, one 64 KiB unit at a time, so a real write is still seen. Local build and libSceAgcDriver ctest (344 tests) pass on this head merged onto main. The NVIDIA failure and fix are confirmed by @fma-rc (RTX 5080) and @milescoviello (RTX 5090 Laptop), thanks. Merging; the extra driver-independent test in the thread is welcome as a separate PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103425414 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2984#issuecomment-6103425414). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:43:25Z. --- Checked the diff: the block is only reused when `compareUntracked` finds it byte-identical to the snapshot, one 64 KiB unit at a time, so a real write is still seen. Local build and `libSceAgcDriver` ctest (344 tests) pass on this head merged onto `main`. The NVIDIA failure and fix are confirmed by @fma-rc (RTX 5080) and @milescoviello (RTX 5090 Laptop), thanks. Merging; the extra driver-independent test in the thread is welcome as a separate PR.
milescoviello commented 2026-10-10 23:58:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-10T23:58:49Z.


@adriadam10 @MarcZX100 thanks for merging this. Two things, the second one more important:

1. The driver-independent test, rebased onto main: milescoviello/AnyPS5:test/dcc-import-window (one commit, 63649253; it cherry-picks cleanly onto current main ed79bde5). I can't open PRs yet under the intake rule, so it's there for whoever can carry it.

2. On current main this fix no longer holds on NVIDIA. agc_driver_dcc_keys_first_write fails again with an unchanged pending image was uploaded again on the merge commit 3db065af and on main (59a8cbab and ed79bde5), while this PR's head c0610950 passes. A first-parent bisect of the 88 merges between this PR's base 4a747c48 and the merge, applying c0610950 at each step, points to #2699 (926ad9e3, "read a fast-cleared surface's guest bytes only when the import is compared").

#2699 makes the DCC fast-clear upload leave originalValid false when the range is write-watched. This PR's comparison needs that snapshot: compareUntracked returns false without one, so a unit of a fast-cleared surface that an import window stamped BlockMaybeWritten counts as changed again. Each change is right on its own; they conflict where imports stay watched. The test's surface is fast-cleared (its keys start at 0000), so it hits exactly this path.

Linux, RTX 5090 Laptop GPU (610.57.04), agc_driver_dcc_keys_first_write with the test commit applied:

Tree Result
main ed79bde5 fails 3/3: an unchanged pending image was uploaded again
main ed79bde5, only the new import-window part (existing watched run skipped) fails 3/3: import window: a pending image was uploaded again after an import that stored nothing new
main 59a8cbab with #2699's three-line clear-path change and its two test lines reverted passes 3/3 (whole test); Intel ANV passes too
this PR's head c0610950 passes 3/3

So the new test catches the regression by itself. It doesn't rely on the import behaving like NVIDIA's, so it should fail on any device whose imports stay watched. I haven't written a fix: it means choosing between #2699's saving and the snapshot this comparison needs (for example, keeping the snapshot on the clear path when the range's import can leave import-window stamps).

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103533926 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2984#issuecomment-6103533926). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-10T23:58:49Z. --- @adriadam10 @MarcZX100 thanks for merging this. Two things, the second one more important: **1. The driver-independent test**, rebased onto `main`: [`milescoviello/AnyPS5:test/dcc-import-window`](https://github.com/milescoviello/AnyPS5/tree/test/dcc-import-window) (one commit, `63649253`; it cherry-picks cleanly onto current `main` ed79bde5). I can't open PRs yet under the intake rule, so it's there for whoever can carry it. **2. On current `main` this fix no longer holds on NVIDIA.** `agc_driver_dcc_keys_first_write` fails again with `an unchanged pending image was uploaded again` on the merge commit 3db065af and on `main` (59a8cbab and ed79bde5), while this PR's head c0610950 passes. A first-parent bisect of the 88 merges between this PR's base 4a747c48 and the merge, applying c0610950 at each step, points to **#2699** (926ad9e3, "read a fast-cleared surface's guest bytes only when the import is compared"). #2699 makes the DCC fast-clear upload leave `originalValid` false when the range is write-watched. This PR's comparison needs that snapshot: `compareUntracked` returns false without one, so a unit of a fast-cleared surface that an import window stamped `BlockMaybeWritten` counts as changed again. Each change is right on its own; they conflict where imports stay watched. The test's surface is fast-cleared (its keys start at 0000), so it hits exactly this path. Linux, RTX 5090 Laptop GPU (610.57.04), `agc_driver_dcc_keys_first_write` with the test commit applied: | Tree | Result | |---|---| | `main` ed79bde5 | fails 3/3: `an unchanged pending image was uploaded again` | | `main` ed79bde5, only the new import-window part (existing watched run skipped) | fails 3/3: `import window: a pending image was uploaded again after an import that stored nothing new` | | `main` 59a8cbab with #2699's three-line clear-path change and its two test lines reverted | passes 3/3 (whole test); Intel ANV passes too | | this PR's head c0610950 | passes 3/3 | So the new test catches the regression by itself. It doesn't rely on the import behaving like NVIDIA's, so it should fail on any device whose imports stay watched. I haven't written a fix: it means choosing between #2699's saving and the snapshot this comparison needs (for example, keeping the snapshot on the clear path when the range's import can leave import-window stamps). AI-assisted: yes
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!2984
No description provided.