Shader: preserve EXEC on stores behind wave-wide SCC branches #78

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

@⁠steven-seagull27 on GitHub · 2026-11-27 09:06 UTC · original
steven-seagull27:codex/coolfox-66-scc-exec-guards → main · +74 −22 · 3 files · 1 commits · closed without merging

Follow-up to #66 and 9a4aa8d3. The original select and branch fixtures now pass on both the RTX 5080 and WARP. Moving the store from the join into the two branch arms exposed another case.

The generated program narrows EXEC to lane < limit. The SCC set by s_and_b64 s[18:19], vcc, exec correctly takes the whole wave into the same arm. Each vector store in that arm still obeys EXEC. With 48 active lanes and lane 37 selected, main wrote 2 to all 64 dwords, including the 16 assigned to inactive lanes. Every address in the fixture is distinct and in bounds.

The lowerer already emitted a wave-wide SCC decision. Structure analysis still used the branch edge as proof of the current lane’s own comparison bit and could remove the store’s EXEC guard. The patch records the existing branch classification during structuring and uses it in both places. The lowerer keeps its existing rules for where the two host waves can exchange.

Nine 64-lane inputs for each branch polarity RTX 5080 WARP 1.0.22
Main, branch on SCC clear 127/576 wrong 127/576 wrong
Main, branch on SCC set 127/576 wrong 127/576 wrong
Patched, branch on SCC clear 0/576 wrong 0/576 wrong
Patched, branch on SCC set 0/576 wrong 0/576 wrong

The patched select, branch and combined controls also produced 0/576 wrong per shader on each adapter. Inbox WARP advertised Wave4 and skipped Wave32 execution. The CPU regression fails on the previous emitter and passes with the fix. Strict all-targets/all-features shader Clippy and the 16 structure tests passed locally.

cargo test --locked -p victory-shader --lib emit::wave64_tests::both_arms_of_a_wave_wide_scc_branch_keep_their_store_guards -- --exact --nocapture
cargo test --locked -p victory-shader --lib emit::wave64_tests::both_halves_observe_the_same_mask_scc_on_a_wave32_device -- --exact --ignored --nocapture

AI-assisted implementation and verification using synthetic instructions and readbacks.

**@⁠steven-seagull27** on GitHub · 2026-11-27 09:06 UTC · [original](https://github.com/DoubleGhosty/cool_fox/pull/78) `steven-seagull27:codex/coolfox-66-scc-exec-guards` → `main` · +74 −22 · 3 files · 1 commits · closed without merging Follow-up to #66 and `9a4aa8d3`. The original select and branch fixtures now pass on both the RTX 5080 and WARP. Moving the store from the join into the two branch arms exposed another case. The generated program narrows EXEC to `lane < limit`. The SCC set by `s_and_b64 s[18:19], vcc, exec` correctly takes the whole wave into the same arm. Each vector store in that arm still obeys EXEC. With 48 active lanes and lane 37 selected, main wrote 2 to all 64 dwords, including the 16 assigned to inactive lanes. Every address in the fixture is distinct and in bounds. The lowerer already emitted a wave-wide SCC decision. Structure analysis still used the branch edge as proof of the current lane’s own comparison bit and could remove the store’s EXEC guard. The patch records the existing branch classification during structuring and uses it in both places. The lowerer keeps its existing rules for where the two host waves can exchange. | Nine 64-lane inputs for each branch polarity | RTX 5080 | WARP 1.0.22 | | --- | ---: | ---: | | Main, branch on SCC clear | 127/576 wrong | 127/576 wrong | | Main, branch on SCC set | 127/576 wrong | 127/576 wrong | | Patched, branch on SCC clear | 0/576 wrong | 0/576 wrong | | Patched, branch on SCC set | 0/576 wrong | 0/576 wrong | The patched select, branch and combined controls also produced 0/576 wrong per shader on each adapter. Inbox WARP advertised Wave4 and skipped Wave32 execution. The CPU regression fails on the previous emitter and passes with the fix. Strict all-targets/all-features shader Clippy and the 16 structure tests passed locally. ```powershell cargo test --locked -p victory-shader --lib emit::wave64_tests::both_arms_of_a_wave_wide_scc_branch_keep_their_store_guards -- --exact --nocapture cargo test --locked -p victory-shader --lib emit::wave64_tests::both_halves_observe_the_same_mask_scc_on_a_wave32_device -- --exact --ignored --nocapture ``` AI-assisted implementation and verification using synthetic instructions and readbacks.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 09:07:15 +00:00
github-bot closed this pull request 2026-11-27 10:46:10 +00:00
Author
Owner

@⁠Hasusmogus on GitHub · 2026-11-27 09:28 UTC · original · reviewed

Looks right to me, and I could reproduce it on other hardware.

Run on an NVIDIA RTX A3000 Laptop GPU (Ampere, waves of 32) through vkd3d-proton:

main + this PR's tests only this PR
both_arms_of_a_wave_wide_scc_branch_keep_their_store_guards fails passes
GPU readback, StoreOnClear 127/576 wrong 0
GPU readback, StoreOnSet wrong 0
Combined / Branch / Select 0 0
whole victory-shader suite 301 passed, 1 failed 302 passed, 1 failed

Same 127 as your RTX 5080 and WARP. The one failure (emit::tests::stub_pipeline_is_created) fails on every build under vkd3d-proton. Clippy (-p victory-shader --all-targets --all-features) is clean.

Notes:

  1. The detection is the old one, slightly tightened: is_wave_scc_branch excluded an SCC if any instruction in its defining block wrote that SCC and EXEC; wave_scc asks only of the writer itself (defs[scc]). s_and_saveexec is still out, where the per-lane split is exact. An unrelated EXEC write in the same block no longer hides it. An SCC that comes through a phi is out in both.
  2. The ordering holds. wave_scc is filled during the reverse-postorder walk in masks_in_order, and edge() there only reads it for already visited predecessors; paths() runs once it is complete; reset() clears it, so each structure_wide round rebuilds it.
  3. Keeping it apart from wide means control_regions still treats these arms as per-lane regions, so exchanges inside them stay refused. That's conservative, as the doc comment says, but may leave some programs untranslated that the wide form would take. Worth a look if VICTORY_WAVE_WHY shows refusals inside such arms.
  4. Not for this PR: a VCC branch (s_and_b64 vcc, vcc, exec then s_cbranch_vccz/vccnz) on a VCC that differs between lanes has the same per-lane split and still goes through the lane-own-bit path. Compilers mostly emit those on uniform VCC, where the split is exact, so it's rare.
  5. Nit: the new test's instruction words are lowercase hex; the neighbouring fixtures use uppercase.

Review written with AI assistance (Claude), tests run and reviewed by me.

**@⁠Hasusmogus** on GitHub · 2026-11-27 09:28 UTC · [original](https://github.com/DoubleGhosty/cool_fox/pull/78#pullrequestreview-6086035310) · **reviewed** Looks right to me, and I could reproduce it on other hardware. **Run on an NVIDIA RTX A3000 Laptop GPU (Ampere, waves of 32) through vkd3d-proton:** | | `main` + this PR's tests only | this PR | |---|---|---| | `both_arms_of_a_wave_wide_scc_branch_keep_their_store_guards` | fails | passes | | GPU readback, `StoreOnClear` | 127/576 wrong | 0 | | GPU readback, `StoreOnSet` | wrong | 0 | | `Combined` / `Branch` / `Select` | 0 | 0 | | whole `victory-shader` suite | 301 passed, 1 failed | 302 passed, 1 failed | Same 127 as your RTX 5080 and WARP. The one failure (`emit::tests::stub_pipeline_is_created`) fails on every build under vkd3d-proton. Clippy (`-p victory-shader --all-targets --all-features`) is clean. **Notes:** 1. The detection is the old one, slightly tightened: `is_wave_scc_branch` excluded an SCC if *any* instruction in its defining block wrote that SCC and EXEC; `wave_scc` asks only of the writer itself (`defs[scc]`). `s_and_saveexec` is still out, where the per-lane split is exact. An unrelated EXEC write in the same block no longer hides it. An SCC that comes through a phi is out in both. 2. The ordering holds. `wave_scc` is filled during the reverse-postorder walk in `masks_in_order`, and `edge()` there only reads it for already visited predecessors; `paths()` runs once it is complete; `reset()` clears it, so each `structure_wide` round rebuilds it. 3. Keeping it apart from `wide` means `control_regions` still treats these arms as per-lane regions, so exchanges inside them stay refused. That's conservative, as the doc comment says, but may leave some programs untranslated that the `wide` form would take. Worth a look if `VICTORY_WAVE_WHY` shows refusals inside such arms. 4. Not for this PR: a VCC branch (`s_and_b64 vcc, vcc, exec` then `s_cbranch_vccz`/`vccnz`) on a VCC that differs between lanes has the same per-lane split and still goes through the lane-own-bit path. Compilers mostly emit those on uniform VCC, where the split is exact, so it's rare. 5. Nit: the new test's instruction words are lowercase hex; the neighbouring fixtures use uppercase. *Review written with AI assistance (Claude), tests run and reviewed by me.*
Author
Owner

@⁠DoubleGhosty on GitHub · 2026-11-27 09:31 UTC · original

Cherry-picked into main as bd8b4f52. Verified on Wave32 hardware (both_halves_observe_the_same_mask_scc_on_a_wave32_device + both_arms_of_a_wave_wide_scc_branch_keep_their_store_guards) and strict shader clippy. Thanks!

**@⁠DoubleGhosty** on GitHub · 2026-11-27 09:31 UTC · [original](https://github.com/DoubleGhosty/cool_fox/pull/78#issuecomment-7214788489) Cherry-picked into main as bd8b4f52. Verified on Wave32 hardware (both_halves_observe_the_same_mask_scc_on_a_wave32_device + both_arms_of_a_wave_wide_scc_branch_keep_their_store_guards) and strict shader clippy. Thanks!

Pull request closed

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