fix(shader): reduce whole-wave integer additions #2008

Closed
github-bot wants to merge 3 commits from gh-pr/2008/head into gh-pr/2008/base
Owner

@⁠bobrass on GitHub · 2026-10-30 22:48 UTC · original
bobrass:codex/kytyps5-issue1944-subgroup-add → main · +21 −7 · 7 files · 3 commits · closed without merging

Summary

  • Recognize the proven whole-wave IAdd32 scan in the existing read-lane elimination pass.
  • Lower it to OpGroupNonUniformIAdd, and include the new opcode in subgroup capability tracking and the existing half-wave emission guard.
  • Keep the negative matcher case negative now that integer addition is a supported reduction.

This targets the add/count pattern reported in issue #1944. It does not change the existing UMin, UMax, or OR matchers.

Validation

  • git show --check and git diff --check are clean.
  • I did not run tests, a build, or the reported GPU reproducer. Validation is still needed on both 32-lane and 64-lane fragment subgroups, including a partly filled wave, using the reporter's expected sum/count checks.
**@⁠bobrass** on GitHub · 2026-10-30 22:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2008) `bobrass:codex/kytyps5-issue1944-subgroup-add` → `main` · +21 −7 · 7 files · 3 commits · closed without merging ## Summary - Recognize the proven whole-wave `IAdd32` scan in the existing read-lane elimination pass. - Lower it to `OpGroupNonUniformIAdd`, and include the new opcode in subgroup capability tracking and the existing half-wave emission guard. - Keep the negative matcher case negative now that integer addition is a supported reduction. This targets the add/count pattern reported in [issue #1944](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1944). It does not change the existing UMin, UMax, or OR matchers. ## Validation - `git show --check` and `git diff --check` are clean. - I did not run tests, a build, or the reported GPU reproducer. Validation is still needed on both 32-lane and 64-lane fragment subgroups, including a partly filled wave, using the reporter's expected sum/count checks.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:11:18 +00:00
github-bot closed this pull request 2026-11-26 10:11:18 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-30 22:57 UTC · original · edited 2026-11-03 14:03 UTC

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The change adds an unsigned 32-bit subgroup integer-add opcode. The IR maps matching IAdd32 wave reductions to this opcode and records it as subgroup arithmetic. The SPIR-V backend emits the reduction with OpGroupNonUniformIAdd and reuses its result for the second lane half. The tests cover addition as a successful reduction and use bitwise XOR for the wrong-operation case.

Suggested reviewers: nmzik

Change: Bug fix

Merge Risk: Minimal · up to 50bce

The change is mergeable with no established blocking correctness or stability risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% 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. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "fix(shader): reduce whole-wave integer additions" matches the main change. The PR recognizes a whole-wave IAdd32 scan in the read-lane elimination pass and lowers it to a subgroup integer-a…
Description check Passed The description states the change clearly. It lists the matcher change in the read-lane elimination pass, the lowering to OpGroupNonUniformIAdd, the capability tracking and half-wave guard updates, an…
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 "fix(shader): reduce whole-wave integer additions" matches the main change. The PR recognizes a whole-wave IAdd32 scan in the read-lane elimination pass and lowers it to a subgroup integer-add reduction (SubgroupIAddU32 / OpGroupNonUniformIAdd). The title is short, specific, and names the affected area (shader) and the change type (fix).

Full details: Description check

Explanation

The description states the change clearly. It lists the matcher change in the read-lane elimination pass, the lowering to OpGroupNonUniformIAdd, the capability tracking and half-wave guard updates, and the updated negative matcher test. It also links issue #1944 and states what validation was and was not run. This is related to the changeset and is not off-topic.

Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% 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 5 functions across 6 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Warning

Some tools did not complete. Review the errors below.

Cppcheck (2.22.0)
tests/ScalarProvenanceTests.cpp

Cppcheck timed out; analysis of this file is incomplete

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between c50559ec3b and 50bce2bfe0.

Files selected for processing: 1
  • tests/ScalarProvenanceTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-30 22:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2008#issuecomment-6535270691) · edited 2026-11-03 14:03 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/2008?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-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- 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> The change adds an unsigned 32-bit subgroup integer-add opcode. The IR maps matching `IAdd32` wave reductions to this opcode and records it as subgroup arithmetic. The SPIR-V backend emits the reduction with `OpGroupNonUniformIAdd` and reuses its result for the second lane half. The tests cover addition as a successful reduction and use bitwise XOR for the wrong-operation case. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"50bce2bfe020b6236dce302e21310d2f8f809a93" --> <!-- change_assessment_priority:{"version":1,"urgency":"p3","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> · up to <code>50bce</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `50bce` --> <!-- final_review_risk_coverage:{"sourceCommitId":"50bce2bfe020b6236dce302e21310d2f8f809a93","coveredCommitId":"50bce2bfe020b6236dce302e21310d2f8f809a93","kind":"reviewed"} --> The change is mergeable with no established blocking correctness or stability risk. <!-- 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 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 warning</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 20.00% 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. Documenta… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><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> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title "fix(shader): reduce whole-wave integer additions" matches the main change. The PR recognizes a whole-wave IAdd32 scan in the read-lane elimination pass and lowers it to a subgroup integer-a… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description states the change clearly. It lists the matcher change in the read-lane elimination pass, the lowering to OpGroupNonUniformIAdd, the capability tracking and half-wave guard updates, an… | | 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> **Explanation** The title "fix(shader): reduce whole-wave integer additions" matches the main change. The PR recognizes a whole-wave IAdd32 scan in the read-lane elimination pass and lowers it to a subgroup integer-add reduction (SubgroupIAddU32 / OpGroupNonUniformIAdd). The title is short, specific, and names the affected area (shader) and the change type (fix). </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> **Explanation** The description states the change clearly. It lists the matcher change in the read-lane elimination pass, the lowering to OpGroupNonUniformIAdd, the capability tracking and half-wave guard updates, and the updated negative matcher test. It also links issue `#1944` and states what validation was and was not run. This is related to the changeset and is not off-topic. </dd> </dl> </details> </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 20.00% 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 5 functions across 6 files. **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- operational_warnings_start --> <!-- This is an auto-generated comment: all tool run failures by coderabbit.ai --> > [!WARNING] > Some tools did not complete. Review the errors below. > > <details> > <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/wrench-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/wrench.svg" width="16" height="16" align="absmiddle" alt=""></picture> Cppcheck (2.22.0)</strong></summary> > <dl> > <dd> > > <details> > <summary><strong>tests/ScalarProvenanceTests.cpp</strong></summary> > <dl> > <dd> > > Cppcheck timed out; analysis of this file is incomplete > > </dd> > </dl> > </details> > > </dd> > </dl> > </details> <!-- end of auto-generated comment: all tool run failures by coderabbit.ai --> <!-- operational_warnings_end --> <!-- announcements_start --> > [!TIP] > <details> > <summary><strong>🎯 Customize your risk assessments</strong></summary> > <dl> > <dd> > > Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using **Merge Risk Instructions** and **Security Risk Instructions** in your review settings. Security architecture risk assessments require the **Advanced plan or above**. > > </dd> > </dl> > </details> > > <details> > <summary><strong>✅ Automatic approvals, with your rules</strong></summary> > <dl> > <dd> > > Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable **Automatic approvals** in review settings, with overrides for teams or file paths. > > </dd> > </dl> > </details> <!-- announcements_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2008)! 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> - [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 --> <!-- verify_invitation_start --> ### CodeRabbit Verify - [ ] <!-- {"checkboxId":"run-qa-agent"} --> Run CodeRabbit Verify to test the changes in this pull request. <!-- verify_invitation_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> <!-- 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> - **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/4919fdb6e6e28f46f1f5df8cf931a7a0823cb93f/.coderabbit.yaml>) - **Commit**: [4919fdb](<https://github.com/KytyPS5/KytyPS5/commit/4919fdb6e6e28f46f1f5df8cf931a7a0823cb93f>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `017e22b8-93b4-4bea-a946-9f1344f4c9df` </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> Reviewing files that changed from the base of the PR and between c50559ec3b399653d6dc16da57f72d93d96f7aba and 50bce2bfe020b6236dce302e21310d2f8f809a93. </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: 1</strong></summary> <dl> <dd> * `tests/ScalarProvenanceTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-30 22:57 UTC · original · reviewed

Nitpick comments: 1
tests/ScalarProvenanceTests.cpp: 1

736-736: Trivial · Functional Correctness · Quick win

Add a positive IAdd32 reduction case.

Case::WrongOperation now uses BitwiseXor32, so it only tests rejection of an unsupported operation. The fixture has no positive IAdd32 case with neutral value 0u and expected opcode SubgroupIAddU32. Without that case, removing or mis-selecting the IAdd32 lowering would not fail these tests.


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4919fdb6e6 and c50559ec3b.

Files selected for processing: 7
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.h
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp
  • src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc
  • src/graphics/shader/recompiler/ir/passes/ReadLaneElimination.cpp
  • src/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpp
  • tests/ScalarProvenanceTests.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-30 22:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2008#pullrequestreview-5719570237) · **reviewed** <!-- coderabbit-ai-generated:v1 --> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/brush-cleaning-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/brush-cleaning.svg" width="16" height="16" align="absmiddle" alt=""></picture> Nitpick comments: 1</summary><blockquote> <dl> <dd> <details> <summary>tests/ScalarProvenanceTests.cpp: 1</summary><blockquote> <dl> <dd> `736-736`: **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/neutral-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Trivial** · **Functional Correctness** · **Quick win** **Add a positive `IAdd32` reduction case.** `Case::WrongOperation` now uses `BitwiseXor32`, so it only tests rejection of an unsupported operation. The fixture has no positive `IAdd32` case with neutral value `0u` and expected opcode `SubgroupIAddU32`. Without that case, removing or mis-selecting the `IAdd32` lowering would not fail these tests. <!-- cr-comment:v1:e3a213311d78c08c25fa9533 --> </dd> </dl> </blockquote></details> </dd> </dl> </blockquote></details> --- <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <details> <summary><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</summary> <dl> <dd> - **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/4919fdb6e6e28f46f1f5df8cf931a7a0823cb93f/.coderabbit.yaml>) - **Commit**: [4919fdb](<https://github.com/KytyPS5/KytyPS5/commit/4919fdb6e6e28f46f1f5df8cf931a7a0823cb93f>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `9bb0a79e-b123-4882-a17b-e26df0875b88` </dd> </dl> </details> <details> <summary><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</summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 4919fdb6e6e28f46f1f5df8cf931a7a0823cb93f and c50559ec3b399653d6dc16da57f72d93d96f7aba. </dd> </dl> </details> <details> <summary><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: 7</summary> <dl> <dd> * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.h` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp` * `src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc` * `src/graphics/shader/recompiler/ir/passes/ReadLaneElimination.cpp` * `src/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpp` * `tests/ScalarProvenanceTests.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> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=06b58dcb-43f8-4a45-b30c-d815b64f183c attempt=d016a478-5e54-42ff-affd-e894f4f4c4c1 batch=1/1 -->
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-31 02:27 UTC · original

Build test of #2008 at c50559ec (main 4919fdb6 + this commit), with the four cases from #1944. Each case ran 4 times on #2008 and on 4919fdb6 with the same cases. RX 9070 XT, Windows 11, AMD 26.10.1. 32 lanes are forced the same way as in the issue. The table counts runs where every pixel is (1, 0, 0, 1), i.e. sum == count:

case 64 lanes, main 64 lanes, #2008 32 lanes, main 32 lanes, #2008
8x8, row_shr, v_readlane 31 + 63 4/4 4/4 0/4 4/4
8x4 (half a wave64), row_shr, 31 + 63 1/4 4/4 0/4 4/4
8x8, row_xmask, v_readlane 0 + 32 4/4 4/4 0/4 0/4
8x4, row_xmask, 0 + 32 1/4 0/4 0/4 0/4
  • For the row_shr + 31/63 shape, the sum equals the active-lane count on both subgroup sizes with #2008, including the half wave.
  • The row_xmask + 0/32 shape gives the same failures as main, so the matcher doesn't cover it yet: sum - count is 32 with 32 lanes, and stale values with 64 lanes (-1.99e9, 1.04e9 on #2008; -1.95e9 on main). The single passes on main are runs where the stale lanes happened to add up to 0 (a pass means sum - count = 0).
  • Four extra cases (the same four shapes) export the raw sum and count. With #2008 the row_shr ones give sum == count in every run: (32, 32) for 8x4, and (64, 64) for 8x8 with 64 lanes. With 32 lanes, 8x8 gives (32, 32): s_bcnt1_i32_b64 of exec also sees only the subgroup's 32 lanes. That's the unsplit wave64 pixel shader from the first paragraph of #1944, not this PR.

Tests. scalar_provenance_tests, shader_cfg_tests and resource_materialization_tests pass on both. A full shader_recompiler_compute_tests run stops at GpuSelectedFormattedRgba16Store on both, so that one says nothing about this change.

No unit test checks that an IAdd32 scan is actually rewritten: the PR only moves WrongOperation off IAdd32. An Add case next to Or in TestCompleteWaveReduction passes with #2008:

-    Endpoint, EndpointSource, CrossBlock, WrongOperation, Or
+    Endpoint, EndpointSource, CrossBlock, WrongOperation, Or, Add
-       Case::CrossBlock, Case::WrongOperation, Case::Or}) {
+       Case::CrossBlock, Case::WrongOperation, Case::Or, Case::Add}) {
     const bool bitwise_or = test == Case::Or;
-    const uint32_t neutral = maximum || bitwise_or ? 0u : UINT32_MAX;
+    const bool add = test == Case::Add;
+    const uint32_t neutral = maximum || bitwise_or || add ? 0u : UINT32_MAX;
...
+    if (add) {
+      operation = ValueOpcode::IAdd32;
+      reduction_opcode = ValueOpcode::SubgroupIAddU32;
+    }
...
-    const bool matches = test == Case::Masked || rows || bitwise_or;
+    const bool matches = test == Case::Masked || rows || bitwise_or || add;

In games. I searched the shader listings in our logs of Demon's Souls, ASTRO BOT and Assassin's Creed Black Flag Resynced (255 distinct shaders with v_permlanex16) for this idiom. The add form (row_shr, v_readlane 31 + 63, s_add_i32) is in compute shaders of Demon's Souls (11) and Assassin's Creed (10), not in any pixel shader, and no game shader there uses the row_xmask shape. In Demon's Souls, #2008 changes two of the 135 shaders that runs of both builds compiled, each 13 SPIR-V words shorter. With #2008 on top of my test build (main with thread-priority changes, where the game gets to character creation), it reaches character creation as before, at the same or a slightly higher frame rate.

Coverage. In these logs, every integer whole-wave reduction (row_shr, both v_readlane ends combined) is now matched: min, max and OR on main, add with #2008. The remaining integer add scans read only lane 31 or use the per-lane values (prefix sums), which the matcher rightly leaves alone. No matcher covers the float forms yet: v_add_f32, v_min_f32 and v_max_f32 whole-wave reductions in compute shaders of Demon's Souls (64) and Assassin's Creed (20), and in ASTRO BOT vertex shaders (2).

**@⁠Nawid3333** on GitHub · 2026-10-31 02:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2008#issuecomment-6537785144) Build test of #2008 at c50559ec (main 4919fdb6 + this commit), with the four cases from #1944. Each case ran 4 times on #2008 and on 4919fdb6 with the same cases. RX 9070 XT, Windows 11, AMD 26.10.1. 32 lanes are forced the same way as in the issue. The table counts runs where every pixel is (1, 0, 0, 1), i.e. sum == count: | case | 64 lanes, main | 64 lanes, #2008 | 32 lanes, main | 32 lanes, #2008 | |---|---|---|---|---| | 8x8, row_shr, `v_readlane` 31 + 63 | 4/4 | 4/4 | 0/4 | 4/4 | | 8x4 (half a wave64), row_shr, 31 + 63 | 1/4 | 4/4 | 0/4 | 4/4 | | 8x8, row_xmask, `v_readlane` 0 + 32 | 4/4 | 4/4 | 0/4 | 0/4 | | 8x4, row_xmask, 0 + 32 | 1/4 | 0/4 | 0/4 | 0/4 | - For the row_shr + 31/63 shape, the sum equals the active-lane count on both subgroup sizes with #2008, including the half wave. - The row_xmask + 0/32 shape gives the same failures as main, so the matcher doesn't cover it yet: sum - count is 32 with 32 lanes, and stale values with 64 lanes (-1.99e9, 1.04e9 on #2008; -1.95e9 on main). The single passes on main are runs where the stale lanes happened to add up to 0 (a pass means sum - count = 0). - Four extra cases (the same four shapes) export the raw sum and count. With #2008 the row_shr ones give sum == count in every run: (32, 32) for 8x4, and (64, 64) for 8x8 with 64 lanes. With 32 lanes, 8x8 gives (32, 32): `s_bcnt1_i32_b64` of exec also sees only the subgroup's 32 lanes. That's the unsplit wave64 pixel shader from the first paragraph of #1944, not this PR. **Tests.** `scalar_provenance_tests`, `shader_cfg_tests` and `resource_materialization_tests` pass on both. A full `shader_recompiler_compute_tests` run stops at `GpuSelectedFormattedRgba16Store` on both, so that one says nothing about this change. No unit test checks that an `IAdd32` scan is actually rewritten: the PR only moves `WrongOperation` off `IAdd32`. An `Add` case next to `Or` in `TestCompleteWaveReduction` passes with #2008: ```diff - Endpoint, EndpointSource, CrossBlock, WrongOperation, Or + Endpoint, EndpointSource, CrossBlock, WrongOperation, Or, Add - Case::CrossBlock, Case::WrongOperation, Case::Or}) { + Case::CrossBlock, Case::WrongOperation, Case::Or, Case::Add}) { const bool bitwise_or = test == Case::Or; - const uint32_t neutral = maximum || bitwise_or ? 0u : UINT32_MAX; + const bool add = test == Case::Add; + const uint32_t neutral = maximum || bitwise_or || add ? 0u : UINT32_MAX; ... + if (add) { + operation = ValueOpcode::IAdd32; + reduction_opcode = ValueOpcode::SubgroupIAddU32; + } ... - const bool matches = test == Case::Masked || rows || bitwise_or; + const bool matches = test == Case::Masked || rows || bitwise_or || add; ``` **In games.** I searched the shader listings in our logs of Demon's Souls, ASTRO BOT and Assassin's Creed Black Flag Resynced (255 distinct shaders with `v_permlanex16`) for this idiom. The add form (row_shr, `v_readlane` 31 + 63, `s_add_i32`) is in compute shaders of Demon's Souls (11) and Assassin's Creed (10), not in any pixel shader, and no game shader there uses the row_xmask shape. In Demon's Souls, #2008 changes two of the 135 shaders that runs of both builds compiled, each 13 SPIR-V words shorter. With #2008 on top of my test build (main with thread-priority changes, where the game gets to character creation), it reaches character creation as before, at the same or a slightly higher frame rate. **Coverage.** In these logs, every integer whole-wave reduction (row_shr, both `v_readlane` ends combined) is now matched: min, max and OR on main, add with #2008. The remaining integer add scans read only lane 31 or use the per-lane values (prefix sums), which the matcher rightly leaves alone. No matcher covers the float forms yet: `v_add_f32`, `v_min_f32` and `v_max_f32` whole-wave reductions in compute shaders of Demon's Souls (64) and Assassin's Creed (20), and in ASTRO BOT vertex shaders (2).
Author
Owner

@⁠bobrass on GitHub · 2026-11-02 20:18 UTC · original

Thanks for the thorough validation across both subgroup sizes and the half-wave case. This confirms the row_shr whole-wave add pattern, including the 32-lane runs. The row_xmask lane-0/lane-32 pattern remains outside this matcher and still fails, so I’ll keep that limitation explicit. The positive IAdd32 test case you outlined is useful; I’ll add it as a regression test. The full shader_recompiler_compute_tests failure at GpuSelectedFormattedRgba16Store reproducing on both builds is noted as unrelated to this change.

**@⁠bobrass** on GitHub · 2026-11-02 20:18 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2008#issuecomment-6587491728) Thanks for the thorough validation across both subgroup sizes and the half-wave case. This confirms the `row_shr` whole-wave add pattern, including the 32-lane runs. The `row_xmask` lane-0/lane-32 pattern remains outside this matcher and still fails, so I’ll keep that limitation explicit. The positive `IAdd32` test case you outlined is useful; I’ll add it as a regression test. The full `shader_recompiler_compute_tests` failure at `GpuSelectedFormattedRgba16Store` reproducing on both builds is noted as unrelated to this change.
Author
Owner

@⁠bobrass on GitHub · 2026-11-03 14:33 UTC · original

Follow-up: the current PR head now includes the positive IAdd32 case you suggested. It checks that the scan is rewritten to SubgroupIAddU32 with the zero-neutral masked input. I haven’t run the test locally; your GPU runs remain the only reported runtime validation so far. Thanks again for the detailed results.

**@⁠bobrass** on GitHub · 2026-11-03 14:33 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2008#issuecomment-6606557655) Follow-up: the current PR head now includes the positive `IAdd32` case you suggested. It checks that the scan is rewritten to `SubgroupIAddU32` with the zero-neutral masked input. I haven’t run the test locally; your GPU runs remain the only reported runtime validation so far. Thanks again for the detailed results.
Author
Owner

@⁠Nmzik on GitHub · 2026-11-04 08:09 UTC · original

Duplicate: #1570

**@⁠Nmzik** on GitHub · 2026-11-04 08:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2008#issuecomment-6625917818) Duplicate: https://git.gtahub.st/github/KytyPS5--KytyPS5/pulls/1570
Author
Owner

@⁠bobrass on GitHub · 2026-11-04 22:47 UTC · original

Thanks for flagging #1570. I checked its description: it includes the same IAdd32 lowering and says the overlapping lines can be dropped from whichever PR lands second. I’ll defer to whichever PR lands first and keep the overlap in mind.

**@⁠bobrass** on GitHub · 2026-11-04 22:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2008#issuecomment-6644116906) Thanks for flagging #1570. I checked its description: it includes the same IAdd32 lowering and says the overlapping lines can be dropped from whichever PR lands second. I’ll defer to whichever PR lands first and keep the overlap in mind.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.