perf(shader): leave out the dead code pass after masked-select elimination #7522
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7522"
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 milescoviello on 2026-10-18T11:49:12Z.
What
PrepareResourceProgram's simplification step runsMaskedSelectEliminator::Eliminate. When it removed selects, the step then ranDeadCodeEliminator::Eliminateover the whole program, after refolding first if a packed ancillary input is live.MaskedSelectEliminator::Eliminatealready runs dead code elimination at the end of every round that removes a select. It returns only after a round that removes nothing, and such a round doesn't change the program. So the program it returns is already free of dead code. Without the ancillary refolding, the following pass had nothing to remove. It now runs only after that refolding, which can create dead code.To check this, I logged the instructions each
Eliminate(IrProgram&)call removed, by call site, over 466 dumped shader requests (below). This call ran 833 times, never with a live ancillary input, and removed nothing each time. Over the 355 PPSA30839 requests plus PPSA31162's 46, it took 115 ms in 712 calls.agc_masked_selectroutes its 39 cases through oneeliminate()helper. After an elimination that removed selects, that helper now runs one more dead code pass and fails if it removes anything. That is the property this PR relies on. With the dead code pass insideMaskedSelectEliminator::Eliminateremoved, 4 cases fail with "dead code is left after the selects were removed".HostInterpolationChecker::Lowerhas the same pattern on its own path. I left it as it is, since #6222 and #7332 add code right after that line.Tested
Ubuntu 24.04 (Linux 6.8), GCC 13.3, NVIDIA RTX 4070 Ti, driver 595.99.02.
ctest -R "^agc_|^shader_ir"on3e3e8b9050: 710/710 pass (3 skipped: host import sparse, sparse dma-buf import, stencil ref export). That run also had theHostInterpolationCheckerchange, which I then dropped. On the final code, the 6 tests matchingmasked_select|interpolat|barycentricpass.agc_shader_replay --spv(Release,ANYPS5_ENABLE_SPIRV_TOOLSoff,ANYPS5_NO_SHADER_CACHE=1) on 466 shader requests I had dumped withAPS5_DUMP_SHADERS: 355 from MXGP 26 (PPSA30839), 107 from PPSA31162 and 4 from another app. All 462.spvfiles (a few names repeat across the dumps) have the same SHA-256 onmain3e3e8b9050and with this PR, and the replay output is identical.main, 25,161 to 25,493 ms with this PR), so I'm only claiming the 115 ms of the removed pass.Title level: no speed claim.
tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.pylists only conflicting PRs that it could not compare onRecompiler.cpp; none of their diffs touch these lines.main0fbfd91e5. It matchesmain, with the same two failures (#7766, #7784), and no test is added, skipped or removed. That's correctness only.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.maindbac9fa15bwas 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 (81180e30362c). 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 falls inside the range of the fivemaincaptures.main1 trace, digest,main2 trace, digest,main3 trace, digest,main4 trace, digest,main5 trace, digest, this PR trace, digestVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -R '^agc_' -Vonmaine2a2914aa1and onmain+ this PR (cabf6ad533, a local merge).main: 815 of 815 pass; with this PR: 815 of 815 pass. Neither log reports the layer missing. VUIDs onmain:VUID-VkImageViewCreateInfo-usage-02275×6,VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605×18,VUID-vkCmdCopyBuffer-srcBuffer-00118×2,VUID-vkCmdDraw-multisampledRenderToSingleSampled-07285×2,VUID-vkCmdWaitEvents-srcStageMask-01158×2,VUID-vkSetEvent-event-09543×2; with this PR:VUID-VkImageViewCreateInfo-usage-02275×6,VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605×18,VUID-vkCmdCopyBuffer-srcBuffer-00118×2,VUID-vkCmdDraw-multisampledRenderToSingleSampled-07285×2,VUID-vkCmdWaitEvents-srcStageMask-01158×2,VUID-vkSetEvent-event-09543×2. None is new with this PR.main1d4164552+ #7516 + #7494:agc_masked_selectwith the no-dead-code check and the 41-test 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
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T16:27:54Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
main0fbfd91e5(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): 1637/1639 with this PR, against 1637/1639 onmain. The failures are the same two on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784). The PR adds no new ctest entry, and no test is skipped or removed compared withmain. This checks correctness only: I did not measure the speed-up.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 milescoviello on 2026-10-19T16:38:46Z.
@DavidAmsellem thank you, the gfx1100 full-suite run is in the description now.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T16:38:59Z.
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 milescoviello on 2026-10-19T21:35:21Z.
The title capture the
perflabel asks for is now in the description, with both summary lines, the traces and the digests: MXGP26 from boot, a cold shader cache,maindbac9fa15bagainstmain+ this PR (81180e30362c). The fivemaincaptures span 17.7% in total shader prepare time, so the capture can't resolve this change, and the replay measurement in the description is still its measurement. This PR's capture falls inside the range of the fivemaincaptures.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-20T15:01:50Z.
Windows run of #7520 and #7522 together. Host: Windows 11 Pro 26220, NVIDIA GeForce RTX 4070 driver 596.21, Ryzen 7 5700X, WinLibs MinGW-w64 GCC 15.2 r7, Release. I stacked #7520 at
d484281b6and #7522 atcabf6ad53onmain1d4164552+ #7516 (f099292f8) + #7494 (0aab6c1f3). None of the four shares a file, and all merges were clean. Targeted build: the shader and AGC test targets pluslibs. MinGW accepts the newstatic_assert(sizeof(IrValue) == 128).shader_ir_use_rewritewith the tightened allocation bounds: 3 of 3.agc_masked_selectwith the new "no dead code left" check: 3 of 3. The rest of the 41-test set also passed 3 of 3, none skipped: the^shader_|^agc_shader_set,agc_ir_reclaim,agc_constant_phiand the f16/f32 min/max GPU tests.mainruns and this stack. I matched keys with the source-version word masked and compared payloads with host pointers masked: 5 Showcase entries hold a host address and differ between twomainruns too. Showcase's two dumped compute requests replay (agc_shader_replay --spv) to identical SHA-256 onmainand the stack.main/#7516+#7494 A B A B. Settings:ANYPS5_NO_SHADER_CACHE=1, a freshly relinked run directory,APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1 APS5_TRACE_SUMMARY_EVERY=10. No stop line. These titles compile on the draw path; they have noShader.PrepareArtifactslices. Draw-path recompile time over the run, summed from the[draw] driver phaseslines:main2594.5 / 2223.2 ms.main46.8 / 35.0 ms.main, p50 8.34 ms in all.mainrange. This is one run, so it shows no regression, not a speed-up.main. The animated frames differ between twomainruns too, so they can't be compared.mainagainst the new UseRewrite bound, and MaskedSelect without the inner DCE).tools/check_conventions.py --base origin/mainandgit diff --check: pass.Not checked: a full build, the
agc_driver_GPU suite (the RADV full-suite run above covers that on AMD), replay CPU time, an A B A B of these two on their own, AMD/Intel on Windows.Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-20T15:03:48Z.
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)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T03:31:44Z.
A data point from a second title, and it doesn't show a gain here. Crimson Desert (PPSA25286) replay: a fixed subset of 152 of its 6,065 registration requests,
agc_shader_replay --prepare, Release, task-clock, 8 interleaved runs per build, i7-13700K:main5d10ea9ea0main+ this PR (cabf6ad533, merged cleanly)The medians are within noise of each other; one run on each side was slowed by other load on the host. The prepared SPIR-V of the 152 requests is byte-identical to
main's.In this title's profile, the dead-code passes inside
MaskedSelectEliminator::Eliminateare about 6 % of that function. Most of its time is inUnreadLanes:settle38 %, its own loop 28 %,readerOf10 %. So there's little here for this PR to remove. The MXGP replay numbers in the description stand as they are.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-03T05:01:00Z.
Review: APPROVED
Windows 11, AMD RX 9070 XT, WinLibs GCC 15.2.0,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, merged onto currentmainf6232fcfda(clean merge):agc_masked_selectpasses, including the new check ineliminate()that one moreDeadCodeEliminatorpass removes nothing after selects were removed. Withmain'score/shader/recompiler/Recompiler.cpprestored it passes too. That's expected: the test checks the property this PR relies on, insideMaskedSelectEliminator::Eliminate, not the removed call. The removed pass is still inPrepareResourceProgramon currentmain(the merge is clean). I didn't reproduce the timing; the summary lines and digests in the description are the performance evidence.