fix(agc): reuse one tiled and one linear texture upload scratch per recorded batch #10773

Merged
fma-rc merged 6 commits from upstream-pr/10773 into main 2026-11-02 07:54:49 +00:00
fma-rc commented 2026-10-24 23:54:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-24T23:54:41Z.


What

Every texture upload recorded into the open batch allocated two device buffers of its own, the tiled copy of the guest bytes and the linear output of the detiler, and kept both until the batch completed. A batch that uploads many textures held all of them at once. In Death Stranding 2 (PPSA02015) while it loads, these two buffers were the largest device allocations after the textures, storage images and shadow copies: 1301 MiB live at 900 s.

The open batch now keeps one tiled and one linear scratch buffer, and every upload recorded into it reuses them. A scratch smaller than the upload is replaced by one of exactly the upload's size; the old one stays with the batch, which already records its use. An upload without a recorder (the dump aid, APS5_SYNC_TEXTURE_UPLOAD, tests) still allocates its own buffers and waits for them.

Reusing the scratch puts a write after the previous upload's reads and writes of the same buffer, so the barrier before the staging copy now also waits on the transfer and compute stages and covers the transfer write.

Tested

New test agc_recorder_upload_scratch: five linear uploads of 64, 32, 64, 128 and 128 pixels into one open batch. Each upload no larger than an earlier one adds only its staging bytes to the batch's kept bytes, the larger one keeps a grown scratch, and each texture samples back its own value.

main this PR
NVIDIA RTX 5080, 615.78.08 fails: a texture upload no larger than an earlier one of its batch allocated scratch of its own pass
RADV, Radeon 680M, Mesa 26.2.4 fails (the check's message is lost to the teardown crash #10684 fixes) pass
lavapipe segfault in the same teardown pass

With the Khronos validation layer's synchronization checks on lavapipe and RADV, the test reports no hazard.

Rebased onto main abed035468 (2026-10-27), keeping main's new agc_recorder_failed_check next to this test: all nine agc_recorder_* tests pass on the RTX 5080, RADV (Radeon 610M) and lavapipe, and the Windows build and ctest show no failure the merge base lacks.

Death Stranding 2, 900 s of loading on the RTX 5080, with the local fixes it needs to get that far, main's upload path against this PR's:

upload scratch live at 900 s device-local peak last frame
without 1301 MiB 7749 MiB 83
with 283 MiB 6955 MiB 133

Astro's Playroom (PPSA01325) into its first level and Animal Well (PPSA22520) in its first room: the same picture as main, and the same speed (Playroom 3684 frames against 3685 over a 170 s run, Animal Well 14311 against 14305 over 240 s).

Full ctest on RADV and on Windows (MinGW GCC) shows no failure that main lacks. Arch Linux.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA RTX 5080 (driver 615.78.08), AMD Radeon 680M (RADV, Mesa 26.2.4), lavapipe, all Arch Linux
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5000260242 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10773). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-24T23:54:41Z. --- ### What Every texture upload recorded into the open batch allocated two device buffers of its own, the tiled copy of the guest bytes and the linear output of the detiler, and kept both until the batch completed. A batch that uploads many textures held all of them at once. In Death Stranding 2 (PPSA02015) while it loads, these two buffers were the largest device allocations after the textures, storage images and shadow copies: 1301 MiB live at 900 s. The open batch now keeps one tiled and one linear scratch buffer, and every upload recorded into it reuses them. A scratch smaller than the upload is replaced by one of exactly the upload's size; the old one stays with the batch, which already records its use. An upload without a recorder (the dump aid, `APS5_SYNC_TEXTURE_UPLOAD`, tests) still allocates its own buffers and waits for them. Reusing the scratch puts a write after the previous upload's reads and writes of the same buffer, so the barrier before the staging copy now also waits on the transfer and compute stages and covers the transfer write. ### Tested New test `agc_recorder_upload_scratch`: five linear uploads of 64, 32, 64, 128 and 128 pixels into one open batch. Each upload no larger than an earlier one adds only its staging bytes to the batch's kept bytes, the larger one keeps a grown scratch, and each texture samples back its own value. | | `main` | this PR | |---|---|---| | NVIDIA RTX 5080, 615.78.08 | fails: `a texture upload no larger than an earlier one of its batch allocated scratch of its own` | pass | | RADV, Radeon 680M, Mesa 26.2.4 | fails (the check's message is lost to the teardown crash #10684 fixes) | pass | | lavapipe | segfault in the same teardown | pass | With the Khronos validation layer's synchronization checks on lavapipe and RADV, the test reports no hazard. Rebased onto `main` abed035468 (2026-10-27), keeping `main`'s new `agc_recorder_failed_check` next to this test: all nine `agc_recorder_*` tests pass on the RTX 5080, RADV (Radeon 610M) and lavapipe, and the Windows build and ctest show no failure the merge base lacks. Death Stranding 2, 900 s of loading on the RTX 5080, with the local fixes it needs to get that far, `main`'s upload path against this PR's: | | upload scratch live at 900 s | device-local peak | last frame | |---|---|---|---| | without | 1301 MiB | 7749 MiB | 83 | | with | 283 MiB | 6955 MiB | 133 | Astro's Playroom (PPSA01325) into its first level and Animal Well (PPSA22520) in its first room: the same picture as `main`, and the same speed (Playroom 3684 frames against 3685 over a 170 s run, Animal Well 14311 against 14305 over 240 s). Full ctest on RADV and on Windows (MinGW GCC) shows no failure that `main` lacks. Arch Linux. ### 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 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA RTX 5080 (driver 615.78.08), AMD Radeon 680M (RADV, Mesa 26.2.4), lavapipe, all Arch Linux - [x] AI-assisted: yes
MarcZX10 commented 2026-10-24 23:59:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T23:59:22Z.

Review: APPROVED


Reviewed exact head 1b752939dc84b69a65e195c5a9b569c847b6aecc. The scratch lifetime stays with the recording batch: each buffer is retained when first allocated, and a grown buffer replaces the active slot without releasing the older buffer before earlier commands complete. The unrecorded, dump, and synchronous-upload paths still allocate private buffers. The barriers provide the needed ordering between prior transfer/compute uses and the next reuse. The regression covers reuse at equal/smaller sizes, growth, and sampling each upload afterward.

git diff --check upstream/main...HEAD and tools/check_conventions.py --base upstream/main --head HEAD pass. I could not run the full CMake/AGC test target locally: this worktree has uninitialized third-party submodules, and compiling the recorder source directly stops at the generated MeshArguments_spv.h. Hosted product-test jobs are path-skipped. The PR records the focused GPU test and synchronization-validation results on NVIDIA, RADV, and lavapipe, plus the game capture comparison. I found no blocking issue in the source review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5640672811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10773#pullrequestreview-5640672811). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T23:59:22Z. **Review:** APPROVED --- Reviewed exact head `1b752939dc84b69a65e195c5a9b569c847b6aecc`. The scratch lifetime stays with the recording batch: each buffer is retained when first allocated, and a grown buffer replaces the active slot without releasing the older buffer before earlier commands complete. The unrecorded, dump, and synchronous-upload paths still allocate private buffers. The barriers provide the needed ordering between prior transfer/compute uses and the next reuse. The regression covers reuse at equal/smaller sizes, growth, and sampling each upload afterward. `git diff --check upstream/main...HEAD` and `tools/check_conventions.py --base upstream/main --head HEAD` pass. I could not run the full CMake/AGC test target locally: this worktree has uninitialized third-party submodules, and compiling the recorder source directly stops at the generated `MeshArguments_spv.h`. Hosted product-test jobs are path-skipped. The PR records the focused GPU test and synchronization-validation results on NVIDIA, RADV, and lavapipe, plus the game capture comparison. I found no blocking issue in the source review.
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!10773
No description provided.