Skip to content

cf_diff: v_readlane / v_writelane inside control flow in the FUZZ-8 fuzzer - #4134

Open
tunczzz wants to merge 8 commits into
ItsNotRexed:mainfrom
tunczzz:fuzz-8-lanes
Open

tunczzz wants to merge 8 commits into
ItsNotRexed:mainfrom
tunczzz:fuzz-8-lanes

Conversation

@tunczzz

@tunczzz tunczzz commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #3918 (comment) (FUZZ-8 follow-up).

Depends on: #4104 (→ #4077 → #663 → #615). Review only the last commit, cf_diff: v_readlane / v_writelane inside control flow.

What

v_readlane_b32 and v_writelane_b32 ignore EXEC (docs/design.md, "Lane select"). A lane that an enclosing if or loop turned off is still read, and still written. FUZZ-7 checks the lane-select arithmetic, but not with lanes off in control flow. This adds:

  • lanes shape in tools/cf_diff.py, at any nesting depth:
    • v_readlane_b32 of a data VGPR, with the result added to every active lane;
    • v_writelane_b32 into a data VGPR (v8/v9 preferred, since they go straight to the export, so a lost write shows);
    • the lane is a constant, possibly past the wave (it wraps: S1[4:0] in wave32, S1[5:0] in wave64), or an SGPR.
  • tools/cf_ref.py: both ops.

No translator change. The current translation (writelane stores to the lane's VGPR without looking at %active; readlane is a shuffle that every invocation runs) matches everywhere.

Sensitivity

With writelane changed to write only when the lane is active (a planted bug, not committed):

  • the LANE_CASES mismatch in wave32 and wave64;
  • seed 7 gives 6 mismatches in 600 runs (before writes were biased towards v8/v9).

Tested

  • CPU campaigns, seeds 401–403, depth 3: structured (150 programs) and --dispatch-loop (100 programs), wave32 and wave64. 1,500 runs: 0 mismatches, 1 skip. The skip is a waterfall whose body widens its own source to 64 distinct values inside a loop, which runs past the interpreter's 2M-step limit. With a 40M limit it matches in both forms.
  • New tests: tests/test_cf_diff.py::test_lane_select_ignores_exec (4 cases × both waves × both forms) and tests/test_cf_ref.py::LaneSelectTests (an inactive lane read and written; lane 52 wraps to 20 in wave32).
  • In WSL Ubuntu (Python 3.14, llvm-mc 21): pytest tests/test_cf_diff.py tests/test_cf_ref.py tests/test_cf_ref_edge_fixes.py tests/semantic/test_spirv_wave_interp.py gives 169 passed. The rest of the suite is unchanged from Translator: wave64 32-bit ops on one half of EXEC/VCC (FUZZ-8) #663.

No GPU test: this PR changes only the CPU fuzzer and its reference. My GPU is an RTX 5070 Ti, but this PC has no Vulkan SDK.

AI-assisted (Claude Code). No game files were used.

Notes

tunczzz and others added 7 commits November 22, 2026 22:36
…low-up to ItsNotRexed#477)

s_not_b32 has its own handler and still set SCC from the lane's own bit
after ItsNotRexed#477 moved the SOP2 forms to the wave vote. It now goes through
scc_logic too (one or two sources). Reported by @kotorvr in ItsNotRexed#477.

- tools/cf_ref.py models s_not_b32/b64; tools/cf_diff.py generates s_not
  in the sccmask/csel shapes; tests/test_cf_diff.py has the two s_not
  regression cases (and they fail with the old per-lane SCC).
- runtime/test/shaders/cs_scc_mask32.asm: @kotorvr's compute test for
  s_and + s_cselect, s_andn2 + s_cbranch_scc1, s_not, s_or, s_xnor,
  registered as a wave32 dump in check.py and run_gpu_tests.py.
- docs/design.md: s_not_b32 in the rule, the ItsNotRexed#477 GPU results and
  @kotorvr's corpus count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es, as main's new rule)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two wave64 findings of tools/cf_diff.py with new mask shapes:

- A register written to exec_lo (s_and_b32 exec_lo, exec_lo, vcc_lo;
  s_mov_b32 exec_lo, s0) set all 64 lanes, and any op but s_mov_b32
  into exec_hi was rejected ("destination exec_hi"). dst() now writes
  one half through exec_half_write; the other half keeps its lanes.
- The SCC of a 32-bit op on one half of a mask (vcc_lo/hi, exec_lo/hi,
  a half-mask SGPR) took the lane's own bit. scc_logic now votes over
  that half (scc_any_half). The half comes from the sources, or from an
  EXEC/VCC destination; an SGPR destination's old half is ignored.

A program with no SCC reader (s_cbranch_scc*, s_cselect, s_addc/subb,
s_cmov*, an scc operand) skips the vote, so --wave64-emulate does not
pay an exchange for an SCC nobody reads (keeps
test_wave64_emulate_reuses_a_mask_exchange at its counts).

Fuzzer: cf_ref treats every _b32 op as a 32-bit word op (halves
included) and models s_cmp_eq/lg_u64 and s_cselect_b64; cf_diff adds
e64 compares into SGPR masks (saveexec, v_cndmask), constant EXEC,
half-EXEC ops, half-mask SCC, s_cmp on masks and s_cselect between
masks, and counts literals in instruction sizes. GPU test
cs_w64_exec_half (wave64 dump; expected 1 0 1 1 0 3 9 9).

Depends on: ItsNotRexed#615

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two loop shapes: per-lane trip counts closed by s_cbranch_vccnz (the
wave loops while any lane wants to, EXEC unchanged), and loops that drop
finished lanes with v_cmpx and close on s_cbranch_execnz. cf_ref models
s_andn1/andn2_wrexec (EXEC = ~S0 & EXEC / S0 & ~EXEC, D = EXEC, SCC).

No new findings: 2,600 cases with the loop shapes (structured, dispatch
loop, depth 4) and s_andn2_wrexec in both wave sizes and forms match.
s_andn1_wrexec and the xor/orn2/nand/nor/xnor/andn1/orn1 saveexec forms
are not translated (Unsupported); every corpus shader translates, so the
game does not use them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two new program shapes cover translator rules the fuzzer did not reach:

- mread: s_bcnt1 / s_ff1 of EXEC, VCC or an SGPR compare mask into a
  uniform SGPR (wave64: _b64, or _b32 on one half), added to every
  active lane, optionally followed by s_cmp on it and a branch.
- waterfall: v_readfirstlane of a lane value -> v_cmp_eq ->
  s_and_saveexec -> body -> s_xor exec, closed by s_cbranch_execnz or
  by the SCC of the s_xor (the descriptor-per-group-of-lanes loop).

cf_ref models v_readfirstlane_b32 (lowest active lane, lane 0 when
none), s_bcnt1_i32_b32/b64 (SCC = count != 0) and s_ff1_i32_b32/b64
(-1 when no bit is set); a _b32 form reads one 32-bit word, one half of
the mask in wave64.

Both shapes are sensitive: with v_readfirstlane read per lane (the
pre-2026-11-21 translation) or s_bcnt1 counting the lane's own bit,
seed 3 gives 5 and 4 mismatches of 120. Waterfalls take v1/v2/v3
(8 or 16 distinct values); v8 (one value per lane) nested inside other
loops ran past the wave interpreter's step limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A `wqm` shape: s_wqm of EXEC after narrowing it to a compare, or of VCC
into EXEC, around a body [-> s_cbranch_execz / scc0 / scc1], with EXEC
restored by s_mov; or s_wqm of a compare into an SGPR feeding an SCC
branch (SCC = some quad has a lane on). Wave64 also gets the _b32 form on
one half. Nested inside a divergent if, it turns quad-mates the if had
turned off back on, which the translator must do through %active.

- cf_ref: s_wqm_b32/b64 (each 4-bit group all ones when any bit of it is
  set; SCC = D != 0; a _b32 form is one 32-bit word).
- spirv_wave_interp: OpGroupNonUniformQuadSwap (direction 0/1/2 reads
  lane ^ 1 / ^ 2 / ^ 3) and QuadBroadcast (lane 4n + index); the
  translator's WQM path in fragment shaders uses QuadSwap.

With s_wqm put back to the identity it was before SHADER-34, 12 of the
38 generated WQM programs of seed 3 mismatch; test_whole_quad_mode_cases_
catch_an_identity_wqm pins one of them.

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

A `lanes` shape at any nesting depth: v_readlane_b32 of a data VGPR
(added to every active lane) or v_writelane_b32 into one (v8/v9 are
preferred, since they go straight to the export), with a constant lane
(also past the wave, which wraps: S1[4:0] in wave32, S1[5:0] in wave64)
or an SGPR lane. Both ignore EXEC, so a lane an enclosing if or loop
turned off is still read and written. cf_ref models both ops.

With writelane changed to honour EXEC (a planted bug, not committed),
the LANE_CASES mismatch in wave32 and wave64 and seed 7 gives 6 of 600
mismatches.

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

Copy link
Copy Markdown
Contributor

Tested at the head (01119b9d) on Windows 11 / Python 3.13.0: test_cf_diff + test_cf_ref + test_cf_ref_edge_fixes give 156 passed / 71 subtests, the new lane test 16/16, regen_fixtures --check and compileall clean, and a seed-401 depth-3 campaign gave 160 structured + 100 dispatch runs with 0 mismatch, all under --spirv-val. Negative control: reverting tools/cf_ref.py fails all 16 lane cases.

The semantics are right: the oracle masks S1 with wave-1, ignores EXEC and writes only the selected lane (tools/cf_ref.py:249-256), matching docs/design.md:328; the expected 120/77 and 77/121 are correct, and writelane clobbering is observable through the probe/export set (tools/cf_diff.py:300,313-315). Inactive-lane reads and writes are exercised.

Minor:

  • tests/test_cf_diff.py:85 uses lane 84 -> 20 in both waves, so it does not distinguish wave32 from wave64 masking.
  • tests/test_cf_ref.py:969 covers only wave32; wave64 lanes >= 32 are unpinned.
  • The PR is 7 commits including tools/rdna2spirv.py (+42), not "last commit only"; the merge is clean, but that scope should be in the body.

Approve. AI-assisted review, no game files, no GPU.

@Kam471 Kam471 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.

Ran this at 01119b9d on Windows 11: pytest tests/test_cf_diff.py tests/test_cf_ref.py tests/test_run_gpu_tests.py tests/semantic/test_spirv_wave_interp.py -q -> 204 passed, 112 subtests passed; compileall (cf_diff/cf_ref/wave interp) and git diff --check clean.

The new lanes shape covers both directions of the rule in and out of control flow: v_writelane and v_readlane on a lane an enclosing if turned off, a lane select past the wave that wraps, and an SGPR lane select inside a loop. The reference interpreter and the fuzzer agree on all of them, and the existing FUZZ-8 programs still pass. The branch carries #4104/#4077/#663/#615's commits; only the final lane-select commit is new, as stated. No blocking issue.

…tsNotRexed#4134)

- test_cf_diff: the wrap case writes lane 100 (lane 4 in wave32, lane 36
  in wave64) from s11 (5); lane 84 was lane 20 in both waves, and s12 is
  0 like the v9 it overwrote, so the write wasn't observable. With the
  wave64 writelane masked by 31 the case now mismatches in both forms.
- test_cf_ref: a wave64 test pins lane 45 read while off and lane
  100 & 63 = 36 written.

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

tunczzz commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @tupacfan04. Both test gaps were real and are fixed in 42bc6293:

AI-assisted (Claude Code).

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 42bc6293 merged onto main 03b09a08 (4 behind; merges cleanly) on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), Vulkan SDK 1.4.363, llvm-mc 23.1.6, test programs from main: pass.

  • tests/test_cf_diff.py, test_cf_ref.py, test_run_gpu_tests.py: 192 passed, 110 subtests passed.
  • tests/semantic: 7458 tests (2 more than main), with the same 7 failures and 2 errors main has on this machine; none new.
  • run_gpu_tests.py: 165/212 passed, 47 skipped, 0 failed. New cs_scc_mask32 passes. New cs_w64_exec_half skips here (no 64-wide compute subgroup); with LEONIDA_W64_EMULATE=1 it passes (1 0 1 1 0 3 9 9).
  • ps_wqm's SPIR-V differs from main's and it still passes (whole-quad mask exact on every pixel); no other suite shader changes.

AI-assisted (Claude Code).

@radv-tinker

Copy link
Copy Markdown
Contributor

Tested 42bc6293 on AMD Radeon RX 9070 XT (RDNA4), RADV GFX1201, Linux (Fedora 43), subgroup 32..64: pass. The earlier checks don't include RADV.

python3 -I scripts/run_gpu_tests.py --filter <test> with the Mesa shader cache off, for the 2 test(s) this PR adds. Each passed in all three configurations: Mesa 25.3.6 (Fedora package) with ACO, the same with LLVM (RADV_DEBUG=llvm), and Mesa 26.3.1 (built from source) with ACO. The three give the same words:

  • cs_scc_mask32: 7 0 0 9 11 13 7 13
  • cs_w64_exec_half: 1 0 1 1 0 3 9 9

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.

5 participants