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

Closed
mrcrapto wants to merge 1 commit from upstream-pr/3298 into main
mrcrapto commented 2026-10-11 06:09:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mrcrapto on 2026-10-11T06:09:36Z.


What

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.

Discard the failed batch on unwind, removing only its labels and completion counts, refreshing the pending-write snapshot and releasing its handles without running its completions. Earlier in-flight batches remain tracked. Reuse the same label-removal helper on normal completion.

For VK_ERROR_DEVICE_LOST from queue submission, wait for device idle before discarding potentially in-use resources, accepting either success or device loss from that wait. This follows the Vulkan lost-device rules; queue-submit allocation failures instead leave submission state unaffected. The original submission error still propagates.

Related to #3171: this fixes a deterministic cleanup defect, but is not a confirmed fix for the reported Windows heap corruption or Intel device loss.

Tested

Windows 11, WinLibs GCC 15.2, Release, BUILD_TESTING=ON. Final base: de129cfd; no game dump is needed for these tests.

  • Extended agc_recorder_kept_bytes with six injected failure cases: host/device allocation failure from command-buffer end and queue submit, plus queue device loss with successful/device-lost idle waits. The tests check labels, snapshots, counters, callbacks, kept-resource lifetime, handle cleanup and preservation of an earlier submission. Passes with the procedure cache enabled and with APS5_NO_PROC_TABLE=1.
  • The initial two-case regression failed on unchanged d7cfa728 with 14 failed assertions before the fix.
  • NVIDIA RTX 4060 Laptop GPU: agc_driver, agc_driver_gated_dispatch_capture and recorder --completion-labels-only pass.
  • Intel UHD Graphics on the initial d7cfa728 base: agc_driver passed; patched gated-dispatch capture failed twice with VK_ERROR_DEVICE_LOST, while a single unchanged-upstream comparison passed. These observations do not establish the cause of the Intel failure. No complete-suite or Linux pass is claimed.
  • Full default Windows build passes: cmake --build build-contribution --parallel 5.
  • python tools/check_conventions.py --base origin/main and git diff --check pass.

Validation logs: https://gist.github.com/mrcrapto/7ff8c0744c2638a47672bc0dc3b394d2

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 (no new code comments)
  • Unimplemented paths throw; silent stubs are listed in TechnicalDebt (no export/stub changes)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4817007769 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3298). Originally posted by [mrcrapto](https://github.com/mrcrapto) on 2026-10-11T06:09:36Z. --- ### What 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. Discard the failed batch on unwind, removing only its labels and completion counts, refreshing the pending-write snapshot and releasing its handles without running its completions. Earlier in-flight batches remain tracked. Reuse the same label-removal helper on normal completion. For `VK_ERROR_DEVICE_LOST` from queue submission, wait for device idle before discarding potentially in-use resources, accepting either success or device loss from that wait. This follows the [Vulkan lost-device rules](https://docs.vulkan.org/spec/latest/chapters/devsandqueues.html#devsandqueues-lost-device); [queue-submit allocation failures](https://docs.vulkan.org/refpages/latest/refpages/source/vkQueueSubmit.html) instead leave submission state unaffected. The original submission error still propagates. Related to #3171: this fixes a deterministic cleanup defect, but is **not a confirmed fix** for the reported Windows heap corruption or Intel device loss. ### Tested Windows 11, WinLibs GCC 15.2, Release, `BUILD_TESTING=ON`. Final base: `de129cfd`; no game dump is needed for these tests. - Extended `agc_recorder_kept_bytes` with six injected failure cases: host/device allocation failure from command-buffer end and queue submit, plus queue device loss with successful/device-lost idle waits. The tests check labels, snapshots, counters, callbacks, kept-resource lifetime, handle cleanup and preservation of an earlier submission. Passes with the procedure cache enabled and with `APS5_NO_PROC_TABLE=1`. - The initial two-case regression failed on unchanged `d7cfa728` with 14 failed assertions before the fix. - NVIDIA RTX 4060 Laptop GPU: `agc_driver`, `agc_driver_gated_dispatch_capture` and recorder `--completion-labels-only` pass. - Intel UHD Graphics on the initial `d7cfa728` base: `agc_driver` passed; patched gated-dispatch capture failed twice with `VK_ERROR_DEVICE_LOST`, while a single unchanged-upstream comparison passed. These observations do not establish the cause of the Intel failure. No complete-suite or Linux pass is claimed. - Full default Windows build passes: `cmake --build build-contribution --parallel 5`. - `python tools/check_conventions.py --base origin/main` and `git diff --check` pass. Validation logs: https://gist.github.com/mrcrapto/7ff8c0744c2638a47672bc0dc3b394d2 ### 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 (no new code comments) - [x] Unimplemented paths throw; silent stubs are listed in TechnicalDebt (no export/stub changes) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 06:09:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T06:09:47Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106115477 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3298#issuecomment-6106115477). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T06:09:47Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

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