fix(agc): retain GPU copy buffers before fallible diagnostics #8667

Closed
VicRaster wants to merge 1 commit from upstream-pr/8667 into main
VicRaster commented 2026-10-20 20:31:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by VicRaster on 2026-10-20T20:31:54Z.


What

With APS5_CAPTURE_GPU_COPIES=1, diagnostic readback allocation can fail after the input copy has been recorded. The destination is kept by the batch later, so unwinding can return it to the buffer pool while the recorded command still refers to it.

Keep the destination before recording the copy, and retain the diagnostic readback before recording commands that use it. Add deferred-fence mock and real Vulkan regressions, including a successful-readback control. No experimental memory policy is included.

Fixes #8659. This PR replaces the standalone patch-review issue.

Tested

Windows 11 Pro build 26300, WinLibs MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 3080 Ti, driver 610.88.

  • Upstream base: a6a4101e190ec408c3ed471d20f06872cae1b4a3. Before tests used this production code with the final regression fixtures added; after tests used the corrected source tree. The regression and CMake sources are identical on both sides.
  • agc_copy_input_failure_lifetime and agc_driver_copy_input_lifetime: both fail before the fix because the destination is reusable before its fence; both pass afterward. The successful-readback control passes on both sides.
  • The GPU regression injects allocation failure after the real first copy command, checks exact first-copy offsets, completed GPU data, surrounding guest guards and Vulkan allocation cleanup. It observes pool reuse without overwriting pending buffers.
  • Same focused controls before and after: agc_buffer_pool, agc_driver_graphics, agc_driver_bda_device, agc_driver_bda_span_reads, agc_driver_guest_memory_lifetime, agc_driver_host_import_windows and agc_copy_input_kept_bytes; 7/7 pass on each side.
  • Runs require ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. Full logs positively show the RTX 3080 Ti and validation instance/device insertion, zero VUID- messages, no missing-layer warnings and no GPU skips.
  • Convention checks and the upstream PR-overlap checker were run before submission. Stale PRs sharing files were reviewed separately; no duplicate diagnostic ownership fix or dependency was identified.

The separate native allocation failure during completion-callback registration was not fault-injected. Linux and other GPUs were not tested. These are synthetic correctness tests; no game compatibility or performance improvement 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
  • Fixes: Fixes #8659
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3080 Ti, driver 610.88, Windows 11 Pro build 26300
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4942091894 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8667). Originally posted by [VicRaster](https://github.com/VicRaster) on 2026-10-20T20:31:54Z. --- ### What With `APS5_CAPTURE_GPU_COPIES=1`, diagnostic readback allocation can fail after the input copy has been recorded. The destination is kept by the batch later, so unwinding can return it to the buffer pool while the recorded command still refers to it. Keep the destination before recording the copy, and retain the diagnostic readback before recording commands that use it. Add deferred-fence mock and real Vulkan regressions, including a successful-readback control. No experimental memory policy is included. Fixes #8659. This PR replaces the standalone patch-review issue. ### Tested Windows 11 Pro build 26300, WinLibs MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 3080 Ti, driver 610.88. - Upstream base: `a6a4101e190ec408c3ed471d20f06872cae1b4a3`. Before tests used this production code with the final regression fixtures added; after tests used the corrected source tree. The regression and CMake sources are identical on both sides. - `agc_copy_input_failure_lifetime` and `agc_driver_copy_input_lifetime`: both fail before the fix because the destination is reusable before its fence; both pass afterward. The successful-readback control passes on both sides. - The GPU regression injects allocation failure after the real first copy command, checks exact first-copy offsets, completed GPU data, surrounding guest guards and Vulkan allocation cleanup. It observes pool reuse without overwriting pending buffers. - Same focused controls before and after: `agc_buffer_pool`, `agc_driver_graphics`, `agc_driver_bda_device`, `agc_driver_bda_span_reads`, `agc_driver_guest_memory_lifetime`, `agc_driver_host_import_windows` and `agc_copy_input_kept_bytes`; 7/7 pass on each side. - Runs require `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`. Full logs positively show the RTX 3080 Ti and validation instance/device insertion, zero `VUID-` messages, no missing-layer warnings and no GPU skips. - Convention checks and the upstream PR-overlap checker were run before submission. Stale PRs sharing files were reviewed separately; no duplicate diagnostic ownership fix or dependency was identified. The separate native allocation failure during completion-callback registration was not fault-injected. Linux and other GPUs were not tested. These are synthetic correctness tests; no game compatibility or performance improvement is claimed. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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 <!-- #PR, or none --> - [x] Fixes: Fixes #8659 <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: NVIDIA GeForce RTX 3080 Ti, driver 610.88, Windows 11 Pro build 26300 <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
MarcZX10 commented 2026-10-20 20:34:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T20:34:44Z.

Review: APPROVED


Reviewed the ownership sequence and both regression paths. region->buffer is retained before the first recorded copy, and the diagnostic readback is retained before the later copy uses it; this covers the allocation-failure unwind in the issue without changing normal copy semantics. The deferred-fence mock directly checks pool reuse before completion, and the reported RTX 3080 Ti run exercises the successful and injected-failure Vulkan paths. I did not independently run the GPU tests; the hosted platform build jobs are not included in the current check results.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5591371526 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8667#pullrequestreview-5591371526). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T20:34:44Z. **Review:** APPROVED --- Reviewed the ownership sequence and both regression paths. `region->buffer` is retained before the first recorded copy, and the diagnostic readback is retained before the later copy uses it; this covers the allocation-failure unwind in the issue without changing normal copy semantics. The deferred-fence mock directly checks pool reuse before completion, and the reported RTX 3080 Ti run exercises the successful and injected-failure Vulkan paths. I did not independently run the GPU tests; the hosted platform build jobs are not included in the current check results.
xXPBSXx commented 2026-10-21 06:48:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T06:48:29Z.


Independent Windows run of this PR with a baseline (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, NVIDIA GeForce RTX 4080 SUPER (the log shows Selected GPU name=NVIDIA GeForce RTX 4080 SUPER vendor=0x10de device=0x2702 subgroup=32, picked with ANYPS5_GPU=4080), WinLibs GCC 15.2.0 (MinGW-w64 UCRT), Release. PR head 47e1539ac5; merge-tree against main is clean. I built agc_driver_copy_input_lifetime_tests and agc_driver_graphics_tests. The tests are agc_driver_copy_input_lifetime (execution), agc_copy_input_failure_lifetime, agc_copy_input_kept_bytes and agc_driver_graphics.

Results (3 runs each):

  • PR head: all four tests pass 3/3.
  • Baseline: I kept the PR's tests and CMakeLists.txt and replaced only Graphics/src/GuestBufferMemory.cpp with its version from the merge base a6a4101e19, then rebuilt. agc_driver_copy_input_lifetime fails 3/3 (AGC graphics: a recorded copy destination became reusable before its fence; its counters read fail=1 refusals=1 early_reuse=1), and agc_copy_input_failure_lifetime fails 3/3 (destination_reusable_before_fence=1). agc_driver_graphics and agc_copy_input_kept_bytes pass in the baseline. I restored the PR's GuestBufferMemory.cpp afterwards.

Not run: other GPUs (no AMD card for this PR), other platforms, the other tests, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6309907553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8667#issuecomment-6309907553). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T06:48:29Z. --- Independent Windows run of this PR with a baseline (data only). **Environment:** Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, NVIDIA GeForce RTX 4080 SUPER (the log shows `Selected GPU name=NVIDIA GeForce RTX 4080 SUPER vendor=0x10de device=0x2702 subgroup=32`, picked with `ANYPS5_GPU=4080`), WinLibs GCC 15.2.0 (MinGW-w64 UCRT), Release. PR head `47e1539ac5`; merge-tree against `main` is clean. I built `agc_driver_copy_input_lifetime_tests` and `agc_driver_graphics_tests`. The tests are `agc_driver_copy_input_lifetime` (execution), `agc_copy_input_failure_lifetime`, `agc_copy_input_kept_bytes` and `agc_driver_graphics`. **Results (3 runs each):** - PR head: all four tests pass 3/3. - Baseline: I kept the PR's tests and `CMakeLists.txt` and replaced only `Graphics/src/GuestBufferMemory.cpp` with its version from the merge base `a6a4101e19`, then rebuilt. `agc_driver_copy_input_lifetime` fails 3/3 (`AGC graphics: a recorded copy destination became reusable before its fence`; its counters read `fail=1 refusals=1 early_reuse=1`), and `agc_copy_input_failure_lifetime` fails 3/3 (`destination_reusable_before_fence=1`). `agc_driver_graphics` and `agc_copy_input_kept_bytes` pass in the baseline. I restored the PR's `GuestBufferMemory.cpp` afterwards. **Not run:** other GPUs (no AMD card for this PR), other platforms, the other tests, the full repository CTest, and any title or console run. AI-assisted (Claude Code).
adriadam10 commented 2026-10-21 18:04:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T18:04:31Z.

Review: CHANGES_REQUESTED


The fix itself reads correctly (recorder->Keep(region->buffer) before the copy and Keep(readback, ...) before its use). Two things need fixing before it can merge:

  • core/libs/prx/libSceAgcDriver/CMakeLists.txt:2390 calls set_tests_properties(agc_driver_copy_input_lifetime ...) but nothing defines that test or its executable: there is no add_executable/add_test, and tests/execution/CopyInputLifetime.cpp is not referenced anywhere. CMake errors at configure ("Can not find test to add properties to"), so the real-Vulkan regression is never built. Add the target and add_test the way the other tests/execution/* Vulkan tests are registered, with the skip-77 handling the CI check_skips.py expects.
  • agc_copy_input_failure_lifetime is only registered under if(WIN32) (and the test body throws elsewhere), so Linux CI exercises neither regression. Please make the mock-based test run on Linux too (the guest registration can use the GuestAllocations::Mutation helper that CopyInputLifetime.cpp already uses), or explain why it cannot.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5604081330 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8667#pullrequestreview-5604081330). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-21T18:04:31Z. **Review:** CHANGES_REQUESTED --- The fix itself reads correctly (`recorder->Keep(region->buffer)` before the copy and `Keep(readback, ...)` before its use). Two things need fixing before it can merge: - `core/libs/prx/libSceAgcDriver/CMakeLists.txt:2390` calls `set_tests_properties(agc_driver_copy_input_lifetime ...)` but nothing defines that test or its executable: there is no `add_executable`/`add_test`, and `tests/execution/CopyInputLifetime.cpp` is not referenced anywhere. CMake errors at configure ("Can not find test to add properties to"), so the real-Vulkan regression is never built. Add the target and `add_test` the way the other `tests/execution/*` Vulkan tests are registered, with the skip-77 handling the CI `check_skips.py` expects. - `agc_copy_input_failure_lifetime` is only registered under `if(WIN32)` (and the test body throws elsewhere), so Linux CI exercises neither regression. Please make the mock-based test run on Linux too (the guest registration can use the `GuestAllocations::Mutation` helper that `CopyInputLifetime.cpp` already uses), or explain why it cannot.

Pull request closed

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!8667
No description provided.