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

Merged
VicRaster merged 3 commits from upstream-pr/10141 into main 2026-11-11 03:12:30 +00:00
VicRaster commented 2026-10-23 10:42:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by VicRaster on 2026-10-23T10:42:11Z.


What

With APS5_CAPTURE_GPU_COPIES=1, diagnostic readback allocation can fail after an input copy is recorded. Retain its destination before recording the copy, and retain diagnostic readback storage before recording commands that use it, so exception unwinding cannot return pending buffers to the pool.

Replaces #8667, which closed after I accidentally deleted the contributor fork. The original commit was recovered from its retained PR ref and applied to current main.

Addresses the review on #8667: current main's execution-test discovery builds and registers CopyInputLifetime.cpp, including skip code 77; the mock regression is now registered on both platforms and uses GuestAllocations::Mutation without a Windows-only test body. No experimental memory policy is included.

Tested

Refreshed on 1 November 2026 against main cae3edaf11db8c6c1694c2d772d07c079755a71f; tested head d08d4ab7a39d1056b383663411bced714e4b9666.

Resolved the CMake registration conflict using upstream's tools/agc_test_split.py resolve: the mock registration now lives in tests/cmake/agc_driver_graphics_tests.cmake, and the Vulkan test settings in tests/cmake/agc_driver_copy_input_lifetime_tests.cmake. The production lifetime fix applied cleanly; reviewed its ordering against the current recorder.

Windows 11 Pro build 26300, Ryzen 9 3900X, NVIDIA GeForce RTX 3080 Ti 12 GB, driver 610.88, WinLibs MinGW-w64 GCC 15.2.0, Release.

Both phases used identical refreshed regression fixtures and registration. For the baseline, only GuestBufferMemory.cpp was restored byte-for-byte from pinned main; the fixed phase used the clean refreshed head. Rebuilt the AGC library and focused test targets for each phase.

Test Main production baseline Refreshed head
agc_copy_input_failure_lifetime Fails: destination reusable before fence Passes: no early reuse
agc_driver_copy_input_lifetime Fails under injected readback-allocation refusal Passes, including GPU data and guest guards
agc_buffer_pool Passes Passes
agc_driver_graphics Passes Passes
agc_copy_input_kept_bytes Passes Passes

The Vulkan successful-readback control passes on both sides. The allocation-refusal path records one refusal on both sides, with early_reuse=1 on baseline and early_reuse=0 after the fix. Fixed selection: 5/5 passed, none skipped.

Both verbose CTest runs used ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, and VK_LOADER_DEBUG=layer. Both logs identify the RTX 3080 Ti and positively show Khronos validation layer insertion, with zero VUID- errors and no missing-layer warnings. The lifetime fixtures also enable APS5_CAPTURE_TRACE=1 and APS5_CAPTURE_GPU_COPIES=1. Binary SHA-256 hashes recorded for both phases.

Focused command: ctest --test-dir build -R '^(agc_buffer_pool|agc_driver_graphics|agc_copy_input_kept_bytes|agc_copy_input_failure_lifetime|agc_driver_copy_input_lifetime)$' -V.

Convention and whitespace checks pass. Targeted open-PR searches for the diagnostic lifetime correction found no duplicate implementation; the earlier full overlap audit remains historical and was not rerun for this refresh.

Not tested locally in this refresh: Linux, other GPUs, the full repository suite, completion-callback registration allocation failure, game compatibility, or performance. The separate contributor NVIDIA/Linux and AMD/Windows reports below apply to the previous head.

AI-assisted refresh, conflict resolution, testing and report: Codex.

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:4981514266 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10141). Originally posted by [VicRaster](https://github.com/VicRaster) on 2026-10-23T10:42:11Z. --- ### What With `APS5_CAPTURE_GPU_COPIES=1`, diagnostic readback allocation can fail after an input copy is recorded. Retain its destination before recording the copy, and retain diagnostic readback storage before recording commands that use it, so exception unwinding cannot return pending buffers to the pool. Replaces #8667, which closed after I accidentally deleted the contributor fork. The original commit was recovered from its retained PR ref and applied to current main. Addresses the review on #8667: current main's execution-test discovery builds and registers `CopyInputLifetime.cpp`, including skip code 77; the mock regression is now registered on both platforms and uses `GuestAllocations::Mutation` without a Windows-only test body. No experimental memory policy is included. ### Tested Refreshed on 1 November 2026 against main `cae3edaf11db8c6c1694c2d772d07c079755a71f`; tested head `d08d4ab7a39d1056b383663411bced714e4b9666`. Resolved the CMake registration conflict using upstream's `tools/agc_test_split.py resolve`: the mock registration now lives in `tests/cmake/agc_driver_graphics_tests.cmake`, and the Vulkan test settings in `tests/cmake/agc_driver_copy_input_lifetime_tests.cmake`. The production lifetime fix applied cleanly; reviewed its ordering against the current recorder. Windows 11 Pro build 26300, Ryzen 9 3900X, NVIDIA GeForce RTX 3080 Ti 12 GB, driver 610.88, WinLibs MinGW-w64 GCC 15.2.0, Release. Both phases used identical refreshed regression fixtures and registration. For the baseline, only `GuestBufferMemory.cpp` was restored byte-for-byte from pinned main; the fixed phase used the clean refreshed head. Rebuilt the AGC library and focused test targets for each phase. | Test | Main production baseline | Refreshed head | |---|---|---| | `agc_copy_input_failure_lifetime` | Fails: destination reusable before fence | Passes: no early reuse | | `agc_driver_copy_input_lifetime` | Fails under injected readback-allocation refusal | Passes, including GPU data and guest guards | | `agc_buffer_pool` | Passes | Passes | | `agc_driver_graphics` | Passes | Passes | | `agc_copy_input_kept_bytes` | Passes | Passes | The Vulkan successful-readback control passes on both sides. The allocation-refusal path records one refusal on both sides, with `early_reuse=1` on baseline and `early_reuse=0` after the fix. Fixed selection: 5/5 passed, none skipped. Both verbose CTest runs used `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, and `VK_LOADER_DEBUG=layer`. Both logs identify the RTX 3080 Ti and positively show Khronos validation layer insertion, with zero `VUID-` errors and no missing-layer warnings. The lifetime fixtures also enable `APS5_CAPTURE_TRACE=1` and `APS5_CAPTURE_GPU_COPIES=1`. Binary SHA-256 hashes recorded for both phases. Focused command: `ctest --test-dir build -R '^(agc_buffer_pool|agc_driver_graphics|agc_copy_input_kept_bytes|agc_copy_input_failure_lifetime|agc_driver_copy_input_lifetime)$' -V`. Convention and whitespace checks pass. Targeted open-PR searches for the diagnostic lifetime correction found no duplicate implementation; the earlier full overlap audit remains historical and was not rerun for this refresh. Not tested locally in this refresh: Linux, other GPUs, the full repository suite, completion-callback registration allocation failure, game compatibility, or performance. The separate contributor NVIDIA/Linux and AMD/Windows reports below apply to the previous head. AI-assisted refresh, conflict resolution, testing and report: Codex. <!-- 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-23 10:55:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T10:55:43Z.

Review: APPROVED


Reviewed the production lifetime ordering, portable mock regression, real Vulkan execution test, and the earlier #8667 review history. This replacement addresses the prior blockers: CopyInputLifetime.cpp is built and registered with skip-77 handling, and the mock regression is registered on both platforms using guest-allocation mutation rather than a Windows-only body. The destination buffer is retained before the recorded input copy; the diagnostic readback is retained before its commands use it. The earlier #8667 evidence reports both regressions failing on baseline and passing after the fix, including independent RTX 4080 SUPER runs and an integration validation run. I did not run the GPU-dependent target locally in this environment. No blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5627264572 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10141#pullrequestreview-5627264572). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T10:55:43Z. **Review:** APPROVED --- Reviewed the production lifetime ordering, portable mock regression, real Vulkan execution test, and the earlier #8667 review history. This replacement addresses the prior blockers: `CopyInputLifetime.cpp` is built and registered with skip-77 handling, and the mock regression is registered on both platforms using guest-allocation mutation rather than a Windows-only body. The destination buffer is retained before the recorded input copy; the diagnostic readback is retained before its commands use it. The earlier #8667 evidence reports both regressions failing on baseline and passing after the fix, including independent RTX 4080 SUPER runs and an integration validation run. I did not run the GPU-dependent target locally in this environment. No blocking issue found.
MarcZX10 commented 2026-10-23 11:44:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T11:44:40Z.

Review: CHANGES_REQUESTED


Correction to my earlier approval after checking the exact head against current main 777bdbb4f80bcc03e870dfda0d292c0c6410fd6a: this branch is 73 commits behind, with merge base c188e01a4286bfc402519df2ceb56441479cc835. Since that base, main has changed all three overlapping paths: Graphics/src/GuestBufferMemory.cpp, tests/Graphics.cpp, and CMakeLists.txt (plus added execution tests under the same tree). The reported before/after and validation-layer runs are qualified against the older base, so they do not establish the new regression and lifetime ordering in the current recorder/test-registration context. Please rebase onto current main, resolve the semantic overlap, and rerun the focused mock and Vulkan lifetime tests on current main and the refreshed head with the AGC validation-layer comparison required by CONTRIBUTING. I am changing my review to CHANGES_REQUESTED until that evidence is available. The existing Windows RTX 3080 Ti runs remain useful for the earlier base; I am not discounting them.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5627750382 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10141#pullrequestreview-5627750382). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T11:44:40Z. **Review:** CHANGES_REQUESTED --- Correction to my earlier approval after checking the exact head against current `main` `777bdbb4f80bcc03e870dfda0d292c0c6410fd6a`: this branch is 73 commits behind, with merge base `c188e01a4286bfc402519df2ceb56441479cc835`. Since that base, `main` has changed all three overlapping paths: `Graphics/src/GuestBufferMemory.cpp`, `tests/Graphics.cpp`, and `CMakeLists.txt` (plus added execution tests under the same tree). The reported before/after and validation-layer runs are qualified against the older base, so they do not establish the new regression and lifetime ordering in the current recorder/test-registration context. Please rebase onto current `main`, resolve the semantic overlap, and rerun the focused mock and Vulkan lifetime tests on current `main` and the refreshed head with the AGC validation-layer comparison required by CONTRIBUTING. I am changing my review to CHANGES_REQUESTED until that evidence is available. The existing Windows RTX 3080 Ti runs remain useful for the earlier base; I am not discounting them.
MarcZX10 commented 2026-11-01 02:36:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T02:36:03Z.

Review: APPROVED


Re-checked — new head, looks good

The rebase resolves the stale test-registration overlap, and the refreshed production fix retains each buffer before recording commands that use it.

What I ran

Reviewed head d08d4ab7a39d1056b383663411bced714e4b9666 against base cae3edaf11db8c6c1694c2d772d07c079755a71f; the merge preview against current main cf79276fee2f042feb6a7c71d0d6a27e9cfe2592 is clean. Environment: Debian Linux x86-64, Python 3.11.2; no local C++ or GPU build.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 10141
git diff cf79276fee2f042feb6a7c71d0d6a27e9cfe2592...d08d4ab7a39d1056b383663411bced714e4b9666 -- core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp core/libs/prx/libSceAgcDriver/tests/Graphics.cpp core/libs/prx/libSceAgcDriver/tests/execution/CopyInputLifetime.cpp core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_copy_input_lifetime_tests.cmake core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_graphics_tests.cmake

Results

Check Result
Diff, conventions and current-main merge preview Passed. The refreshed five-file diff preserves the intended Keep-before-copy ordering and registers the mock and Vulkan tests in the current CMake fragments.
Author-reported exact-head tests Windows RTX 3080 Ti: 5/5 focused tests passed with Vulkan validation enabled and zero VUID errors. The author reports both lifetime regressions reproduce on the production baseline and pass on the refreshed head. I did not reproduce these locally.
Hosted checks Conventions and labels passed; no product build/test job ran in the hosted workflow.
Optional local ABI/test-quality helpers Absent from the isolated PR snapshot; not applicable to the source change.

Negative control

Assertion Change to code under test Did the new test fail?
Recorded input and diagnostic-readback buffers must not be reused before the GPU work completes. The author restored the production baseline GuestBufferMemory.cpp byte-for-byte while keeping the refreshed fixtures. Yes, author reports both lifetime regressions fail on baseline and pass on the refreshed head; I did not run this control.

Findings

Blocking

None found in the refreshed head.

Non-blocking

Linux, other GPUs, completion-callback registration allocation failure, and the full suite were not tested in this refresh. The detailed Windows runs and baseline control are author-reported.

Sources

Not verified

I did not run a local build, CTest, Vulkan validation, or the baseline control. The Windows test run and negative control are author-reported.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5726090074 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10141#pullrequestreview-5726090074). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-01T02:36:03Z. **Review:** APPROVED --- # Re-checked — new head, looks good The rebase resolves the stale test-registration overlap, and the refreshed production fix retains each buffer before recording commands that use it. ## What I ran Reviewed head `d08d4ab7a39d1056b383663411bced714e4b9666` against base `cae3edaf11db8c6c1694c2d772d07c079755a71f`; the merge preview against current `main` `cf79276fee2f042feb6a7c71d0d6a27e9cfe2592` is clean. Environment: Debian Linux x86-64, Python 3.11.2; no local C++ or GPU build. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 10141 git diff cf79276fee2f042feb6a7c71d0d6a27e9cfe2592...d08d4ab7a39d1056b383663411bced714e4b9666 -- core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp core/libs/prx/libSceAgcDriver/tests/Graphics.cpp core/libs/prx/libSceAgcDriver/tests/execution/CopyInputLifetime.cpp core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_copy_input_lifetime_tests.cmake core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_graphics_tests.cmake ``` ## Results | Check | Result | |---|---| | Diff, conventions and current-main merge preview | Passed. The refreshed five-file diff preserves the intended `Keep`-before-copy ordering and registers the mock and Vulkan tests in the current CMake fragments. | | Author-reported exact-head tests | Windows RTX 3080 Ti: 5/5 focused tests passed with Vulkan validation enabled and zero VUID errors. The author reports both lifetime regressions reproduce on the production baseline and pass on the refreshed head. I did not reproduce these locally. | | Hosted checks | Conventions and labels passed; no product build/test job ran in the hosted workflow. | | Optional local ABI/test-quality helpers | Absent from the isolated PR snapshot; not applicable to the source change. | ## Negative control | Assertion | Change to code under test | Did the new test fail? | |---|---|---| | Recorded input and diagnostic-readback buffers must not be reused before the GPU work completes. | The author restored the production baseline `GuestBufferMemory.cpp` byte-for-byte while keeping the refreshed fixtures. | Yes, author reports both lifetime regressions fail on baseline and pass on the refreshed head; I did not run this control. | ## Findings ### Blocking None found in the refreshed head. ### Non-blocking Linux, other GPUs, completion-callback registration allocation failure, and the full suite were not tested in this refresh. The detailed Windows runs and baseline control are author-reported. ## Sources - [Production lifetime fix at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/d08d4ab7a39d1056b383663411bced714e4b9666/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp) - [Author’s refreshed exact-head report](https://github.com/boykopovar/AnyPS5/pull/10141#issuecomment-6552308122) ## Not verified I did not run a local build, CTest, Vulkan validation, or the baseline control. The Windows test run and negative control are author-reported.
adriadam10 commented 2026-11-09 18:55:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-09T18:55:51Z.

Review: CHANGES_REQUESTED


The production change looks right, but the full Build on this head fails on the test this PR adds: agc_driver_copy_input_lifetime (Linux job on lavapipe, run 42489330618). Output:

copy-input lifetime: fail=0 refusals=0 early_reuse=0 GPU_data_checked=0
AGC graphics: a recorded copy destination became reusable before its fence
  • core/libs/prx/libSceAgcDriver/tests/execution/CopyInputLifetime.cpp, final Require(checked && !earlyReuse, ...): in the success scenario (fail=0) the copy destination is never found in the pool after recorder.Sync(), so checked stays 0 and the test aborts even though early_reuse=0. The CI host is llvmpipe without /dev/udmabuf, so the buffer path differs from the NVIDIA/RADV/Windows runs that passed. The test needs to pass there too (queue's Linux job is the gate); either don't require the destination to reappear in the pool (assert on earlyReuse and read back through a handle the test owns), or make the check hold on that driver.

Once the test passes on the Linux CI job it should be good to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5831015867 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10141#pullrequestreview-5831015867). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-11-09T18:55:51Z. **Review:** CHANGES_REQUESTED --- The production change looks right, but the full Build on this head fails on the test this PR adds: `agc_driver_copy_input_lifetime` (Linux job on lavapipe, run 42489330618). Output: ``` copy-input lifetime: fail=0 refusals=0 early_reuse=0 GPU_data_checked=0 AGC graphics: a recorded copy destination became reusable before its fence ``` - `core/libs/prx/libSceAgcDriver/tests/execution/CopyInputLifetime.cpp`, final `Require(checked && !earlyReuse, ...)`: in the success scenario (`fail=0`) the copy destination is never found in the pool after `recorder.Sync()`, so `checked` stays 0 and the test aborts even though `early_reuse=0`. The CI host is llvmpipe without `/dev/udmabuf`, so the buffer path differs from the NVIDIA/RADV/Windows runs that passed. The test needs to pass there too (queue's Linux job is the gate); either don't require the destination to reappear in the pool (assert on `earlyReuse` and read back through a handle the test owns), or make the check hold on that driver. Once the test passes on the Linux CI job it should be good to merge.
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!10141
No description provided.