shader: also lower whole-wave reductions built as row_xmask butterflies #1570
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!1570
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1570"
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-16 21:27 UTC · original
Nawid3333:shader/lower-whole-wave-reductions→main· +76 −41 · 3 files · 3 commits · open1e871718fnow lowers the whole-wave row_shr scan of every operation this PR added (IAdd, SMin, SMax, And, Xor, next to UMin, UMax and OR), so this PR is cut down to the part main does not cover yet. The change is one commit (831b3d22b, ona0b083c85); main4e9065450is merged in after it, and5b577d55dadds one test case.What is left (
ReadLaneElimination.cpp)The same reduction can also be built as a row_xmask butterfly (DPP xmask 1, 2, 4, 8 instead of row_shr 1, 2, 4, 8). After it, every lane of a row holds the row's result (wave64: after the
v_permlanex16join, every lane of a half holds the half's result), so the code reads any lane of each half, not only 31 and 63 (wave32: 15 and 31). Main's matcher only accepts row_shr steps read at the half ends, so these reductions still go through the lane reads: with 32-lane fragment subgroups (NVIDIA, Intel) a read of a lane in the upper half is undefined, and in a half-filled wave on a 64-lane host it returns stale values.The matcher now tries both step kinds. A row_xmask butterfly is accepted with one constant read in each half of the wave at any lane, in either order. A row_shr scan still needs the half-end reads, since only the last lane of a row holds the row's result. The four steps must all be of one kind and in the order main already requires; everything else is unchanged.
Tests
ScalarProvenanceTests: the whole-wave matcher test runs for both step kinds. It gains reads in the same half and at a non-constant lane (rejected for both), and the existing lane-30 case is now accepted for butterflies only. A wave32 read at two lanes of one row is rejected too: there each row holds only its own result.shader_recompiler_compute_tests: each wave64 reduction case (and the masked minimum) also runs as a butterfly read at lanes 0 and 32; each requires itsOpGroupNonUniform*reduction in the SPIR-V.Results (RX 9070 XT, Windows 11)
scalar_provenance_tests: all cases pass. The same tests on main'sReadLaneElimination.cppfail atwave reduction proof failed case 0 row_xmask.shader_recompiler_compute_tests --dpp-only: all cases pass. On main's matcher exactly the eight butterfly cases fail, each missing itsOpGroupNonUniform*reduction.--wave64-onlyandshader_cfg_tests: the same result as main (--wave64-onlyfails onlyVectorAddcWritesPerLaneCarryOut, on main too).GraphicsSparseWave*cases.Games
None that I can name. In the 785 Kyty logs I have (my game runs and logs attached to issues here: 590 distinct shaders with a
v_permlanex16wave join, from Demon's Souls, ASTRO BOT, Assassin's Creed Black Flag Resynced, Marvel's Wolverine and others), no whole-wave reduction uses the butterfly form; the integer ones are row_shr scans, most of them already lowered by main. This covers the other form the ISA allows for the same reduction, so a shader that uses it gets the subgroup reduction instead of the lane reads.Related
1e871718flanded the operation list of this PR's previous version.If you'd like this done differently, tell me and I'll change it.
Written with Claude Code (AI): it wrote the change and the tests and ran them on my PC (RX 9070 XT, Windows 11). I reviewed the diff and this description.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-16 21:34 UTC · original · edited 2026-11-23 23:44 UTC
No actionable comments were generated in the recent review.
Walkthrough
The IR pass now matches full-EXEC reduction scans with row-shift or row-XMASK controls. It accepts immediate endpoint selectors in either order when they identify opposite wave halves, and passes the selected control through wave32 and wave64 scan matching. Scalar-provenance and wave64 compute tests cover both variants, additional endpoint cases, and butterfly reductions.
Suggested reviewers:
nmzik,artyomzabrodaChange: Bug fix
Merge Risk:
Minimal · previous review
9299fThis change lets the shader recompiler turn row_xmask butterfly wave reductions into subgroup reductions, in addition to the existing row_shr scans. The matching logic is consistent with the instruction semantics, and the tests cover both forms and the rejected cases. No merge-blocking risk was found.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: whole-wave reductions built as row_xmask butterflies are now lowered. It matches the objectives, which extend ReadLaneElimination.cpp to match butterfly forms alongside row_shr scans. The title is specific and does not use vague terms.
Full details: Description check
Explanation
The description explains the change in detail. It covers the matcher change in ReadLaneElimination.cpp, the test updates in ScalarProvenanceTests and shader_recompiler_compute_tests, and the reported test results. It is related to the changeset.
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
3bb13612-18f3-4b68-9be8-60a107a6e28dReviewing files that changed from the base of the PR and between
831b3d22baand9299f8c210.src/graphics/shader/recompiler/ir/passes/ReadLaneElimination.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@NeySlim on GitHub · 2026-10-17 23:09 UTC · original
RADV data point: Radeon 8060S (RDNA 3.5), Mesa 26.2.4, against
763d3be3, pixel shaders in wave64. With only the new tests on main, 7 of the 32 graphics cases fail, all on the 8x4 (half wave) target: both Count cases, UMax scan and butterfly, SMin scan, Xor scan and butterfly. With the PR all 32 pass and the compute suite is unchanged.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.