perf(shader): don't wait on GPU-pending branch words that only select read-only buffers #7891
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7891"
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 eljackjoestar-cmd on 2026-10-19T12:35:07Z.
What
A resource capture walks the control flow of a shader's resource plan and evaluates each branch condition with reads that wait for pending GPU writes (
SrtRuntime::pendingWrite). When a condition reads a word that a queued dispatch still writes, the capture waits for the GPU, although the branch only selects which descriptors are bound.ConditionSelectsResources) is no longer evaluated; the walk takes both successors, which bind the same resources.ConditionGuardsImagesOrWrites). An extra read-only buffer binding does not change what the shader reads.EvaluateRuntimeSourcesImpl).SrtTapeand the generic evaluator apply the same rule. A first version took both sides of every condition over a pending word. On PPSA28099 it made the water flicker with red, green and white flares (bursts in a run with a frame dump every third flip). A version that kept the condition exact only when the guarded blocks write showed no flare frame in a run with the same dumps. This version is stricter: it also keeps the condition exact for every image.New checks in
verifyGuardedDescriptorSources(agc_shader_memory):Tested
Windows 11 Pro 26300, Ryzen 7 7800X3D, NVIDIA GeForce RTX 5070 (driver 617.14), WinLibs GCC 15.2 UCRT, Release.
Focused tests. Run on
main676269473and on this branch, same machine, withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -R <pattern> -V.was not found but was requested by env var VK_INSTANCE_LAYERS.agc_driver_indirect_arguments_pending_producer:VUID-vkCmdWaitEvents-srcStageMask-01158andVUID-vkSetEvent-event-09543. This change adds none.The 63 focused tests (same set on main and the change)
agc_command_batch_fence_failure,agc_compute_descriptor_layout_flags,agc_copy_input_kept_bytes,agc_dcc_key_sharing,agc_depth_copy_kept_bytes,agc_descriptor_cache,agc_descriptor_pool_reset_failure,agc_display_buffer_dcc,agc_driver_address_space_teardown,agc_driver_alpha_to_coverage_state,agc_driver_buffer_descriptor_runtime,agc_driver_covered_centroid_state,agc_driver_dcc_key_presync,agc_driver_dcc_keys_first_write,agc_driver_fill_cover_keys,agc_driver_gpu_indirect_arguments_misaligned_writer_ahead,agc_driver_gpu_indirect_arguments_written_ahead,agc_driver_graphics,agc_driver_guarded_null_pointer,agc_driver_indirect_arguments_pending_producer,agc_driver_indirect_arguments_written_ahead,agc_driver_indirect_patched_stage,agc_driver_memory_value_fill,agc_driver_mesh,agc_driver_mesh_draw_relocation,agc_driver_mesh_index_cache,agc_driver_mesh_provoking_layer,agc_driver_mesh_provoking_vertex,agc_driver_msaa_dcc_state,agc_driver_rect_list_indirect,agc_driver_sample_location_grid_fallback,agc_driver_sparse_indirect_indices,agc_driver_sparse_indirect_indices_unreadable,agc_driver_staged_clear_sampled_read,agc_driver_undithered_alpha_to_coverage_state,agc_driver_unused_viewport_depth,agc_heap_mirror_run_unwatch,agc_heap_mirror_run_unwatch_no_space_cache,agc_heap_mirror_unwatch,agc_heap_mirror_unwatch_no_space_cache,agc_pipeline_journal,agc_pipeline_library_clear_waits_for_build,agc_pipeline_store_lazy_buffer_pool,agc_shader_bindless,agc_shader_entry_lane_proof_budget,agc_shader_frontend_pair,agc_shader_frontend_pair_off,agc_shader_layout_pair,agc_shader_layout_pair_off,agc_shader_memory,agc_shader_quad_mask_no_demote,agc_shader_selected_records_direct_image_limit,agc_shader_selected_records_direct_pair_limit,agc_shader_selected_records_image_limit,agc_shader_selected_records_pair_limit,agc_shader_srt_read_patching,agc_shader_table_snapshot_reuse,agc_shader_type_zero_image_materialization,agc_sparse_buffer_holes,agc_sparse_heap_mirror_unwatch,agc_sparse_heap_mirror_unwatch_no_space_cache,agc_write_tracking,agc_write_watch_coveragePerformance. PPSA28099 start screen ("Press any button to continue"), 3840x2160.
maincannot run this title: at676269473it stops at boot withindirect register sentinel semantics are not implemented(Execution/src/Pm4.cpp:47). The captures below use the base the title runs on: maina62c724c3with #6094 and #6160 (both merged since), #6146, #6366 and #7644, commit b3d5d03d6.b3d5d03d6d13. The base lines have"dirty":falseand the change lines"dirty":true.APS5_TRACE_SUMMARY_EVERY=10,APS5_LAZY_SHADER_PREPARE=1andAPS5_NO_PAD_INPUT=1, a warm shader cache, and no otherAPS5_TRACE_*orAPS5_PROFILE_*switch. Only interval summary lines were written; there is no trace file to attach.This version was not captured on its own: strict-1 also holds the non-indexed mesh indirect change and the DCC key extent fix (separate PRs). Its build chose this rule through a temporary switch,
APS5_DEBUG_STRICT_UNION=1in its lines, which is not part of this PR. The first version gained 2.7 % on average over the base; strict-1 gained 7.6 %.tools/trace_digest.py, base (ctl-2)
17 intervals, 0.0 to 179.1 s, 416 presents
NVIDIA GeForce RTX 5070, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit b3d5d03d6d13
tools/trace_digest.py, first version (srt-2)
17 intervals, 0.0 to 175.9 s, 408 presents
NVIDIA GeForce RTX 5070, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit b3d5d03d6d13 (dirty)
tools/trace_digest.py, this change + mesh indirect + DCC extent (strict-1)
16 intervals, 0.0 to 177.5 s, 375 presents
NVIDIA GeForce RTX 5070, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit b3d5d03d6d13 (dirty)
The raw
aps5-summary.jsonllines of the 90-155 s window for every run above are in the two comments below.Overlap.
tools/pr_overlap.py --branchfinds no open PR that changes the same lines. It lists PRs that conflict withmainand share files. On the SRT walker these are #1341, #5609, #6539, #6947 and #7642; none of them changes how branch conditions are evaluated.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 github-actions[bot] on 2026-10-19T12:35:21Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by eljackjoestar-cmd on 2026-10-19T12:36:46Z.
Raw
aps5-summary.jsonllines of the 90-155 s window, base (ctl-1, ctl-2):ctl-1ctl-2Imported from boykopovar/AnyPS5. Originally posted by eljackjoestar-cmd on 2026-10-19T12:38:10Z.
Raw
aps5-summary.jsonllines of the 90-155 s window, first version of this change (srt-1, srt-2) and this change + mesh indirect + DCC extent (strict-1):srt-1srt-2strict-1Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T12:48:21Z.
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.
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtEvaluator.hppcore/shader/recompiler/Optimization/src/SrtWalker/SrtDescriptorEvaluation.cppcore/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtEvaluator.hppcore/shader/recompiler/Optimization/src/SrtWalker/SrtDescriptorEvaluation.cppcore/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/include/Optimization/SrtWalker.hppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/include/Optimization/SrtWalker.hppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/SrtWalker/SrtDescriptorEvaluation.cppcore/shader/recompiler/Optimization/src/SrtWalker/SrtTape.cppImported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-19T17:50:58Z.
Review: COMMENTED
The idea is sound (a branch that only selects which read-only buffer to bind needn't wait for the GPU), the strictness after the water-flare incident is the right call, and the four new checks cover the rule's edges. Three gaps.
strict-1, 2.98 fps against 2.76 and 2.78 for the base) also carries the non-indexed mesh indirect PR and the DCC extent PR, and its rule is chosen through a temporaryAPS5_DEBUG_STRICT_UNIONswitch that isn't in the PR. The first version "gained 2.7%" and was rejected, so the +7.6% belongs to the mix. Please capture base against base plus this PR alone, interleaved, same scene; at 2.8 fps on a start screen the window needs to be much longer than 90-155 s to resolve a few percent. GPU busy per present barely moves (254-259 ms to 250 ms), so the saving is CPU wait; say which phase shrinks (Driver.Packet.memory_wait?) with the numbers.Smaller:
EvaluateRuntimeSourcesImplredoes a walk that failed without waiting, "after rolling back the read trace and user-data use it recorded". A rollback bug leaves a stale trace on the second walk and the draw-cache key wrong. Say which test fails when the rollback is removed.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T18:02:32Z.
Review: CHANGES_REQUESTED
Checked the diff and
ShaderMemory::pending(the probe has no side effects, so refusing a read costs nothing). The rule is coherent and the stricter version after the flare is the right shape. What is missing:strict-1also carries the mesh indirect and DCC extent PRs and the temporaryAPS5_DEBUG_STRICT_UNIONswitch. Theperflabel asks for base vs this PR alone on the same scene; at ~2.8 fps the window must be much longer than 90-155 s, runs interleaved. GPU busy barely moves, so say which CPU phase shrinks (e.g. memory wait) with numbers.ConditionSelectsResourceshas no test. None of the four new checks reaches the "both successors reach the same frontier, condition not evaluated" path (SrtDescriptorEvaluation.cppline 109,SrtTape.cppline 56). Add a plan where that holds and a condition read that would otherwise be wrong or pending, and check that both the generic evaluator andSrtTapeskip it.EvaluateRuntimeSourcesImpl(lines 356-373) is untested. Add a case where the refusing walk fails and the waiting redo must give the same result, trace anduserDataUseas a plain waiting walk; it should fail if theresizecalls are removed.Linux/lavapipe was not run by the author; the full Build covers it.
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-20T04:07:31Z.
Independent Windows validation of the equivalent-resource-frontier test requested by @adriadam10. The test-only addition is 68b7138, on a clean composition of this PR's
0f2d297fhead with main525e299f(b88cbeea). Attribution and the original PR history are retained.The new synthetic diamond plan has a runtime-evaluable scalar-address condition and two successors reaching the same descriptor. Its memory reader refuses reads, and cases configure the pending-probe callback to report false or true. Both the generic evaluator and tape must capture the descriptor without reading or probing the condition, or recording it in the read trace/user-data use. A separate tape-only invocation allows its failure to be checked independently.
an irrelevant condition was read or probed(three repetitions each of the generic-leading and tape-only cases).agc_driver_mesh,agc_driver_guarded_null_pointer,agc_driver_draw_cache_reuse, three repetitions each: 9/9 pass per side. Required Vulkan, shader cache disabled, loaded Khronos validation layer, actual RTX 5080 / driver 610.62 / Windows 11 Enterprise 26200. Both sides have zero validation errors/VUIDs and the same nine shader-output-not-consumed warnings in draw-cache reuse.Conventions pass. Cppcheck and clang-tidy completed with no diagnostics on the new test lines; the translation unit still has inherited findings, including the borrowed
Regions()spans already tracked by #7754/#7759. This frontier case does not callRegions().This supplies a focused test for the equivalent-frontier rule. The performance, rollback, invalid untaken V#, and dispatch/draw image-selection review requests remain open. GPU coverage here is NVIDIA only; Linux/AMD and title behavior were not validated by this comparison. AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by CPritch on 2026-10-20T07:26:47Z.
Ran this on GTA V (PPSA04263 01.010.002), Linux 7.2.8-zen1-2-zen, NVIDIA GeForce RTX 5060 Laptop GPU, NVIDIA 615.71.09, Graphics Mode Performance, the Story prologue after Resume Story, with no input.
main
eaa5c9238against maineaa5c9238+ #7891 at0f2d297f5, same machine and session, two runs each in the order A B A B, window frames 3500:700, caches warm, APS5_TRACE_EVENTS=4194304 (BUILD.md's remedy for full trace buffers), no other APS5_TRACE_* or APS5_PROFILE_* switch, log not redirected. The harness navigates the menus from frame dumps in boot and load to present 3300 (APS5_DUMP_FRAMES=110, every 30 presents), which stop before the window.Frame p50: main 80.5, 81.2 ms, with #7891 81.4, 81.4 ms (+0.6 ms, +0.7 %). GPU busy per present: 64.6 and 64.3 ms.
p90: main 90.2, 89.4 ms, with #7891 93.8, 94.4 ms; p99: main 107.5, 113.1 ms, with #7891 134.2, 146.7 ms. Queue 0's Driver.Draw went up by 2.6 and 3.2 ms per frame (tools/performance_compare.py).
Not tested: other scenes, Fidelity mode, other GPUs.
Written with AI assistance (Claude Code); measured on the machine above.
Summary lines (main, then the PR):
{"commit":"eaa5c9238687","dirty":false,"env":{"APS5_DUMP_FRAMES":"110","APS5_DUMP_FRAMES_EVERY":"30","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"","APS5_TRACE_EVENTS":"4194304","APS5_TRACE_FRAMES":"3500:700"},"gpu":"NVIDIA GeForce RTX 5060 Laptop GPU","driver":"NVIDIA 615.71.09","os":"Linux 7.2.8-zen1-2-zen","resolution":"3840x2160","window":{"spec":"frames 3500:700","first_present":3500,"ms":57363.452},"presents":700,"frame_ms":{"p50":80.501,"p90":90.214,"p99":107.534,"max":138.909},"gpu_busy_ms_per_present":64.175,"worker_busy_pct":{"queue worker 0x0":3680.742},"top_phases_ms_per_frame":{"Driver.EndSubmission":2951.239,"Driver.Packet":62.787,"Graphics.Draw":60.008,"Graphics.Draw.draw_and_resource_release":56.422,"Driver.Packet.draw":49.69,"Driver.Draw":49.474,"VideoOut.Flip":25.695,"Driver.Present":25.68},"trace_dropped":false,"trace":"aps5-trace-eaa5c9238687-1343642.json.gz"}
{"commit":"6e54a939396a","dirty":false,"env":{"APS5_DUMP_FRAMES":"110","APS5_DUMP_FRAMES_EVERY":"30","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"","APS5_TRACE_EVENTS":"4194304","APS5_TRACE_FRAMES":"3500:700"},"gpu":"NVIDIA GeForce RTX 5060 Laptop GPU","driver":"NVIDIA 615.71.09","os":"Linux 7.2.8-zen1-2-zen","resolution":"3840x2160","window":{"spec":"frames 3500:700","first_present":3500,"ms":58798.206},"presents":700,"frame_ms":{"p50":81.412,"p90":93.759,"p99":134.227,"max":163.259},"gpu_busy_ms_per_present":64.142,"worker_busy_pct":{"queue worker 0x0":3697.151},"top_phases_ms_per_frame":{"Driver.EndSubmission":3037.375,"Driver.Packet":65.775,"Graphics.Draw":61.13,"Graphics.Draw.draw_and_resource_release":57.173,"Driver.Packet.draw":52.316,"Driver.Draw":52.081,"VideoOut.Flip":25.122,"Driver.Present":25.107},"trace_dropped":false,"trace":"aps5-trace-6e54a939396a-1351612.json.gz"}
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-20T10:00:09Z.
There is a new integration consideration with #8295 / #8272, separate from my earlier equivalent-frontier validation at this PR's
0f2d297f53be23a0d880fc4532508ac752d3d966head.#8295 adds
ResourceBlock.flatSlotsso a known branch can exclude a direct-root scalar load from capture. At this head,ResourceFrontierstops only for a condition, descriptor sources or images;BlockNeedsExactConditionalso ignores flat slots. A block containing only such a scalar load can therefore be treated as empty. If the successor frontiers then compare equal, both evaluators skip the condition and visit both successors, activating the unreachable flat load again.Please account for flat-slot uses in the frontier and exact-condition decisions when combining these changes. The direct-root regression, now included in #8295 at
d739a4167ced06b1eece610cfe47e0f33edfffd8, provides a starting case: mapped/taken and mapped/skipped outputs succeed, invalid/taken is refused, and the same invalid/skipped pointer must not be read. Cover both generic and tape evaluation, including a pending condition.This is a public-source review of the interaction between two unmerged changes, not a reported runtime failure of this PR alone or a completed combined-branch test. My earlier validation keeps its original pins. AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-20T16:59:22Z.
First Linux run of this PR, on AMD with RADV. Head
0f2d297f5merged ontomain6bef96df7(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8) atfd6916d8d: 1712/1713 with this PR, against 1712/1713 onmain. The one failure is the same on both, so this PR adds none:agc_driver_guest_memory_lifetime(#7784).Comparing the JUnit output with
main: this PR adds no ctest entry, and none is skipped or removed.This checks correctness only; I did not measure performance.
GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-20T23:55:58Z.
Review: COMMENTED
@CPritch's GTA V pair is the only isolated A/B this PR has so far, and it points the wrong way: frame p50 +0.6 ms (80.5/81.2 to 81.4/81.4), p90 about +4 ms (90.2/89.4 to 93.8/94.4), p99 +27 to +33 ms (107.5/113.1 to 134.2/146.7), and queue 0's
Driver.Drawup 2.6 and 3.2 ms per frame. The Stray gain in the description (+7.6%) comes from the mixedstrict-1build with two other PRs, and the +2.7% from the first version, which was rejected for the flares.A rule that skips a GPU wait should make
Driver.Drawcheaper, not dearer. The likeliest reason for the extra time is the one in my review: binding both successors captures and imports buffers the taken branch would not have used, and in a scene with many such branches that is more work per draw than the wait it avoids. Please post, for GTA V and for Stray, the count of conditions skipped, the count of extra buffers bound because of them, and thememory_waittime saved, so the trade is visible. If the extra bindings cost more than the waits save, the rule needs a narrower condition (for example, only skip when the other successor's read-only buffers are already bound for this draw) or the PR doesn't pay for itself.Pull request closed