fix(agc): keep CPU writes when a pending storage result is stored over untracked memory #5024

Merged
oneandonlydean merged 1 commit from upstream-pr/5024 into main 2026-10-13 10:33:09 +00:00
oneandonlydean commented 2026-10-13 08:49:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T08:49:02Z.


What

A storage image's results stay on the GPU until something reads their memory. If the CPU writes that memory first, the store has to leave the 64 KiB blocks it wrote alone. On write-watched memory the block stamps decide that. On memory outside the watch (direct host imports on Windows, imports on Linux when the driver resolves write protection, any range the tracker does not cover) the store compares guest memory with the bytes saved at the upload. On main three things leave it with nothing to compare, and the layer is then stored whole over the CPU's bytes:

  • A store of some of the image's units marks the whole saved copy invalid (originalValid), so every later store of the other units is whole.
  • A fill turned into an image clear (StorageTexture::FillClear) never saves the bytes under it.
  • An image copy (StorageTexture::CopyFrom) never saves them either.

GTA V (PPSA04264) showed it on Windows, reported on #4410: an image over memory the title reuses as its JobManager pool stays pending, the pool is written, and after

[flush] image 0x2a63e0000+0x870000 for memory access 0x2a63ee000+0x1000

the kernels read ffffffff buffer descriptors. #4410 did not introduce this. Results stay pending longer since it went in, so the store now lands after the CPU write more often. The new test fails on main with or without it.

The change:

  • The saved copy is valid per tracked unit (layerOriginal). A store, a drop or a stale eviction invalidates only the units it touched. A CPU-path store makes the units it stored valid again and reads guest memory only for the units without saved bytes.
  • writeBackLayers compares each run of selected units that has saved bytes, instead of the whole stored span or nothing.
  • FillClear and CopyFrom save the bytes of the units they fill when the surface is not watched, as an upload already does.
  • One case is left: results over a range that leaves the watch while they are pending (a host import that does not keep the range watched). Nothing was saved for them, so there is nothing to compare. Storing them now throws instead of overwriting the CPU's writes. This throw is new behaviour; it is listed in docs/dev/debt/libSceAgcDriver.md.

On watched memory nothing is saved or compared, as before; the only additions there are one GuestMemory::Watched call per fill and per copy, and per-unit flags where there was one.

Tested

Linux, RTX 4090 (NVIDIA 610.57.04), Release, at cac4e9688f. main is the same tree with Texture.cpp and Texture.hpp from main and the new test kept.

New test agc_driver_store_over_untracked (0.3 s): a surface outside the watch, a CPU write while its result is pending, then a read through the flush hook and a store of everything. Five cases: another block read after the CPU write, another block read before it, a fill of the surface, an image copy into it, and a surface that leaves the watch while its result is pending (that one expects the throw and the CPU's bytes intact). 10 runs each:

default import watching APS5_WRITE_WATCH_IMPORTS=unwatch
main fails 10/10 fails 10/10
this PR passes 10/10 passes 10/10

On main the read/fill/copy cases lose bytes (32 or all 4096 of the 4096 written in the first, all 4096 in the others), and the surface that left the watch is stored whole. With APS5_WRITE_WATCH_IMPORTS=unwatch the import already unwatches the surface at the upload, before anything is pending, so the last case does not apply there (the test prints that) and the bytes are saved as for any unwatched upload.

ctest -R '^agc_' -E 'agc_driver_flat_|agc_driver_scalar_wide_loads|agc_driver_bda_span_reads|agc_driver_pixel_interlock', 441 tests, with this PR: all pass in both modes (agc_driver_stencil_ref_export skips on this device). No existing test reaches the new throw. The excluded tests hang on this driver on main too.

Not tested: Windows (not built here), so the new throw has not been seen there and whether a Windows run reaches it is unknown. No lavapipe, no title. GTA V was not run, so whether its failure is one of these cases is not confirmed. No speed measurement; none is claimed.

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: none
  • Unblocks: none confirmed (PPSA04264 #1203 reported it; not run with this change)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4840737014 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5024). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T08:49:02Z. --- ### What A storage image's results stay on the GPU until something reads their memory. If the CPU writes that memory first, the store has to leave the 64 KiB blocks it wrote alone. On write-watched memory the block stamps decide that. On memory outside the watch (direct host imports on Windows, imports on Linux when the driver resolves write protection, any range the tracker does not cover) the store compares guest memory with the bytes saved at the upload. On `main` three things leave it with nothing to compare, and the layer is then stored whole over the CPU's bytes: - A store of some of the image's units marks the whole saved copy invalid (`originalValid`), so every later store of the other units is whole. - A fill turned into an image clear (`StorageTexture::FillClear`) never saves the bytes under it. - An image copy (`StorageTexture::CopyFrom`) never saves them either. GTA V (PPSA04264) showed it on Windows, reported on #4410: an image over memory the title reuses as its JobManager pool stays pending, the pool is written, and after ``` [flush] image 0x2a63e0000+0x870000 for memory access 0x2a63ee000+0x1000 ``` the kernels read `ffffffff` buffer descriptors. #4410 did not introduce this. Results stay pending longer since it went in, so the store now lands after the CPU write more often. The new test fails on `main` with or without it. The change: - The saved copy is valid per tracked unit (`layerOriginal`). A store, a drop or a stale eviction invalidates only the units it touched. A CPU-path store makes the units it stored valid again and reads guest memory only for the units without saved bytes. - `writeBackLayers` compares each run of selected units that has saved bytes, instead of the whole stored span or nothing. - `FillClear` and `CopyFrom` save the bytes of the units they fill when the surface is not watched, as an upload already does. - One case is left: results over a range that leaves the watch while they are pending (a host import that does not keep the range watched). Nothing was saved for them, so there is nothing to compare. Storing them now throws instead of overwriting the CPU's writes. This throw is new behaviour; it is listed in `docs/dev/debt/libSceAgcDriver.md`. On watched memory nothing is saved or compared, as before; the only additions there are one `GuestMemory::Watched` call per fill and per copy, and per-unit flags where there was one. ### Tested Linux, RTX 4090 (NVIDIA 610.57.04), Release, at cac4e9688f9. `main` is the same tree with `Texture.cpp` and `Texture.hpp` from `main` and the new test kept. New test `agc_driver_store_over_untracked` (0.3 s): a surface outside the watch, a CPU write while its result is pending, then a read through the flush hook and a store of everything. Five cases: another block read after the CPU write, another block read before it, a fill of the surface, an image copy into it, and a surface that leaves the watch while its result is pending (that one expects the throw and the CPU's bytes intact). 10 runs each: | | default import watching | `APS5_WRITE_WATCH_IMPORTS=unwatch` | |---|---|---| | `main` | fails 10/10 | fails 10/10 | | this PR | passes 10/10 | passes 10/10 | On `main` the read/fill/copy cases lose bytes (32 or all 4096 of the 4096 written in the first, all 4096 in the others), and the surface that left the watch is stored whole. With `APS5_WRITE_WATCH_IMPORTS=unwatch` the import already unwatches the surface at the upload, before anything is pending, so the last case does not apply there (the test prints that) and the bytes are saved as for any unwatched upload. `ctest -R '^agc_' -E 'agc_driver_flat_|agc_driver_scalar_wide_loads|agc_driver_bda_span_reads|agc_driver_pixel_interlock'`, 441 tests, with this PR: all pass in both modes (`agc_driver_stencil_ref_export` skips on this device). No existing test reaches the new throw. The excluded tests hang on this driver on `main` too. Not tested: Windows (not built here), so the new throw has not been seen there and whether a Windows run reaches it is unknown. No lavapipe, no title. GTA V was not run, so whether its failure is one of these cases is not confirmed. No speed measurement; none is claimed. ### 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: none - [x] Unblocks: none confirmed (PPSA04264 #1203 reported it; not run with this change) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 08:53:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T08:53:26Z.


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
#4878 docs/dev/debt/libSceAgcDriver.md L43-44
#5030 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L4356
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141934530 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5024#issuecomment-6141934530). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T08:53:26Z. --- <!-- 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 | |---|---|---|---| | #4878 | `docs/dev/debt/libSceAgcDriver.md` [L43-44](https://github.com/boykopovar/AnyPS5/blob/c7632f036f68f71a5e514f5b20f6df68a9062ada/docs/dev/debt/libSceAgcDriver.md#L43-L44) | | | | #5030 | `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` [L4356](https://github.com/boykopovar/AnyPS5/blob/c7632f036f68f71a5e514f5b20f6df68a9062ada/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L4356) | | |
tibzejoker commented 2026-10-14 00:00:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-14T00:00:19Z.


@oneandonlydean confirmation from GTA V (PPSA04264), the title from #4410's regression report. Windows 11, RTX 4090.

On main 8d98e8851, with #4410 in and no local revert, plus the open PRs GTA needs to reach Story, the Story prologue ran for 150 s with none of the earlier failures. Before #5024 it died about 30 s in, after JobManager kernels 0x...1200 read all-0xFF V#s and 0x...7400 threw buffer descriptor has reserved bits set. This run had neither. Thanks for tracking it down.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157765266 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5024#issuecomment-6157765266). Originally posted by [tibzejoker](https://github.com/tibzejoker) on 2026-10-14T00:00:19Z. --- @oneandonlydean confirmation from GTA V (PPSA04264), the title from #4410's regression report. Windows 11, RTX 4090. On `main` 8d98e8851, with #4410 in and no local revert, plus the open PRs GTA needs to reach Story, the Story prologue ran for 150 s with none of the earlier failures. Before #5024 it died about 30 s in, after JobManager kernels 0x...1200 read all-0xFF V#s and 0x...7400 threw `buffer descriptor has reserved bits set`. This run had neither. Thanks for tracking it down. AI-assisted (Claude Code).
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!5024
No description provided.