shader: also lower whole-wave reductions built as row_xmask butterflies #1570

Open
github-bot wants to merge 3 commits from github-bot/gh-1570 into main AGit
Owner

@⁠Nawid3333 on GitHub · 2026-10-16 21:27 UTC · original
Nawid3333:shader/lower-whole-wave-reductions → main · +76 −41 · 3 files · 3 commits · open

1e871718f now 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, on a0b083c85); main 4e9065450 is merged in after it, and 5b577d55d adds 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_permlanex16 join, 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 its OpGroupNonUniform* reduction in the SPIR-V.

Results (RX 9070 XT, Windows 11)

  • scalar_provenance_tests: all cases pass. The same tests on main's ReadLaneElimination.cpp fail at wave 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 its OpGroupNonUniform* reduction.
  • --wave64-only and shader_cfg_tests: the same result as main (--wave64-only fails only VectorAddcWritesPerLaneCarryOut, on main too).
  • Not run on this GPU: the robust buffer and rasterization cases, so the 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_permlanex16 wave 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

  • 1e871718f landed 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

**@⁠Nawid3333** on GitHub · 2026-10-16 21:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1570) `Nawid3333:shader/lower-whole-wave-reductions` → `main` · +76 −41 · 3 files · 3 commits · open 1e871718f now 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, on a0b083c85); main 4e9065450 is merged in after it, and 5b577d55d adds 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_permlanex16` join, 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 its `OpGroupNonUniform*` reduction in the SPIR-V. **Results** (RX 9070 XT, Windows 11) - `scalar_provenance_tests`: all cases pass. The same tests on main's `ReadLaneElimination.cpp` fail at `wave 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 its `OpGroupNonUniform*` reduction. - `--wave64-only` and `shader_cfg_tests`: the same result as main (`--wave64-only` fails only `VectorAddcWritesPerLaneCarryOut`, on main too). - Not run on this GPU: the robust buffer and rasterization cases, so the `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_permlanex16` wave 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** - 1e871718f landed 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](https://claude.com/claude-code)
1e871718f lowers whole-wave row_shr scans of every associative operation
whose two half-wave reads take the half endpoints (lanes 31 and 63 in
wave64, 15 and 31 in wave32). Code that builds the reduction as a row_xmask
butterfly (xmask 1, 2, 4, 8) leaves the row's result in every lane of the
row, reads any lane of each half, and still goes through the lane reads.

The matcher now also accepts the row_xmask butterfly, with one constant
read in each half of the wave at any lane. A row_shr scan still needs the
endpoint reads, since only the last lane of a row holds the row's result.

The whole-wave matcher test runs for both shapes and gains reads in the
same half and at a lane that is not a constant; each wave64 compute
reduction case also runs as a butterfly read at lanes 0 and 32.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
In wave32 each half is one row: after a row_xmask butterfly every lane
of a row holds only that row's result, so reading two lanes of the same
row combines one row with itself and must not become a whole-wave
reduction.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:59:59 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-16 21:34 UTC · original · edited 2026-11-23 23:44 UTC

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

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, artyomzabroda

Change: Bug fix

Merge Risk: Minimal · previous review 9299f

This 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: Passed 4

Check name Status Explanation
Title check Passed 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 alongsid…
Description check Passed 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 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 831b3d22ba and 9299f8c210.

Files selected for processing: 2

  • src/graphics/shader/recompiler/ir/passes/ReadLaneElimination.cpp
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-16 21:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1570#issuecomment-6225135108) · edited 2026-11-23 23:44 UTC <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1570?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > - Last reviewed commit: 9299f8c2101fcc7931d2df80a56bcb0904a26aaa > - Latest commit, not reviewed: 5b577d55da3d038739cf42a33ff8644c38375f77 > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> 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`, `artyomzabroda` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"9299f8c2101fcc7931d2df80a56bcb0904a26aaa" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · previous review <code>9299f</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `9299f` --> <!-- final_review_risk_coverage:{"sourceCommitId":"9299f8c2101fcc7931d2df80a56bcb0904a26aaa","coveredCommitId":"9299f8c2101fcc7931d2df80a56bcb0904a26aaa","kind":"reviewed"} --> This 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. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | 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 alongsid… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | 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 … | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **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. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **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. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1570)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>Share</strong></summary> <dl> <dd> <br> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <!-- tips_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <br> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/4e90654506c8078649e2c1d22c763164406497da/.coderabbit.yaml>) - **Commit**: [4e90654](<https://github.com/KytyPS5/KytyPS5/commit/4e90654506c8078649e2c1d22c763164406497da>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `3bb13612-18f3-4b68-9be8-60a107a6e28d` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 831b3d22ba71b1f34cffc689308de8a5c4acbc61 and 9299f8c2101fcc7931d2df80a56bcb0904a26aaa. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 2</strong></summary> <dl> <dd> <br> * `src/graphics/shader/recompiler/ir/passes/ReadLaneElimination.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
Author
Owner

@⁠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.

**@⁠NeySlim** on GitHub · 2026-10-17 23:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1570#issuecomment-6242864797) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1570/head:github-bot/gh-1570'
git switch 'github-bot/gh-1570'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1570'
git switch 'github-bot/gh-1570'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1570'
git switch 'github-bot/gh-1570'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1570'
git switch 'main'
git merge --squash 'github-bot/gh-1570'
git switch 'main'
git merge --ff-only 'github-bot/gh-1570'
git switch 'main'
git merge 'github-bot/gh-1570'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.