Repository navigation
Conversation
|
Tested
So at least on MoltenVK this is a regression against an existing GPU test: a mask word read as data cannot be reconstructed by a ballot that the current EXEC restricts. AI-assisted; synthetic fixtures only, no game data. |
3ec97f5 to
b9cea5a
Compare
|
I tested the mask word and the EXEC write mask independently on an RTX 4090, Windows 11, NVIDIA 616.64, with a 32-lane compute subgroup. At head The existing For comparison with the MoltenVK report, the original fixture produced byte-identical SPIR-V from Both revisions' five modules passed Vulkan 1.2 SPIR-V validation. I built the compute harness from the PR head. Separately, all 33 tests in the four changed CPU semantic test files passed on the head. AI-assisted verification. |
|
Merged b9cea5a into current main (bfef489): no conflicts. The four test files this PR touches pass, and the changed expectations look right to me: a mask SGPR read by a VALU op is the 32-bit word on hardware, not the lane's 0 / ~0. The full translator suite (Linux, Python 3.13) has one new failure, and it's a good one: AI-assisted (Claude). |
|
I'm the author of #1043 (SHADER-MASK-AS-DATA), which overlaps. I ran both on main Your branch ( Two gaps:
|
|
Another card, native Windows: NVIDIA RTX 4050 Laptop (Ada, 10de:28a1), driver 621.01, Windows 11 build 26200, subgroup 32..32. No game files, nothing online.
Every mismatching program on main includes the Two things this PR leaves, for the record:
The other fuzzers on main, same card, three seeds each, show nothing: AI-assisted: yes |
b9cea5a to
8ece74e
Compare
|
Pushed Independent GPU verification on this head (RTX 4070 SUPER + AMD Radeon gfx1036 iGPU,
AI-assisted work. |
|
With all 32 lanes active,
Across the previous 25-dispatch test, the parent matched 800/800 lane results. The new head had 224 wrong lane results across 16 dispatches. This includes VCC and compare-written I also replayed the two exact programs from the RTX 4050 report against the fuzzer’s CPU reference:
Windows, NVIDIA 616.64, LLVM 23.1.6. I rebuilt |
|
Thanks ecox982745 — confirmed reading. The |
|
Tested 8ece74e with
So every wave64 mismatch on these seeds is gone. The 7 wave32 mismatches left ( In both cases the bits of lanes 20..31, which are not in the group, read back as set. Full-wave groups fail the same way, for example AI-assisted (Claude Code ran the fuzzer and the reductions). No game files. |
…R round-trips Review follow-up on the mask-word gather gate (ProjectLeonida#1397): `s_mov_b32 s4, exec_lo` under an unknown EXEC narrowing recorded nothing for s4, so the later `s_mov_b32 exec_lo, s4` restore minted a fresh ("n", id) tag in _exec_src_ex. mask_exec_sigs coverage then failed and the read kept this lane's 0 / ~0 bit, while the equivalent literal `s_mov_b32 exec_lo, -1` resolved to a constant half-state and gathered — register and literal restores of the same runtime value disagreed. _mov_sgpr_vals now returns an ("al", halves) alias for an EXEC source whose half-state is an unknown narrowing, the same scheme saveexec uses: exec_lo gives (state, None), exec_hi (None, state), exec gives each half in its own register for b64 moves. _exec_src_ex already resolves those aliases, so the restore reproduces the original tag and the gather stays exact; untracked SGPR sources still mint a fresh narrowing and stay conservative. Tests: two semantic cases (wave32 and wave64) assert the register round-trip gathers OpGroupNonUniformBitwiseOr identically to the literal -1 restore; cs_exec_copy.asm (+ fixture, check.py/run_gpu_tests.py dump entries) stores the mask word, exec_lo's own word and the literal-restore word side by side on real hardware — PASS on RTX 4070 and Radeon (64-wide), wave64 exec filters 9/9 on AMD. Co-Authored-By: Devin <noreply@cognition.ai>
|
Pushed Root cause: New coverage: 2 semantic tests (wave32 + wave64 EXEC round-trip asserting the Verification (RTX 4070 SUPER + AMD gfx1036 iGPU, |
|
I verified Here's a small way to reproduce that distinction using the PR's own v_mov_b32_e32 v7, -1
v_readfirstlane_b32 s7, v7
-s_mov_b32 exec_lo, s7
v_and_b32 v1, 1, v0
v_cmp_ne_u32_e64 s8, v1, 0
-s_mov_b32 s4, exec_lo
-s_mov_b32 exec_lo, s4
+s_mov_b32 exec_lo, s7
v_mov_b32_e32 v2, s8EXEC is full when the comparison defines The original five synthetic modules are byte-identical across these two commits. Re-running their 25 dispatches gave the same 224/800 wrong lane results across 16 dispatches. A diagnostic that reads the complete mask into a VGPR immediately after the compare, before changing EXEC, matched all 96 lane results across three full and partial EXEC patterns. This gives a passing control for investigating where the complete mask word can be preserved. Native wave32, Windows 11, NVIDIA 616.64, LLVM 23.1.6. The edited fixture passed Vulkan 1.2 SPIR-V validation. All 16 CPU tests in |
|
Tested The fixtures on MoltenVK
#953 is the whole-wave mask gather that MoltenVK needs stored, so the right-hand column is the one to read on this driver. The The 12 programs left at What this run adds: all 12 matched at the first head, wave64 emulate, Not tested: any other GPU, and the game corpus. |
|
Apple check of the new
Both Apple drivers run these at subgroup size 32 natively, so the lane-mask-as-data read is not being emulated in either run. MoltenVK's SPIRV-Cross path and KosmicKrisp's AI-assisted. No game data: hand-written fixtures, and the numbers above are test output. |
|
Follow-up: the regression I reported at
So this is fixed on macOS 26.7.3 as well, not just on the 27.x runs above. AI-assisted; synthetic fixtures only, no game data. |
|
Thanks, @whoalin1. The saved-EXEC round trip is fixed. Open points:
AI-assisted (Claude Code, Claude Opus 5.5). |
|
I compared #1043 (
The move and XOR rows each cover six runtime mask pairs for each of two sources, VCC and compare-written For the overlapping fixes, #1043's handling of |
|
Pushed
Verified here (no game files):
The residual is On overlap: #1043 currently fixes the independent-EXEC AI-assisted (SWE-2.1 Max). |
|
Apple run of the new head
Two things worth stating plainly:
AI-assisted. No game data. |
|
@EvgHaze, here are the synthetic fixtures for the Apple run. On the RTX 4090, I ran the PR head directly with native wave32 on Windows 11, NVIDIA 616.64. I also translated all seven programs after merging this head onto the same Independent SGPR fixture and all-lane checkSave as ; group: 32,1,1
; mattr: +wavefrontsize32,-wavefrontsize64
v_mov_b32_e32 v7, -1
v_readfirstlane_b32 s7, v7
v_and_b32 v1, 1, v0
v_cmp_ne_u32_e64 s8, v1, 0
s_mov_b32 exec_lo, s7
v_mov_b32_e32 v2, s8
v_mov_b32_e32 v4, exec_lo
s_mov_b32 exec_lo, -1
v_mov_b32_e32 v5, s8
v_lshlrev_b32_e32 v3, 4, v0
v_mov_b32_e32 v20, v2
v_mov_b32_e32 v21, v3
buffer_store_dword v20, v21, s[0:3], 0 offen
v_mov_b32_e32 v20, v4
v_add_nc_u32_e32 v21, 4, v3
buffer_store_dword v20, v21, s[0:3], 0 offen
v_mov_b32_e32 v20, v5
v_add_nc_u32_e32 v21, 8, v3
buffer_store_dword v20, v21, s[0:3], 0 offen
v_mov_b32_e32 v20, v0
v_add_nc_u32_e32 v21, 12, v3
buffer_store_dword v20, v21, s[0:3], 0 offen
s_endpgmFrom the repo root, with your usual driver and push-constant settings and mask_dir=$(mktemp -d)
python3 -I runtime/test/shaders/build.py "$mask_dir" cs_exec_copy_independent &&
VKC_SUBGROUP_SIZE=32 VKC_OUT_WORDS=144 VKC_DUMP="$mask_dir/independent.raw" vk_compute_test "$mask_dir/spirv/cs_exec_copy_independent.spv" 1 dump &&
python3 - "$mask_dir/independent.raw" <<'PY'
from pathlib import Path
import struct
import sys
actual = struct.unpack("<144I", Path(sys.argv[1]).read_bytes())
expected = tuple(w for lane in range(32) for w in (0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa, lane))
assert actual == expected + (0xeeeeeeee,) * 16
print("128/128 output words and all guard words match")
PYIndependent-EXEC move and XOR rowsThis is the exact ; group: 32,1,1
; rsrc2: 0x8090
v_mbcnt_lo_u32_b32 v1, -1, 0
v_mov_b32_e32 v2, 0xdeadbeef
v_mov_b32_e32 v5, s5
v_lshrrev_b32_e32 v5, v1, v5
v_and_b32_e32 v5, 1, v5
v_mov_b32_e32 v7, 0x12345678
v_cmp_ne_u32_e64 s8, v5, 0
s_mov_b32 exec_lo, s4
v_xor_b32_e32 v2, s8, v7
s_mov_b32 exec_lo, -1
v_lshlrev_b32_e32 v3, 2, v1
buffer_store_dword v2, v3, s[0:3], 0 offen
s_endpgmRun each variant once per pair below, setting AI-assisted verification with OpenAI Codex. |
|
Tested Setup:
With The one left here:
It is not a regression: main fails the same program differently (each lane gets its own For comparison, the four programs #1043 leaves on this seed reduce to a Not tested: native wave64 (this card has no 64-wide subgroup), other seeds on this head, and the semantic suite. AI-assisted (Claude Code). |
|
I narrowed down the RTX 3060 result on an RTX 4090. It also happens when both the move and the read have active lanes. This gives a regression test independent of the semantics of a read with empty EXEC. On
v_add_nc_u32_e32 v3, 0xd4718f66, v0 ; v0 is the local lane index
v_cmp_eq_u32_e64 s20, s4, v0 ; dispatch input s4 = 7
s_and_saveexec_b32 s24, s20
v_mov_b32_e32 v3, s20 ; only lane 7 writes
s_mov_b32 exec_lo, s5 ; dispatch input s5 = 0xffffffff
v_readfirstlane_b32 s14, v3 ; lane 0 supplies its original word
s_mov_b32 exec_lo, -1
v_mov_b32_e32 v4, s14 ; store v3 and v4 side by sideRemoving only the predicated In the 20-thread module, Native wave32, Windows 11, NVIDIA 616.64. Six synthetic modules per revision passed Vulkan 1.2 validation, with all readback guards intact. Baseline |
|
Thanks for narrowing this down. I agree with the interpretation that this is a mixed-provenance case rather than a regression introduced by The current model has one static provenance for the whole VGPR. I do not see a small sound fix inside this PR without tracking which lanes of the VGPR received the mask word (or otherwise carrying per-lane provenance) through the copy and the first-lane selection. Since the case exists on main as well, my preference is to treat it as a follow-up rather than block the lane-mask data-read improvement here. If others prefer, I can write the finding up separately with your reduced shader as the reproducer. AI-assisted analysis with Devin. |
… mask word A lane mask (EXEC/VCC or a mask-tracked SGPR) that a VALU op reads as a 32-bit value — v_mov_b32 of it into a plain VGPR, or any VALU source where the mask is data rather than a mask operand — materialized each lane's own 0 / ~0 bit. Hardware holds the whole wave's mask word there (tools/crosslane_fuzz.py's op_maskdata model: the uniform word written to the active lanes), so every lane gets the word, the same in each. - src_u materializes the wave mask word (lane_mask_word) for SGPR and EXEC/VCC operands when the instruction's VGPR destination makes the read a data read (mask_read_is_data); SGPR/EXEC/VCC destinations keep this lane's bit, which mask_src readers rely on. Mask-holding VGPRs already store the word, so their reads are plain loads. - mask_src extracts this lane's bit back out of a mask-holding VGPR (_vgpr_mask_lane_bit), half-aware in wave64 via mask_half. - mask_data_src keeps instructions that materialize the word out of EXEC-gated active runs (a subgroup op can't sit inside if (active)). - v_readfirstlane_b32 of a mask VGPR broadcasts the first active lane's copy — the only lane guaranteed fresh after an EXEC-gated v_mov_b32 — as the word itself into a VGPR destination (VGPR writes are never mask-tracked), or this lane's bit for a mask-tracked SGPR/special one; fixes cs_wavemask lanes 48-63. Found by tools/crosslane_fuzz.py (ProjectLeonida#293). docs/design.md's whole-wave mask contract updated. Co-Authored-By: Devin <noreply@cognition.ai>
…er reads Review fixes for the mask-as-data change: - The wave-mask gather is a group op over the lanes EXEC leaves active, and drivers differ on whether lanes EXEC has off still vote: NVIDIA, AMD and KosmicKrisp return the whole subgroup's bits, MoltenVK's ballot/reduce saw only the lanes a narrowed EXEC left on and produced the EXEC value instead of the frozen mask word (cs_mask_vgpr_exec). mask_word_read_ok now gathers only when a CFG must-analysis (mark_exec_state) proves every lane that can hold a set bit of the mask is EXEC-active at the read: each EXEC half is tracked as clean, a constant mask, or an unknown narrowing (s_mov/s_cselect resolve constants, saved-EXEC aliases and unchanged EXEC, so the common restore idioms still gather), and mask_exec_sigs records every EXEC state seen while each mask register held a mask. Unproven reads keep this lane's 0 / ~0 bit, the pre-change answer. - Scalar number ops read a lane mask operand as data too (MASK_NUMBER_READERS, ProjectLeonida#1043's NUMBER_READERS): s_add_u32 s20, s10, K after v_cmp wrote s10 yields the wave's mask word, while mask moves and mask logic ops keep this lane's bit for the saveexec idioms. - wave64_emulate_opt treats ins["mask_words"] (a mask read that will gather) as a cross-lane exchange for the lane-local fold planner and barrier scheduler, covering the scalar readers as well. - test_slot67_operand_forms' expectedFailure comes off: the packed vcc_hi word now reaches the data read. Co-Authored-By: Devin <noreply@cognition.ai>
…R round-trips Review follow-up on the mask-word gather gate (ProjectLeonida#1397): `s_mov_b32 s4, exec_lo` under an unknown EXEC narrowing recorded nothing for s4, so the later `s_mov_b32 exec_lo, s4` restore minted a fresh ("n", id) tag in _exec_src_ex. mask_exec_sigs coverage then failed and the read kept this lane's 0 / ~0 bit, while the equivalent literal `s_mov_b32 exec_lo, -1` resolved to a constant half-state and gathered — register and literal restores of the same runtime value disagreed. _mov_sgpr_vals now returns an ("al", halves) alias for an EXEC source whose half-state is an unknown narrowing, the same scheme saveexec uses: exec_lo gives (state, None), exec_hi (None, state), exec gives each half in its own register for b64 moves. _exec_src_ex already resolves those aliases, so the restore reproduces the original tag and the gather stays exact; untracked SGPR sources still mint a fresh narrowing and stay conservative. Tests: two semantic cases (wave32 and wave64) assert the register round-trip gathers OpGroupNonUniformBitwiseOr identically to the literal -1 restore; cs_exec_copy.asm (+ fixture, check.py/run_gpu_tests.py dump entries) stores the mask word, exec_lo's own word and the literal-restore word side by side on real hardware — PASS on RTX 4070 and Radeon (64-wide), wave64 exec filters 9/9 on AMD. Co-Authored-By: Devin <noreply@cognition.ai>
…y lane runs it (SHADER-WAVEMASK-EAGER)
A register holds this lane's bit of a lane mask; v_mbcnt, s_bcnt1 and
s_ff1 gather the other lanes' bits with a subgroup operation
(Gen.wave_mask). v_mbcnt writes a VGPR, so its result is selected on the
lane's EXEC, and MoltenVK's SPIRV-Cross inlined the single-use gather
into the taken arm of that ternary:
v6 = active ? popcount(simd_or(mine ? bit : 0) & below) + acc : v6;
A lane that is off never ran the gather, so its bit was missing from
every other lane's count. Gen.wave_mask now stores the gather to a
variable of its own with Gen.eager, as SHADER-529 did for DPP's ballot
and shuffle.
On an Apple M5 (MoltenVK 1.4.2), tools/crosslane_fuzz.py with wave 32,
native and no maskdata goes from 92 of 100 programs matching to 100 of
100, and from 193 to 200 of 200 with DPP at seed 7.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: SWE-2.1 Max <noreply@google.com>
…EXEC A lane mask in an SGPR, EXEC or VCC is one wave-wide word on hardware. The EXEC-coverage gate added earlier in this pull request could not prove the independent-SGPR restore idioms crosslane_fuzz uses, so it fell back to this lane's 0 / ~0 bit for exactly the programs the read is meant to fix. It also encoded the wrong control-flow model: EXEC narrowing is a per-lane value here, not a SPIR-V edge. Mask-data readers are already kept out of lane-local `if (active)` runs, and the eager wave-mask store keeps lowering from moving the subgroup gather into an EXEC-selected arm, so lanes EXEC has off still contribute their mask bits. Remove the gate and the CFG EXEC provenance analysis it needed, gather the mask word for every lane-mask data read, and cover narrowed SGPR and VCC reads, an independent all-ones SGPR EXEC restore, and the composed vector-bitwise mask words. The vector-bitwise expectations now check the uniform mask words and the resulting per-lane cndmask bits and popcounts rather than the old fallback artifact. Co-Authored-By: SWE-2.1 Max <noreply@google.com>
52fb230 to
e3e119a
Compare
|
Rebased onto current Post-rebase verification on this machine:
No game files used. AI-assisted with Devin. |
|
Additional AMD evidence on the current head e3e119a. Same synthetic crosslane slice before/after, no game files:
So this PR fixes both seed-14 wave64-emulate divergences on AMD, including the non-hypothesis cs_xl64_1400067 case. |
|
@ecox982745 ran your five fixtures on the Apple side, at this head (
Every lane value and Two notes on reproducing it:
AI-assisted. No game data: hand-written shaders, and every number above is a readback comparison. |
|
@sdelectron, I checked the six seed-1 cases you reported on the RTX 5080 against this PR on a physical RTX 4090. All six also differ from the CPU reference on current main. All six match after merging this PR locally. That includes the three read-first-lane cases (
I used main's I also retested the separate lane-7 fixture on that merge tree to check what remains for the mixed-provenance claim. After only lane 7 writes a mask to its vector register and full EXEC is restored, the direct lane values are all correct. The broadcast of lane 0 should give AI-assisted verification (OpenAI Codex). All shaders and inputs were synthetic. |
|
Verified on NVIDIA: this pull request clears 19 of the 20 Setup: RTX 3060 Ti (subgroup 32), NVIDIA 621.24, Windows 11, MSVC
No game files. AI-assisted (Claude Code). |
|
I checked The bug is there on the mesh path too, and this fixes it. Take
With this PR both are right, in the structured form and in the forced round-loop form. No regressions on the mesh path:
Cost, for the record. Each mask-as-data read site adds one exchange segment under On #1043: plamea's seed-1 sweep (#1608) and the runs above have this PR covering everything #1043 does, plus the AI-assisted (Claude Code). |
|
Independent check of e3e119a under
Every one of main's 21 failing programs has a mask read as data (
No regressions seen on this head (each its own seed): Generated by Claude Code |
Claimed in the coordination issue: #14 (comment)
Depends on: #953
What
A lane mask (EXEC/VCC or a mask-tracked SGPR) that an instruction reads as a 32-bit value — for example
v_mov_b32of it into a plain VGPR, or a scalar number reader such ass_add_u32 s20, s10, K— must produce the wave's mask word. Hardware SGPRs hold that wave-wide word; the translator previously produced each lane's own0/~0bit in the VALU path.This pull request now:
src_u/lane_mask_word), while mask consumers keep extracting the lane bit throughmask_src;if (active)runs, since the gather is a cross-lane operation;docs/design.mdrecords the contract. Semantic coverage includes narrowed SGPR/VCC reads, independent all-ones SGPR EXEC restore, EXEC round trips, scalar readers, vector-bitwise mask composition, native/emulated wave64 structure, and the eager-gather shape.Tested
python -I scripts/run_semantic_tests.py tests/semantic— 488 files, 6298 tests, 0 files failed;compileallclean;tests/test_lane_masks.pypassed.VK_LOADER_DRIVERS_SELECT=*nv-vk*):tools/crosslane_fuzz.py --programs 200 --seed 7 --wave 32 --modes native— 199 match / 1 mismatch / 0 hypothesis-only versus 186 / 9 / 5 atba315fbf1. The remainingcs_xl32_700032minimizes to an inactive-EXEC write-predication case (v_cmpx+ maskdatav_mov+v_xor), distinct from the narrowed-EXEC mask-word family and already present before this change.--programs 106) � 105 match / 1 mismatch / 0 hypothesis-only versus 100 / 3 / 3 atba315fbf1. The remainingcs_xl32_10200411is an EXEC-zero/readfirstlane control-flow case. AMD evidence is reported in the pull-request comments; no game files were used.AI-assisted (SWE-2.1 Max).