fix(agc): store pending storage results before a use writes the same memory as a buffer #4654

Merged
GustavoGamarra95 merged 2 commits from upstream-pr/4654 into main 2026-10-13 04:53:26 +00:00
GustavoGamarra95 commented 2026-10-12 17:56:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-12T17:56:46Z.


What

Before a dispatch or draw that writes buffer ranges is recorded, the results of storage images still pending in those ranges are now stored (GuestBufferMemory::UploadFinish), whatever path serves the range: in place, copied, or a leased address-based heap, which the per-region flush exempts. A revalidated resource set also includes its written ranges in the pending scan.

Without it, the image's write-back could follow the buffer write in two ways:

  • a buffer write that covers part of a 64 KiB block made the image's later write-back keep the whole block as written, so the image's results in the rest of the block never reached guest memory;
  • a write-back recorded after the buffer write stored the image's older texels over the buffer.

Unreal Engine's render graph transient allocator reuses the same memory for textures and buffers within a frame. In Beast of Reincarnation (PPSA29343) at 1080p output, APS5_CAPTURE_TRACE showed a 60x34 R16G16 float tile image written by a compute pass and left pending, then a 40800-byte buffer written at the same address by another dispatch, then the image written back when a later pass read the buffer. The title screen showed 64x64-pixel blocks of stale content, a stepped dark area and stray fragments. r.RDG.TransientAllocator=0 in the title's saved/ps5/engine.ini removes them, which is how the aliasing was first confirmed.

Tested

Linux (CachyOS, kernel 7.2), Ryzen 5 7535HS, GCC, Release. RTX 3050 Laptop 4 GB (NVIDIA 615.78.08) and Radeon 660M (RADV, Mesa).

  • Built on current main; tools/check_conventions.py passes.
  • Full ctest on the RTX 3050: 964 of 964 pass (7 of them skipped: the video_out_flip/frame_dump tests and agc_driver_stencil_ref_export).
  • New agc_storage_written_buffer_order: a storage image is written on the GPU and left pending, then a leased address-based use writes the first 40800 bytes of the same memory as a buffer and every pending image is flushed; guest memory must hold the buffer's bytes where it wrote and the image's texels everywhere else. It runs with watched and compared imports and returns 77 when host imports or write watching are unavailable. Drivers selected with VK_DRIVER_FILES:
Driver Host imports Without this change With it
NVIDIA 615.78.08 watched fails: the image's texels outside the buffer are lost passes
RADV, Radeon 660M compared fails the same way passes
lavapipe compared fails the same way passes
  • PPSA29343, title screen at 1080p output with the transient allocator on, on a local branch that also carries the title's rendering fixes: the blocks, the stepped area and the fragments are gone and the title ran at 33-35 presents per 10 s (32 before). In one of three runs the rate fell to 10 per 10 s after two minutes; that did not repeat. With r.RDG.TransientAllocator=0 the title is unchanged.
Before With this change Transient allocator off (reference)
before after reference

The title was not run on the Radeon 660M (too slow there to reach it); the RADV coverage is the test above.

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:4833127198 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4654). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-12T17:56:46Z. --- ### What Before a dispatch or draw that writes buffer ranges is recorded, the results of storage images still pending in those ranges are now stored (`GuestBufferMemory::UploadFinish`), whatever path serves the range: in place, copied, or a leased address-based heap, which the per-region flush exempts. A revalidated resource set also includes its written ranges in the pending scan. Without it, the image's write-back could follow the buffer write in two ways: - a buffer write that covers part of a 64 KiB block made the image's later write-back keep the whole block as written, so the image's results in the rest of the block never reached guest memory; - a write-back recorded after the buffer write stored the image's older texels over the buffer. Unreal Engine's render graph transient allocator reuses the same memory for textures and buffers within a frame. In Beast of Reincarnation (PPSA29343) at 1080p output, `APS5_CAPTURE_TRACE` showed a 60x34 R16G16 float tile image written by a compute pass and left pending, then a 40800-byte buffer written at the same address by another dispatch, then the image written back when a later pass read the buffer. The title screen showed 64x64-pixel blocks of stale content, a stepped dark area and stray fragments. `r.RDG.TransientAllocator=0` in the title's `saved/ps5/engine.ini` removes them, which is how the aliasing was first confirmed. ### Tested Linux (CachyOS, kernel 7.2), Ryzen 5 7535HS, GCC, Release. RTX 3050 Laptop 4 GB (NVIDIA 615.78.08) and Radeon 660M (RADV, Mesa). - Built on current `main`; `tools/check_conventions.py` passes. - Full `ctest` on the RTX 3050: 964 of 964 pass (7 of them skipped: the `video_out_flip`/`frame_dump` tests and `agc_driver_stencil_ref_export`). - New `agc_storage_written_buffer_order`: a storage image is written on the GPU and left pending, then a leased address-based use writes the first 40800 bytes of the same memory as a buffer and every pending image is flushed; guest memory must hold the buffer's bytes where it wrote and the image's texels everywhere else. It runs with watched and compared imports and returns 77 when host imports or write watching are unavailable. Drivers selected with `VK_DRIVER_FILES`: | Driver | Host imports | Without this change | With it | |---|---|---|---| | NVIDIA 615.78.08 | watched | fails: the image's texels outside the buffer are lost | passes | | RADV, Radeon 660M | compared | fails the same way | passes | | lavapipe | compared | fails the same way | passes | - PPSA29343, title screen at 1080p output with the transient allocator on, on a local branch that also carries the title's rendering fixes: the blocks, the stepped area and the fragments are gone and the title ran at 33-35 presents per 10 s (32 before). In one of three runs the rate fell to 10 per 10 s after two minutes; that did not repeat. With `r.RDG.TransientAllocator=0` the title is unchanged. | Before | With this change | Transient allocator off (reference) | |---|---|---| | ![before](https://github.com/GustavoGamarra95/AnyPS5/releases/download/evidence-written-buffer-order-20261012/ppsa29343-title-1080p-before.png) | ![after](https://github.com/GustavoGamarra95/AnyPS5/releases/download/evidence-written-buffer-order-20261012/ppsa29343-title-1080p-after.png) | ![reference](https://github.com/GustavoGamarra95/AnyPS5/releases/download/evidence-written-buffer-order-20261012/ppsa29343-title-1080p-no-transient-allocator.png) | The title was not run on the Radeon 660M (too slow there to reach it); the RADV coverage is the test above. ### 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
Scramblrrrr commented 2026-10-12 18:03:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T18:03:55Z.


Preparing a Windows/RTX5070Ti cross-test in the older 007 integration, preserving your authorship: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-written-buffer-order head24d8fe68efaffac18dadaf898228c6f547138f66. Your production/test commits ported as91ca6f84f and24d8fe68e. UploadFinish conflict resolved by retaining the existing CompletePendingCpuWrites pass before uploaded=true, then your written-range flush before import lookup; both CTest registrations retained. Conventions pass. Source-only, not built/staged or a claimed fix yet; current game still runs preceding5b8661ad2. Will run your native regression and an isolated production negative control before the next game comparison. AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6129810641 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4654#issuecomment-6129810641). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T18:03:55Z. --- Preparing a Windows/RTX5070Ti cross-test in the older 007 integration, preserving your authorship: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-written-buffer-order head24d8fe68efaffac18dadaf898228c6f547138f66. Your production/test commits ported as91ca6f84f and24d8fe68e. UploadFinish conflict resolved by retaining the existing CompletePendingCpuWrites pass before uploaded=true, then your written-range flush before import lookup; both CTest registrations retained. Conventions pass. Source-only, not built/staged or a claimed fix yet; current game still runs preceding5b8661ad2. Will run your native regression and an isolated production negative control before the next game comparison. AI-assisted: Codex.
Scramblrrrr commented 2026-10-12 18:13:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T18:13:10Z.


Windows native validation complete on the credited port24d8fe68e, RTX5070Ti/compared host imports: agc_storage_written_buffer_order PASS0.51s, no skip. Isolated negative: restoring only your two production files to preceding5b8661ad2, leaving the fixture unchanged, FAIL0.42s with storage results outside the written buffer did not reach guest memory. Restoring the fix:6/6 focused ordering tests PASS2.24s (your regression, copied_direct_ordering, depth_surface_last_writer, image_indirect_arguments_written_ahead, original indirect_arguments_written_ahead, write_data_written_ahead), no skips. Added a separate public synthetic image-to-indirect fixture in c9774f7265c08cf835864e12b92ed879834fa575; default GPU-capable path passes and logs the expected argument flush. Its optional thread-dimension mode reproduces a different stale-read case on this integration, not a claimed current-main defect or #4654 regression. Conventions pass. Starting the007 comparison with graphics SHA2569C990502..., same libc7540B4D8... and12GiB config. No title/FPS effect claimed yet. AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6129955212 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4654#issuecomment-6129955212). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T18:13:10Z. --- Windows native validation complete on the credited port24d8fe68e, RTX5070Ti/compared host imports: agc_storage_written_buffer_order PASS0.51s, no skip. Isolated negative: restoring only your two production files to preceding5b8661ad2, leaving the fixture unchanged, FAIL0.42s with storage results outside the written buffer did not reach guest memory. Restoring the fix:6/6 focused ordering tests PASS2.24s (your regression, copied_direct_ordering, depth_surface_last_writer, image_indirect_arguments_written_ahead, original indirect_arguments_written_ahead, write_data_written_ahead), no skips. Added a separate public synthetic image-to-indirect fixture in c9774f7265c08cf835864e12b92ed879834fa575; default GPU-capable path passes and logs the expected argument flush. Its optional thread-dimension mode reproduces a different stale-read case on this integration, not a claimed current-main defect or #4654 regression. Conventions pass. Starting the007 comparison with graphics SHA2569C990502..., same libc7540B4D8... and12GiB config. No title/FPS effect claimed yet. AI-assisted: Codex.
GustavoGamarra95 commented 2026-10-12 18:18:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-12T18:18:35Z.


@Scramblrrrr thanks for validating it on Windows with the RTX 5070 Ti and compared imports, and for the isolated negative control: that is the platform and import mode I could only cover with RADV and lavapipe here. Looking forward to the 007 comparison.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6130039766 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4654#issuecomment-6130039766). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-12T18:18:35Z. --- @Scramblrrrr thanks for validating it on Windows with the RTX 5070 Ti and compared imports, and for the isolated negative control: that is the platform and import mode I could only cover with RADV and lavapipe here. Looking forward to the 007 comparison.
github-actions[bot] commented 2026-10-12 18:29:10 +00:00 (Migrated from github.com)

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


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
#1359 core/libs/prx/libSceAgcDriver/CMakeLists.txt L904
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L2911
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6130204940 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4654#issuecomment-6130204940). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T18:29:10Z. --- <!-- 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 | |---|---|---|---| | #1359 | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` [L904](https://github.com/boykopovar/AnyPS5/blob/e15c316ead335690a6693b711a5c5e33cfda7652/core/libs/prx/libSceAgcDriver/CMakeLists.txt#L904)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L2911](https://github.com/boykopovar/AnyPS5/blob/e15c316ead335690a6693b711a5c5e33cfda7652/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L2911) | | |
GustavoGamarra95 commented 2026-10-12 18:41:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-12T18:41:16Z.


@TibixDev #1359 and this PR overlap in the first lines of GuestBufferMemory::UploadFinish and in neighbouring test registrations in CMakeLists.txt. The changes are independent: the resolution keeps your CompletePendingCpuWrites pass before uploaded = true, then this PR's written-range flush, with both ctest entries (Scramblrrrr merged them that way in their 007 integration and the tests pass). Either order works for me; if #1359 lands first I'll rebase this one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6130404240 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4654#issuecomment-6130404240). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-12T18:41:16Z. --- @TibixDev #1359 and this PR overlap in the first lines of `GuestBufferMemory::UploadFinish` and in neighbouring test registrations in `CMakeLists.txt`. The changes are independent: the resolution keeps your `CompletePendingCpuWrites` pass before `uploaded = true`, then this PR's written-range flush, with both ctest entries (Scramblrrrr merged them that way in their 007 integration and the tests pass). Either order works for me; if #1359 lands first I'll rebase this one.
GustavoGamarra95 commented 2026-10-13 00:54:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-13T00:54:32Z.


@oneandonlydean when you have time, could you also take a look at this one? It touches the same storage write-back paths as #4468: it stores an image's pending results before a use writes the same memory as a buffer. Scramblrrrr validated it on Windows with compared imports, including a negative control. It overlaps #1359 in the first lines of UploadFinish; the resolution is described above.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135665269 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4654#issuecomment-6135665269). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-13T00:54:32Z. --- @oneandonlydean when you have time, could you also take a look at this one? It touches the same storage write-back paths as #4468: it stores an image's pending results before a use writes the same memory as a buffer. Scramblrrrr validated it on Windows with compared imports, including a negative control. It overlaps #1359 in the first lines of `UploadFinish`; the resolution is described above.
kr4y4 commented 2026-10-13 03:46:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-13T03:46:41Z.


A Windows run on NVIDIA and Intel, to add to the Linux drivers in the table.

Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head 554e61552 merged into main 495bf91a0, which passes 1023 of 1023 on both GPUs.

  • agc_storage_written_buffer_order and the other 16 recorder and graphics entries the changed test file feeds pass on both GPUs with --repeat until-fail:3. The new test ran on both, without returning 77. The full suite (ctest --timeout 120 --parallel 4) passes 1024 of 1024 on both.
  • With GuestBufferMemory.cpp and ShaderResources.cpp as on main, agc_storage_written_buffer_order fails on both GPUs with the storage results outside the written buffer did not reach guest memory, and the other 16 pass.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137769422 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4654#issuecomment-6137769422). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-13T03:46:41Z. --- A Windows run on NVIDIA and Intel, to add to the Linux drivers in the table. Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head 554e61552 merged into `main` 495bf91a0, which passes 1023 of 1023 on both GPUs. - `agc_storage_written_buffer_order` and the other 16 recorder and graphics entries the changed test file feeds pass on both GPUs with `--repeat until-fail:3`. The new test ran on both, without returning 77. The full suite (`ctest --timeout 120 --parallel 4`) passes 1024 of 1024 on both. - With `GuestBufferMemory.cpp` and `ShaderResources.cpp` as on `main`, `agc_storage_written_buffer_order` fails on both GPUs with `the storage results outside the written buffer did not reach guest memory`, and the other 16 pass. Written with AI assistance.
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!4654
No description provided.