Repository navigation
Translator: a lane mask computed in the vector unit is data, written to the active lanes only (SHADER-402) - #3900
simonbronk wants to merge 6 commits into
Conversation
The corpus is disassembled for gfx1013 without +wavefrontsize64, so the 64-bit SDST of a wave64 v_cmp_*_e64 or carry-out prints as one register (v_cmp_gt_f32_e64 s0, ...) while the wave writes s[0:1]. lane_masks.py took it as s0 alone, so s1 was unknown and a later s_and_b64 / s_or_b64 of two compare results took the 64-bit data path: SCC was each lane's own bit instead of the wave's vote, and s_bcnt1_i32_b64 of it counted data bits. lane_masks.step/analyse take the shader's wave size; mask_sdst widens a one-register VALU mask destination to the pair in wave64. rdna2spirv's valu_mask_dst writes both registers: since 804f4ae a pair read as a wave64 mask takes lanes 32-63 from the high register, which the one-register write left stale. Corpus (26,503 shaders): one-register SDSTs in 18,866 of 23,839 wave64 shaders; 18,868 translate differently, all wave64; the same 26,501 still translate and pass spirv-val as on main. New GPU test cs_w64_sdst_pair (corpus form) and tests/semantic/test_w64_sdst_pair.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… part 1, ItsNotRexed#210) A register holding a lane mask keeps only this lane's bit (0 or ~0). When an instruction reads it as a plain value (a VALU source, store data, s_lshr / s_and with a constant, s_lshr_b64, s_add, exec_lo/hi or vcc_lo/hi as a value), hardware sees the whole wave's mask; the translation saw the lane's bool. lane_masks.data_reads finds those reads, leaving mask readers (bcnt, ff1, mbcnt, cmp, bitcmp), copies, mask-to-mask bitwise ops, saveexec, the v_cndmask selector, carry-ins and EXEC/VCC writes alone. The translator gathers each half with OpGroupNonUniformBitwiseOr (or the emulated wave64 round) before the instruction and returns it from load_reg / src_u. New GPU tests cs_wm_as_data, cs_wm_as_data2 (wave64) and cs_wm_as_data32 (wave32), all failing before; data_reads unit tests; design.md row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…exec_lo takes the lane's bit Follow-up to the lane-mask-as-data change (ItsNotRexed#210), rebased on main's 64-bit SALU data path (src64_data / dst64_data): - s_and/or/xor/andn2/orn2_b64 and s_cselect_b64 whose lane-mask sources are read as data (mask_data64) take main's data path on both words instead of the per-lane mask path. - mask_src reads the raw register, so the v_cndmask selector stays a mask when the same register is also a value operand. - A register written to exec_lo turns on the lanes 0-31 whose bit is set (the same as non-zero for a one-bit-per-lane mask), so a mask combined with data and moved to EXEC no longer turns on every lane; in wave64 lanes 32-63 keep their EXEC (exec_half_write). - tests/semantic: test_salu64_bitwise_data and test_scselect_b64_data expected v_mov_b32 vN, s<mask> to give the lane's bool; it gives the wave's bits (ItsNotRexed#210). New GPU tests cs_wm_as_data64 and cs_wm_as_exec. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… gathered when read as data A mask copied into a VGPR (v_mov_b32 v7, s16) and then given data in one lane (v_writelane_b32 v7, s15, 27) was gathered as the wave's bits when read as data, so lane 27's data set bit 27 in every lane. Mark such a VGPR (and VGPR copies of it) so data_reads reads it lane by lane, as main does (crosslane_fuzz seed 6, cs_xl32_600042, which passed on main and failed with this PR). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its at the copy With ItsNotRexed#2290 merged, a v_mov_b32 copy of a mask into a VGPR is an EXEC-gated write, so lanes EXEC leaves off keep their old VGPR. Gathering the mask at a later read (the store) then took those lanes' old words as set bits and overwrote them: cs_mask_vgpr_exec failed on AMD and on the RTX 5070. Hardware writes the wave's bits to the active lanes, so the copy now reads its mask source as data (lane_masks.data_reads) and the VGPR holds data from there on. cs_mask_vgpr_exec2 uses a mask that differs per lane: lanes 0-3 get 0x1f, lanes 4-31 keep 0xdeadbeef; main gives 0xffffffff in lanes 0-3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…to the active lanes only
A VALU op that reads a lane mask (v_or_b32 vN, vcc_lo, s20; v_or3_b32; v_xor_b32 vN, s20, s21 with both
wave64 halves) now reads it as data, like the v_mov_b32 copy already does: data_reads gathers each mask
source, the op runs on the words, and the write is EXEC-gated. Before, each lane computed its own bit in
every lane, active or not, so lanes EXEC had left off lost their old VGPR, and a VGPR mixing both wave64
halves gave a per-lane bit instead of the word.
A VGPR now never holds a lane mask. The ("v", r) and ("vw", r) state, the all-lanes store
(write_all_lanes) and v_readfirstlane's per-lane path for such a VGPR are gone. An SGPR read back with
v_readfirstlane is data, and used as a mask each lane takes its own bit (ItsNotRexed#1792).
New GPU tests: cs_mask_vgpr_or (wave32) and cs_wm_vgpr_halves (wave64); both fail on the parent.
SHADER-402, follow-up to SHADER-21 (ItsNotRexed#210).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Semantically this checks out, but it cannot land as-is: What I verified: full Three fixes while rebasing:
AI-assisted review, no game files, no GPU. |
|
GPU run for this PR, since the review above had no GPU. I tested head Hardware: AMD Ryzen 5 7600X, Windows 11 Home 26300. GPUs: AMD Radeon(TM) Graphics iGPU (RDNA2 gfx1036, subgroup 32..64), driver 24.10.24 (Vulkan driver 2.0.302); NVIDIA GeForce RTX 5060 Ti, driver 610.88 (subgroup 32..32). MSVC 14.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, Python 3.12.10. Test programs built at the PR head with
The one NVIDIA failure is The new tests, all PASS with the same words on every run that executed them:
For example,
|
|
Tested aa8f538 (a re-test at the new head) on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions against its merge base.
No game files. AI-assisted. |
Depends on: #293
SHADER-402, follow-up to SHADER-21 (#210): a lane mask computed in the vector unit is read as data and written only to the lanes EXEC has on.
#293 gathers the wave's bits when a lane mask is read as data, and its last commit does that at a
v_mov_b32copy (needed with #2290). One gap was left: a mask computed in the vector unit (v_or_b32 vN, vcc_lo, s20,v_or3_b32,v_xor_b32 vN, s20, s21). There, each lane computed its own bit into the VGPR in every lane, active or not. Two things went wrong with that:Change
tools/lane_masks.py: a VGPR never holds a lane mask. A VALU op with a mask source reads it as data, sodata_readsgathers each mask source, as it already did forv_mov_b32. The("v", r)/("vw", r)state andstep's "writes a mask to a VGPR" result are gone.analysestill returnswrites(always empty), so callers unpack it as before.tools/rdna2spirv.py: removes the all-lanes VGPR store (write_all_lanes,mask_writes) andv_readfirstlane's per-lane path for a mask VGPR. An SGPR read back withv_readfirstlaneis now data; used as a mask, each lane takes its own bit (rdna2spirv: a constant used as a lane mask through an SGPR (or a b32 SOP2 on EXEC) gives each lane its bit #1792), as it already did after av_mov_b32copy.docs/design.md: the "Lane mask read as data" row covers this case. Two known gaps are dropped: a wave64 VGPR mixing both halves, and a mask computed in the vector unit under a partial EXEC.Tests
Two new GPU tests, both failing on #293's head (004e31f):
cs_mask_vgpr_or(wave32)vcc_lo= lanes 0-4,s20= lanes 30-31,v_or_b32_e64 v2, vcc_lo, s20with EXEC = lanes 0-3, then every lane stores0xc000001fin all 8 dumped lanes0xc000001f, lanes 4-7 keep0xdeadbeefcs_wm_vgpr_halves(wave64)s[20:21]= lanes 0-35,v_xor_b32_e64 v10, s20, s21with EXEC = lanes 0-30in all 80xfffffff0, lanes 4-7 keep0xdeadbeefWindows 11, LLVM 21.1.8
llvm-mc, GPU picked withVK_LOADER_DRIVERS_SELECT:run_gpu_tests.pyLEONIDA_W64_EMULATE=1The skips are the same as on
main. Other checks:python -I -m unittest discover -s tests/semantic: 4145 OK.tests/test_lane_masks.py: updated for the new shape, OK.tests/test_shader_checks.py: OK.compileall: clean.crosslane_fuzz.py --wave both --w64-nativeon the AMD iGPU, seeds 5 and 6 (--dpp, 50 programs) and 9001 (150): 0 non-hypothesis mismatches in every mode, the same as Translator: a lane mask read as data gives the wave's bits (SHADER-21 part 1, #210) #293.Corpus (player's own copy, 1.0.2.1,
--wave64-emulate): 26,501 translate and passspirv-val, the same asmainand #293. No SPIR-V binary differs from #293. The game's shaders don't compute a lane mask in the vector unit under these conditions, so this PR changes nothing the game runs today. It fixes the translator's semantics for code that does, and it removes a special path (the all-lanes store) that only this case used.Remaining gaps, unchanged from #293: SALU bitwise ops that combine wave64 halves (
s_xor_b32 s0, s4, s5); a 64-bit EXEC write from a data pair.AI-assisted (Claude Code). No game data used.
🤖 Generated with Claude Code