Repository navigation
Translator: a constant lane mask gives lane L its bit L (mask_src immediates) - #1367
Conversation
Gen.mask_src turned an immediate lane-mask operand into bit 0 of the constant for every lane, so s_and_saveexec_b32 s7, 0xff00 with all lanes on left none on and an inline 5 left all 32 on. Lane L now takes bit L: of the 64-bit value for the 64-bit forms (inline constants sign-extended, literals with a zero high word, as src64_data) and of the 32-bit value at L mod 32 for s_*_saveexec_b32 and s_andn2_wrexec_b32. 0 and -1 stay constants. s_bcnt0/1_i32_b64 of a constant now counts the constant's bits (scalar data, like s_ff1_i32_b64) instead of this lane's mask copy. SGPR operands are unchanged. GPU tests cs_w32_mask_imm.asm and cs_w64_mask_imm.asm, words derived in their headers, failed on main on an RTX 5080 and an RDNA2 iGPU and pass now; LaneMaskConstants runs both across every lane in the semantic suite. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts with main's DPP and TEST-175 entries in check.py, run_gpu_tests.py and regen_fixtures.py: main's lists with cs_w32_mask_imm / cs_w64_mask_imm added back. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent CPU-side verification of
I did not run the new |
dcastell1
left a comment
There was a problem hiding this comment.
Verified locally (CPU): the full semantic suite on this branch → 1180 tests OK (1 skip), including LaneMaskConstants.test_words (the eight wave32 words), and tests/test_rdna2spirv_cli.py → 6 passed, 22 subtests. The two new .asm files assemble with llvm-mc gfx1013, translate, and their modules pass spirv-val.
Reading the change: the per-lane ShiftRightLogical on the lane (rather than OpBitFieldUExtract) is the right call — it dodges the Intel mod-16 bug this file already documents — and the 0 / -1 fast path keeps the common case free. Truncating a b32 op to 32 bits and a b64 op to 64 with inline constants sign-extended matches src64_data.
I could not add a GPU confirmation: I assembled and translated both shaders on the 5090, but my ad-hoc harness invocation is wrong (existing tests such as cs_exec_const and cs_dpp print the 0xEEEEEEEE fill instead of their words), so I am not claiming a GPU result. Your 5080 + RDNA2 numbers stand on their own.
One gap worth a line in the description, not a blocker: for a wave64 shader, s_and_saveexec_b32 only rewrites EXEC_LO, so lanes 32-63 keep their previous bits; the wide=False path gives every lane bit L mod 32, high half included. It is still strictly better than the bit-0 behaviour it replaces, and the new tests are wave32, but the combination is not modelled.
|
Tested
No game files. |
|
Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51, llvm-mc 23.1.6): no regression. |
|
Tested dc0cd5d on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass, including the wave64 fixture under emulation. The PR's diff applied cleanly to
|
|
Tested dc0cd5d on AMD Radeon RX 7900 XTX (RDNA3, Navi 31), AMD driver 26.11.2, Vulkan 1.4.359, Windows 11: pass.
Tools: llvm-mc 21.1.8 (WSL), Vulkan SDK 1.4.363.0, MSVC 14.44. |
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested All five harnesses ( AMD Radeon 780M (subgroups 32..64)
NVIDIA GeForce RTX 5060 Laptop GPU (subgroup 32..32)
Unit & Semantic Verification
No game data or proprietary assets used. |
…p to ItsNotRexed#1367) s_ff0/1_i32_b64 of a constant read only the low word, so s_ff0_i32_b64 of -1 gave 32 instead of -1. It now reads the constant with src64_data, as s_bcnt does (inline constants sign-extended); the b32 forms are unchanged. GPU test cs_imm_mask.asm (wave64, exact on any subgroup size; word 6 is this case), run on the CPU by tests/semantic/test_imm_lane_masks.py on 64- and 32-wide subgroups. One sentence in the "Constant lane masks" row. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (s_ff0_i32_b64 of -1 included) A regression test for ItsNotRexed#1367's constant lane masks and for s_ff0/1_i32_b64 of a negative constant, which read only the low word until 2026-11-22 (s_ff0_i32_b64 of -1 gave 32). Both are fixed on main; nothing else tests s_ff0 of a negative constant. runtime/test/shaders/cs_imm_mask.asm: wave64, exact on any subgroup size, expected 1 100 111 10 60 0 4294967295 64. Registered in check.py and run_gpu_tests.py; tests/semantic/test_imm_lane_masks.py runs it on one 64-wide and two 32-wide subgroups. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (s_ff0_i32_b64 of -1 included) A regression test for ItsNotRexed#1367's constant lane masks and for s_ff0/1_i32_b64 of a negative constant, which read only the low word until 2026-11-22 (s_ff0_i32_b64 of -1 gave 32). Both are fixed on main; nothing else tests s_ff0 of a negative constant. runtime/test/shaders/cs_imm_mask.asm: wave64, exact on any subgroup size, expected 1 100 111 10 60 0 4294967295 64. Registered in check.py and run_gpu_tests.py; tests/semantic/test_imm_lane_masks.py runs it on one 64-wide and two 32-wide subgroups. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (s_ff0_i32_b64 of -1 included) A regression test for ItsNotRexed#1367's constant lane masks and for s_ff0/1_i32_b64 of a negative constant, which read only the low word until 2026-11-22 (s_ff0_i32_b64 of -1 gave 32). Both are fixed on main; nothing else tests s_ff0 of a negative constant. runtime/test/shaders/cs_imm_mask.asm: wave64, exact on any subgroup size, expected 1 100 111 10 60 0 4294967295 64. Registered in check.py and run_gpu_tests.py; tests/semantic/test_imm_lane_masks.py runs it on one 64-wide and two 32-wide subgroups. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (s_ff0_i32_b64 of -1 included) A regression test for ItsNotRexed#1367's constant lane masks and for s_ff0/1_i32_b64 of a negative constant, which read only the low word until 2026-11-22 (s_ff0_i32_b64 of -1 gave 32). Both are fixed on main; nothing else tests s_ff0 of a negative constant. runtime/test/shaders/cs_imm_mask.asm: wave64, exact on any subgroup size, expected 1 100 111 10 60 0 4294967295 64. Registered in check.py and run_gpu_tests.py; tests/semantic/test_imm_lane_masks.py runs it on one 64-wide and two 32-wide subgroups. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Requested by Lucas · project thread
Claimed in the coordination issue as: the immediate half of the mask_src finding (finding: 7077396617).
Related: #293 also edits the
mask_srcdocstring and its SGPR line, a few lines above this change. Expect a small textual conflict; whichever lands second rebases.What and why
Gen.mask_srcturned an immediate lane-mask operand into bit 0 of the constant for every lane. With all 32 lanes on,s_and_saveexec_b32 s7, 0xff00therefore left no lane on, ands_and_saveexec_b32 s7, 5left all 32 on. A constant used as a lane mask has one bit per lane, so lane L now takes bit L:s_*_saveexec_b64,s_andn2_wrexec_b64,s_mov_b64/s_not_b64into EXEC or VCC, ands_and/or/xor/andn2/orn2_b64ands_cselect_b64on the lane-mask path. Lane L takes bit L of the 64-bit value. Inline constants are sign-extended and literals get a zero high word, the same waysrc64_datareads 64-bit constants.s_*_saveexec_b32ands_andn2_wrexec_b32. Lane L takes bit L mod 32 of the 32-bit value.s_bcnt0/1_i32_b64of a constant now counts the constant's own 64 bits, as scalar data likes_ff1_i32_b64, instead of this lane's copy of the mask.s_bcnt0_i32_b64 s17, 7gave 32 and now gives 61;salu_diff --inline64found it.Not changed:
v_cndmask_b32_e64/v_add_co_ci_u32_e64, and decodes one as "Invalid immediate", so those callers never see a constant.A literal with bit 31 set in a 64-bit position (zero- vs sign-extension) is not measured, and the tests avoid it.
Tests:
runtime/test/shaders/cs_w32_mask_imm.asmandcs_w64_mask_imm.asm, with the expected words derived in their headers. They are registered incheck.py,run_gpu_tests.pyandregen_fixtures.py.LaneMaskConstantsintests/semantic/test_value_semantics.pyruns both shaders across every lane (32 and 64 lanes) and checks them against a plain-Python reference.docs/design.md.Tested
NVIDIA GeForce RTX 5080 (driver 616.92, 32-wide subgroups) and AMD Radeon RDNA2 iGPU (Ryzen 9 9950X3D, driver 26.10.1, subgroups 32..64), Windows 11. The device was chosen with
LEONIDA_VK_DEVICEand each tool's "device:" line was checked.run_gpu_tests.py, AMDrun_gpu_tests.py, RTX 5080run_gpu_tests.py, RTX 5080LEONIDA_W64_EMULATE=1check.py, AMDcheck.py, RTX 5080 emulatedunittest discover -s tests/semantic--ignore=tests/semanticsalu_diff400 programssalu_diff --inline64400 programscf_diff300 programs × wave32/64crosslane_fuzz200 programs, both GPUsrun_gpu_tests.pythe only differences are the two new tests. On AMD,check.py's remaining failure iscs_barrier_loop, the same as on main; check.py: run compute tests at the wave size index.json records, as run_gpu_tests.py does #1261 fixes it.crosslane_fuzzmismatches come from the mask-as-data ops in Translator: a lane mask read as data gives the wave's bits (SHADER-21 part 1, #210) #293; with--no-maskdatathere are 0 on both GPUs.test_shader_checks.pyOK, and the two new GPU tests pass again. On AMD both pass; on RTX 5080 the wave32 one passes and the wave64 one is skipped natively.AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed.🤖 Generated with Claude Code