perf(shader): skip masked-select families that have no candidate select #7491
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7491"
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-18T09:22:02Z.
What
Every round of
MaskedSelectEliminator::EliminaterunsUnreadLanes::Removefor each of the four mask families. EachRemovefirst walks every instruction of the program, newest block first, to find the selects whose mask belongs to its family. If it finds none, it returns 0 without changing anything, but it has already walked the whole program.In the largest compute shader of PPSA31162 (about 152,000 IR instructions when the pass runs), each
Eliminatecall runs two rounds. Only one family ever has candidates: masks that are constants or are defined in a block that runs once, and that are not whole-quad masks. It has 20,614 selects, and 308 are removed in the first round. The other three families find nothing in either round. With a temporary timer, each of those empty walks took 4.7 to 8.9 ms.removeFullWaveSelectsalready walks every instruction at the start of each round. It now also collects the selects ofOnce-region blocks that it keeps. A family runs only when one of those selects is still in its block, has uses and has a mask of that family. That is exactly the testRemovestarts with. It is checked when the family's turn comes, not at the start of the round, because removing a select can change another select's mask (aSelectU1can be a mask, andfamilyOflooks at the mask's sources). Removed selects have no parent, and no pass in the round adds selects. So a family is skipped only whenRemovewould have returned 0 without touching the program orsteps, and the output is unchanged.There's no new test, because the output doesn't change.
agc_masked_selectalready covers loop, whole-quad and first-lane masks.Tested
Ubuntu 24.04 (Linux 6.8), GCC 13.3, NVIDIA RTX 4070 Ti, driver 595.99.02.
ctest -R "^agc_|^shader_ir"onccb0c09268: 708/708 pass (3 skipped: host import sparse, sparse dma-buf import, stencil ref export). After rebasing ontocb1d6e5bd6:agc_masked_select,agc_shader_memoryandagc_shader_srt_read_patchingpass.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. Onmainccb0c09268and 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. A temporary timer around
Eliminate(not part of this PR), on the replay of PPSA31162's largest compute shader (1,056,287 SPIR-V words), summed over its 2 calls, 20 runs per build, interleaved:mainccb0c09268The whole replay takes about 1.2 s of CPU time, so that is about 5% of it. Whole-replay
task-clock(40 runs each) was 1234.0 ± 123.5 ms onmainand 1182.7 ± 124.6 ms with this PR, with equal medians: another workload was using about 8 cores of the host, and the whole-replay spread is larger than the gain. I'm only claiming the pass time.Title level: no speed claim. This is background shader preparation. I didn't run a title for it.
This is independent of #7431, which changes
PlanBuilder::PatchReadsin the same shader preparation.tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.pylists only #4072, which it could not compare. That PR adds one opcode toisLaneLocalin this file and doesn't touchEliminateorremoveFullWaveSelects.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 (a40ccbfbb85a). 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, digestChecklist
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 github-actions[bot] on 2026-10-18T09:30:43Z.
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/shader/recompiler/Optimization/src/MaskedSelectEliminator.cppImported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T21:35:35Z.
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 (a40ccbfbb85a). 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 adriadam10 on 2026-10-19T22:09:50Z.
Checked that
hasUnreadCandidatematches the early-out test inUnreadLanes::Remove(Once-region select with 3 args, uses, same mask family), evaluated at each family's turn so mask changes between families are seen; output unchanged. merged.