shader: lower a conditional branch with identical targets to OpBranch #1012
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1012
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1012"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@wuboo on GitHub · 2026-10-03 17:21 UTC · original
wuboo:pr/degenerate-branch→main· +85 −0 · 2 files · 2 commits · openThe SPIR-V emitter can produce
OpSelectionMerge %mfollowed byOpBranchConditional %c %m %m: anifwhose arm was emptied, so both edges of the conditional go to the merge block. The SPIR-V is valid, but
SPIRV-Cross (used by MoltenVK for MSL) discards all code that follows such a selection.
Impact
In Astro Bot, 2 of 666 shaders contain this shape. Compute shader
01d6…has two such branches and its MSLshrank from about 30k lines (370 stores) to about 1k lines with no stores, so on macOS the shader compiled
fine and silently did nothing.
Fix
In
EmitStructuredTerminator, when a non-loopConditionalBranchhastrue_block == false_block, emit a plainOpBranchto that block (noOpSelectionMerge). The result is semantically identical and always valid.Testing
TestNewShaderRecompilerCfgIdenticalBranchTargetsinshader_cfg_tests: a hand-built IR program whoseentry block ends in a conditional branch with
true == false == merge; asserts the emitted SPIR-V has noOpBranchConditionalwith equal targets and passesspirv-val. Without the fix it aborts with"SPIR-V has OpBranchConditional with identical targets"; with it the test passes. (The IR is built by hand
because I could not produce this shape from a small guest shader through the CFG builder.)
ctestidentical tomain19a9464b: 34 pass, 16 need a Vulkan device and were not run here.@coderabbitai[bot] on GitHub · 2026-10-03 17:28 UTC · original · edited 2026-10-03 19:18 UTC
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
3f5a20c8-06f6-4287-a9e7-964c039a3b38📥 Commits
Reviewing files that changed from the base of the PR and between
3e1d888458andca04dbdb4a.📒 Files selected for processing (1)
tests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough
The SPIR-V emitter now emits an unconditional branch when a non-loop conditional has identical true and false targets. The regression test checks the emitted instructions and validates the resulting SPIR-V.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
ca04dThe change appears mergeable: the targeted branch-lowering regression is covered, and no actionable risk remains in the supplied evidence.
🚥 Pre-merge checks | ✅ 4 | ❓ 1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
OpBranch.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 1 functions across 1 files. (1 skipped: 1 too large.)
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 helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-03 17:28 UTC · original · reviewed
🧹 Nitpick comments (1)
ℹ️ Review info
⚙️ Run configuration
5740ae0f-544f-43f1-88ce-f18d05f5cd0c📥 Commits
Reviewing files that changed from the base of the PR and between
e7f6327068and3e1d888458.📒 Files selected for processing (2)
src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@wuboo on GitHub · 2026-10-03 19:05 UTC · original
Added in
ca04dbdb: the test now also checks that no OpBranchConditional (250) is emitted and that there are at least two OpBranch (249) — the entry->merge edge and the lowered conditional. Checked against the fixture; with the emitter fix reverted the test fails.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.