fix(agc): discard recorder batches after submission failure #5837

Merged
akkadbakkad89 merged 1 commit from upstream-pr/5837 into main 2026-10-15 21:00:37 +00:00
akkadbakkad89 commented 2026-10-14 13:02:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-14T13:02:55Z.


What

Carries #3298 by @mrcrapto, which was closed automatically by the intake pause (author has no merged PRs and cannot reopen it). Rebased onto current main; no open PR implements the same change.

If vkEndCommandBuffer or vkQueueSubmit fails after Recorder::Submit() moves out the open batch, the batch destructor releases kept objects but leaves its Vulkan handles, label-table entries, completion counts and pending-write snapshot behind. Label entries can then refer to the destroyed batch.

The batch is now discarded on unwind: its labels and completion counts are removed, the pending-write snapshot refreshed and its handles released without running its completions. Earlier in-flight batches remain tracked. The same label-removal helper is reused on normal completion.

Cherry-picked e487ff005 with the original authorship kept; it applied cleanly onto current main.

Tested

WSL Ubuntu 24.04, llvmpipe (LLVM 20.1.2). Rebuilt libSceAgcDriver and the recorder tests on this branch: agc_recorder_kept_bytes passes (includes the new mocked vkEndCommandBuffer/vkQueueSubmit failure cases) and agc_driver_recorder_tests runs clean under llvmpipe. tools/check_conventions.py --base upstream/main passes.

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
  • Unblocks: none
  • GPUs tested: llvmpipe (LLVM 20.1.2, Mesa software rasterizer) on Linux — device-level failures are exercised through the mocked-device unit test, not real hardware
  • AI-assisted: yes (Devin)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4858299195 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5837). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-14T13:02:55Z. --- ### What Carries #3298 by @mrcrapto, which was closed automatically by the intake pause (author has no merged PRs and cannot reopen it). Rebased onto current main; no open PR implements the same change. If `vkEndCommandBuffer` or `vkQueueSubmit` fails after `Recorder::Submit()` moves out the open batch, the batch destructor releases kept objects but leaves its Vulkan handles, label-table entries, completion counts and pending-write snapshot behind. Label entries can then refer to the destroyed batch. The batch is now discarded on unwind: its labels and completion counts are removed, the pending-write snapshot refreshed and its handles released without running its completions. Earlier in-flight batches remain tracked. The same label-removal helper is reused on normal completion. Cherry-picked `e487ff005` with the original authorship kept; it applied cleanly onto current `main`. ### Tested WSL Ubuntu 24.04, llvmpipe (LLVM 20.1.2). Rebuilt `libSceAgcDriver` and the recorder tests on this branch: `agc_recorder_kept_bytes` passes (includes the new mocked vkEndCommandBuffer/vkQueueSubmit failure cases) and `agc_driver_recorder_tests` runs clean under llvmpipe. `tools/check_conventions.py --base upstream/main` passes. ### Checklist - [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] Unblocks: none - [x] GPUs tested: llvmpipe (LLVM 20.1.2, Mesa software rasterizer) on Linux — device-level failures are exercised through the mocked-device unit test, not real hardware - [x] AI-assisted: yes (Devin)
Dextroid17 commented 2026-10-15 01:03:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-15T01:03:00Z.


Ran this on PR head 27886f847 (merge base 131171e77, 501 commits behind main ab9a47684).

Setup: PR head checked out as-is (not rebased), default CMake build (CMAKE_BUILD_TYPE empty, unoptimized), Linux. The test uses a MockDevice; no GPU was used.

  • agc_recorder_kept_bytes_tests on the PR: 3 of 3 passed ("recorder kept bytes tests passed").
  • Mutation check: kept the PR's test, put back the merge-base Graphics/include/Recorder.hpp and Graphics/src/Recorder.cpp, rebuilt, ran 3 times: 3 of 3 failed: "46 recorder kept bytes checks failed".

So on this setup the test fails without the change and passes with it. Main has changed the Recorder files since the merge base (6 commits on Recorder.cpp), and many open PRs touch Recorder.cpp. I did not test the PR rebased onto main.

Not checked: real GPU submission failures, or any title.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6181962634 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5837#issuecomment-6181962634). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-15T01:03:00Z. --- Ran this on PR head 27886f847 (merge base 131171e77, 501 commits behind main ab9a47684). Setup: PR head checked out as-is (not rebased), default CMake build (CMAKE_BUILD_TYPE empty, unoptimized), Linux. The test uses a MockDevice; no GPU was used. - agc_recorder_kept_bytes_tests on the PR: 3 of 3 passed ("recorder kept bytes tests passed"). - Mutation check: kept the PR's test, put back the merge-base Graphics/include/Recorder.hpp and Graphics/src/Recorder.cpp, rebuilt, ran 3 times: 3 of 3 failed: "46 recorder kept bytes checks failed". So on this setup the test fails without the change and passes with it. Main has changed the Recorder files since the merge base (6 commits on Recorder.cpp), and many open PRs touch Recorder.cpp. I did not test the PR rebased onto main. Not checked: real GPU submission failures, or any title. AI-assisted: yes
github-actions[bot] commented 2026-10-15 12:10:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:10:14Z.


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
PR 5431 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp L754-755
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp L3317-3318, L3334-3343, L3872-3874

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 1896 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 3891 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4156 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4396 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4397 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4422 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4423 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4424 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4520 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4521 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4522 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4523 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4566 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4599 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4718 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4740 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4749 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4760 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 4813 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 5021 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191714929 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5837#issuecomment-6191714929). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:10:14Z. --- <!-- 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 | |---|---|---|---| | [PR 5431](https://www.github.com/boykopovar/AnyPS5/pull/5431) | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp` [L754-755](https://github.com/boykopovar/AnyPS5/blob/ec1193dc39d9cf8a66fc4bb9807afe8632749ae5/core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp#L754-L755)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` [L3317-3318](https://github.com/boykopovar/AnyPS5/blob/ec1193dc39d9cf8a66fc4bb9807afe8632749ae5/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp#L3317-L3318), [L3334-3343](https://github.com/boykopovar/AnyPS5/blob/ec1193dc39d9cf8a66fc4bb9807afe8632749ae5/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp#L3334-L3343), [L3872-3874](https://github.com/boykopovar/AnyPS5/blob/ec1193dc39d9cf8a66fc4bb9807afe8632749ae5/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp#L3872-L3874) | | | 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 1896](https://www.github.com/boykopovar/AnyPS5/pull/1896) | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 3891](https://www.github.com/boykopovar/AnyPS5/pull/3891) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4156](https://www.github.com/boykopovar/AnyPS5/pull/4156) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4396](https://www.github.com/boykopovar/AnyPS5/pull/4396) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4397](https://www.github.com/boykopovar/AnyPS5/pull/4397) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4422](https://www.github.com/boykopovar/AnyPS5/pull/4422) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4423](https://www.github.com/boykopovar/AnyPS5/pull/4423) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4424](https://www.github.com/boykopovar/AnyPS5/pull/4424) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4520](https://www.github.com/boykopovar/AnyPS5/pull/4520) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4521](https://www.github.com/boykopovar/AnyPS5/pull/4521) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4522](https://www.github.com/boykopovar/AnyPS5/pull/4522) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4523](https://www.github.com/boykopovar/AnyPS5/pull/4523) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4566](https://www.github.com/boykopovar/AnyPS5/pull/4566) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4599](https://www.github.com/boykopovar/AnyPS5/pull/4599) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4718](https://www.github.com/boykopovar/AnyPS5/pull/4718) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4740](https://www.github.com/boykopovar/AnyPS5/pull/4740) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4749](https://www.github.com/boykopovar/AnyPS5/pull/4749) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4760](https://www.github.com/boykopovar/AnyPS5/pull/4760) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 4813](https://www.github.com/boykopovar/AnyPS5/pull/4813) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` | | [PR 6188](https://www.github.com/boykopovar/AnyPS5/pull/6188) | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp` |
akkadbakkad89 commented 2026-10-15 12:18:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-15T12:18:40Z.


Manual overlap review (per the pr-overlap note above — the listed PRs are dirty against base so they could not be diffed):

Of the same-file PRs, #5431 is a real semantic overlap: its Submit() implements the same discard-on-failure path — batch is pushed to inFlight, and on vkEndCommandBuffer/vkQueueSubmit failure it does inFlightKeptBytes -= ...; inFlight.pop_back(); discardUnsubmitted(std::move(discarded), false); return;, and it defines Recorder::discardUnsubmitted(std::unique_ptr<Batch>, bool reusable). discardUnsubmitted is a name invented in #3298, so that machinery was derived from this change and extended for draw-token tracing. If #5431 merges first, this PR becomes largely redundant; conversely this PR is the standalone fix without the tracing feature.

Other same-file PRs checked manually — #5609, #6188, #1747, #1896 touch Recorder.* but none implement the submission-failure discard path (vkQueueSubmit/vkEndCommandBuffer failure → drop the batch).

Rebased onto current main (d92a8dad3); agc_recorder_kept_bytes_tests and agc_driver_recorder_tests pass on the new base.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191868837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5837#issuecomment-6191868837). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-15T12:18:40Z. --- Manual overlap review (per the pr-overlap note above — the listed PRs are dirty against base so they could not be diffed): Of the same-file PRs, **#5431** is a real semantic overlap: its `Submit()` implements the same discard-on-failure path — batch is pushed to `inFlight`, and on `vkEndCommandBuffer`/`vkQueueSubmit` failure it does `inFlightKeptBytes -= ...; inFlight.pop_back(); discardUnsubmitted(std::move(discarded), false); return;`, and it defines `Recorder::discardUnsubmitted(std::unique_ptr<Batch>, bool reusable)`. `discardUnsubmitted` is a name invented in #3298, so that machinery was derived from this change and extended for draw-token tracing. If #5431 merges first, this PR becomes largely redundant; conversely this PR is the standalone fix without the tracing feature. Other same-file PRs checked manually — #5609, #6188, #1747, #1896 touch `Recorder.*` but none implement the submission-failure discard path (`vkQueueSubmit`/`vkEndCommandBuffer` failure → drop the batch). Rebased onto current main (`d92a8dad3`); `agc_recorder_kept_bytes_tests` and `agc_driver_recorder_tests` pass on the new base.
adriadam10 commented 2026-10-15 13:34:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:34:33Z.


Checked on the PR merged onto current main: agc_recorder_kept_bytes passes and fails with Recorder.* reverted, the rest of the libSceAgcDriver ctest is green apart from agc_driver_preparation_scope_settle and agc_driver_tessellation, which also fail on main. The submission-failure cases (host/device OOM, device lost with idle success/loss) pin labels, completion counts, the write snapshot and earlier in-flight batches. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6193351181 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5837#issuecomment-6193351181). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T13:34:33Z. --- Checked on the PR merged onto current main: `agc_recorder_kept_bytes` passes and fails with `Recorder.*` reverted, the rest of the libSceAgcDriver ctest is green apart from `agc_driver_preparation_scope_settle` and `agc_driver_tessellation`, which also fail on main. The submission-failure cases (host/device OOM, device lost with idle success/loss) pin labels, completion counts, the write snapshot and earlier in-flight batches. Merging once the full Build is green.
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!5837
No description provided.