Wave64 on Wave32: s_cbranch_scc0 after s_and_b64 branches per lane #66

Closed
opened 2026-11-27 06:08:18 +00:00 by github-bot · 2 comments
Owner

@⁠steven-seagull27 on GitHub · 2026-11-27 05:45 UTC · original

On 963f7195, a generated Wave64 compute program translates and runs on a Wave32 host, but a scalar conditional branch acts on each lane’s own comparison. A separate program that consumes the same SCC with s_cselect_b32 produces the expected wave-wide value.

The fixture uses 64 threads. It narrows EXEC to lanes below a supplied limit and compares the remaining lane IDs with one selected ID. s_and_b64 s[18:19], vcc, exec sets SCC when any active lane matched. The branch-only control uses s_cbranch_scc0 to choose between storing literal 1 and literal 2. Neither arm changes EXEC. When the selected lane is active, all active lanes should store 2. When it is absent, all active lanes should store 1. Inactive output stays zero. These scalar instruction and EXEC rules are documented in the AMD RDNA 2 ISA guide, §§3.9, 7.3, 12.1 and 12.5.

Generated program RTX 5080 mismatches WARP 1.0.22 mismatches
Independent DXC HLSL using a group-wide OR 0/576 0/576
Scalar select only 0/576 0/576
Scalar branch only, with literal stores 188/576 188/576
Scalar select and branch together 188/576 188/576

For example, with 48 active lanes and lane 37 selected, lane 37 stored 2. Lanes 0, 31, 32 and 47 stored 1 instead of 2. Lane 48 kept zero. Across nine inputs, every branch-only word matched the lane-local predicate. The group-wide HLSL matched the independent CPU expectation for every word. Windows inbox WARP advertised only Wave4 and ran zero Wave32 comparisons.

The direct lowerer refused the combined fixture with a lane mask exchanged where not every lane runs. The normal emitter accepted it through the without skips Wave32 retry. The tests use generated instruction words, a scalar descriptor-load wait, and a fresh zeroed UAV for each readback. The reference above is the documented ISA calculation and independent HLSL; a physical AMD ISA run would provide another comparison.

The test-only commit and HLSL source apply to 963f7195. On Windows:

git fetch https://github.com/steven-seagull27/cool_fox.git codex/wave64-nested-scc
git cherry-pick 41ae0ecc6ba34aa656388e863d74ef30cabf88aa
cargo test --locked -p victory-shader --lib emit::wave64_tests::the_mask_scc_in_a_lane_branch_lowers_without_its_exec_skip -- --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

The second command prints every actual vector and fails its equality check on the affected build. The independent HLSL check can be run separately:

$env:SCC_REFERENCE_DXIL = Join-Path $env:TEMP 'wave64-mask-scc-ref.dxil'
dxc -T cs_6_6 -E main -Fo $env:SCC_REFERENCE_DXIL crates/victory-shader/src/emit/testdata/wave64-mask-scc.hlsl
cargo test --locked -p victory-shader --lib emit::wave64_tests::independent_hlsl_group_any_scc_oracle -- --exact --ignored --nocapture

AI-assisted investigation and verification.

**@⁠steven-seagull27** on GitHub · 2026-11-27 05:45 UTC · [original](https://github.com/DoubleGhosty/cool_fox/issues/66) On `963f7195`, a generated Wave64 compute program translates and runs on a Wave32 host, but a scalar conditional branch acts on each lane’s own comparison. A separate program that consumes the same SCC with `s_cselect_b32` produces the expected wave-wide value. The fixture uses 64 threads. It narrows EXEC to lanes below a supplied limit and compares the remaining lane IDs with one selected ID. `s_and_b64 s[18:19], vcc, exec` sets SCC when any active lane matched. The branch-only control uses `s_cbranch_scc0` to choose between storing literal 1 and literal 2. Neither arm changes EXEC. When the selected lane is active, all active lanes should store 2. When it is absent, all active lanes should store 1. Inactive output stays zero. These scalar instruction and EXEC rules are documented in the [AMD RDNA 2 ISA guide, §§3.9, 7.3, 12.1 and 12.5](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content). | Generated program | RTX 5080 mismatches | WARP 1.0.22 mismatches | | --- | ---: | ---: | | Independent DXC HLSL using a group-wide OR | 0/576 | 0/576 | | Scalar select only | 0/576 | 0/576 | | Scalar branch only, with literal stores | 188/576 | 188/576 | | Scalar select and branch together | 188/576 | 188/576 | For example, with 48 active lanes and lane 37 selected, lane 37 stored 2. Lanes 0, 31, 32 and 47 stored 1 instead of 2. Lane 48 kept zero. Across nine inputs, every branch-only word matched the lane-local predicate. The group-wide HLSL matched the independent CPU expectation for every word. Windows inbox WARP advertised only Wave4 and ran zero Wave32 comparisons. The direct lowerer refused the combined fixture with `a lane mask exchanged where not every lane runs`. The normal emitter accepted it through the `without skips` Wave32 retry. The tests use generated instruction words, a scalar descriptor-load wait, and a fresh zeroed UAV for each readback. The reference above is the documented ISA calculation and independent HLSL; a physical AMD ISA run would provide another comparison. The [test-only commit and HLSL source](https://github.com/steven-seagull27/cool_fox/commit/41ae0ecc6ba34aa656388e863d74ef30cabf88aa) apply to `963f7195`. On Windows: ```powershell git fetch https://github.com/steven-seagull27/cool_fox.git codex/wave64-nested-scc git cherry-pick 41ae0ecc6ba34aa656388e863d74ef30cabf88aa cargo test --locked -p victory-shader --lib emit::wave64_tests::the_mask_scc_in_a_lane_branch_lowers_without_its_exec_skip -- --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 ``` The second command prints every actual vector and fails its equality check on the affected build. The independent HLSL check can be run separately: ```powershell $env:SCC_REFERENCE_DXIL = Join-Path $env:TEMP 'wave64-mask-scc-ref.dxil' dxc -T cs_6_6 -E main -Fo $env:SCC_REFERENCE_DXIL crates/victory-shader/src/emit/testdata/wave64-mask-scc.hlsl cargo test --locked -p victory-shader --lib emit::wave64_tests::independent_hlsl_group_any_scc_oracle -- --exact --ignored --nocapture ``` AI-assisted investigation and verification.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 06:08:18 +00:00
Author
Owner

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

Fixed in commit 9a4aa8d3. Non-EXEC s_cbranch_scc0/1 branches reading scc_some now lower via wave_wide (waveAnyTrue + Wave32 half-exchange) instead of per-lane evaluation. Verified on Wave32 hardware (both_halves_observe_the_same_mask_scc_on_a_wave32_device: 0/64 mismatches across all Combined/Branch/Select cases) and victory-shader unit tests.

**@⁠DoubleGhosty** on GitHub · 2026-11-27 08:41 UTC · [original](https://github.com/DoubleGhosty/cool_fox/issues/66#issuecomment-7213816285) Fixed in commit 9a4aa8d3. Non-EXEC s_cbranch_scc0/1 branches reading scc_some now lower via wave_wide (waveAnyTrue + Wave32 half-exchange) instead of per-lane evaluation. Verified on Wave32 hardware (both_halves_observe_the_same_mask_scc_on_a_wave32_device: 0/64 mismatches across all Combined/Branch/Select cases) and victory-shader unit tests.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-27 09:08 UTC · original

I confirmed 9a4aa8d3 fixes the original branch, scalar-select, and combined cases on both the RTX 5080 and WARP 1.0.22. Each case had 0/576 incorrect readbacks on each adapter.

Moving the store into each branch arm exposed a separate EXEC issue. With 48 lanes active and lane 37 matched, lanes 48–63 wrote 2 even though their output should have stayed 0. The branch decision was correct across the whole wave, but the stores still needed each lane's EXEC guard. With the follow-up patch, both s_cbranch_scc0 and s_cbranch_scc1 went from 127/576 wrong to 0/576 on each adapter. Patch and regression tests in #78.

**@⁠steven-seagull27** on GitHub · 2026-11-27 09:08 UTC · [original](https://github.com/DoubleGhosty/cool_fox/issues/66#issuecomment-7214336842) I confirmed `9a4aa8d3` fixes the original branch, scalar-select, and combined cases on both the RTX 5080 and WARP 1.0.22. Each case had 0/576 incorrect readbacks on each adapter. Moving the store into each branch arm exposed a separate EXEC issue. With 48 lanes active and lane 37 matched, lanes 48–63 wrote `2` even though their output should have stayed `0`. The branch decision was correct across the whole wave, but the stores still needed each lane's EXEC guard. With the follow-up patch, both `s_cbranch_scc0` and `s_cbranch_scc1` went from 127/576 wrong to 0/576 on each adapter. [Patch and regression tests in #78](https://git.gtahub.st/github/DoubleGhosty--cool_fox/pulls/78).
This discussion has been locked. Commenting is limited to contributors.
No description provided.