feat(agc): trace shader failures through draw submission batches #5431
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5431"
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 sktharunbalaji13-cmd on 2026-10-13T19:34:31Z.
What
Add opt-in diagnostic correlation across draw attempts, shader selection and preparation failures, actual draw-command recording, and recorder batch submission in the AGC driver.
Each draw attempt receives a correlation token. Relevant failure and recording events preserve that identity. Recorder batches collect a deduplicated set of the tokens associated with commands recorded in the batch, allowing one batch to represent multiple draws. Submission-attempt diagnostics are distinguished from confirmation records emitted only after successful queue submission and finalized required recorder bookkeeping. Diagnostic formatting and logging are bounded and best-effort to prevent trace failures from masking original exceptions or blocking otherwise valid submission.
Tested
Clean PR branch \eat/shader-draw-submission-correlation-5166-fresh, rebased on current \main\ (\
80249ea54).Checklist
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T19:38:01Z.
I inspected the failing conventions run. It reports 39 errors: inline comments in
CaptureTrace.hppare disallowed unless the PR also documents the associated technical debt underdocs/dev/TechnicalDebt.mdordocs/dev/debt/, and the PR description is missing the requiredWhat,Tested, andChecklistsections. Please address those findings and rerun the check; the current PR body has validation details, but they need to be placed under the required headings so the repository check can recognize them.I also compared this with #5238. Both PRs change
Execution/src/Driver/Draw/Draw.cppand thelibSceAgcDriverCMake target, while tracing different points in the draw path. Could you clarify how the two tracing mechanisms are intended to compose and whether one can reuse the other, so they do not add duplicate or conflicting instrumentation?Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-13T19:42:34Z.
Thank you for the review. The conventions findings are addressed in commit
6b5c7fbda03e9b9469e786b34d98a87dde438383: the non-technical-debt diagnostic comments were removed, the PR body now uses the required### What,### Tested, and### Checklistsections, andtools/check_conventions.pypasses locally against basedacd78525e537a779682032c0ace7f7af120af05. The GitHub conventions run subsequently passed.On composition with #5238: they are intended to be complementary. PR #5238 gives per-draw shader address information (stage, role, code/entry address, queue, submission context), which helps identify the selected program. This PR assigns a correlation token to each draw attempt and tracks whether the draw reaches selection, actual command recording, submission attempt, and successful queue submission; it also associates recorded draws with a deduplicated set of tokens per recorder batch. In practice, #5238 helps answer "which shader was selected?" while this PR helps answer "did that draw attempt survive setup and get recorded/submitted?"
Both PRs touch the same
Draw.cppand CMake target, so their merge order will matter. If #5238 lands first, this PR should adapt to its address-formatting and per-draw structures rather than duplicating them. I avoided copying or renaming its address-formatting implementation; the remaining overlap is in the shared Draw/composition points where both may hook logging. They do not need to emit duplicate records for the same event, but some reconciliation at those shared points is likely during integration.No runtime/game validation is claimed yet, and the platform build jobs remain skipped for this PR.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T19:42:43Z.
Thanks, that addresses both points. The distinction between identifying the selected shader and tracking a draw attempt through recording/submission is clear, and your note about reconciling the shared Draw hooks if #5238 lands first gives a workable integration plan. I verified the new conventions check passes; the platform build jobs remain skipped for this path. No runtime validation is claimed.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:09:43Z.
Review: COMMENTED
Checked the cost with the trace off: the token is 0 and
NoteDrawTraceTokenreturns at once, so the disabled path stays cheap. Two points about the enabled path and the scope:NoteDrawTraceTokenis quadratic per batch. It runsstd::findoveropen->drawTraceTokensfor every recorded draw. A batch holding a few thousand draws (common in a busy frame) then does millions of comparisons on the queue worker, under the recorder's open-batch state, while the trace measures that same worker. That distorts the timings the correlation is meant to explain. The tokens come from a counter, so a draw's commands are recorded contiguously and the token can only repeat back to back. Comparing againstback()gives the same dedup in O(1). If tokens can interleave, anunordered_setbeside the vector also works.Driver::materializeDrawStage(27 parameters, several of them out-parameters) changes the hottest function in the driver as part of a diagnostics PR. It may well be behaviour-neutral, but reviewers have to verify that across ~200 lines, and it conflicts with every other open PR that touchesDriver::draw(#5238 already). Keeping the token as one extra argument through the existing code, and leaving the restructure to its ownrefactor(agc)PR, would make both easier to review.Minor: the
catch (...) {}inNoteDrawTraceTokenhides allocation failures. In a diagnostics path, losing a token silently makes the trace look complete when it isn't. Letting it throw, or counting the drops in the trace, is safer.Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-14T04:18:43Z.
Thank you for the detailed review. I’ve addressed the three points in commit
2c3502d01f902b3cd6de2a67f658d68b35bf1389.A. Token deduplication
NoteDrawTraceTokennow uses an accompanyingstd::unordered_setbeside the existing ordered token vector. A token is pushed only when the set insert succeeds, so dedup is O(1) average instead of O(batch size) per recorded draw, duplicates still cannot repeat in the vector, and ordering is unchanged. The side set is also rolled back if the vector append throws, so a failed append does not leave later recording unable to reintroduce that token.B. Scope of the draw-path change
The PR mainly adds parameters rather than introducing a broad new draw refactor. The existing
Driver::materializeDrawStagehelper was already present upstream; PR #5431 threadedpacketOffsetand the correlation token through it and throughDriver::drawso materialization/decode failures can preserve correlation identity. The materialization calls and try/catch wrappers are the instrumentation path, and they keep the original early-return behavior. If this second parameter pass is still judged too broad after review, I can split it into arefactor(agc)preparatory change, but it currently supports the request/materialization failure records described in the PR.C. Silent allocation failures
The previous empty catch now emits
draw-token-note-failed token=...through the best-effort logging path, so dropped correlation data is observable rather than indistinguishable from a complete trace. As before, this cannot throw past the call site, append to the reordered token list before success, or blockQueueSubmit/draw success.Validation
core/libs/libs/libSceAgcDriver.prxand NID patching.git diff --check: passed.conventions,eligibility, andreportpassed; platform jobs remained skipped, as in the earlier runs.#5238 overlap
I compared the overlap with PR #5238. It remains complementary: #5238 exposes per-draw shader address/context details, while this PR adds token lifecycle and submission-batch correlation. If #5238 lands first, this PR should adapt to its address formatting rather than duplicating it. No changes were made to #5238's branch.
No claim of GPU/game-runtime validation is made.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:43:07Z.
Review: CHANGES_REQUESTED
Thanks for the quick follow-ups on the dedup and the empty
catch. Blocking points:mainin code, not just adjacency:Execution/src/Driver/Draw/Draw.cppandDraw/DrawCapture.cpp(main's73a808e9achanged how draw stages use their shared compiled result).Driver::materializeDrawStagehas to be redone on top of that code, and the draw tests rerun after the rebase.Driver::materializeDrawStage(27 parameters, several out-parameters) rewrites the hottest function in the driver, and it is the part that conflicts with #5238, #5364, #5441, #5609 and #5656. Send that as its ownrefactor(agc)PR that is behaviour-neutral and has its own tests; then keep this PR to the token passed as one extra argument through the existing code.Welcome back once it is rebased and the refactor is separated.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T14:40:42Z.
Review: CHANGES_REQUESTED
Thanks for the rebase. Re-checked on the head merged onto current
main; the conflict and thematerializeDrawStagesplit points are resolved (main already has that function). Blocking points left:libSceAgcDriveron the merged tree):agc_driver_draw_shader_failure("the capture trace received no draw-shader-request-failed record", log showsunsupported SOP1 opcode 2),agc_driver_draw_shader_failure_successful, andagc_driver_draw_shader_failure_request_correlation_disabled("driver shutdown failed unexpectedly"). Theagc_capture_trace_*tests pass. Please run them against a rebase on currentmainand fix whatever changed under them.Welcome back once the tests pass on the rebased head.
Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-18T07:25:25Z.
Rebased cleanly on current \main\ (\
80249ea54) and resolved all conflicts.All 14 unit tests in \libSceAgcDriver\ now pass 100%:
Test fixture adjustments:
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-18T16:33:34Z.
Review: CHANGES_REQUESTED
Re-checked the new head against our last comment: the tests point and the PPSA02225 claim are both resolved (claim dropped), and conventions pass. One blocking point left:
DrawPipeline.cpp:78:if (stopped) return;inEnqueueis unrelated to tracing and hides a fatal failure. Once a commit fails fatally the worker setsstopped = trueand storesfailure; before this change the nextEnqueuecalledrethrowFailure()and surfaced it to the submitting packet. With the early return, draws are dropped silently andfailureis never rethrown. Please remove it. If a test needs a clean shutdown after a fatal failure, make the test handle that (or send it as a separate PR with a test that fails without it).Lifecycle.cpp:10adds an include ofDrawPipeline.hppthatLifecycle.cpp:5already has; drop it.Welcome back once the early return is gone and the tests still pass.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-18T19:58:25Z.
Review: CHANGES_REQUESTED
The merge queue's Linux Build run on the current head (run 39157472408, PR merged onto main) fails four of this PR's own tests, deterministically:
agc_driver_draw_shader_failure_successful,agc_driver_draw_shader_failure_correlation_disabled,agc_driver_draw_shader_failure_materialization,agc_driver_draw_shader_failure_materialization_correlation_disabled.[gpu] driver failure: AGC driver: guest memory has no write permission(the colour-target writability check atGraphics/src/Draw.cpp:2566) andAGC graphics: the submission failure lost the original shader-request error. The first test and therequest_correlation_disabledone pass, so it looks tied to submitting further draws into the sameColorMemoryafter an earlier one in the process.Please rebase on current
main, runctest -R agc_driver_draw_shader_failure(Linux/lavapipe if you can, or check the Windows run too) and make the tests independent of each other, e.g. a fresh writable colour buffer per case, or find why the buffer loses write permission. (agc_driver_depth_bias_per_facealso fails in that run but is not caused by this PR.)Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-19T04:42:49Z.
Rebased on current \main\ (\
676d423968) and resolved the test failures:Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T05:39:29Z.
Review: CHANGES_REQUESTED
The Windows Build of the current head fails to compile (run 39202586561):
Execution/src/Driver/Draw/DrawCapture.cpp:105:error: binding reference of type 'ShaderRecompiler::PreparedShaderInvocation&' to 'const ShaderRecompiler::PreparedShaderInvocation' discards qualifiers. The PR declaresconst auto invocation = [&] {...}();(line 76) and passes it toCaptureInvocation(..., PreparedShaderInvocation& invocation)(ShaderRegistry.hpp:221); onmainit isauto invocation. Dropping theconstfixes it.main,agc_driver_depth_bias_per_facefails on lavapipe (the driver CI's Linux job uses) and passes onmain. Please rebase, rerun thelibSceAgcDrivertests on lavapipe and check whether your changes to the draw/recorder path affect it.Please push both and the Build will be re-run.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T01:14:23Z.
Review: CHANGES_REQUESTED
No push since our last comment, and the head no longer applies to
main:Execution/src/Driver/Draw/DrawCapture.cpp:76declaresconst auto invocation, and:105passes it toCaptureInvocation(..., PreparedShaderInvocation&). Onmainit isauto invocation; dropping theconstfixes it (run 39202586561).main, not adjacency:Execution/src/Driver/Draw/Draw.cpp(9 hunks),Execution/include/Driver/Driver.hpp,Execution/include/VulkanDevice.hpp,Execution/src/Driver/Draw/DrawCapture.cpp,Graphics/src/Draw.cppandGraphics/include/Draw.hpp.mainhas since moved the draw path intoDrawTail/finishDrawand changedmaterializeDrawStage's signature, so the correlation token has to be threaded through that new structure. That is a design decision for you, so we are not rebasing it for you.agc_driver_depth_bias_per_facefailed on lavapipe and passes onmain; please rerun thelibSceAgcDrivertests on lavapipe and check whether your draw/recorder changes affect it.Please rebase on current
main, fix the above and push; the Build will then run again.