shader: lower whole-wave OR reductions to subgroup reductions (ASTRO BOT) #1962
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!1962
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1962/head"
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?
@Nawid3333 on GitHub · 2026-10-28 16:35 UTC · original
Nawid3333:fix/wave-or-reduction→main· +154 −53 · 8 files · 1 commits · closed without mergingASTRO BOT ORs per-pixel bit masks across the wave with the idiom
302240daand6357740flower for UMin/UMax:s_orn2_saveexec,v_cndmaskwith 0 for the lanes outside the saved mask,v_or_b32with DPP row_shr1/2/4/8,
v_permlanex16_b32+v_or_b32(wave64), thenv_readlaneof lanes 31 and 63 (wave64) or 15 and 31(wave32) and
s_or_b32. The matcher only takes UMin/UMax, so for OR the shuffles stay, and in a partly filledfragment subgroup (or a 32-wide one for wave64) they read invocations that don't exist.
This adds BitwiseOr32 to
EliminateReadLane(oneSubgroupReduction()map for the three operations) and emitsOpGroupNonUniformBitwiseOrthroughEmitSubgroupReduceU32.ASTRO BOT (PPSA21564, RX 9070 XT, AMD 26.10.1, Windows):
6c014018with and without this change, three5-minute runs each from boot into the first area with the same input script. Both builds also carry my lab-only
input-script player and a 65536-iteration shader loop cap that I use for ASTRO BOT runs since #1511.
read-lane elimination: reads=0 reductions=1for 18 pixel shaders, among them16f9df575a3aa74f (wave64) and 5457609506174517 (wave32). On main there is no such line.
shaders and their screenshots show the same scenes.
127 shaders. That happens with and without this change, so it is a separate problem.
Tests:
GraphicsSparseWaveOr(the shape ofGraphicsSparseWaveMinimum, one quad): main returns values that changebetween runs (0x3f17dc04, 0x66e84e9f, 0x3e7 at 64 lanes; 0x24041c04, 0x1f, 0x516c2b9a at 32 lanes) instead
of 0x3e800000. It passes with the change.
ComputeWave64Or/OrMasked, andComputeWave32OrSavedExec/ComputeWave64OrSavedExecwith ASTRO BOT's EXECsequence (save to an SGPR,
v_cmpxand branches, restore,s_orn2_saveexecof the SGPR), requireOpGroupNonUniformBitwiseOrand the exact value; they fail on main.compute subgroups (wave64 compute split in halves). In the first and the last mode the full
shader_recompiler_compute_testssuite has no other change against main.shader_cfg_testspasses.#1503, my older #1570 and #1898 also lower the OR form. This one only adds OR to the matcher as it is after
6357740f/ce5e57aa, and it is tested in the game. If you'd rather take one of the others, close this one.
AI use: Claude Code found the idiom in the shader dumps, wrote the change and the tests, and ran them and the
game runs on my PC; I read the change and the results before opening this.
@coderabbitai[bot] on GitHub · 2026-10-28 16:47 UTC · original
No actionable comments were generated in the recent review.
0ca2048b-2771-4094-a0be-d3e52e150d20Reviewing files that changed from the base of the PR and between
6c01401862and3da2b1a773.src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cppsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.incsrc/graphics/shader/recompiler/ir/passes/ReadLaneElimination.cppsrc/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpptests/ScalarProvenanceTests.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Walkthrough
The IR reduction pass now recognizes bitwise-OR reductions and rewrites accepted cases to a subgroup opcode. The SPIR-V backend emits that opcode through the shared reduction helper. Tests cover OR reductions with different masks and wave sizes. The second-half result-sharing condition now includes
ReadConstBuffer.Suggested reviewers:
nmzik,claxten10,senaxxPriority:
Normal
Change: Bug fix
Merge Risk:
Minimal · up to
3da2bNo confirmed issue blocks merging after normal checks.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 6 files. (2 skipped: 1 unsupported, 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-10-30 19:38 UTC · original
Closing this: main does the same since
0c2546e8("shader: lower whole-wave OR scans to subgroup reductions"), apart from names. It addsBitwiseOr32to the same reduction switch inReadLaneElimination.cpp, emits it asOpGroupNonUniformBitwiseOr, and adds the same entries for both halves of a wave64 and forsubgroup_arithmetic.Some tests here are not on main (among them OR in wave32, OR under a partial EXEC, the ASTRO BOT saved-EXEC pattern, and a check that
OpGroupNonUniformBitwiseOris emitted). They can go in a small follow-up if you want them.Pull request closed