shader: forward EXEC-guarded selects into guarded ALU operands #1295
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1295
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1295"
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?
@NeySlim on GitHub · 2026-10-09 10:52 UTC · original
NeySlim:perf/select-forwarding→main· +316 −1 · 4 files · 1 commits · openProblem
A VALU instruction only writes the lanes enabled by EXEC. The translator models this per write: every VGPR write becomes
Select(exec, result, old). Inside a region that runs under a partial EXEC (afters_and_saveexec,v_cmpxand the like), each instruction then reads the selects of the previous ones, so the SPIR-V keeps oneOpSelectper guest instruction, and ACO emits onev_cndmask_b32for each.In God of War Ragnarök (PPSA08332) these selects are 17 to 35 % of the VALU instructions of the compute shaders that take the most GPU time (pipeline statistics from
VK_KHR_pipeline_executable_properties). For example, the 4K compute pass2b5700922e84e88ehas 2586 VALU instructions, 752 of themv_cndmask_b32, for 1023 guest instructions.Change
New IR pass
ForwardGuardedSelects, run inCompileProgramafter dead code elimination:Select(c, ., .), or by other such instructions, only matters on lanes wherecis true. Its operands of the formSelect(c, a, b)are replaced bya.Select(c, x, Select(c, y, z))becomesSelect(c, x, z).atakes its place: no value is kept live longer than before, and register pressure does not grow.Instructions that read other lanes (DPP, permutes, ballots, read/write lane), memory and image operations, interpolation and Phi are never rewritten or used as a path, so a value whose result may be observed on a lane where
cis false keeps its select. The result of every lane where the original select chain is observable is unchanged.In an EXEC region whose intermediate values are only used inside it, only the values that leave the region keep their select.
Test
VectorExecRegionForwardsSelects: four dependent writes to two VGPRs under a partial EXEC (v_cmp_gt_u32+s_and_saveexec_b64), wave64. Active lanes get the chained results and inactive lanes keep their old values; the final IR keeps twoSelectU32(one per register that leaves the region) instead of five. It fails without the pass.Validation
shader_recompiler_compute_tests, one case per process: identical results to origin/main apart from the new passing case. The 10 cases that already fail on origin/main with this driver fail the same way.2b5700922e84e88e: 2586 to 2100,v_cndmask_b32752 to 379), with the same VGPR count for each.AI use
I used Claude Code (AI agent) to profile the GPU time and the compiled code of the hottest shaders, write the pass and the test, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.
@coderabbitai[bot] on GitHub · 2026-10-09 10:57 UTC · original · edited 2026-10-23 17:49 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
91abf94e-5706-4afa-8506-439195cede95📥 Commits
Reviewing files that changed from the base of the PR and between 5770c98f9a2b19a42dc819f45127694e1175ba22 and
6771fea594.📒 Files selected for processing: 3
src/graphics/shader/recompiler/ShaderRecompiler.cppsrc/graphics/shader/recompiler/ir/passes/SelectForwarding.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
📝 Walkthrough
The shader recompiler now forwards selects guarded by matching conditions, then runs dead-code elimination again. A new compute test checks outputs across 64 lanes after dependent vector operations run under a lane predicate and EXEC is restored.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Refactor
Merge Risk: ⚪ Minimal · up to
6771fNo identified issue blocks merging after normal checks.
Pre-merge checks:
4 ·
1
Full details: Title check
Explanation
The title names the main change: a new pass that forwards EXEC-guarded Select operands into guarded ALU operands in the shader recompiler. It matches the changeset, which adds ForwardGuardedSelects and runs it in CompileProgram. The title is 62 characters and 8 words, so it is concise and specific.
Full details: Description check
Explanation
The description explains the problem (per-write Select(exec, result, old) producing many v_cndmask_b32 instructions in EXEC regions), the new ForwardGuardedSelects pass and its rewrite rules, a targeted test named VectorExecRegionForwardsSelects, validation results, and AI use. It relates directly to the changeset.
Full details: Docstring Coverage
Explanation
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. (1 skipped: 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@Nawid3333 on GitHub · 2026-11-12 13:23 UTC · original
Measured on a second game without a game run: the 172 Ghost of Yōtei programs from a capture of 11-03 (113 CS, 43 PS, 16 VS), recompiled offline by main (
bc934ef03) and by main with this PR, with the same captured inputs (a replay tool on top of both feeds them to the recompiler; it changes nothing in the recompiler). Guest memory reads as zeros in the replay, so each program is compiled in a real variant, but not necessarily the one the game used.maintenance8on both builds.-s vk-spv-offline), scheduling hints (s_delay_alu, waits,s_nop,s_clause,s_set_inst_prefetch) left out:v_cndmaskThe PR conflicts with main only in the include block at the top of
ShaderRecompiler.cpp; keeping main's two lines there (ShaderCalls.h,Tessellation.h) gives the build measured above.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.