Shaders: a lane-mask operation's SCC read as data is whether some lane is set #1334

Closed
KainanP wants to merge 1 commit from upstream-pr/1334 into main
KainanP commented 2026-11-24 17:31:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-24T17:31:09Z.


What

A scalar lane-mask operation (s_and_b64 of a compare with EXEC, s_xor_b64 …, exec, s_and_saveexec_b64, …) sets SCC when its result is not zero (RDNA 2 ISA, S_AND_B64: SCC = (D != 0); S_AND_SAVEEXEC_B64: SCC = (EXEC != 0)). Branches on it already lowered, per lane. Every other read stopped with a lane mask read as data, for example s_cselect_b32 s6, 1.0, 0, or the uniform-branch idiom s_cselect_b64 vcc, exec, 0 + s_cbranch_vccnz, whose select becomes a uniform atom.

  • structure records such SCC values in Structured::any_lane, with the result's per-lane bit. It does so only when the result is set in no lane except those running there: it implies EXEC at that point, and it is clear in the lanes outside EXEC on entry. A new Lanes::clear tracks the second condition (compare and carry results; and, andn2/andn1, or/xor with EXEC keep it). s_not, s_orn2 and XOR with -1 set bits for lanes that never ran, so they stay refused, and so do s_wqm results.
  • lower reads such an SCC as dx.op.waveAnyTrue of the bit, taken where the operation runs.
    • Compute: programs that read it declare the console's wave size, as for masks read as numbers.
    • Pixel and vertex: it is the host wave's any-true, which means the same on any wave, as s_cmp_lg_u64 m, 0 already does there.
    • Mesh: unchanged.

Relation to other PRs

#309 contains a compute-only version of this (its mask_scc), as one hunk of the spill-forwarding change. This PR does not depend on spills and also covers pixel and vertex programs, which #309 leaves refused. It also checks the lanes outside EXEC on entry, so a complement of a compare (s_not_b64 s, vcc) at the top of a program is refused rather than counted wrongly, and it declares the wave size in compute. Whichever lands first, the other drops or rebases its version. It does not overlap #878 (s_bcnt1's SCC for branches), #1073 (mask/number joins), #298/#1074 (spilled masks), #1084/#585/#1221 (selects on untracked masks), #269 (mask set operations as numbers) or #434/#145 (ballot halves on 64-lane hosts).

Tests

All words are assembled with llvm-mc (gfx1030); no game data.

  • valu_tests::the_scc_of_a_mask_operation_is_whether_some_lane_is_set (GPU): one wave32, with 32 and with 24 threads (8 lanes outside EXEC from the start), 10 (k, j) cases. It covers s_and + s_cselect, the uniform-branch idiom, s_and_saveexec's SCC, and s_and/s_xor with EXEC inside a branch only some lanes take. It fails on main with a lane mask read as data. It is skipped on devices without 32-lane waves.
  • lower::tests::the_scc_of_a_mask_operation_is_whether_some_lane_is_set: wave64 and wave32 pixel programs (s_and/s_xor/s_andn2 with EXEC, both readers) lower and pass dxil.dll validation. They fail on main.
  • lower::tests::the_scc_of_a_mask_holding_lanes_elsewhere_stays_refused: s_not_b64, s_xor_b64 …, -1, s_orn2_b64 still refuse.

Results:

  • cargo test --workspace --locked on Windows 11 with an RTX 4060 Laptop as the default adapter: 345 passed, 0 failed, 6 ignored (victory-shader: 123 passed, 1 ignored).
  • cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings: clean.
  • cargo xtask policy: 154 files ok.
  • WARP and an Intel UHD (no 32-lane waves) skip the GPU test.

Not measured

I did not run this on the title's shaders, so I can't say how many of the a lane mask read as data programs it unblocks. A victory translate --validate before/after would show it.

Known limits

  • Pixel shaders: WaveAnyTrue ignores helper lanes, which the console's EXEC includes (the same holds for the existing ballots).
  • A wave32 pixel program on a 64-lane host wave takes the any-true of both console waves (#131).
  • Inside a divergent loop each lane keeps its own last iteration's value, as for other scalars (#269).

AI use: Claude Code (Claude Opus 5.5) chose the target after reading the open PRs, wrote the change and the tests, and ran everything above. Reviewed and re-tested locally before opening.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6587662740 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1334). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-24T17:31:09Z. --- ## What A scalar lane-mask operation (`s_and_b64` of a compare with EXEC, `s_xor_b64 …, exec`, `s_and_saveexec_b64`, …) sets SCC when its result is not zero (RDNA 2 ISA, S_AND_B64: `SCC = (D != 0)`; S_AND_SAVEEXEC_B64: `SCC = (EXEC != 0)`). Branches on it already lowered, per lane. Every other read stopped with `a lane mask read as data`, for example `s_cselect_b32 s6, 1.0, 0`, or the uniform-branch idiom `s_cselect_b64 vcc, exec, 0` + `s_cbranch_vccnz`, whose select becomes a uniform atom. - `structure` records such SCC values in `Structured::any_lane`, with the result's per-lane bit. It does so only when the result is set in no lane except those running there: it implies EXEC at that point, and it is clear in the lanes outside EXEC on entry. A new `Lanes::clear` tracks the second condition (compare and carry results; `and`, `andn2`/`andn1`, `or`/`xor` with EXEC keep it). `s_not`, `s_orn2` and XOR with -1 set bits for lanes that never ran, so they stay refused, and so do `s_wqm` results. - `lower` reads such an SCC as `dx.op.waveAnyTrue` of the bit, taken where the operation runs. - Compute: programs that read it declare the console's wave size, as for masks read as numbers. - Pixel and vertex: it is the host wave's any-true, which means the same on any wave, as `s_cmp_lg_u64 m, 0` already does there. - Mesh: unchanged. ## Relation to other PRs #309 contains a compute-only version of this (its `mask_scc`), as one hunk of the spill-forwarding change. This PR does not depend on spills and also covers pixel and vertex programs, which #309 leaves refused. It also checks the lanes outside EXEC on entry, so a complement of a compare (`s_not_b64 s, vcc`) at the top of a program is refused rather than counted wrongly, and it declares the wave size in compute. Whichever lands first, the other drops or rebases its version. It does not overlap #878 (`s_bcnt1`'s SCC for branches), #1073 (mask/number joins), #298/#1074 (spilled masks), #1084/#585/#1221 (selects on untracked masks), #269 (mask set operations as numbers) or #434/#145 (ballot halves on 64-lane hosts). ## Tests All words are assembled with llvm-mc (gfx1030); no game data. - `valu_tests::the_scc_of_a_mask_operation_is_whether_some_lane_is_set` (GPU): one wave32, with 32 and with 24 threads (8 lanes outside EXEC from the start), 10 (k, j) cases. It covers `s_and` + `s_cselect`, the uniform-branch idiom, `s_and_saveexec`'s SCC, and `s_and`/`s_xor` with EXEC inside a branch only some lanes take. It fails on `main` with `a lane mask read as data`. It is skipped on devices without 32-lane waves. - `lower::tests::the_scc_of_a_mask_operation_is_whether_some_lane_is_set`: wave64 and wave32 pixel programs (`s_and`/`s_xor`/`s_andn2` with EXEC, both readers) lower and pass `dxil.dll` validation. They fail on `main`. - `lower::tests::the_scc_of_a_mask_holding_lanes_elsewhere_stays_refused`: `s_not_b64`, `s_xor_b64 …, -1`, `s_orn2_b64` still refuse. Results: - `cargo test --workspace --locked` on Windows 11 with an RTX 4060 Laptop as the default adapter: 345 passed, 0 failed, 6 ignored (`victory-shader`: 123 passed, 1 ignored). - `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings`: clean. - `cargo xtask policy`: 154 files ok. - WARP and an Intel UHD (no 32-lane waves) skip the GPU test. ## Not measured I did not run this on the title's shaders, so I can't say how many of the `a lane mask read as data` programs it unblocks. A `victory translate --validate` before/after would show it. ## Known limits - Pixel shaders: WaveAnyTrue ignores helper lanes, which the console's EXEC includes (the same holds for the existing ballots). - A wave32 pixel program on a 64-lane host wave takes the any-true of both console waves (#131). - Inside a divergent loop each lane keeps its own last iteration's value, as for other scalars (#269). AI use: Claude Code (Claude Opus 5.5) chose the target after reading the open PRs, wrote the change and the tests, and ran everything above. Reviewed and re-tested locally before opening. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 19:03:01 +00:00
rezioliver-collab commented 2026-11-24 19:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by rezioliver-collab on 2026-11-24T18:11:13Z.


I ran an offline A/B comparison of ffe310e and 0f2c09b on Windows 11 with Rust 1.98.1 (MSVC) and dxil.dll 1.8.2502.11. I reused two baseline runs after verifying that the archive and validator matched by SHA-256, then ran victory translate --validate --list --jobs 1 twice on the PR with the same local shaders.rpf.

Each run processed 26,503 containers and built IR for 26,084 native programs. All 25,889 listed outcomes matched by archive offset and shader stage. Both revisions validated 21,724 shaders, with zero validation gains or losses.

The same 250 shaders still reported a lane mask read as data.

Stage Baseline PR
Vertex 11 11
Pixel 132 132
Compute 4 4
Mesh 103 103
Total 250 250

The related a lane mask holding lanes elsewhere read as data count also stayed at 272.

For the synthetic check, I copied only the PR's two SCC test fixtures into a separate baseline checkout. The positive test reproduced a lane mask read as data on the first Wave64 AND followed by a scalar select. On the PR, all 12 combinations passed, covering Wave32 and Wave64, AND/XOR/ANDN2, and SCC consumed by a scalar select or uniform branch. The test that checks rejection of masks with bits outside entry EXEC passed on both revisions. cargo xtask policy passed on both.

AI use : Assisted by GPT 6.2 Sol.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140282420 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1334#issuecomment-7140282420). Originally posted by [rezioliver-collab](https://github.com/rezioliver-collab) on 2026-11-24T18:11:13Z. --- I ran an offline A/B comparison of `ffe310e` and `0f2c09b` on Windows 11 with Rust 1.98.1 (MSVC) and `dxil.dll` 1.8.2502.11. I reused two baseline runs after verifying that the archive and validator matched by SHA-256, then ran `victory translate --validate --list --jobs 1` twice on the PR with the same local `shaders.rpf`. Each run processed 26,503 containers and built IR for 26,084 native programs. All 25,889 listed outcomes matched by archive offset and shader stage. Both revisions validated **21,724 shaders**, with zero validation gains or losses. The same 250 shaders still reported `a lane mask read as data`. | Stage | Baseline | PR | |---|---:|---:| | Vertex | 11 | 11 | | Pixel | 132 | 132 | | Compute | 4 | 4 | | Mesh | 103 | 103 | | **Total** | **250** | **250** | The related `a lane mask holding lanes elsewhere read as data` count also stayed at 272. For the synthetic check, I copied only the PR's two SCC test fixtures into a separate baseline checkout. The positive test reproduced `a lane mask read as data` on the first Wave64 AND followed by a scalar select. On the PR, all 12 combinations passed, covering Wave32 and Wave64, AND/XOR/ANDN2, and SCC consumed by a scalar select or uniform branch. The test that checks rejection of masks with bits outside entry EXEC passed on both revisions. `cargo xtask policy` passed on both. AI use : Assisted by GPT 6.2 Sol.
KainanP commented 2026-11-24 19:04:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-24T18:15:03Z.


Thanks @rezioliver-collab, this is exactly the measurement the PR was missing ("Not measured" above).

So the title never reads the SCC of a lane-mask operation as data: all 250 a lane mask read as data programs stop somewhere else. In lower.rs that refusal has three sources: mask_dword on a value that isn't a tracked mask, a scalar op writing EXEC or a tracked mask that sop doesn't handle, and the VOPC/carry results left as Val::Missing. This PR only touches a fourth path that the shaders don't use.

A change that unblocks nothing in the title isn't worth review time here, so I'm closing it. The parts that might matter later (Lanes::clear, the pixel/vertex any-true) are in the branch if someone needs them.

Written with the help of an AI (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140375238 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1334#issuecomment-7140375238). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-24T18:15:03Z. --- Thanks @rezioliver-collab, this is exactly the measurement the PR was missing ("Not measured" above). So the title never reads the SCC of a lane-mask operation as data: all 250 `a lane mask read as data` programs stop somewhere else. In `lower.rs` that refusal has three sources: `mask_dword` on a value that isn't a tracked mask, a scalar op writing EXEC or a tracked mask that `sop` doesn't handle, and the VOPC/carry results left as `Val::Missing`. This PR only touches a fourth path that the shaders don't use. A change that unblocks nothing in the title isn't worth review time here, so I'm closing it. The parts that might matter later (`Lanes::clear`, the pixel/vertex any-true) are in the branch if someone needs them. _Written with the help of an AI (Claude Code)._

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1334
No description provided.