shader: fold constant lane-mask bit tests #637

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

@⁠carbonimax on GitHub · 2026-09-16 13:15 UTC · original
carbonimax:fix/constant-lane-mask → main · +216 −44 · 2 files · 2 commits · closed without merging

Constant lane-mask tests such as ((0xffffffff >> (lane & 31)) & 1) != 0 retained their LaneId dependency after constant propagation. This caused a vertex shader to require SubgroupLocalInvocationId, which MoltenVK cannot translate for a vertex function, even though these predicates were independent of the lane.

Fold the low-bit test to 0 or 1 when the source word is uniformly zero or one and the shift count is proven to be within 0–31. Existing dead-code elimination then removes the unused lane query. Mixed or dynamic masks, other output bits, and unbounded shifts remain unchanged; other consumers of the shifted value are preserved.

Validation on Apple M4 Pro with the x86_64 build under Rosetta:

  • The new regression fails against the pre-patch implementation and passes with this change. It covers both constants, commuted operands, dead lane-query removal, and the cases that must not fold.
  • Built the emulator and relevant test targets; all seven selected CTests passed in an integration checkout containing #633 and #635.
  • The affected vertex shader went from four subgroup-ID loads to none (894 to 519 SPIR-V words), passed spirv-val --target-env vulkan1.3, and its graphics pipeline was created successfully by MoltenVK.
  • The game progressed to 19 compiled shaders, then stopped on the separately unsupported MIMG opcode 0xe6. This change does not establish playability.

This PR contains only the constant-propagation change and its tests; the startup fixes from #633 and #635 are separate.

AI assistance: DeepSeek generated the implementation and tests; Codex reviewed them, requested test corrections, and performed build, regression, SPIR-V, and game validation. An independent Codex review reported no correctness findings.

**@⁠carbonimax** on GitHub · 2026-09-16 13:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/637) `carbonimax:fix/constant-lane-mask` → `main` · +216 −44 · 2 files · 2 commits · closed without merging Constant lane-mask tests such as `((0xffffffff >> (lane & 31)) & 1) != 0` retained their `LaneId` dependency after constant propagation. This caused a vertex shader to require `SubgroupLocalInvocationId`, which MoltenVK cannot translate for a vertex function, even though these predicates were independent of the lane. Fold the low-bit test to 0 or 1 when the source word is uniformly zero or one and the shift count is proven to be within 0–31. Existing dead-code elimination then removes the unused lane query. Mixed or dynamic masks, other output bits, and unbounded shifts remain unchanged; other consumers of the shifted value are preserved. Validation on Apple M4 Pro with the x86_64 build under Rosetta: - The new regression fails against the pre-patch implementation and passes with this change. It covers both constants, commuted operands, dead lane-query removal, and the cases that must not fold. - Built the emulator and relevant test targets; all seven selected CTests passed in an integration checkout containing #633 and #635. - The affected vertex shader went from four subgroup-ID loads to none (894 to 519 SPIR-V words), passed `spirv-val --target-env vulkan1.3`, and its graphics pipeline was created successfully by MoltenVK. - The game progressed to 19 compiled shaders, then stopped on the separately unsupported MIMG opcode `0xe6`. This change does not establish playability. This PR contains only the constant-propagation change and its tests; the startup fixes from #633 and #635 are separate. AI assistance: DeepSeek generated the implementation and tests; Codex reviewed them, requested test corrections, and performed build, regression, SPIR-V, and game validation. An independent Codex review reported no correctness findings.
Apply the repository's pinned clang-format 22.1.3 hook to the source files modified by this pull request.

Assisted-by: OpenAI GPT-6.1 Sol
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:27:46 +00:00
github-bot closed this pull request 2026-11-26 09:27:46 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-16 13:15 UTC · original · edited 2026-10-10 22:51 UTC

Review in Change Stack →

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. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: df74cc72-06ff-43ab-a352-d34dd25859bf

📥 Commits

Reviewing files that changed from the base of the PR and between d0d4787e3a4ed1b2cb6c53430290001c3532bc0c and c3ed65636f11d2f49e4d925a69c13f3074c53890.


📒 Files selected for processing (2)
  • src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp
  • tests/ScalarProvenanceTests.cpp

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



📝 Walkthrough

Walkthrough

The constant propagation pass now folds bounded shifted-bit tests for zero and all-ones words. New scalar provenance tests cover foldable cases and cases that remain lane-dependent.

Changes

Constant shifted-bit folding

Layer / File(s) Summary
Shifted-bit optimization
src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp
The BitwiseAnd32 folding path detects bounded shifts below 32. It replaces qualifying tests with 0 or 1 for zero or all-ones words. Formatting-only changes are also included.
Shifted-bit optimization tests
tests/ScalarProvenanceTests.cpp
New helpers and tests cover constant words, commuted operands, mixed or dynamic words, wider output masks, and unbounded shifts. The test is registered in main.

Suggested reviewers: nmzik


Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to c3ed6

This change folds constant lane-mask bit tests so unused lane queries can be removed. The supplied evidence shows no actionable merge risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: folding constant lane-mask bit tests in shaders.
Description check Passed The description directly explains the constant-propagation change, preserved cases, regression coverage, and validation results.
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.


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 help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-16 13:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/637#issuecomment-5698075082) · edited 2026-10-10 22:51 UTC <!-- 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/637?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></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. > > 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_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `df74cc72-06ff-43ab-a352-d34dd25859bf` <hr> </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between d0d4787e3a4ed1b2cb6c53430290001c3532bc0c and c3ed65636f11d2f49e4d925a69c13f3074c53890. <hr> </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing (2)</strong></summary> <dl> <dd> * `src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp` * `tests/ScalarProvenanceTests.cpp` <hr> </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review. <hr> </dd> </dl> </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> ## Walkthrough The constant propagation pass now folds bounded shifted-bit tests for zero and all-ones words. New scalar provenance tests cover foldable cases and cases that remain lane-dependent. ### Changes **Constant shifted-bit folding** |Layer / File(s)|Summary| |:---|:---| |**Shifted-bit optimization** <br> `src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp`|The `BitwiseAnd32` folding path detects bounded shifts below 32. It replaces qualifying tests with `0` or `1` for zero or all-ones words. Formatting-only changes are also included.| |**Shifted-bit optimization tests** <br> `tests/ScalarProvenanceTests.cpp`|New helpers and tests cover constant words, commuted operands, mixed or dynamic words, wider output masks, and unbounded shifts. The test is registered in `main`.| **Suggested reviewers:** `nmzik` <hr> </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"c3ed65636f11d2f49e4d925a69c13f3074c53890" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **⚪ Minimal** · up to `c3ed6` <!-- final_review_risk_coverage:{"sourceCommitId":"c3ed65636f11d2f49e4d925a69c13f3074c53890","coveredCommitId":"c3ed65636f11d2f49e4d925a69c13f3074c53890","kind":"reviewed"} --> This change folds constant lane-mask bit tests so unused lane queries can be removed. The supplied evidence shows no actionable merge risk. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>🚥 Pre-merge checks | ✅ 4 | ❌ 1</strong></summary> <dl> <dd> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 2 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong>✅ 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 clearly and concisely describes the main change: folding constant lane-mask bit tests in shaders. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the constant-propagation change, preserved cases, regression coverage, and validation results. | | 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. | </dd> </dl> </details> <hr> </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=637)! 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) <hr> </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠carbonimax on GitHub · 2026-10-14 07:36 UTC · original

Closing: main now covers this. fa68e10 (fold full wave64 masks before register predication) folds the uniform zero / all-ones lane-mask bit test in LaneMaskProjection, and the worklist pass (df08b83) removes the dead lane query. Applied on main without this PR's code, the zero and all-ones regression cases already pass; the only remaining difference is the commuted-operand form, which Translator::ThreadBit never emits.

**@⁠carbonimax** on GitHub · 2026-10-14 07:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/637#issuecomment-6163351542) Closing: main now covers this. fa68e10 (fold full wave64 masks before register predication) folds the uniform zero / all-ones lane-mask bit test in LaneMaskProjection, and the worklist pass (df08b83) removes the dead lane query. Applied on main without this PR's code, the zero and all-ones regression cases already pass; the only remaining difference is the commuted-operand form, which Translator::ThreadBit never emits.

Pull request closed

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