Repository navigation
fix(agc): clean up what a discarded batch leaves behind - #20186
chitters2004 wants to merge 13 commits into
Conversation
A dispatch or draw whose stores go through copied buffers is listed as a pending CPU writer until its batch's completion action delists it. A batch that is discarded instead of submitted dropped that action, so the writer stayed listed for good: AnyPendingCpuWrites stayed true, indirect work over its range stayed on the CPU path, and its kept resources held the guest allocation's lease until the pin wait timed out. Recorder::OnDiscard registers actions that run only when the batch is discarded; each runs even if an earlier one throws. The dispatch and draw paths register their delisting there next to their completion action. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… its own A batch that folds earlier batches' occlusion segments (a sample dump, a queued dump at a store flush, or a fold at capacity) removed them from the recorder's pending list. When that batch failed to submit, discard did not put them back, so the earlier batches' samples were lost from every later total. The discarded batch's own ended segments stayed pending, so a later fold copied queries that never ran. Each batch now keeps the segments it folded. Discard drops the segments the batch ended itself and returns the rest to the front of the pending list. Capacity for that return is reserved whenever a segment is pushed, so discard (noexcept) never allocates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An HTILE mask clear dispatch arms the native depth surface's clear (its generation) and queues the completion that marks the metadata written. When the dispatch's batch failed to submit, the completion never ran: the surface kept a queued completion and an armed clear for a dispatch that never executed. The next sample then failed on a missing HTILE store, and every later clear was refused as overlapping. The dispatch now registers a discard action that clears the queued completion and refuses sampling of that surface with the reason. The clear's transition is not undone; the debt entry says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…idle waiters Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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.
|
|
Test report, NVIDIA on Windows: the new
Cause, from temporary
Why CI and llvmpipe pass: on this RTX the write-watch probe reports Possible fix (test side): make sure the driver device exists before Logs available on request. AI-assisted (Claude Code). |
|
Verified this PR on three real AMD RADV generations (Mesa 26.2.6, validation layer 1.4.363,
i.e. Scope: this test is added by this PR's earlier commit Happy to rebuild AI-assisted: yes |
|
Building on @hamdanpor-ctrl's NVIDIA/Windows report above — taken together, AI-assisted: yes |
A dispatch that clears HTILE armed the clear before registering the action that undoes it on discard, so a failed registration left the clear armed with nothing to refuse sampling if the batch was dropped. Recorder::ChangeUndoneOnDiscard reserves the undo's slot first, then makes the change and stores the undo, which cannot throw. Recorder::discard is noexcept and caught only std::exception from its actions; any other exception terminated the process. It now logs and continues for every exception. The discard action test adds an action throwing a non-standard value and an injected registration failure that must leave the change unmade.
… or at capacity The discarded sample test covered only a dump recorded at once. It now discards a batch whose two queued dumps, split by a flush, each fold earlier segments, and a batch whose submit folds a submitted batch's samples at the fold capacity, and requires the total to keep exactly the submitted samples. A new capacityFolds count in the sample dump statistics, also printed with the profile, shows the capacity fold ran.
…host The discarded HTILE clear test checked only that sampling was refused, which needs the write tracker to cover the imported HTILE range; where it does not, as on Linux with host imports, it skipped, and removing the dispatch's discard registration went unnoticed. DiscardHtileDepthClear now counts its calls, and the test requires exactly one undo for the discarded dispatch before it checks the refusal where it can.
…ng idle waiters The fix for a failed deferred completion was shown only by a reproducer that loses the race most of the time. The new test parks an idle waiter, completes a deferred submission whose submit fails, and holds the caller's own failure report until the waiter has returned, so the waiter sees the failure only if completeSubmission latched it before waking it. With the report moved back after the wake the waiter returns without the failure every time.
The discarded clear check injected one submit failure and then made the driver's first PM4 dispatch, so the driver created its device inside that dispatch. Where device start-up or the dispatch's drain submits work, that submit took the injected failure and threw before the dispatch matched its HTILE clear. The clear was never recorded, armed or discarded, yet the test passed on "injected failure", and on real GPUs the sampled texture was then not refused. The test now starts the driver's device and waits for the driver to go idle before it injects the failure, and requires that the dispatch armed exactly one HTILE clear before its batch failed. ArmedHtileDepthClearCount counts the clears armed at registration on every host.
|
The new Setup: Windows 11 Pro, NVIDIA GeForce RTX 5070 Ti, driver 621.01, WinLibs GCC 15.2.0 r7 UCRT, Release,
Output, identical in every run: So the AI-assisted: yes |
|
@hamdanpor-ctrl @tablefrogpillow @rth9z thanks for the hardware runs. You were right, and @hamdanpor-ctrl's trace pinned the cause: the test, not the driver, was wrong on real GPUs.
Pushed
RTX 3080, driver 621.24, Windows 11, Khronos validation layer, 3 runs each:
The third column is the check that the test now catches the real-GPU failure; lavapipe can't show it. If you can rerun on the 3050, the 5070 Ti or RADV, that would confirm it on your hardware. AI-assisted: yes |
|
@chitters2004 confirmed on the RTX 5070 Ti with Head
AI-assisted: yes |
Keep both sides in Recorder and DepthSurface: the discard actions and the write-complete callbacks are separate batch hooks, and the HTILE clear counters sit next to the depth upload switch.
A native HTILE clear dispatch raised clearDispatchesPending on every matching depth surface when it was queued, and only completion lowered it. A batch discarded after queuing left the count raised for good, so a later completion never reached zero and clearCompletionQueued stayed set. Lowering it by address on discard would be wrong as well: a batch that threw before queuing would undo another batch's dispatch. Each dispatch now carries an HtileClearDispatch that records the surfaces its queue step counted. Completion and discard lower exactly those surfaces that still exist, so a batch that never queued undoes nothing. PendingHtileDepthClearDispatches reports the count. The discarded-arm case queues an earlier dispatch and a discarded one, checks one stays pending after the discard, that discarding an unqueued dispatch keeps it, and that completing it reaches zero. The driver discarded-dispatch case checks the count returns to its value before the failed batch. No decrement on discard fails both cases; an address-based decrement fails the unqueued check.
MarcZX10
left a comment
There was a problem hiding this comment.
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 5bbee1f81d90132f5e859099248148652d87905b using 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
| Check | Result | Note |
|---|---|---|
| Targeted code review | passed | Discard, sample restore, HTILE and submit failure paths inspected |
| Tests in this review | not run | PR-reported results only |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of core/libs/prx/libSceAgcDriver/tests/Recorder.cpp and core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp was excluded from the review folder; relevant changed ranges in VulkanDevice.cpp were 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 in QueueWorker.cpp, VulkanDevice.cpp, Recorder.hpp, Recorder.cpp, DepthSurface.cpp, Draw.cpp, DeferredCompletionFailure.cpp, DiscardedCopiedWriter.cpp, NativeMultisampleDepth.cpp, and agc_driver_native_multisample_depth_tests.cmake. Excluded by size: tests/Recorder.cpp and VulkanDevice.cpp full texts; the former's changed ranges were not read.
To get this to a good state
Nothing is required.
MarcZX10
left a comment
There was a problem hiding this comment.
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 7d815d97c84bd0bd3e4edae0832c00fb3146bd9d using the prepared diff and repo_read.py-backed reader. No tests or builds were run in this review.
Results
| Check | Result | Note |
|---|---|---|
| Patch and targeted source review | passed | Discard handling and affected call sites inspected |
| Build and tests | not run | Results in the description are author reported |
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.cpp and tests/Recorder.cpp (targeted ranges were read through repo_read.py); files listed in files.json were 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, and docs/dev/debt/libSceAgcDriver.md.
To get this to a good state
Nothing is required.
|
Ran the tests from the Tested section with the Khronos validation layer on Linux and an NVIDIA GPU, which CI does not cover. Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor
No new AI-assisted: yes (Claude Code) |
VulkanDevice recordDispatch: keep this branch's discard-undone HTILE clear arming with main's MarkGpuWrites(recorder, record.bindings.get()).
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this change; I reviewed the discard cleanup and its tests at head aa4974be6e39b393cf0810fb17ea19a2b104e110 and 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
| Check | Result | Note |
|---|---|---|
| Diff and changed code | passed | Targeted review completed |
| Tests | not run | Author-reported runs only |
| Build | not run | No build performed |
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.cpp was 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), and docs/dev/debt/libSceAgcDriver.md (diff). Excluded from full-text review: VulkanDevice.cpp and tests/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.
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 6786420, 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.tools/check_conventions.py --base origin/main: passes.Original run (base 1d1ff11), Linux, llvmpipe (Mesa 25.2.8, LLVM 20.1.2). No title; these paths are only reachable through a failed submission, which
Recorder::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 1d1ff11 vs 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 fix(agc): read polled guest labels with acquire loads #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