Skip to content

Shaders: the SCC of a lane-mask operation, read as data, is whether the mask is not zero - #3401

Open
Lyrnc wants to merge 1 commit into
Marvisak:mainfrom
Lyrnc:fix/mask-op-scc-as-data
Open

Lyrnc wants to merge 1 commit into
Marvisak:mainfrom
Lyrnc:fix/mask-op-scc-as-data

Conversation

@Lyrnc

@Lyrnc Lyrnc commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What was refused

Four compute programs of the title's FidelityFX upscaler DLL (amd_fidelityfx_upscaler_xbox.dll) stop with
emit: a lane mask read as data: 8e614708143ef917 (wave32), 17af85f170e66f30, 477b52e73ddeb6f2,
8b437ab61d8008fe (wave64). They are four of the six untranslated passes of the title's own upscaler that the
README lists under Series S.

Each waits in a bounded poll loop whose exit test reads the SCC of a lane-mask operation as data. The shape,
as this PR's test writes it:

loop:
    s_add_u32       s22, s22, 1
    v_cmp_gt_u32    vcc_lo, s22, v4       ; the lanes done
    s_and_b32       s20, vcc_lo, exec_lo  ; a lane mask; SCC = (s20 != 0)
    s_cselect_b32   s21, 0, -1            ; reads that SCC as data: -1 if no lane is done
    s_cmp_ge_u32    s22, 64
    s_cselect_b32   s23, -1, 0            ; -1 at the iteration limit
    s_orn2_b32      s23, s23, s21         ; SCC = limit reached or some lane done
    s_cbranch_scc0  loop

sop() refuses every SALU instruction that writes a lane mask, and the refusal marks all it writes, its SCC
too, as a lane mask read as data. A branch on such an SCC already lowers (it is the lane's own bit,
structure's scc_lane), but nothing resolved an SCC that another instruction reads as data, so the
s_cselect carried the refusal on to the loop's branch.

What changed

emit/lower.rs:

  • mask_sccs_read_as_data finds the SCC values of bitwise operations (s_and/or/xor/andn2/orn2/nand/nor/xnor/not,
    32 and 64 bit) that write a lane mask and no EXEC, read by an instruction other than an s_cbranch.
  • In sop(), such an operation in a compute program (MaskData::Console: host lane n is console lane n) sets
    its SCC to the mask's number tested for zero (mask_nonzero: mask_dword's ballot, or its exact number for a
    mask holding lanes elsewhere such as a complement; both dwords in wave64), taken where the operation runs. The
    mask itself stays a mask, read as a number where it is read, as before. Vertex, pixel and mesh programs keep
    the refusal (their ballots are over the host's wave).
  • A program with such a read declares the console's wave size, as programs reading a mask as a number already do.

The ISA rule (SCC = D != 0 over the whole register, the lanes outside EXEC included) was checked on RDNA2
hardware (below).

Tests

emit/crosslane_tests.rs, hand-encoded words:

  • mask_operation_scc_read_as_data_is_the_waves_any_on_gpu (wave32, 32 lanes, hardware adapter; skipped where
    32-lane waves are not available): s_and_b32 of a compare with some lanes set / none set; s_not_b32 of a
    mask set in every running lane under a branch on the even lanes (the odd lanes' bits make it not zero);
    s_andn2_b32 of EXEC and that mask (zero); and a poll loop of the shape above that must leave at the same
    count in every lane. Each s_cselect result is checked in all 32 lanes, so a lowering that used the lane's
    own bit fails.
  • wave64_mask_operation_scc_reads_both_dwords: a wave64 program whose mask is set only in the high dword (and
    one with no lane set); lowered and validated everywhere, run where the host has 64-lane waves.

Results:

  • RTX 5080 (the default adapter): both pass; the wave32 test runs all five cases, the wave64 one is lowered and
    validated (no 64-lane waves on NVIDIA).
  • AMD Radeon iGPU (RDNA2 gfx1036, picked with a local adapter filter that is not part of this PR): both pass,
    the wave64 program dispatched on 64-lane waves.
  • Against main's lowering (this PR's tests, lower.rs from main) both fail at lowering with
    a lane mask read as data.
  • RDNA2 hardware (gfx1036 through a hardware oracle running hand-written GFX10 assembly, 64 rows): the same
    sequences (s_and_b32 of a compare with and without lanes set, s_not_b32 and s_andn2_b32 under a
    narrowed EXEC, the poll loop; wave64 s_and_b64 with only high-dword lanes set, none set, low-dword lanes
    set) read through s_cselect_b32: 0 differences from SCC = (result != 0) over the whole register.
  • cargo clippy -p victory-shader --lib --tests -- -D warnings: clean. cargo xtask policy: 191 files ok.
  • cargo test -p victory-shader --lib -- --test-threads=1 on the RTX 5080, skipping
    heap_direct_texture_reads_mark_their_heap_index (it kills the test process on this machine, as Shader tests: heap_direct_texture_reads_mark_their_heap_index kills the test process on a real GPU (RTX 5070, main 67e8ae1) #2571 reports):
    300 passed, 3 failed, 3 ignored. The three (stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,
    stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,
    synthetic_tests::gathers_at_a_level_match_the_hardware) fail the same way on main 63bcca4 here.

Census (offline, the title's shader pack, exe and DLLs)

translate --list --validate over shaders.rpf, the executable, XboxBvhBuilder.dll and
amd_fidelityfx_upscaler_xbox.dll, validator dxc 1.9.2609 dxil.dll, main 63bcca4 against this branch,
compared program by program:

main 63bcca4 this branch
compute programs emitted / validated 2,733 / 1,985 2,734 / 1,986
all programs validated 24,937 24,938
  • 8e614708143ef917 (wave32) now validates.
  • 17af85f170e66f30, 477b52e73ddeb6f2, 8b437ab61d8008fe (wave64) get past this refusal and stop at the next
    one, a whole-wave section step the simulation does not follow: their wave OR reduction finishes in the high
    half and is read at lane 63 after the section. Shaders: one lane of a whole-wave section's value, read after the section #3402
    handles that; with both, all four validate (24,937 -> 24,941 programs validated, compute 1,985 -> 1,989, nothing else changes).
  • No other program changes outcome, and no other emitted program changes by a byte (every emitted program's
    DXIL compared by hash).

This touches the same lines of sop() as #3016 (the SCC of a waterfall loop's s_andn2_wrexec), which fixes
the other four a lane mask read as data programs of the pack (827b309e779552d7, 82a2ad6d07417d36,
90a0692af4320129, 9ffcaff533995118); the two changes are independent and combine by hand.

Not tested

  • No live run: the title's own upscaler runs only in Series S mode without VICTORY_FIDELITYFX_DIR, and the
    game was not started.
  • The wave64 programs need a host with 64-lane waves; NVIDIA hosts refuse a WaveSize(64) compute pipeline
    whatever this change does.

AI use: Claude Code (Claude Opus 5.5) found the refusal in the offline census, wrote the change, the tests and
this text, and ran the checks on our machine; Lyrnc reviews what goes out. No game data is included (hashes,
counts and error text only; the snippet above is the test's, written by hand).

🤖 Generated with Claude Code

…he mask is not zero

A bitwise SALU operation that writes a lane mask (s_and_b32 of a compare
and EXEC, s_not_b32 of one) sets SCC to whether its result is not zero.
A branch on that SCC already lowers, as the lane's own bit; but sop()
refuses every operation writing a mask and marks its SCC "a lane mask
read as data" too, so an instruction reading the SCC as data was
refused. The console compiler's bounded poll loops read it so: an
s_cselect of "some lane is set", combined with an iteration limit, then
s_cbranch_scc0 back. Four compute passes of the title's FidelityFX
upscaler wait in such loops.

In compute programs, where a mask's number is the console's, an SCC of
such an operation that an instruction other than a branch reads is now
the mask's number (both dwords in wave64) tested for zero, taken where
the operation runs; the mask itself stays a mask. Such a program
declares the console's wave size, as programs reading a mask as a
number already do. Vertex, pixel and mesh programs keep the refusal.

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

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — verified on RTX 5090 and VICTORY_WARP=1 (Windows / D3D12) against origin/main (63bcca4).

  • Lowering SCC from a lane-mask operation read as data to wave-any non-zero (across both dwords for wave64) passes cleanly on both RTX 5090 and WARP.
  • cargo test -p victory-shader --lib emit::crosslane_tests:: -- --test-threads=1: 7 passed, 0 failed on RTX 5090 and 7 passed, 0 failed on VICTORY_WARP=1 (mask_operation_scc_read_as_data_is_the_waves_any_on_gpu and wave64_mask_operation_scc_reads_both_dwords).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the wave32 mask-SCC test at d9ed313 on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build.

cargo test -p victory-shader --lib mask_operation_scc_read_as_data_is_the_waves_any_on_gpu -- --test-threads=1
1 passed; 0 failed; 0 ignored; 0 measured; 306 filtered out      (exit 0)

The test passes on the real adapter with native 32-lane waves. The PR also adds wave64_mask_operation_scc_reads_both_dwords, which I did not run here: this card cannot dispatch a WaveSize(64) pipeline. The thread has no comments yet; the author ran the same test on an RTX 5080, so this adds a second NVIDIA part with driver 32.0.16.2124.

Not tested: the wave64 GPU path, the title's FidelityFX shaders, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on s_cselect / scalar polling loops using the SCC of bitwise lane-mask instructions. The existing test suite passes (40/40 on both RTX 5090 and WARP, with all 5 Wave32 cases running on RTX 5090 and the Wave64 case passing DXIL validation), and crates/victory-shader/src/emit/lower.rs stays under the 512 KiB ceiling at 523,600 bytes.

However, there are two P1 semantic bugs where newly accepted shaders silently diverge from RDNA2 ISA (previously rejected with Err(LANE_MASK)):

  1. Partial-wave dispatch + bitwise complement/negation flips SCC from 1 to 0:
    In crates/victory-shader/src/structure.rs:703-710, entry EXEC is modeled as Bool::TRUE. Because implies(m, Bool::TRUE) is always true at structure.rs:1198, an operation like s_not_b32 s20, vcc_lo in the entry block marks s20 in self.active. On a partial wave (e.g., 16 threads in Wave32 or 32 in Wave64) where every running lane sets vcc, native s20 is 0xFFFF_0000 (SCC = 1), yet lower.rs:1874 skips mask_number because s20 is in active and runs waveActiveBallot(!vcc) over only the active host lanes, returning 0 and turning SCC into 0.
  2. Same SCC read both as data and by s_cbranch_scc* disagrees across lanes:
    If s_and_b32 s20, vcc_lo, exec_lo (say only lane 0 set under full EXEC) has its SCC read by s_cselect_b32 s21, 1, 2 and then branched on by s_cbranch_scc1 on the same SSA SCC value, lower.rs:454 + lower.rs:3648 give s_cselect the wave-wide bit (1 in all lanes), while structure.rs:1204 / structure.rs:1368 and lower.rs:10248 still branch per-lane using scc_lane (taking the branch only in lane 0 instead of the whole wave). (The loop test at crosslane_tests.rs:1122-1142 missed this because the branch and s_cselect consume different SCC definitions.)

Please address both cases (ensure s_cbranch_scc* on an SCC in mask_sccs is consistent—unified as wave-wide nonzero or rejected rather than silently splitting the wave—and handle partial waves / active classification cleanly for complements). Non-blocking P2 notes: phi joins before an SCC data read, s_wqm_b32/b64 / *saveexec producers, and SCC escaping a whole-wave section are also not yet handled.

@zzm1234560621-prog

Copy link
Copy Markdown

Hardware verification on Intel (Xe-LPG), d9ed313 on top of 63bcca4:

cargo test -p victory-shader --lib -- crosslane --nocapture
[SUMMARY] mask operation SCC: 5 passed, 0 failed, 0 skipped
[SUMMARY] DPP8/DPP8FI: 5 passed, 0 failed, 0 skipped
[SUMMARY] ds_swizzle_b32: 6 passed, 0 failed, 0 skipped
[SUMMARY] DPP16: 18 passed, 0 failed, 0 skipped
test result: ok. 7 passed; 0 failed; 0 ignored

Full suite on the same head: 297 passed, 7 failed, 3 ignored — and every one of the seven is the set this adapter already fails on unmodified 63bcca4 (documented in #3196: three BVH tests one ULP off from this driver's reassociation, arithmetic_matches_the_hardware and the MAD signed zero which #3212 fixes, image_atomics_of_64_bits and the view-heap test which #3203 and #3178 cover, and fspx_…dot_products). So the PR adds no failure here, and the two extra passes over the 295 the baseline has are its own tests.

cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.

On the shape itself: reading the SCC of a mask-producing scalar op as data is a good catch, and it is a different question from the one I assumed on #3253 — there the missing value was the mask (s_and_b32/s_cmp writing EXEC/SCC) and I argued for materialising at the use site; here the SCC is a scalar "any lane", so it belongs at the write, where you put it. I have said so on #3253 so the two do not get confused.

No game files. AI-assisted (Claude).

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I combined this exact head d9ed313 with #3402 at d1158c9 and published the tested merge and Wave64 regression.

The regression runs the two patterns in a single synthetic shader. The first true comparison is in lane 63 on iteration 2 of a bounded poll. The shader then performs the whole-wave OR and reads lane 63 after restoring EXEC. Readback must contain 0x55555557 in the 32 participating lanes and the original sentinel 7 in the other 32.

With the identical fixture, #3402 alone stops at a lane mask read as data and #3401 alone stops at a whole-wave section step the simulation does not follow. The combined branch validated and dispatched the Wave64 shader in three fresh WARP 1.0.22 processes, with all 64 words matching each time. The cross-lane and wave suites reported 18 passed. This WARP runtime skipped Wave32 dispatches. Strict clippy with default and all features and the 192-file asset-policy check passed.

The merge retains both parent commits and both sets of tests. It moves the mask-SCC helpers to keep lower.rs below the size limit. Maintainers can use the composition when ordering the two PRs. If folding the new regression into another commit, please retain the Git author or add Co-authored-by: andrewpozdnakov7-jpg.

@andrewpozdnakov7-jpg

andrewpozdnakov7-jpg commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

@Lyrnc 15057a5 is a follow-up directly on d9ed313 for the two blocking SCC observations.

With a 16-thread group in Wave32, the original produced SCC=0 in all 16 results after complementing VCC. The patch reconstructs the numeric mask on a partial wave and all 16 results show SCC=1. It also rejects the case where the same mask SCC is consumed as scalar data and as a branch condition, so the same SSA value cannot take different meanings. Both focused regressions and strict shader Clippy (default and all features) passed.

If you take the patch, please retain Git authorship when cherry-picking or rebasing. If folded into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>.

AI-assisted with Codex. Synthetic shaders only.

I also resolved the test-file overlap and the shader file-size limit in c75cc68, which combines the two reviewed follow-ups. Both SCC regressions and both section-lane tests passed in the combined app-local WARP build.

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.

6 participants