Shader: branch-only SCC from s_and_b32/b64 VCC & EXEC chooses a different arm per lane #3491

Open
opened 2026-11-27 10:42:54 +00:00 by github-bot · 2 comments
Owner

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

On official main 63bcca43, s_and_b32/b64 s18, vcc, exec followed directly by s_cbranch_scc0/1 makes each active lane choose its own branch. The scalar AND sets SCC when any bit of its result is set, so all active lanes of that console wave should take the same arm. These programs compile, validate, and dispatch.

For example, in one console Wave64 group, lanes 0–47 are active and the comparison matches only lane 37. The chosen arm writes 2 and the other arm writes 1. Both adapters returned 2 only at lane 37 and 1 at the other 47 active lanes. All 48 should contain 2. Lanes 48–63 correctly kept their initial zero.

Results

Each cell gives incorrect output dwords over nine dispatches. Each invocation has its own in-bounds dword. The three GFX variants use SCC exclusively as a branch condition. The DXC control computes the group-wide decision with groupshared memory and writes only for active lanes.

Program RTX 5080, console Wave32 WARP, console Wave32 RTX 5080, console Wave64 WARP, console Wave64
DXC control 0/288 0/288 0/576 0/576
s_cbranch_scc0, one common store 92/288 92/288 188/576 188/576
s_cbranch_scc0, store in each arm 92/288 92/288 188/576 188/576
s_cbranch_scc1, store in each arm 92/288 92/288 188/576 188/576

The RTX 5080 used driver 32.0.16.2140 and reports 32–32 physical wave lanes. App-local x64 WARP 1.0.22.0 reports 4–128. For these specific programs main emits 32 or 64 threads per group with no fixed host wave size. The RTX therefore executed the 64-thread case on two physical 32-lane waves. The selected WARP wave width was not instrumented. DXC disassembly of the translated stores shows a direct branch on selected == threadIdInGroup, with no reduction across active lanes.

Reproduce

The test-only commit adds hand-written GFX10 instructions and a separate PC HLSL control. The synthetic sources and full nine-case matrix are in b803d16.

git clone --single-branch --branch test/branch-only-mask-scc https://github.com/steven-seagull27/VIctory.git mask-scc-repro
cd mask-scc-repro
$env:VICTORY_WARP = "0"
cargo test --locked -p victory-shader --lib mask_branch_repro -- --ignored --nocapture --test-threads=1

The test locates PC DXC in the Windows SDK, or accepts its path through VICTORY_PC_DXC. It prints the control and each variant before failing the final assertion on this revision. For the same portable WARP run, use cargo test --locked -p victory-shader --lib --no-run to locate the test executable. Put a copy in its own directory beside the x64 d3d10warp.dll from WARP 1.0.22, set $env:VICTORY_WARP = "1", and launch that copy with mask_branch_repro --ignored --nocapture --test-threads=1.

Relation to existing work

Lyrnc’s #3401 handles mask SCC consumed as scalar data. The review and andrewpozdnakov7-jpg’s follow-up address a definition used as both data and branch condition. The six branch-only outputs here were byte-identical across main, #3401 at d9ed3138, and the follow-up at 15057a5b. I also compared #233 at 87d1f423 with a 32–32 target and #2633 at 706c006c with host_wave32 enabled. Both emitted the same six bytecodes for these programs.

The synthetic cases build on DoubleGhosty’s SCC fix and the branch-arm store regression in that fork. Its cross-half lowering differs from official main. On official main the failure here is the wrong value in active lanes. Across this matrix there were zero unexpected writes to inactive lanes.

**@⁠steven-seagull27** on GitHub · 2026-11-27 09:43 UTC · [original](https://github.com/Marvisak/VIctory/issues/3491) On official main `63bcca43`, `s_and_b32/b64 s18, vcc, exec` followed directly by `s_cbranch_scc0/1` makes each active lane choose its own branch. The scalar AND sets SCC when **any bit of its result is set**, so all active lanes of that console wave should take the same arm. These programs compile, validate, and dispatch. For example, in one console Wave64 group, lanes 0–47 are active and the comparison matches only lane 37. The chosen arm writes `2` and the other arm writes `1`. Both adapters returned `2` only at lane 37 and `1` at the other 47 active lanes. All 48 should contain `2`. Lanes 48–63 correctly kept their initial zero. ### Results Each cell gives incorrect output dwords over nine dispatches. Each invocation has its own in-bounds dword. The three GFX variants use SCC exclusively as a branch condition. The DXC control computes the group-wide decision with groupshared memory and writes only for active lanes. | Program | RTX 5080, console Wave32 | WARP, console Wave32 | RTX 5080, console Wave64 | WARP, console Wave64 | |---|---:|---:|---:|---:| | DXC control | 0/288 | 0/288 | 0/576 | 0/576 | | `s_cbranch_scc0`, one common store | 92/288 | 92/288 | 188/576 | 188/576 | | `s_cbranch_scc0`, store in each arm | 92/288 | 92/288 | 188/576 | 188/576 | | `s_cbranch_scc1`, store in each arm | 92/288 | 92/288 | 188/576 | 188/576 | The RTX 5080 used driver `32.0.16.2140` and reports 32–32 physical wave lanes. App-local x64 WARP `1.0.22.0` reports 4–128. For these specific programs main emits 32 or 64 threads per group with **no fixed host wave size**. The RTX therefore executed the 64-thread case on two physical 32-lane waves. The selected WARP wave width was not instrumented. DXC disassembly of the translated stores shows a direct branch on `selected == threadIdInGroup`, with no reduction across active lanes. ### Reproduce The test-only commit adds hand-written GFX10 instructions and a separate PC HLSL control. The synthetic sources and full nine-case matrix are in [b803d16](https://github.com/steven-seagull27/VIctory/commit/b803d168944b5b167eaf09b7b533f7e261a90736). ```powershell git clone --single-branch --branch test/branch-only-mask-scc https://github.com/steven-seagull27/VIctory.git mask-scc-repro cd mask-scc-repro $env:VICTORY_WARP = "0" cargo test --locked -p victory-shader --lib mask_branch_repro -- --ignored --nocapture --test-threads=1 ``` The test locates PC DXC in the Windows SDK, or accepts its path through `VICTORY_PC_DXC`. It prints the control and each variant before failing the final assertion on this revision. For the same portable WARP run, use `cargo test --locked -p victory-shader --lib --no-run` to locate the test executable. Put a copy in its own directory beside the x64 `d3d10warp.dll` from WARP 1.0.22, set `$env:VICTORY_WARP = "1"`, and launch that copy with `mask_branch_repro --ignored --nocapture --test-threads=1`. ### Relation to existing work Lyrnc’s #3401 handles mask SCC consumed as scalar data. The [review](https://git.gtahub.st/github/Marvisak--VIctory/pulls/3401) and [andrewpozdnakov7-jpg’s follow-up](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/15057a5b47c689bb586cab62a04d2109859f316c) address a definition used as both data and branch condition. The six **branch-only** outputs here were byte-identical across main, #3401 at `d9ed3138`, and the follow-up at `15057a5b`. I also compared #233 at `87d1f423` with a 32–32 target and #2633 at `706c006c` with `host_wave32` enabled. Both emitted the same six bytecodes for these programs. The synthetic cases build on [DoubleGhosty’s SCC fix](https://github.com/DoubleGhosty/cool_fox/issues/66#issuecomment-7213816285) and the [branch-arm store regression](https://github.com/DoubleGhosty/cool_fox/pull/78) in that fork. Its cross-half lowering differs from official main. On official main the failure here is the **wrong value in active lanes**. Across this matrix there were zero unexpected writes to inactive lanes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 10:42:54 +00:00
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-27 10:44 UTC · original

I have a source-only fix for the branch-only case in this issue on top of #233 at 87d1f42. It selects the existing whole-wave control flow when an eligible one-wave compute group branches on the scalar condition from a native-width VCC & EXEC. The selection excludes mixed-use conditions and multiwave groups. Commit 79c6a98

The original synthetic reproducer covers three branch variants. Results below are incorrect 32-bit outputs per variant. All three produced the same counts, and all inactive-lane sentinels remained intact.

Device Guest Wave32, before → after Guest Wave64, before → after
RTX 5080 92/288 → 0/288 188/576 → 0/576
WARP 1.0.22 92/288 → 0/288 188/576 → 0/576

Both DXC controls passed. The added source tests cover a partially active mask, a match inside or outside that mask, and exclusions for multiwave groups and a scalar-data consumer. Strict shader Clippy and the repository policy check passed.

The commit uses the control-flow implementation in #233. To apply it on that PR’s branch:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/fix/3491-branch-only-mask-scc
git cherry-pick 79c6a98af755676f93eddf299e8b7234ef3cb32e

AI-assisted with Codex.

**@⁠steven-seagull27** on GitHub · 2026-11-27 10:44 UTC · [original](https://github.com/Marvisak/VIctory/issues/3491#issuecomment-7216238625) I have a source-only fix for the branch-only case in this issue on top of #233 at `87d1f42`. It selects the existing whole-wave control flow when an eligible one-wave compute group branches on the scalar condition from a native-width `VCC & EXEC`. The selection excludes mixed-use conditions and multiwave groups. [Commit 79c6a98](https://github.com/steven-seagull27/VIctory/commit/79c6a98af755676f93eddf299e8b7234ef3cb32e) The original synthetic reproducer covers three branch variants. Results below are incorrect 32-bit outputs **per variant**. All three produced the same counts, and all inactive-lane sentinels remained intact. | Device | Guest Wave32, before → after | Guest Wave64, before → after | |---|---:|---:| | RTX 5080 | 92/288 → 0/288 | 188/576 → 0/576 | | WARP 1.0.22 | 92/288 → 0/288 | 188/576 → 0/576 | Both DXC controls passed. The added source tests cover a partially active mask, a match inside or outside that mask, and exclusions for multiwave groups and a scalar-data consumer. Strict shader Clippy and the repository policy check passed. The commit uses the control-flow implementation in #233. To apply it on that PR’s branch: ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/fix/3491-branch-only-mask-scc git cherry-pick 79c6a98af755676f93eddf299e8b7234ef3cb32e ``` AI-assisted with Codex.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-27 11:16 UTC · original

Independent WARP run of the test in this issue, to go with the source-only fix above.

Setup: app-local WARP SM 6.6 (D3D12Core 1.620.2, d3d10warp 1.0.22), PC DXC 1.9.2609, --test-threads=1. The test is Steven's, kept with authorship (cde6aa2); no game data, synthetic only.

Base Configuration Wave32 Wave64
63bcca4 as on main 92/288 per program, 3 programs 188/576 per program, 3 programs (840 total)
#320 960b3e1 Target { 32, 32 }, no console flow unchanged, 840 unchanged, 840
#320 960b3e1 console-flow forced (test-only toggle in lower.rs) 0 0
#320 960b3e1 both 0 0

So forcing the 32-lane split changes nothing, while the existing whole-wave control flow gets every case right: a test-only wants_console_flow override makes all six translated variants agree with the DXC reference, with no inactive-lane writes.

That matches the approach in 79c6a98 (select the whole-wave path when a one-wave compute group branches on a native-width VCC & EXEC). The override is a diagnostic in a local tree, not a proposed fix; I have not run 79c6a98 itself here.

@⁠steven-seagull27 if it helps, I can run the same matrix against 79c6a98 on WARP and report what it gives for these 840 cells.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-27 11:16 UTC · [original](https://github.com/Marvisak/VIctory/issues/3491#issuecomment-7216874292) Independent WARP run of the test in this issue, to go with the source-only fix above. Setup: app-local WARP SM 6.6 (`D3D12Core` 1.620.2, `d3d10warp` 1.0.22), PC DXC 1.9.2609, `--test-threads=1`. The test is Steven's, kept with authorship (`cde6aa2`); no game data, synthetic only. | Base | Configuration | Wave32 | Wave64 | |---|---|---|---| | `63bcca4` | as on main | 92/288 per program, 3 programs | 188/576 per program, 3 programs (**840** total) | | `#320` `960b3e1` | `Target { 32, 32 }`, no console flow | unchanged, 840 | unchanged, 840 | | `#320` `960b3e1` | console-flow forced (test-only toggle in `lower.rs`) | **0** | **0** | | `#320` `960b3e1` | both | **0** | **0** | So forcing the 32-lane split changes nothing, while the existing whole-wave control flow gets every case right: a test-only `wants_console_flow` override makes all six translated variants agree with the DXC reference, with no inactive-lane writes. That matches the approach in `79c6a98` (select the whole-wave path when a one-wave compute group branches on a native-width `VCC & EXEC`). The override is a diagnostic in a local tree, not a proposed fix; I have not run `79c6a98` itself here. @⁠steven-seagull27 if it helps, I can run the same matrix against `79c6a98` on WARP and report what it gives for these 840 cells.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#3491
No description provided.