Repository navigation
perf(shader): end dead code elimination when no released value is left dead - #7494
Conversation
…t dead DeadCodeEliminator::Eliminate repeated its pass over every block until a pass removed nothing, so each call that removed anything paid one more full pass that only confirmed the result. The pass walks the blocks backwards, so an instruction it already visited can only become dead when the removal of one of its users drops its last use. The pass now keeps the arguments of the instructions it removes and runs again only when one of them is still in a block, has no uses and has no side effects. Otherwise the next pass would have removed nothing. agc_ir_reclaim now checks that an unused phi and its input from a later block are both removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4b011bf to
0aab6c1
Compare
|
The title capture the AI-assisted: yes (Claude Code) |
|
Independent run, Windows. Host: Windows 11 Pro 26220, NVIDIA GeForce RTX 4070 driver 596.21, Ryzen 7 5700X, WinLibs MinGW-w64 GCC 15.2 r7, Release. This PR at
Not checked: a full build, the Written with Claude Code assistance (validation by a subagent, reviewed in this session). |
|
Thanks @screamm, the first Windows title runs of this one, and the identical cache entries and replay hashes are the right check for a bit-exact change. Added to the description. AI-assisted: yes (Claude Code) |
|
A second title for this one: Crimson Desert (PPSA25286), whose start-up is CPU-bound on preparing registered shaders. I dumped 6,065 of its registration requests as they were prepared, then replayed them with
That's 2.5 % less CPU for these requests. The prepared SPIR-V of the 152 requests is byte-identical to I also tried replacing the remaining rescans with a worklist over the removed instructions' operands. All 6,065 prepared modules and 458 recompiled MXGP and SMB3D modules came out identical, but it measured 16.11 s (16.04 to 16.20 s), no better than this PR. So I'm not proposing it: this PR already takes nearly all of the dead-code pass's cost here. AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
The termination check is sound for the reverse walk: removing an instruction can only make one of its operands newly dead, so the pass repeats only when a released operand still belongs to a block, has no uses and has no side effects. The new later-block phi regression exercises that exception, and the reported control fails when the recheck is removed. The replay reports byte-identical SPIR-V/output hashes across 419 produced modules, and the second title replay shows a small CPU-time reduction with overlapping ranges. The MXGP title capture is noisy and slower than all five main captures; the description appropriately makes no title-speed claim. Conventions, eligibility, labels and report pass; hosted product jobs are skipped. Current tools/pr_overlap.py reports no overlap across 1,105 open PRs. I did not run the tests locally. No blocking issue found; approved.
|
Thanks @MarcZX10 for the review, and for re-running AI-assisted: yes (Claude Code) |
|
Static review plus an independent Linux/AMD run on both trees per the repo AGENTS shader-recompiler protocol (CachyOS, kernel 7.2.10, GCC 16.2.1, Ninja 1.13.2, Release, What I checked
Focused paired run (VVL env)
Comparing logs, no new validation errors from this change. Not covered No benchmark measurement accompanies the perf claim (one confirmation pass saved per call that removed anything). That is a cheap self-evident win rather than a trace-visible one — repo AGENTS asks for |
|
@blawesom thanks for the review and the paired run. On the measurement: the description's Replay table has it. AI-assisted: yes (Claude Code) |
✅ NVIDIA GPU test: passedPR head
Intermittent validation messages (1, seen once in the parallel run, not reproduced when the test was re-run alone 2 times; not counted against this PR)Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (5, not counted against this PR)Passed on retry (1, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)Validation IDs already present on main (4 IDs in 404 tests)Skipped (39)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
Checked the new termination condition against |
What
DeadCodeEliminator::Eliminaterepeats a pass over every block until a pass removes nothing. So every call that removes anything pays one more full pass that only confirms the result.The pass walks the blocks and their instructions backwards. An instruction it has already visited can only become dead later in the pass when the removal of one of its users drops its last use. For a non-phi user, that argument is usually defined earlier and is still ahead in the walk. The exception is an argument the walk has already passed, such as a phi's input from a later block. Uses only shrink during the pass, and an instruction's side effects don't change.
The pass now keeps the arguments of the instructions it removes. It runs again only when one of them is still in a block, has no uses and has no side effects. If none is, nothing removable is left in the blocks, and the next pass would have removed nothing. When one is, the next pass runs as before. The set of removed instructions, the order of the instructions that remain, and so the SPIR-V are unchanged.
agc_ir_reclaimnow checks that an unused phi in the first block and its input in a later block are both removed. That passes onmain(in a second pass) and with this PR. With the recheck replaced bychanged = false, it fails with "the input of an eliminated phi from a later block was not eliminated".Tested
Ubuntu 24.04 (Linux 6.8), GCC 13.3, NVIDIA RTX 4070 Ti, driver 595.99.02.
ctest -R "^agc_|^shader_ir"on cb1d6e5: 709/709 pass (3 skipped: host import sparse, sparse dma-buf import, stencil ref export). After rebasing onto 9caecfd:agc_ir_reclaim,agc_masked_selectandagc_constant_phipass.agc_shader_replay --spv(Release,ANYPS5_ENABLE_SPIRV_TOOLSoff,ANYPS5_NO_SHADER_CACHE=1) on 420 shader requests I had dumped withAPS5_DUMP_SHADERS: 355 from MXGP 26 (PPSA30839, two dumps), 61 from PPSA31162 and 4 from another app. Onmaincb1d6e5 and with this PR, all 419.spvfiles that are produced have the same SHA-256, and the replay output is identical, including the one request that fails on both.Pass time, from a temporary timer and pass counter in
Eliminatethat are not part of this PR:mainmainIn the PPSA30839 requests, 334 passes beyond the first per call remain with this PR, for values that the walk had already passed. The largest shader's whole replay takes about 1.2 s of CPU time, so its gain is about 3.5% of that.
Title level: no speed claim. This is background shader preparation. I didn't run a title for it.
This is independent of #7431 (
PlanBuilder::PatchReads) and #7491 (MaskedSelectEliminator), which change other passes of the same shader preparation. #7491 callsEliminateafter rounds that remove a select.tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.pyreports no overlap with open pull requests.Title capture
As the
perflabel asks, these are captures of one title and scene on one machine. MXGP26 (PPSA30839) ran from boot withAPS5_TRACE_SECONDS=0:60,ANYPS5_NO_SHADER_CACHE=1and a fresh run directory (cold AnyPS5 and NVIDIA caches), so the shaders compile inside the window. NVIDIA RTX 4070 Ti (595.99.02), Ubuntu 24.04, release libs, Xvfb display, no input.maindbac9fa was captured five times: before the PR captures, after them, and three more times in a row after that. Each PR capture and the first twomaincaptures followed a rebuild of the release libraries; the last threemaincaptures did not, and they came out lower. The change ismainwith this PR merged on top as a local merge commit (da0ca697c5e9). The time is the wall time of theShader.PrepareArtifactslices on theshader preparethreads in each trace.main1main2main3main4main5The five
maincaptures span 17.7% in total prepare time, and the 13 prepare threads run in parallel with the title, so a title capture can't resolve a recompiler change of a few percent. The replay measurement above is this change's measurement. This PR's capture is above all fivemaincaptures in total prepare time. With one capture of the change I can't tell that apart from noise, and the replay measurement above points the other way. I can repeat the capture if that would help.main1 trace, digest,main2 trace, digest,main3 trace, digest,main4 trace, digest,main5 trace, digest, this PR trace, digest{"commit":"dbac9fa15b61","dirty":false,"env":{"APS5_TRACE_SECONDS":"0:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 595.99.02","os":"Linux 6.8.0-147-generic","resolution":"3840x2160","window":{"spec":"seconds 0:60","first_present":0,"ms":120148.301},"presents":194,"frame_ms":{"p50":16.686,"p90":32.765,"p99":2921.590,"max":112847.624},"gpu_busy_ms_per_present":6.483,"worker_busy_pct":{"queue worker 0x0":88.481,"queue worker 0x20":73.127},"top_phases_ms_per_frame":{"Driver.Packet":1000.862,"Driver.Packet.dispatch":503.561,"Driver.Dispatch":503.451,"Shader.PrepareArtifact":450.125,"Driver.Packet.memory_wait":424.003,"Vulkan.GraphicsPipeline":132.519,"Vulkan.GraphicsPipelineLibrary":126.497,"Vulkan.GraphicsPipelinePrebuild":77.312},"trace_dropped":false,"trace":"aps5-trace-dbac9fa15b61-3.json.gz"} {"commit":"da0ca697c5e9","dirty":false,"env":{"APS5_TRACE_SECONDS":"0:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 595.99.02","os":"Linux 6.8.0-147-generic","resolution":"3840x2160","window":{"spec":"seconds 0:60","first_present":0,"ms":117333.848},"presents":187,"frame_ms":{"p50":16.709,"p90":31.588,"p99":2098.845,"max":110882.020},"gpu_busy_ms_per_present":4.954,"worker_busy_pct":{"queue worker 0x0":88.094,"queue worker 0x20":71.639},"top_phases_ms_per_frame":{"Driver.Packet":1002.245,"Driver.Packet.dispatch":509.476,"Driver.Dispatch":509.370,"Shader.PrepareArtifact":509.078,"Driver.Packet.memory_wait":419.504,"Vulkan.GraphicsPipeline":125.361,"Vulkan.GraphicsPipelineLibrary":119.275,"Vulkan.GraphicsPipelinePrebuild":72.435},"trace_dropped":false,"trace":"aps5-trace-da0ca697c5e9-3.json.gz"}VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -R '^agc_' -Vonmaine2a2914 and onmain+ this PR (0aab6c1, a local merge).main: 815 of 815 pass. With this PR, 814 of 815 pass:agc_storage_written_buffer_orderaborted in the dynamic loader before the test began (Inconsistency detected by ld.so: ... elf_machine_rela_relative: Assertion ... failed). A test in another PR's run hit the same assertion that evening, so it isn't this change. Rerun 5 times under the layer on the same merge,agc_storage_written_buffer_orderpasses 5 of 5 with no VUIDs. Neither log reports the layer missing. VUIDs onmainand with this PR:VUID-vkCmdCopyBuffer-srcBuffer-00118×2,VUID-vkCmdDraw-multisampledRenderToSingleSampled-07285×2,VUID-vkCmdWaitEvents-srcStageMask-01158×2,VUID-VkImageViewCreateInfo-usage-02275×6,VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605×18,VUID-vkSetEvent-event-09543×2. None is new with this PR.main1d41645 (and with perf(shader): keep one use list per IR value #7520/perf(shader): leave out the dead code pass after masked-select elimination #7522 in a second arm):agc_ir_reclaim(including the later-block phi case),agc_masked_select,agc_constant_phiand the 41-test shader set pass 3 of 3; identical shader-cache entries and replay hashes against twomainruns (Showcase PPSA99005, RetroArch PPSA99169, vkQuake PPSA99010), static frames bit-identical, and draw-path recompile time withinmain's spread.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