perf(agc): leave a capture's branch over a pending GPU write unpruned instead of waiting #12616
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12616"
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 Raghav314 on 2026-10-28T23:02:41Z.
What
A dispatch's resource capture prunes the untaken side of a scalar branch by evaluating the branch condition on the CPU. When the condition word has a pending GPU write (typically a flag in a constant buffer that the previous compute dispatch wrote),
ShaderMemorywaits for that GPU work before it can read the word.Changes:
SrtEvaluatingBranch()is a thread-local flag.SrtBranchScopesets it around the branch-condition evaluation in both SRT walkers (SrtDescriptorEvaluation.cppandSrtTape.cpp), and only there.ShaderMemory::readdoes not wait for a word-wise word whose pending write needs a sync; it reports the read as unavailable instead. The walkers already treat an unreadable condition as not cleanly evaluable and keep both successors, so the capture becomes a superset: it includes the resources of both sides, and the GPU shader still evaluates the real branch.runtime image descriptor is invalid. When a capture that refused a branch read throws,ShaderMemory::Captureredoes it once with waiting on, which is exactly main's behaviour.APS5_WAIT_PENDING_BRANCHESrestores waiting, with a row indocs/dev/ENVIRONMENT.md.[capture]line (APS5_PROFILE_DRAW) counts refused branch reads and redone captures.SrtEvaluatingBranchis added to the shader disk cache's reviewed names. It does not change compiled output.Why
In the
APS5_PROFILE_DRAWdiagnostic runs, main's capture waited word by word for 4,927 words, 8.77 s per 90 s. Every one of those waits was a branch-condition read; a diagnostic build classified each waited word by consumer, and only branch was non-zero. With the change, those waits are 0, and about 8,700 branch-condition reads per 90 s leave their branch unpruned instead. Capture time fell from 12.5 s to 4.2 s.Tested
Performance
Minecraft Dungeons II (PPSA16064, gameplay, same spot), RTX 4090, 3840x2160, warm caches. The runs alternated main, change, main, change, main, change in one session.
APS5_TRACE_SECONDS=50:8was the only switch.Driver.Packet.dispatchms/frameDriver.Packet.memory_waitms/frame319621ba2e5c4323035f319621ba2e5c4323035f319621ba2e7a13a20b84Driver.Packet.dispatchfalls by about 6 ms per frame in every pair (41.6–41.8 → 35.2–36.1), andDriver.Dispatch.capture_resources(11.8 ms per frame on main) leaves the top slices.Driver.Packet.pipeline_draingrows.Notes:
sceHttp2SetResolveRetry("not implemented", the new nghttp2 libSceHttp2). Both arms used the same olderlibSceHttp2.prxso they could reach gameplay; that library is not on the graphics path.Traces (release assets on the fork):
Summary lines
trace_digest: main (CM3)
seconds 50:8 from present 1847: 142 presents, frame p50 55.5 / p90 58.4 / p99 86.7 / max 87.6 ms, GPU busy 38.4 ms per present
NVIDIA GeForce RTX 4090, NVIDIA 615.78.08, Linux 7.3.0-3-cachyos, 3840x2160, commit
319621ba2e, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 105.3, Driver.Packet.dispatch 41.7, Driver.Dispatch 40.1, batch 38.4, Driver.Packet.memory_wait 35.0, Vulkan.Dispatch 14.6, Vulkan.Dispatch.shader_resources 12.8, Driver.Packet.pipeline_drain 12.2, Driver.Dispatch.capture_resources 11.8, Driver.Packet.draw 10.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest: change (CF1)
seconds 50:8 from present 1850: 143 presents, frame p50 55.5 / p90 58.1 / p99 87.2 / max 91.6 ms, GPU busy 39.4 ms per present
NVIDIA GeForce RTX 4090, NVIDIA 615.78.08, Linux 7.3.0-3-cachyos, 3840x2160, commit
7a13a20b84, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 105.5, batch 39.4, Driver.Packet.dispatch 36.1, Driver.Dispatch 35.0, Driver.Packet.memory_wait 30.9, Driver.Packet.pipeline_drain 17.1, Vulkan.Dispatch 11.9, Driver.Packet.draw 10.6, Driver.Draw 10.5, Vulkan.Dispatch.shader_resources 10.0
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Tests
New
verifyPendingBranchLeftUnpruned(recompiler walkers): a condition read inside the branch scope that cannot be read keeps both successors, the tape walk and the tree walk agree, and the scope is closed afterwards.New
verifyPendingBranchCapture(ShaderMemory): the flag is loaded withs_buffer_loadfrom a constant buffer that has a pending Sync write. The test checks three cases:It fails with
APS5_WAIT_PENDING_BRANCHES=1and fails with the redo removed.Focused ctest (
agc_shader_memory|srt|capture|agc_driver_dispatch|agc_driver_pipelined|agc_driver_storage|agc_driver_copied|wait|recompiler_plan) passed 117/117 on main and on the change, in both default andAPS5_GPU_HEAP=1modes. The runs usedANYPS5_NO_SHADER_CACHE=1andVK_LAYER_KHRONOS_validationand logged noVUID-lines.tools/check_conventions.py --base origin/mainandtools/env_reference.py --checkboth pass.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)Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:49:45Z.
Review: COMMENTED
The Minecraft Dungeons II table is the right kind of evidence, and the idea of not stalling the capture on a word that is only a branch condition is reasonable. Some points on what the unpruned superset costs, which the table does not show.
Superset capture changes what is compiled. With the refused read, both successors of the branch stay in the capture, so the
ResourceCapturefor a given shader can now contain descriptors the pruned walk would have dropped. Does that feed the pipeline or shader key? If it does, the same shader can produce a different key depending on whether the flag word happened to have a pending GPU write at capture time, so the same draw can compile twice and the disk cache grows with both variants. Please state whether the key is built from the pruned or the unpruned capture, and show the shader compile count and shader cache size on main versus the change for the same scene.captureWaitingOnFailureretries on anystd::exception. The retry is guarded only bybranchReadsRefused != 0, not by the kind of failure. A failure that has nothing to do with the dropped pruning (for example a genuinely unreadable page) now runs the whole capture twice before it surfaces, and the first failure is discarded without a log line. Either narrow the catch to the descriptor-validity failures the description names, or log the first error. ThebranchCapturesRedonecounter only exists underAPS5_PROFILE_DRAW, so a title that redoes every capture would not be visible in a normal trace.The superset can reach memory the real branch never reads. The description covers an invalid T# that throws. It does not cover a descriptor that is valid-looking but stale, or one that points at memory that is only mapped on the taken side. Those are captured, bound and barriered for nothing. Is there a bound on how many extra resources a capture can pick up, and has anyone counted them on the title used for the measurement?
Evidence beyond one title. The performance rows come from one title on one GPU. The capture time figure (12.5 s to 4.2 s) comes from
APS5_PROFILE_DRAWdiagnostics, which are not accepted as the speed claim on their own. Thetools/trace_digest.pysummaries of main and the change from the same session are what carry it; please attach those summaries explicitly rather than the table alone. The comment from Tamalero shows no change on Marvel's Guardians of the Galaxy; that is a useful negative result and should be in the description with the claim scoped to titles that have flags written by the previous dispatch.Negative control for the new test.
verifyPendingBranchLeftUnprunedshows the branch is left unpruned with the refusal. Is there a case in the same test that fails if theSrtBranchScopeis also active around a non-branch read (the flat-slot case in the description that must still wait)? That is the case that would turn this into a wrong-data bug, and it is the one I would want pinned.