fix(agc): save the bytes a GPU-side store writes outside the write watch #5760

Merged
oneandonlydean merged 1 commit from upstream-pr/5760 into main 2026-10-14 18:58:35 +00:00
oneandonlydean commented 2026-10-14 09:50:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T09:50:12Z.


What

A write-back stored on the GPU over memory outside the write watch left its units without saved guest bytes. Only the CPU path saved them. The next store of results there threw "storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented" (#5711, #5693), and every refresh re-uploaded the image.

  • The stored ranges are copied from the retile scratch into a host-visible buffer behind the store (both the block-unit and the whole-layer path). They become original when the batch completes (OnComplete). A write-back or refresh that needs them first syncs that batch. Anything that replaces or drops a unit's saved bytes in the meantime cancels the save for that unit.
  • A pending unit without a write generation whose range leaves the watch saves its bytes in saveBeforeUnwatch, as the watch would store it whole.
  • StoreOverUntracked: a surface outside the watch from the start is stored twice, with a CPU write to another block in between. On main the first store leaves no saved bytes (the test fails); with this change the CPU block is kept and the second result is stored.

Stacked on #5707 (review only the top commit). Once #5679 is in, its capture at landing has to skip units whose save is still pending (savedTicket[layer] == 0).

Tested

  • Linux (CachyOS, GCC 16.2.1, RTX 4090), Release, BUILD_TESTING=ON: ctest -R "agc_|guest_memory|write_watch" 504 of 504 (one skipped); the new StoreOverUntracked case fails on #5707's head and passes with this, 10 of 10 repeats.
  • On main + #5671 + #5679 + #5707 + this (with the savedTicket skip in #5679's capture): 509 of 509 (one skipped).
  • Not run on Windows or with the titles yet; a combined test build for the reporters is in #5761.

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: #5707
  • Unblocks: #5711, #5693 (PPSA01746, PPSA01530, PPSA03001), likely #361
  • GPUs tested: NVIDIA RTX 4090, Linux
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4856039055 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5760). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T09:50:12Z. --- ### What A write-back stored on the GPU over memory outside the write watch left its units without saved guest bytes. Only the CPU path saved them. The next store of results there threw "storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented" (#5711, #5693), and every refresh re-uploaded the image. - The stored ranges are copied from the retile scratch into a host-visible buffer behind the store (both the block-unit and the whole-layer path). They become `original` when the batch completes (`OnComplete`). A write-back or refresh that needs them first syncs that batch. Anything that replaces or drops a unit's saved bytes in the meantime cancels the save for that unit. - A pending unit without a write generation whose range leaves the watch saves its bytes in `saveBeforeUnwatch`, as the watch would store it whole. - `StoreOverUntracked`: a surface outside the watch from the start is stored twice, with a CPU write to another block in between. On main the first store leaves no saved bytes (the test fails); with this change the CPU block is kept and the second result is stored. Stacked on #5707 (review only the top commit). Once #5679 is in, its capture at landing has to skip units whose save is still pending (`savedTicket[layer] == 0`). ### Tested - Linux (CachyOS, GCC 16.2.1, RTX 4090), Release, `BUILD_TESTING=ON`: `ctest -R "agc_|guest_memory|write_watch"` 504 of 504 (one skipped); the new `StoreOverUntracked` case fails on #5707's head and passes with this, 10 of 10 repeats. - On `main` + #5671 + #5679 + #5707 + this (with the `savedTicket` skip in #5679's capture): 509 of 509 (one skipped). - Not run on Windows or with the titles yet; a combined test build for the reporters is in #5761. ### 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 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: #5707 - [x] Unblocks: #5711, #5693 (PPSA01746, PPSA01530, PPSA03001), likely #361 - [x] GPUs tested: NVIDIA RTX 4090, Linux - [x] AI-assisted: yes
Amoenus commented 2026-10-14 11:04:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-14T11:04:49Z.


@oneandonlydean While refreshing the PPSA99902 validation stack, StoreOverUntracked access-violated on Windows NVIDIA. I reproduced it on unchanged main3e (initial failure, then nine passes followed by another failure); AMD passed20. Run can return while a Store is still queued, then destroy its local surfaces. #5789 records the reproduction.

The separate three-line cleanup wait in #5790 passed100 repetitions on each GPU, both before and after rebase onto main82. It leaves the GPU mutex before waiting and retains the original store assertions. Your new RunSecondStore also has early returns after submission, so it may need the same lifetime ordering. I have not tested #5760 or established that its new case crashes. This report concerns fixture lifetime, not validation/rejection of your production correction. AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6166907111 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5760#issuecomment-6166907111). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-14T11:04:49Z. --- @oneandonlydean While refreshing the PPSA99902 validation stack, StoreOverUntracked access-violated on Windows NVIDIA. I reproduced it on unchanged main3e (initial failure, then nine passes followed by another failure); AMD passed20. Run can return while a Store is still queued, then destroy its local surfaces. [#5789](https://github.com/boykopovar/AnyPS5/issues/5789) records the reproduction. The separate three-line cleanup wait in [#5790](https://github.com/boykopovar/AnyPS5/pull/5790) passed100 repetitions on each GPU, both before and after rebase onto main82. It leaves the GPU mutex before waiting and retains the original store assertions. Your new RunSecondStore also has early returns after submission, so it may need the same lifetime ordering. I have not tested #5760 or established that its new case crashes. This report concerns fixture lifetime, not validation/rejection of your production correction. AI-assisted: Codex.
oneandonlydean commented 2026-10-14 11:40:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T11:40:19Z.


Rebased on main (#5707 is in, so only this commit is left); RunSecondStore now waits for the GPU before freeing its surface, as #5790 does. Thanks @Amoenus for spotting it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167488839 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5760#issuecomment-6167488839). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T11:40:19Z. --- Rebased on main (#5707 is in, so only this commit is left); `RunSecondStore` now waits for the GPU before freeing its surface, as #5790 does. Thanks @Amoenus for spotting it.
github-actions[bot] commented 2026-10-14 18:20:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T18:20:04Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5892 docs/dev/debt/libSceAgcDriver.md L56-57
#5906 docs/dev/debt/libSceAgcDriver.md L56-57
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6175268558 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5760#issuecomment-6175268558). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T18:20:04Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5892 | `docs/dev/debt/libSceAgcDriver.md` [L56-57](https://github.com/boykopovar/AnyPS5/blob/06ae8eebeddefcbd1c188817d87cd1058c3c5c85/docs/dev/debt/libSceAgcDriver.md#L56-L57) | | | | #5906 | `docs/dev/debt/libSceAgcDriver.md` [L56-57](https://github.com/boykopovar/AnyPS5/blob/06ae8eebeddefcbd1c188817d87cd1058c3c5c85/docs/dev/debt/libSceAgcDriver.md#L56-L57) | | |
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!5760
No description provided.