fix(agc): decide an edge unit's CPU keep from the pages the unit overlaps #1387

Merged
Dextroid17 merged 1 commit from upstream-pr/1387 into main 2026-10-08 09:36:49 +00:00
Dextroid17 commented 2026-10-08 01:30:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T01:30:52Z.


What

StorageTexture::writeBackLayers keeps the CPU's bytes for an edge unit when StoredOver reports that the CPU wrote it since the unit's generation. That check read one generation per 64 KiB block, so a store to another allocation sharing the block counted as a store over this surface, the whole block was kept, and GPU results written into it were discarded.

This is the report's finding 1. The driver path in the same check already compares range pieces (driverPieces); the CPU path did not:

if (tracker.cpuStampOf(block) > generation) return true;                     // whole block
...
const auto from = std::max(address, begin) - begin;                          // driver: exact
const auto to   = std::min(end, begin + WriteBlockBytes) - begin;
for (const auto& piece : entry.pieces)
    if (piece.generation > generation && piece.begin < to && from < piece.end) return true;

The CPU path now does the same. Each collect records the generation of every page it found dirty — Windows already has the dirty pages, Linux already has the dirty runs — and StoredOver tests only the pages its range overlaps. A block with no page record keeps the previous whole-block answer, so nothing that does not collect holds less information than before.

Tested

Linux (CachyOS, GCC, Release, BUILD_TESTING=ON), RTX 3080 Ti, main at df16c4c2.

agc_write_tracking stores at base + Block + 8, which is inside the shared block but outside the queried range — exactly the report's case at one page of scale. That assertion fails on main and passes here:

without the fix:  write tracking test failed: a CPU store outside the shared range counts for it
with it:          write tracking tests passed

Full suite: 408 of 408. tools/check_conventions.py --base upstream/main passes.

What this does not fix

The report's finding 2 is untouched. There, the newer stamps fall on the surface's own pages, and dumping those bytes shows they still equal the fill pattern, so the block is kept even with exact range overlap. I have no measurement for why those stamps exist; the report asks what rule is wanted and offers three variants. This PR is the one that follows from the code's own driver path, so it is the piece that is exact on its own.

I have no PPSA12544 dump, so I ran no title — the regression is at the tracker level, and this is offered for the report's own repro (Windows, RX 9070 XT) to confirm the tail-block half and to say whether the boxed letters change.

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:4780551434 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1387). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-08T01:30:52Z. --- ### What `StorageTexture::writeBackLayers` keeps the CPU's bytes for an **edge** unit when `StoredOver` reports that the CPU wrote it since the unit's generation. That check read **one generation per 64 KiB block**, so a store to *another allocation sharing the block* counted as a store over this surface, the whole block was kept, and GPU results written into it were discarded. This is the report's **finding 1**. The driver path in the same check already compares range pieces (`driverPieces`); the CPU path did not: ```cpp if (tracker.cpuStampOf(block) > generation) return true; // whole block ... const auto from = std::max(address, begin) - begin; // driver: exact const auto to = std::min(end, begin + WriteBlockBytes) - begin; for (const auto& piece : entry.pieces) if (piece.generation > generation && piece.begin < to && from < piece.end) return true; ``` The CPU path now does the same. Each collect records the generation of every page it found dirty — Windows already has the dirty pages, Linux already has the dirty runs — and `StoredOver` tests only the pages its range overlaps. A block with no page record keeps the previous whole-block answer, so nothing that does not collect holds less information than before. ### Tested Linux (CachyOS, GCC, Release, `BUILD_TESTING=ON`), RTX 3080 Ti, `main` at df16c4c2. `agc_write_tracking` stores at `base + Block + 8`, which is inside the shared block but **outside** the queried range — exactly the report's case at one page of scale. That assertion **fails on `main`** and passes here: ``` without the fix: write tracking test failed: a CPU store outside the shared range counts for it with it: write tracking tests passed ``` Full suite: **408 of 408**. `tools/check_conventions.py --base upstream/main` passes. ### What this does not fix The report's **finding 2** is untouched. There, the newer stamps fall on the surface's *own* pages, and dumping those bytes shows they still equal the fill pattern, so the block is kept even with exact range overlap. I have no measurement for why those stamps exist; the report asks what rule is wanted and offers three variants. This PR is the one that follows from the code's own driver path, so it is the piece that is exact on its own. I have no PPSA12544 dump, so I ran no title — the regression is at the tracker level, and this is offered for the report's own repro (Windows, RX 9070 XT) to confirm the tail-block half and to say whether the boxed letters change. ### 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
Dextroid17 commented 2026-10-08 03:10:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T03:10:41Z.


@oneandonlydean ready for eyes — fixes the CPU keep decision to consider only the pages an edge unit overlaps; the regression test fails on main and passes here. Four checks green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6051381285 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1387#issuecomment-6051381285). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-08T03:10:41Z. --- @oneandonlydean ready for eyes — fixes the CPU keep decision to consider only the pages an edge unit overlaps; the regression test fails on main and passes here. Four checks green.
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!1387
No description provided.