shader: find a ballot's first lane without OpGroupNonUniformBallotFindLSB #983

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

@⁠wuboo on GitHub · 2026-10-02 19:57 UTC · original
wuboo:pr/ballot-first-lane → main · +10 −6 · 2 files · 2 commits · closed without merging

Problem

ValueEmitContext::FirstLane emits OpGroupNonUniformBallotFindLSB when the wave is a single subgroup. SPIRV-Cross lowers that op to a helper that takes the subgroup size (threads_per_simdgroup), and Metal does not allow that attribute in vertex functions. On macOS/MoltenVK, a vertex shader in Astro Bot's (PPSA21564) main menu failed pipeline creation with:

invalid threads_per_simdgroup attribute

Change

Always find the first lane with FindILsb on the ballot's first two words, which is what the two-half wave64 path in the same function already does. Bits past the subgroup size are always zero in a ballot, so the result is the same on every host. The only SPIR-V difference is an OpExtInst/OpSelect pair instead of the group op.

The DS append loop test in shaderCfgTests (which reaches FirstLane) now checks that OpGroupNonUniformBallotFindLSB is not emitted and that a GLSL.std.450 FindILsb is. Without the emitter change that test fails. The older FindLSB expectation sits in TestNewShaderRecompilerMoreAluFamilies, which main() does not call, so it is left as it was.

Testing

  • shader_cfg_tests (Release, macOS x86_64) passes.
  • The same change has been in my macOS/MoltenVK integration build since 27 September. With it, Astro Bot's menu and first level render, and this shader no longer fails pipeline creation.
**@⁠wuboo** on GitHub · 2026-10-02 19:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/983) `wuboo:pr/ballot-first-lane` → `main` · +10 −6 · 2 files · 2 commits · closed without merging ### Problem `ValueEmitContext::FirstLane` emits `OpGroupNonUniformBallotFindLSB` when the wave is a single subgroup. SPIRV-Cross lowers that op to a helper that takes the subgroup size (`threads_per_simdgroup`), and Metal does not allow that attribute in vertex functions. On macOS/MoltenVK, a vertex shader in Astro Bot's (PPSA21564) main menu failed pipeline creation with: ``` invalid threads_per_simdgroup attribute ``` ### Change Always find the first lane with `FindILsb` on the ballot's first two words, which is what the two-half wave64 path in the same function already does. Bits past the subgroup size are always zero in a ballot, so the result is the same on every host. The only SPIR-V difference is an `OpExtInst`/`OpSelect` pair instead of the group op. The DS append loop test in `shaderCfgTests` (which reaches `FirstLane`) now checks that `OpGroupNonUniformBallotFindLSB` is not emitted and that a GLSL.std.450 `FindILsb` is. Without the emitter change that test fails. The older FindLSB expectation sits in `TestNewShaderRecompilerMoreAluFamilies`, which `main()` does not call, so it is left as it was. ### Testing - `shader_cfg_tests` (Release, macOS x86_64) passes. - The same change has been in my macOS/MoltenVK integration build since 27 September. With it, Astro Bot's menu and first level render, and this shader no longer fails pipeline creation.
SPIRV-Cross lowers OpGroupNonUniformBallotFindLSB to a helper that takes the
subgroup size (threads_per_simdgroup), and Metal does not allow that attribute
in vertex functions. On macOS/MoltenVK a vertex shader in Astro Bot's menu
failed to compile with 'invalid threads_per_simdgroup attribute'.

Find the lowest set bit of the ballot words with FindILsb instead, which the
two-half wave64 path already does. Bits past the subgroup size are zero in a
ballot, so the result is the same.
The FindLSB expectation lived in TestNewShaderRecompilerMoreAluFamilies, which
main() does not call (it fails on unrelated decoder changes), so the previous
check never ran. Restore that test as it was and check the lowering in the DS
append loop test instead, which reaches FirstLane: no
OpGroupNonUniformBallotFindLSB, at least one GLSL.std.450 FindILsb. Without the
emitter change this test now fails.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:39:15 +00:00
github-bot closed this pull request 2026-11-26 09:39:15 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 20:07 UTC · original · edited 2026-10-02 21:12 UTC

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: 6cbd09f7-7d60-4843-a509-de37895cb017

📥 Commits

Reviewing files that changed from the base of the PR and between 6f1af3f465 and 44dd44bcd7.

📒 Files selected for processing (1)
  • tests/shaderCfgTests.cpp

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


📝 Walkthrough

Walkthrough

FirstLane now finds the least-significant set bit directly from ballot words in both single-half and two-half execution. The test checks that generated SPIR-V omits opcode 343 and contains the FindILsb extended instruction, opcode 73.

Suggested reviewers: nmzik

Priority: ⬆️ High

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 44dd4

The changed lowering is exercised by the DS append/consume test, which rejects the previous instruction. The remaining stale expectation is not reached by the configured test entrypoint; no actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❓ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ❓ Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly describes the main change: replacing OpGroupNonUniformBallotFindLSB with a ballot-based first-lane lookup.
Description check ✅ Passed The description explains the Metal pipeline failure, the emitter change, the test update, and the reported validation results.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (1 skipped: 1 too large.)

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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-10-02 20:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/983#issuecomment-5960600895) · edited 2026-10-02 21:12 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/983?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> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `6cbd09f7-7d60-4843-a509-de37895cb017` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 6f1af3f465f8797f298156157796eb5dadfa63e5 and 44dd44bcd76f3377d59d0c0ebcebfee75965b01b. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `tests/shaderCfgTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough `FirstLane` now finds the least-significant set bit directly from ballot words in both single-half and two-half execution. The test checks that generated SPIR-V omits opcode 343 and contains the `FindILsb` extended instruction, opcode 73. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬆️ High <!-- change_assessment_commit:"44dd44bcd76f3377d59d0c0ebcebfee75965b01b" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `44dd4` <!-- final_review_risk_coverage:{"sourceCommitId":"44dd44bcd76f3377d59d0c0ebcebfee75965b01b","coveredCommitId":"44dd44bcd76f3377d59d0c0ebcebfee75965b01b","kind":"reviewed"} --> The changed lowering is exercised by the DS append/consume test, which rejects the previous instruction. The remaining stale expectation is not reached by the configured test entrypoint; no actionable merge risk remains. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❓ 1</summary> ### ❌ Failed checks (1 inconclusive) | Check name | Status | Explanation | Resolution | | :----------------: | :------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ❓ Inconclusive | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (1 skipped: 1 … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :----------------------------------------------------------------------------------------------------------------------------- | | 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. | | Title check | ✅ Passed | The title clearly describes the main change: replacing OpGroupNonUniformBallotFindLSB with a ballot-based first-lane lookup. | | Description check | ✅ Passed | The description explains the Metal pipeline failure, the emitter change, the test update, and the reported validation results. | </details> <details> <summary>Full details: Docstring Coverage</summary> **Explanation** Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (1 skipped: 1 too large.) </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts > Autopilot is currently an internal CodeRabbit preview. <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=983)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [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) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 20:07 UTC · original · reviewed

🧹 Nitpick comments (1)
tests/shaderCfgTests.cpp (1)

3144-3145: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Count the expected FindILsb instructions.

The generic OpExtInst check is not specific. A SpirvContainsExtInst(result.spirv, 73) check is also insufficient because this shader emits two unrelated FindILsb instructions for V_FFBL_B32. The ballot lowering emits two more. Check the expected total instead.

Suggested fix
-  Check(SpirvContainsOpcode(result.spirv, 12),
-        "SPIR-V binary does not contain OpExtInst for the ballot's first lane");
+  Check(SpirvExtInstCount(result.spirv, 73) == 4,
+        "SPIR-V binary does not contain all expected GLSL.std.450 FindILsb instructions");

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: b63943b4-8d4b-4f46-938e-95c5da7aa575

📥 Commits

Reviewing files that changed from the base of the PR and between e317465d8a and 6f1af3f465.

📒 Files selected for processing (2)
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp
  • tests/shaderCfgTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 20:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/983#pullrequestreview-5396304431) · **reviewed** <details> <summary>🧹 Nitpick comments (1)</summary><blockquote> <details> <summary>tests/shaderCfgTests.cpp (1)</summary><blockquote> `3144-3145`: _🎯 Functional Correctness_ | _🔵 Trivial_ | _⚡ Quick win_ **Count the expected `FindILsb` instructions.** The generic `OpExtInst` check is not specific. A `SpirvContainsExtInst(result.spirv, 73)` check is also insufficient because this shader emits two unrelated `FindILsb` instructions for `V_FFBL_B32`. The ballot lowering emits two more. Check the expected total instead. <details> <summary>Suggested fix</summary> ```diff - Check(SpirvContainsOpcode(result.spirv, 12), - "SPIR-V binary does not contain OpExtInst for the ballot's first lane"); + Check(SpirvExtInstCount(result.spirv, 73) == 4, + "SPIR-V binary does not contain all expected GLSL.std.450 FindILsb instructions"); ``` </details> <!-- cr-comment:v1:d6edf7e5e6b8cecc3ce51c0b --> </blockquote></details> </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `b63943b4-8d4b-4f46-938e-95c5da7aa575` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e317465d8a773b33482ad367ad2f856154c8bc6d and 6f1af3f465f8797f298156157796eb5dadfa63e5. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp` * `tests/shaderCfgTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Author
Owner

@⁠wuboo on GitHub · 2026-10-02 20:58 UTC · original

Good catch. Looking closer, the problem was bigger: TestNewShaderRecompilerMoreAluFamilies is not called from main() (it fails earlier on unrelated decoder expectations), so that check never ran, either before or after this change. In 44dd44bc I restored that test as it was and moved the check into the DS append loop test, which does run and reaches FirstLane. It now asserts there is no OpGroupNonUniformBallotFindLSB and at least one FindILsb. I verified that it fails with the old emitter and passes with this change.

**@⁠wuboo** on GitHub · 2026-10-02 20:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/983#issuecomment-5961367989) Good catch. Looking closer, the problem was bigger: `TestNewShaderRecompilerMoreAluFamilies` is not called from `main()` (it fails earlier on unrelated decoder expectations), so that check never ran, either before or after this change. In 44dd44bc I restored that test as it was and moved the check into the DS append loop test, which does run and reaches `FirstLane`. It now asserts there is no `OpGroupNonUniformBallotFindLSB` and at least one `FindILsb`. I verified that it fails with the old emitter and passes with this change.

Pull request closed

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