Skip to content

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

Closed
embersas wants to merge 1 commit into
boykopovar:mainfrom
embersas:fix/agc-copy-input-lifetime
Closed

embersas wants to merge 1 commit into
boykopovar:mainfrom
embersas:fix/agc-copy-input-lifetime

Conversation

@embersas

Copy link
Copy Markdown

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 fix(agc): retain GPU copy buffers before fallible diagnostics (standalone patch for review) #8659
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3080 Ti, driver 610.88, Windows 11 Pro build 26300
  • AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1191 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 1368 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 1395 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 2434 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 4040 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 4449 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 5021 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 5371 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5431 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5441 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5925 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6044 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6169 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6186 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6187 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6188 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6192 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6194 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6209 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6235 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6280 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6292 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6300 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6412 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6481 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6501 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6548 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6612 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6615 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6642 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6741 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6788 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6804 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6808 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6868 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6959 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7201 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7256 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 7275 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7410 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 7457 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7604 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7642 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7705 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7803 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8212 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8246 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8365 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8395 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8484 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8527 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 8542 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8552 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8564 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8592 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8672 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9020 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9193 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9335 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9348 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9356 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9387 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9412 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9450 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9489 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9508 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9597 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9675 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9748 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9892 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 9898 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp

@github-actions github-actions Bot added fix error Closes an issue (Fixes #N) build agc libSceAgc* labels Oct 20, 2026
@xXPBSXx

xXPBSXx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

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 adriadam10 self-assigned this Oct 21, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@embersas

Copy link
Copy Markdown
Author

Additional integration validation on base cc0078595d4f24e9df0698ca5a4a062c61592f6f, with the production corrections from #6782 (4433a62b3bf6248df830994a255701c72581cc95), #862 (bbcaad4b2f0fd8b91dd4430e520c86c1bacb147f) and #8667 (47e1539ac5afe87b602fe450d744999cd97cae9e) applied together. This was a local integration of the corrections, not a merge of the three PR branches.

Windows, Ryzen 9 3900X / RTX 3080 Ti, WinLibs GCC 15.2, Release. All 25 focused CTest selections qualified. The 23 GPU executions positively loaded Khronos validation 1.4.363 and identified the RTX 3080 Ti; full stdout/stderr contained no VUID errors, synchronization hazards, missing-layer warnings or skipped tests. The other two selections were non-GPU controls.

The real GPU-copy lifetime regression passed with APS5_CAPTURE_TRACE=1 and APS5_CAPTURE_GPU_COPIES=1, including its injected allocation-failure path. This supplements the original before/after regression evidence with a newer-source integration check.

Focused correctness testing on this configuration; not a full repository suite or a performance result.

AI-assisted testing and report: Codex.

@embersas embersas closed this by deleting the head repository Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build fix error Closes an issue (Fixes #N)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(agc): retain GPU copy buffers before fallible diagnostics (standalone patch for review)

4 participants