fix(agc): clean up what a discarded batch leaves behind #20186
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20186"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by chitters2004 on 2026-11-14T19:42:33Z.
What
A recorder batch whose submission fails (
vkEndCommandBufferorvkQueueSubmitfails, or anything throws between closing the batch and the submit) is discarded: its labels, completion counters and resources are released, and its completion actions never run. Three pieces of state lived only in those completions or were moved into the batch, so a discard left them stale. Each commit fixes one and adds a test that fails without the fix.Copied writers stay listed (
fix(agc): delist a discarded batch's copied writers). A draw (keepRecordedDraw) or dispatch whose stores go through a copied buffer is listed inDrawCopiedWriters()/ the device'scopiedWritersuntil its completion delists it and writes the buffer back. After a discard it stayed listed for good:AnyPendingCpuWritesstayed true;APS5_PIN_WAIT_MS(60 s) and threw.Recorder::OnDiscard(action)adds per-batch discard actions.discard()runs each one under try/catch: a failure is logged and the remaining actions still run. Both sites register a delist action next to their completion.Folded occlusion samples are lost (
fix(agc): restore occlusion samples a discarded batch folded and drop its own).foldedSamples). Discard drops the batch's own segments and returns the rest to the front of the pending list. Capacity for that return is reserved whenever a segment is pushed (reserveSampleRestore), sodiscard(noexcept) never allocates. If it ever cannot restore them, it logs the loss.An HTILE clear completion is dropped (
fix(agc): refuse native depth sampling after a discarded HTILE clear).docs/dev/debt/libSceAgcDriver.mdsays so.A failed submit is completed before it is reported (
fix(agc): latch a deferred completion's submit failure before waking idle waiters).Driver::completeSubmission, theCompleteguard's destructor marks the serial completed and wakes idle waiters while the submit failure is still unwinding. The draw pipeline reports the failure only after that. SoAgcDriverWaitIdlecan wake, see completed ≥ accepted and no failure, and return cleanly after a failed submit.ReportFailure) before the guard runs.ProcessShutdownstill passes through unreported.agc_driver_native_depth_discarded_clear. Windows CI showed it as that test's red, and on Linux unfixed it fails 1/40 serial runs and 28/64 runs with 8 in parallel, against 0/64 fixed. Without commit 4, commit 3's test is flaky.Tested
Refresh on main
6786420207, ASAN gcc RelWithDebInfo, llvmpipe (LLVM 20.1.2),detect_leaks=0(llvmpipe threads leak 112 B):agc_driver_recorder,agc_driver_discarded_copied_writer,agc_driver_native_depth_discarded_clear,agc_driver_native_depth_clears,agc_driver_native_multisample_depth, and the four kept-bytes tests.1d1ff1118d.tools/check_conventions.py --base origin/main: passes.Original run (base
1d1ff1118d), Linux, llvmpipe (Mesa 25.2.8, LLVM 20.1.2). No title; these paths are only reachable through a failed submission, whichRecorder::FailNextSubmitsForTestinjects.New
agc_driver_discarded_copied_writer_tests:VulkanDevice::Draw) are each completed, discarded and repeated;AnyPendingCpuWrites, and that the discarded one stored nothing.agc_driver_recorder_tests:occlusionQueryPrecise.agc_driver_native_depth_discarded_clear(new ctest):Fail-without-fix (each fix removed with the tests kept):
vkGetQueryPoolResults occlusion: Vulkan result 1(a fold of queries that never ran)The writer test also runs against main's own sources: it fails there on the dispatch check.
Commit 4 (the submit-failure race): unfixed,
agc_driver_native_depth_discarded_clearfails 1/40 serial and 28/64 with 8 in parallel, with "serials accepted 1 completed 1, failure latched after the wait: 'vkQueueSubmit recorder: injected failure'"; fixed, 0/64. The flip, PM4-failure, worker-failure, pipeline-queue-failure and submit-progress tests pass.Validation layers (VVL 1.4.363.1, sync validation on), main
1d1ff1118dvs this branch, same machine,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation.--clears--discarded-clearThe layer loaded on every run, and neither log has "was not found but was requested by env var VK_INSTANCE_LAYERS".
python3 tools/check_conventions.py --base 1d1ff1118d(main): passes, no findings.Fork CI on this tree (run 43629859674): the Linux gate, ASan and Windows pass the listed tests on both sides.
agc_driver_flip: the volatile guest-label poll race that is onmainand that #20185 fixes. None of the reports involves this change.tools/pr_overlap.py --base main: overlaps at file level only. No open pull request touches the discard path.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T15:49:57Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks merging this change; the code inspected addresses the described discard cleanup paths, and the test evidence supplied in the PR description is consistent with those changes.
What I ran
Inspected the prepared diff and targeted files at head
5bbee1f81d90132f5e859099248148652d87905busing the review reader. No tests or build commands were run. The PR description reports test and CI results; those were not independently run here.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
core/libs/prx/libSceAgcDriver/tests/Recorder.cppandcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppwas excluded from the review folder; relevant changed ranges inVulkanDevice.cppwere read through the reader, but the changed ranges in the large test file were not. Other files listed as included were not all read in full. Build/test results and console or hardware GPU behavior were not independently verified. Read:review/description.md,review/commits.md,review/manifest.json,review/diff.patch, plus targeted ranges inQueueWorker.cpp,VulkanDevice.cpp,Recorder.hpp,Recorder.cpp,DepthSurface.cpp,Draw.cpp,DeferredCompletionFailure.cpp,DiscardedCopiedWriter.cpp,NativeMultisampleDepth.cpp, andagc_driver_native_multisample_depth_tests.cmake. Excluded by size:tests/Recorder.cppandVulkanDevice.cppfull texts; the former's changed ranges were not read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T17:47:14Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected implementation shows a verified blocking defect; the prepared artifacts report focused regression coverage, but I did not run those checks.
What I ran
Reviewed head
7d815d97c84bd0bd3e4edae0832c00fb3146bd9dusing the prepared diff andrepo_read.py-backed reader. No tests or builds were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build, test, validation-layer, or console-hardware checks were run. The description's reported test results were not independently verified. Excluded by the review-folder rules: full text for
Execution/src/VulkanDevice.cppandtests/Recorder.cpp(targeted ranges were read throughrepo_read.py); files listed infiles.jsonwere not available as a reader document. Other changed files read:Execution/src/Driver/Queues/QueueWorker.cpp,Graphics/include/DepthSurface.hpp,Graphics/include/Recorder.hpp,Graphics/src/DepthSurface.cpp,Graphics/src/Draw.cpp,Graphics/src/Recorder.cpp,tests/cmake/agc_driver_native_multisample_depth_tests.cmake,tests/execution/DeferredCompletionFailure.cpp,tests/execution/DiscardedCopiedWriter.cpp,tests/execution/NativeMultisampleDepth.cpp, anddocs/dev/debt/libSceAgcDriver.md.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T13:10:52Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; I reviewed the discard cleanup and its tests at head
aa4974be6e39b393cf0810fb17ea19a2b104e110and found no verified defect.What I ran
No commands or tests were run. I inspected the prepared diff and targeted source ranges through
repo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not read every changed line required for a complete approval:
core/libs/prx/libSceAgcDriver/tests/Recorder.cppwas too large for the review folder, and I read only targeted ranges of the other included files. I also did not run the tests or build, and did not verify hardware GPU behavior. Files reviewed:QueueWorker.cpp,VulkanDevice.cpp(targeted range),DepthSurface.hpp,Recorder.hpp,DepthSurface.cpp(targeted ranges),Draw.cpp(targeted range),Recorder.cpp(targeted ranges),DeferredCompletionFailure.cpp,DiscardedCopiedWriter.cpp(diff),NativeMultisampleDepth.cpp(targeted ranges and diff),agc_driver_native_multisample_depth_tests.cmake(diff), anddocs/dev/debt/libSceAgcDriver.md(diff). Excluded from full-text review:VulkanDevice.cppandtests/Recorder.cpp, both marked too large; the remaining included changed files were not read in full.To get this to a good state
Nothing is required. Optional: run the new regression tests and build on the pinned head, then review the full text of the two excluded files.