fix(agc): keep a surface's results in the 64 KiB block it shares with its neighbour #441

Merged
oneandonlydean merged 1 commit from upstream-pr/441 into main 2026-10-03 22:32:25 +00:00
oneandonlydean commented 2026-10-03 07:35:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-03T07:35:07Z.


What

Write stamps are kept per 64 KiB block, so a write-back of one surface stamps the whole block it shares with a surface packed right after it. A pending storage image of that neighbour read the stamp as a store over its own bytes: its write-back kept the guest bytes of the shared block in place of its results, and its next refresh re-uploaded those stale bytes.

PPSA21564's half-resolution fog texture (960x540 RGBA16F, linear) starts 0xb800 bytes before a block end, right after another 960x540 surface. It lost its first 6 rows that way, and the fog composite upsampled them into an orange band across the top 12 rows of the scene in one of its cinematics. It depended on when the deferred write-backs ran, so some runs showed it every frame and others rarely.

  • The write tracker now remembers the byte ranges of the driver's own stores (MarkWritten) in the blocks they cover only in part: up to four ranges per block. When a range is overwritten, the block keeps its generation, so a forgotten range still counts as a store.
  • New GuestMemory::StoredOver(address, bytes, generation) says whether a store reached that range since a generation. A CPU store, a whole-block driver store, a dropped range or an unwatched range still counts for the whole block, so the answer is never "not stored" when a store may have landed.
  • The write-back keep rule (writeBackLayers) and the refresh drop rule (Refresh) ask it only for the blocks a surface covers in part; whole blocks behave as before.

Tested

  • Linux (CachyOS, x86-64): full build with BUILD_TESTING=ON and ctest pass (127/127).
  • New agc_write_tracking (ctest, CPU only; skipped with code 77 when write watching is unavailable): two surfaces sharing a block at the same 0xb800 offset; a store of the first surface's bytes does not count over the second surface's part of the shared block but does over its own; a store into the second part, a whole-block store, more partial stores than the tracker keeps, and a CPU store in the block all count; a store older than the generation does not; a range the tracker does not cover always counts (checked on Linux; on Windows the tracker covers the whole guest arena range, so the test has no such range there). StoredOver is new, so the test does not build without this change.
  • PPSA21564: the cinematic showed the band in 252 frames of a run before and in none after, and the change has been on my integration branch through repeated passes of my visual regression check (checkpoint frames, flicker, shimmer, video tearing, FPS).

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4724926319 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/441). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-03T07:35:07Z. --- ### What Write stamps are kept per 64 KiB block, so a write-back of one surface stamps the whole block it shares with a surface packed right after it. A pending storage image of that neighbour read the stamp as a store over its own bytes: its write-back kept the guest bytes of the shared block in place of its results, and its next refresh re-uploaded those stale bytes. PPSA21564's half-resolution fog texture (960x540 RGBA16F, linear) starts 0xb800 bytes before a block end, right after another 960x540 surface. It lost its first 6 rows that way, and the fog composite upsampled them into an orange band across the top 12 rows of the scene in one of its cinematics. It depended on when the deferred write-backs ran, so some runs showed it every frame and others rarely. - The write tracker now remembers the byte ranges of the driver's own stores (`MarkWritten`) in the blocks they cover only in part: up to four ranges per block. When a range is overwritten, the block keeps its generation, so a forgotten range still counts as a store. - New `GuestMemory::StoredOver(address, bytes, generation)` says whether a store reached that range since a generation. A CPU store, a whole-block driver store, a dropped range or an unwatched range still counts for the whole block, so the answer is never "not stored" when a store may have landed. - The write-back keep rule (`writeBackLayers`) and the refresh drop rule (`Refresh`) ask it only for the blocks a surface covers in part; whole blocks behave as before. ### Tested - Linux (CachyOS, x86-64): full build with `BUILD_TESTING=ON` and `ctest` pass (127/127). - New `agc_write_tracking` (ctest, CPU only; skipped with code 77 when write watching is unavailable): two surfaces sharing a block at the same 0xb800 offset; a store of the first surface's bytes does not count over the second surface's part of the shared block but does over its own; a store into the second part, a whole-block store, more partial stores than the tracker keeps, and a CPU store in the block all count; a store older than the generation does not; a range the tracker does not cover always counts (checked on Linux; on Windows the tracker covers the whole guest arena range, so the test has no such range there). `StoredOver` is new, so the test does not build without this change. - PPSA21564: the cinematic showed the band in 252 frames of a run before and in none after, and the change has been on my integration branch through repeated passes of my visual regression check (checkpoint frames, flicker, shimmer, video tearing, FPS). ### 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 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
oneandonlydean commented 2026-10-03 07:44:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-03T07:44:06Z.


The Linux failure in the first CI run is agc_driver_vopc_compare (thread 1 compare 39 is 0, expected 1), the intermittent llvmpipe failure I described in https://github.com/boykopovar/AnyPS5/pull/399#issuecomment-5964789931. This PR doesn't touch the shader path; Windows passed in the same run. I rebased onto current main to start a fresh run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5966877692 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/441#issuecomment-5966877692). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-03T07:44:06Z. --- The Linux failure in the first CI run is `agc_driver_vopc_compare` (`thread 1 compare 39 is 0, expected 1`), the intermittent llvmpipe failure I described in https://github.com/boykopovar/AnyPS5/pull/399#issuecomment-5964789931. This PR doesn't touch the shader path; Windows passed in the same run. I rebased onto current `main` to start a fresh run.
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!441
No description provided.