Skip to content

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

Closed
KainanP wants to merge 1 commit into
Marvisak:mainfrom
KainanP:shaders/mask-scc-any-lane
Closed

KainanP wants to merge 1 commit into
Marvisak:mainfrom
KainanP:shaders/mask-scc-any-lane

Conversation

@KainanP

@KainanP KainanP commented Nov 24, 2026

Copy link
Copy Markdown

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

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

…e is set

A scalar lane-mask operation (s_and_b64 of a compare with EXEC,
s_and_saveexec_b64, ...) sets SCC when its result is not zero. Branches
already take that SCC per lane; any other read (s_cselect_b32, or
s_cselect_b64 vcc, exec, 0 before a VCC branch, which structurisation
turns into a uniform atom) stopped with "a lane mask read as data".

It is now the wave's any-true of the result's lane bit (dx.op.waveAnyTrue),
taken where the operation runs. That is exact when every lane with the
bit set runs there, so structure records SCC values (Structured::any_lane)
only for results that are clear outside EXEC there and clear in the lanes
outside EXEC on entry: compares and carries write 0 for those, and, and
andn2/andn1/or/xor with EXEC keep them clear, so s_xor/s_andn2 of a
compare with EXEC qualify; s_not, s_orn2 or an XOR with -1 do not, and
stay refused.

Compute programs that read it declare the console's wave size, as for
masks read as numbers. Pixel and vertex programs take the host wave's
any-true, which means the same on any wave, as s_cmp_lg_u64 m, 0 already
does there. Mesh programs are unchanged.

Tests: a GPU test runs one wave32 of 32 and of 24 threads (8 lanes outside
EXEC from the start) through s_and, the uniform-branch idiom,
s_and_saveexec and s_xor with EXEC; pixel programs (wave64 and wave32)
with each of s_and/s_xor/s_andn2 with EXEC now lower and validate, and
s_not/s_orn2/XOR with -1 still refuse. Encodings from llvm-mc (gfx1030).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rezioliver-collab

Copy link
Copy Markdown

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

KainanP commented Nov 24, 2026

Copy link
Copy Markdown
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants