shader: test a wave-wide zero branch as no lane failing #985

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

@⁠wuboo on GitHub · 2026-10-02 21:01 UTC · original
wuboo:pr/zero-branch-ballot → main · +59 −14 · 4 files · 2 commits · closed without merging

Problem

s_cbranch_execz, s_cbranch_vccz and s_cbranch_scc0 are taken when the condition holds on every lane. EmitConditionRef on current main implements that as an all-ones ballot: AND the two wave halves and compare with ~0.

A ballot does not set bits for lanes that have no work. A per-vertex capture wave past the vertex count, or a wave64 shader run as two wave32 halves, therefore never sees all-ones. Every such loop stays taken and runs until an iteration cap, or forever if there is no cap.

On Astro Bot's world scene that was about 50 seconds per frame at a cap of 65536 iterations, once per vertex. 35759e48 (wave32 guards) and f29bd0fe (ballot reuse) do not change this compare. EmitConditionRef still uses OpBitwiseAnd and OpIEqual against ~0 for a *Zero branch. The split itself is still there: lane_count is 2 when the guest wave is 64 and the host subgroup is 32.

Change

For a *Zero branch the ballot is of the inverted condition, the two halves are OR-ed, and the branch is taken when that word is 0: no lane fails the condition. Lanes that never vote do not keep the wave in the loop. When every lane is active the result matches the old all-ones test.

Other branches stay "any lane is true" (OpINotEqual against 0), without the invert.

Tests

shader_cfg_tests, Release, macOS, KYTY_VS_LANE_FROM_INDEX=0: exit 0.

TestZeroBranchBallotIgnoresInactiveLanes compiles the same small loop as s_cbranch_execz and as s_cbranch_execnz, with wave_size 64 and host_subgroup_size 32. Both binaries validate. The execz binary contains more OpLogicalNot (opcode 168) than the execnz binary, which is the inverted ballot.

Release kyty_emulator from this branch links.

Limits

The test checks the opcode, not a rendered frame.

**@⁠wuboo** on GitHub · 2026-10-02 21:01 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/985) `wuboo:pr/zero-branch-ballot` → `main` · +59 −14 · 4 files · 2 commits · closed without merging ### Problem `s_cbranch_execz`, `s_cbranch_vccz` and `s_cbranch_scc0` are taken when the condition holds on every lane. `EmitConditionRef` on current main implements that as an all-ones ballot: AND the two wave halves and compare with `~0`. A ballot does not set bits for lanes that have no work. A per-vertex capture wave past the vertex count, or a wave64 shader run as two wave32 halves, therefore never sees all-ones. Every such loop stays taken and runs until an iteration cap, or forever if there is no cap. On Astro Bot's world scene that was about 50 seconds per frame at a cap of 65536 iterations, once per vertex. `35759e48` (wave32 guards) and `f29bd0fe` (ballot reuse) do not change this compare. `EmitConditionRef` still uses `OpBitwiseAnd` and `OpIEqual` against `~0` for a `*Zero` branch. The split itself is still there: `lane_count` is 2 when the guest wave is 64 and the host subgroup is 32. ### Change For a `*Zero` branch the ballot is of the inverted condition, the two halves are OR-ed, and the branch is taken when that word is 0: no lane fails the condition. Lanes that never vote do not keep the wave in the loop. When every lane is active the result matches the old all-ones test. Other branches stay "any lane is true" (`OpINotEqual` against 0), without the invert. ### Tests `shader_cfg_tests`, Release, macOS, `KYTY_VS_LANE_FROM_INDEX=0`: exit 0. `TestZeroBranchBallotIgnoresInactiveLanes` compiles the same small loop as `s_cbranch_execz` and as `s_cbranch_execnz`, with `wave_size` 64 and `host_subgroup_size` 32. Both binaries validate. The execz binary contains more `OpLogicalNot` (opcode 168) than the execnz binary, which is the inverted ballot. Release `kyty_emulator` from this branch links. ### Limits The test checks the opcode, not a rendered frame.
An all-ones ballot of a *Zero condition counts lanes that have no work as
failures, so a capture wave past the vertex count never left its loops and
ran them out to the iteration cap. Ballot the inverted condition and take
the branch when no lane fails it. Every lane active gives the same result.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:39:19 +00:00
github-bot closed this pull request 2026-11-26 09:39:19 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 21:06 UTC · original · edited 2026-10-02 21:29 UTC

Review in Change Stack →

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

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

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

Review profile: CHILL

Plan: Advanced

Run ID: d985a0b0-e062-44b5-9d7c-0ea7d3265573

📥 Commits

Reviewing files that changed from the base of the PR and between 139a260e49 and daff547ea4.

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

Walkthrough

The SPIR-V emitter now negates ballot predicates for ExecZero, VccZero, and SccZero, then checks whether the combined ballot words are zero. Other branch conditions retain the nonzero comparison. A regression test compiles and validates EXECZ and EXECNZ shaders with host subgroup size 32 and wave size 64, then compares their opcode 168 counts.

Suggested reviewers: nmzik

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: 🔵 Low · up to 139a2

The zero-branch change is mergeable with a bounded testing gap: the new test does not check that EXECZ takes the intended reduction direction.

🚥 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 3 functions across 3 files. (1 skipped: 1 … 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 identifies the shader zero-branch change and its wave-wide behavior. It is concise and related to the main changeset.
Description check ✅ Passed The description clearly explains the zero-branch ballot change, the inactive-lane problem, and the validation performed by the tests.
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: 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 3 functions across 3 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 21:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/985#issuecomment-5961488001) · edited 2026-10-02 21:29 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/985?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 --> <!-- This is an auto-generated comment: rate limited by coderabbit.ai --> > [!WARNING] > ## Review limit reached > > You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. > > **Next included review available in 13 minutes.** > > [Check out review usage here](https://app.coderabbit.ai/dashboard/review-capacity?orgId=d7cf2749-f181-4119-ba0c-ad79606afdfe). > > <details> > <summary>View limit details</summary> > > **Limit details:** You’ve used all 8 included reviews currently available. > > [Learn how review limits work](https://docs.coderabbit.ai/management/plans#rate-limits). > > **Review configuration:** > > <details> > <summary>⚙️ Run configuration</summary> > > **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml > > **Review profile**: CHILL > > **Plan**: Advanced > > **Run ID**: `d985a0b0-e062-44b5-9d7c-0ea7d3265573` > > </details> > > <details> > <summary>📥 Commits</summary> > > Reviewing files that changed from the base of the PR and between 139a260e4975dd612cfc4e84d84c002bfa9c2b39 and daff547ea478875d4394b3c58d038f4b59c65aa5. > > </details> > > <details> > <summary>📒 Files selected for processing (1)</summary> > > * `tests/shaderCfgTests.cpp` > > </details> > > </details> <!-- end of auto-generated comment: rate limited by coderabbit.ai --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The SPIR-V emitter now negates ballot predicates for `ExecZero`, `VccZero`, and `SccZero`, then checks whether the combined ballot words are zero. Other branch conditions retain the nonzero comparison. A regression test compiles and validates EXECZ and EXECNZ shaders with host subgroup size 32 and wave size 64, then compares their opcode 168 counts. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"139a260e4975dd612cfc4e84d84c002bfa9c2b39" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🔵 Low_ · up to `139a2` <!-- final_review_risk_coverage:{"sourceCommitId":"139a260e4975dd612cfc4e84d84c002bfa9c2b39","coveredCommitId":"139a260e4975dd612cfc4e84d84c002bfa9c2b39","kind":"reviewed"} --> The zero-branch change is mergeable with a bounded testing gap: the new test does not check that EXECZ takes the intended reduction direction. <!-- 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 3 functions across 3 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 | | :------------------------: | :------- | :------------------------------------------------------------------------------------------------------------------------------------ | | Title check | ✅ Passed | The title identifies the shader zero-branch change and its wave-wide behavior. It is concise and related to the main changeset. | | Description check | ✅ Passed | The description clearly explains the zero-branch ballot change, the inactive-lane problem, and the validation performed by the tests. | | 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. | </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 3 functions across 3 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=985)! 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 21:06 UTC · original · reviewed

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

14261-14286: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the EXECZ reduction direction.

This test only compiles the fixture. The fixture does not modify EXEC, and the assertion only counts OpLogicalNot. A regression that keeps predicate inversion but changes the EXECZ reduction from OpIEqual to OpINotEqual can pass.

Suggested fix
   Check(SpirvInstructionOpcodeCount(zero.spirv, 168u) >
             SpirvInstructionOpcodeCount(nonzero.spirv, 168u),
         "an ExecZero branch on a split wave did not ballot the inverted condition");
+  Check(SpirvContainsOpcode(zero.spirv, 170u) &&
+            !SpirvContainsOpcode(zero.spirv, 171u) &&
+            SpirvContainsOpcode(nonzero.spirv, 171u) &&
+            !SpirvContainsOpcode(nonzero.spirv, 170u),
+        "split-wave EXECZ and EXECNZ used the wrong zero reduction");

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Advanced

Run ID: 0fbb8d96-f80b-4ea0-bf34-904cecbfe60c

📥 Commits

Reviewing files that changed from the base of the PR and between e317465d8a and 139a260e49.

📒 Files selected for processing (4)
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h
  • 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; 4 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 21:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/985#pullrequestreview-5396858943) · **reviewed** <details> <summary>🧹 Nitpick comments (1)</summary><blockquote> <details> <summary>tests/shaderCfgTests.cpp (1)</summary><blockquote> `14261-14286`: _🎯 Functional Correctness_ | _🔵 Trivial_ | _⚡ Quick win_ **Assert the EXECZ reduction direction.** This test only compiles the fixture. The fixture does not modify `EXEC`, and the assertion only counts `OpLogicalNot`. A regression that keeps predicate inversion but changes the EXECZ reduction from `OpIEqual` to `OpINotEqual` can pass. <details> <summary>Suggested fix</summary> ```diff Check(SpirvInstructionOpcodeCount(zero.spirv, 168u) > SpirvInstructionOpcodeCount(nonzero.spirv, 168u), "an ExecZero branch on a split wave did not ballot the inverted condition"); + Check(SpirvContainsOpcode(zero.spirv, 170u) && + !SpirvContainsOpcode(zero.spirv, 171u) && + SpirvContainsOpcode(nonzero.spirv, 171u) && + !SpirvContainsOpcode(nonzero.spirv, 170u), + "split-wave EXECZ and EXECNZ used the wrong zero reduction"); ``` </details> <!-- cr-comment:v1:c5c31624da7d0c9642d91bcb --> </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**: `0fbb8d96-f80b-4ea0-bf34-904cecbfe60c` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e317465d8a773b33482ad367ad2f856154c8bc6d and 139a260e4975dd612cfc4e84d84c002bfa9c2b39. </details> <details> <summary>📒 Files selected for processing (4)</summary> * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h` * `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; 4 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Author
Owner

@⁠wuboo on GitHub · 2026-10-02 21:29 UTC · original

Re the nitpick on the reduction direction: daff547e adds direct checks. The EXECZ fixture must have more OpIEqual (170) and the EXECNZ fixture more OpINotEqual (171). The fixtures contain no other integer compares (EXECZ 170=1/171=0, EXECNZ 170=0/171=1), so the comparison is exact. Swapping the two opcodes in the emitter makes the test abort.

**@⁠wuboo** on GitHub · 2026-10-02 21:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/985#issuecomment-5961772095) Re the nitpick on the reduction direction: daff547e adds direct checks. The EXECZ fixture must have more `OpIEqual` (170) and the EXECNZ fixture more `OpINotEqual` (171). The fixtures contain no other integer compares (EXECZ 170=1/171=0, EXECNZ 170=0/171=1), so the comparison is exact. Swapping the two opcodes in the emitter makes the test abort.
Author
Owner

@⁠Nmzik on GitHub · 2026-10-21 19:41 UTC · original

Superseded by bb2d6dbeb.

**@⁠Nmzik** on GitHub · 2026-10-21 19:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/985#issuecomment-6324935531) Superseded by bb2d6dbeb.

Pull request closed

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