shader: a branch on a lane mask whose arms keep EXEC is taken by the whole wave (#66) #72

Closed
github-bot wants to merge 0 commits from github-bot/gh-72 into main AGit
Owner

@⁠Hasusmogus on GitHub · 2026-11-27 08:13 UTC · original
Hasusmogus:fix-66-scc-branch → main · +411 −1 · 4 files · 2 commits · closed without merging

Fixes #66.

The bug

s_and_b64 s, vcc, exec sets SCC when some lane of the wave has its bit, and s_cbranch_scc0 on it sends the whole wave one way. The structure (structure.rs) split such a branch per lane, each lane by its own bit. That is exact only where the arm narrows EXEC to the lanes that went its way (s_and_saveexec + s_cbranch_execz). Where the arms keep EXEC, the lanes whose own bit was clear ran the other arm.

The fix

  • Lanes::lane_split_loses: a branch on a lane mask (SCC of a mask operation, or VCC; not EXEC branches, not conditions over uniform atoms only) whose arms run vector instructions under an EXEC that is not inside the lanes that went that way is kept as the console has it. It goes into Structured::wide, the same thing structure_wide does for the branches the lowering asks for: one decision for the wave, exchanged between the two host halves.
  • A program that then needs every lane where such a branch stands goes through the existing retry forms (all three variants from the issue translate exactly with "without skips").
  • If no form translates, emit falls back to the old per-lane split (structure::structure_per_lane), so nothing that translated before is dropped. VICTORY_LANE_SPLIT=exact refuses it instead, and VICTORY_WAVE_WHY=1 logs when the fallback is used.
  • Two tests expected the old split: the issue's own the_mask_scc_in_a_lane_branch_lowers_without_its_exec_skip, and the s_cbranch_scc0 case of a_wave_or_inside_a_lane_branch_needs_the_branch_wave_wide, whose body is whole-wave code (s_or_saveexec_b64 -1) that every lane runs on the console.

The issue author's test commit is kept as is (thanks @⁠steven-seagull27 for the precise repro).

Tested

On an NVIDIA RTX A3000 Laptop GPU (Ampere, waves of 32) through vkd3d-proton (Proton Experimental):

Combined Branch Select
before 188/576 wrong 188/576 wrong 0
after 0 0 0

(both_halves_observe_the_same_mask_scc_on_a_wave32_device, the same 188 as on the RTX 5080.)

  • The whole victory-shader suite on that GPU: 301 passed both before and after; the one failure (emit::tests::stub_pipeline_is_created) fails on both.
  • cargo clippy --workspace --all-targets [--all-features] -- -D warnings: clean.
  • Not tested on the title: more branches than before may now be taken wave-wide or go through the retry forms. VICTORY_WAVE_WHY=1 shows which, and VICTORY_LANE_SPLIT=exact shows what would be refused without the fallback.

🤖 Generated with Claude Code

**@⁠Hasusmogus** on GitHub · 2026-11-27 08:13 UTC · [original](https://github.com/DoubleGhosty/cool_fox/pull/72) `Hasusmogus:fix-66-scc-branch` → `main` · +411 −1 · 4 files · 2 commits · closed without merging Fixes #66. ## The bug `s_and_b64 s, vcc, exec` sets SCC when *some* lane of the wave has its bit, and `s_cbranch_scc0` on it sends the whole wave one way. The structure (`structure.rs`) split such a branch per lane, each lane by its own bit. That is exact only where the arm narrows EXEC to the lanes that went its way (`s_and_saveexec` + `s_cbranch_execz`). Where the arms keep EXEC, the lanes whose own bit was clear ran the other arm. ## The fix - `Lanes::lane_split_loses`: a branch on a lane mask (SCC of a mask operation, or VCC; not EXEC branches, not conditions over uniform atoms only) whose arms run vector instructions under an EXEC that is not inside the lanes that went that way is kept as the console has it. It goes into `Structured::wide`, the same thing `structure_wide` does for the branches the lowering asks for: one decision for the wave, exchanged between the two host halves. - A program that then needs every lane where such a branch stands goes through the existing retry forms (all three variants from the issue translate exactly with "without skips"). - If no form translates, `emit` falls back to the old per-lane split (`structure::structure_per_lane`), so nothing that translated before is dropped. `VICTORY_LANE_SPLIT=exact` refuses it instead, and `VICTORY_WAVE_WHY=1` logs when the fallback is used. - Two tests expected the old split: the issue's own `the_mask_scc_in_a_lane_branch_lowers_without_its_exec_skip`, and the `s_cbranch_scc0` case of `a_wave_or_inside_a_lane_branch_needs_the_branch_wave_wide`, whose body is whole-wave code (`s_or_saveexec_b64 -1`) that every lane runs on the console. The issue author's test commit is kept as is (thanks @⁠steven-seagull27 for the precise repro). ## Tested On an NVIDIA RTX A3000 Laptop GPU (Ampere, waves of 32) through vkd3d-proton (Proton Experimental): | | Combined | Branch | Select | |---|---:|---:|---:| | before | 188/576 wrong | 188/576 wrong | 0 | | after | 0 | 0 | 0 | (`both_halves_observe_the_same_mask_scc_on_a_wave32_device`, the same 188 as on the RTX 5080.) - The whole `victory-shader` suite on that GPU: 301 passed both before and after; the one failure (`emit::tests::stub_pipeline_is_created`) fails on both. - `cargo clippy --workspace --all-targets [--all-features] -- -D warnings`: clean. - Not tested on the title: more branches than before may now be taken wave-wide or go through the retry forms. `VICTORY_WAVE_WHY=1` shows which, and `VICTORY_LANE_SPLIT=exact` shows what would be refused without the fallback. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`s_and_b64 s, vcc, exec` sets SCC when some lane of the wave has its bit,
and `s_cbranch_scc0` on it sends the whole wave one way. The structure
split such a branch per lane, each lane by its own bit: exact only where
the arm narrows EXEC to the lanes that went its way (`s_and_saveexec` and
`execz`). Where the arms keep EXEC, the lanes whose own bit was clear ran
the other arm (188 of 576 words wrong on an RTX 5080 and on WARP).

Such branches (SCC of a mask operation, VCC; not EXEC, not over uniform
atoms only) are now kept as the console has them, as `structure_wide`
does for the ones the lowering asks for: one decision for the wave, the
two host halves exchanging it. A program that then needs every lane
where one stands is retried in its other forms ("without skips" for the
issue's three); if none translates, it is taken split per lane as before
(`structure_per_lane`; `VICTORY_LANE_SPLIT=exact` refuses it instead).

The issue's test and the wave-OR test expected the old split.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 08:16:48 +00:00
github-bot closed this pull request 2026-11-27 08:56:30 +00:00
Author
Owner

@⁠DoubleGhosty on GitHub · 2026-11-27 08:53 UTC · original

Issue #66 was already fixed in main (9a4aa8d3, verified 0/64 mismatches on Wave32 hardware).

**@⁠DoubleGhosty** on GitHub · 2026-11-27 08:53 UTC · [original](https://github.com/DoubleGhosty/cool_fox/pull/72#issuecomment-7214049166) Issue #66 was already fixed in main (9a4aa8d3, verified 0/64 mismatches on Wave32 hardware).

Pull request closed

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