Skip to content

rdna2spirv/lane_masks: keep wave64 s_*_saveexec_b32 and _wrexec_b32 on EXEC_LO - #3582

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
SweatierKey:fix/w64-saveexec-b32
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
SweatierKey:fix/w64-saveexec-b32

Conversation

@SweatierKey

Copy link
Copy Markdown
Contributor

Summary

Fix wave64 handling of all 10 s_<op>_saveexec_b32 ops and s_andn{1,2}_wrexec_b32 in tools/rdna2spirv.py and tools/lane_masks.py so they operate strictly on EXEC_LO (lanes 0..31) without clobbering EXEC_HI (lanes 32..63) or polluting SCC and downstream mask consumers.

Claim: #3381 (comment)

Bug

On RDNA2 in wave64 mode:

  • s_<op>_saveexec_b32 D, S0: D.u32 = EXEC_LO; EXEC_LO = f(S0.u32, EXEC_LO); SCC = (EXEC_LO != 0)
  • s_andn{1,2}_wrexec_b32 D, S0: EXEC_LO = f(S0.u32, EXEC_LO); D.u32 = EXEC_LO; SCC = (EXEC_LO != 0)
  • EXEC_HI (lanes 32..63) is untouched.

Previously on main:

  1. self.set_exec(r) overwrote lanes 32..63 of %active as well (corrupting EXEC_HI).
  2. self.scc_from_mask(r) voted over all 64 lanes instead of lanes 0..31 (e.g. EXEC = 0x000000FF_0000000F, s_and_saveexec_b32 s8, 0xf0 left SCC = 1 instead of 0 while corrupting EXEC_HI from 0xFF to 0xF0).
  3. self.mask_dst(a[0], ...) overwrote vcc_hi (lanes 32..63 of %vcc) when writing vcc_lo.
  4. tools/lane_masks.py tagged _saveexec_b32 / _wrexec_b32 destinations as full MASK instead of MASK_LO, causing subsequent s_bcnt1_i32_b32 / s_ff1_i32_b32 / s_cmp_eq_u32 consumers to count/read lanes 32..63 too.

Fix

  • tools/rdna2spirv.py: in wave64 _b32 saveexec/wrexec, update EXEC via self.exec_half_write(0, r), set SCC via self.scc_any_half(r, "lo"), write destinations via self.put_mask(..., "lo"), and transfer the 32-bit word via self.wave_mask when crossing halves (exec_hi/vcc_hi/MASK_HI sources or exec_hi/vcc_hi destinations). Wave32 and _b64 paths are unchanged.
  • tools/lane_masks.py: tag _saveexec_b32 and _wrexec_b32 destinations as MASK_LO (_b64 remains MASK).

Verification (CPU 64-lane interpreter + spirv-val Vulkan 1.3, no game data)

  • tests/semantic/test_wave64_saveexec_b32.py (5/5 OK, native wave64 + --wave64-emulate spirv-val + 64-lane spirv_mini_interp.run_workgroup):
    • All 10 s_<op>_saveexec_b32 ops: exact EXEC_LO, untouched EXEC_HI, low-half-only SCC, MASK_LO s_bcnt1_i32_b32.
    • s_andn2_wrexec_b32 and s_andn1_wrexec_b32 (both EXEC_LO == 0 with EXEC_HI != 0 and non-zero cases).
    • Cross-half exec_hi source and exec_hi destination.
    • vcc_lo destination leaving vcc_hi untouched.
    • lane_masks.analyse MASK_LO tagging unit test.
  • tests/test_lane_masks.py (OK), test_wrexec_b32.py (5/5), test_saveexec_variants.py (4/4), test_or_saveexec.py (4/4), test_mask_src_sgpr_const.py (7/7), test_wave64_vcc_half_write.py (7/7), test_text_write_line_endings.py (2/2).

…n EXEC_LO

In wave64 mode, the 32-bit SOP1 forms s_<op>_saveexec_b32 (all 10
EXEC_LOGIC ops) and s_andn{1,2}_wrexec_b32 operate strictly on EXEC_LO
(lanes 0..31): EXEC_HI (lanes 32..63) stays unchanged, SCC reflects
(EXEC_LO != 0) only, and the destination holds the low-half 32-bit mask.

Previously:
- set_exec(r) overwrote lanes 32..63 of %active as well;
- scc_from_mask(r) voted over all 64 lanes instead of lanes 0..31;
- mask_dst(a[0], ...) clobbered vcc_hi when targeting vcc_lo;
- tools/lane_masks.py tagged the destination SGPR as full MASK instead
  of MASK_LO, causing subsequent s_bcnt1_i32_b32 / s_ff1_i32_b32 /
  s_cmp_eq_u32 consumers to include lanes 32..63.

Use exec_half_write(0, r), scc_any_half(r, 'lo'), put_mask(..., 'lo')
(plus wave_mask cross-half bit transfer when S0 is a MASK_HI operand or
D is exec_hi/vcc_hi), and tag _b32 saveexec/wrexec destinations as
MASK_LO in tools/lane_masks.py. Wave32 and _b64 paths are unchanged.

Verified with tests/semantic/test_wave64_saveexec_b32.py (5/5, 64-lane
interpreter + spirv-val Vulkan 1.3 native and --wave64-emulate),
test_lane_masks.py, test_wrexec_b32.py, test_saveexec_variants.py,
test_or_saveexec.py, test_mask_src_sgpr_const.py, and
test_wave64_vcc_half_write.py.
@CaravelaLabs

Copy link
Copy Markdown
Contributor

Automated test: d714ee8e merged onto main f847748c on AMD Radeon 8060S (RADV GFX1151, RDNA 3.5), Mesa 25.2.8, Ubuntu 24.04, runtime rebuilt from this branch in a clean sandbox. Result: pass.

  • scripts/run_gpu_tests.py: 182/199 passed, 15 skipped (plain main: 182/199 passed, 15 skipped).
  • Python tests this PR touches: 5 passed, 14 subtests passed.

Same machine and setup as my earlier manual reports. AI-assisted (Claude Code).

@kacper-serewis kacper-serewis 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.

RTX 5070 / 616.56, subgroup 32, wave64 emulated: d714ee8 passed all 28 direct operation probes (parent f847748 translated 20/28). Including a subsequent SGPR-to-EXEC_LO restore, 14/28 head readbacks passed with 112/8960 words mismatching. The restore incorrectly reactivates high-half lanes after EXEC_HI was explicitly cleared. Reproduced on the parent too. All 28 head modules passed spirv-val and all 16 scalar equality checks passed. Synthetic only; native wave64 untested. AI-assisted.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested d714ee8 on Windows 11, AMD Radeon iGPU gfx1036 (driver 26.10.1, subgroup 32..64, native wave64) and RTX 5080 (driver 616.92, subgroup 32), runtime built from this head (MSVC, RelWithDebInfo), LEONIDA_VK_DEVICE set per run with the device line confirmed, VK_LOADER_LAYERS_DISABLE=~implicit~ (no validation layer installed):

  • test_wave64_saveexec_b32 5/5, test_wrexec_b32 5/5, test_saveexec_variants 4/4, test_or_saveexec 4/4, tests/test_lane_masks.py OK.
  • scripts/run_gpu_tests.py (all shaders): Radeon 184/199 passed, 15 skipped, 0 failed (all 25 runnable w64 cases pass natively, ps_w64x_readlane skipped); RTX 5080 153/199 passed, 46 skipped (the wave64-only cases), 0 failed.

No GPU fixture in the suite uses a _b32 saveexec/wrexec in wave64, so the GPU run is a regression check only. No negative control run.

AI-assisted.

@kacper-serewis kacper-serewis 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.

SHADER-688: the clean #3225 (99c048f) + #3582 (d714ee8) tree bb00d21be4ccb6c3319bea5f8712c8064caa3a27 passed 28/28 synthetic probes, spirv-val Vulkan 1.3, 8960/8960 readback words and 1024/1024 SGPR restore lanes. RTX 5070 616.56, Vulkan 1.4.351, subgroup 32, emulated wave64. #3582 alone had 112 wrong restore words; the common parent rejected eight probes and mismatched 1028 words. Native wave64 was outside this run. AI-assisted.

@zzEmmazz

Copy link
Copy Markdown
Contributor

Tested d714ee8e, applied alone on main f847748c: pass.
Windows 11 (26200), MSVC 14.50 (VS 2026), Ninja RelWithDebInfo. Two GPUs: Ryzen 7 9700X iGPU (RDNA2, AMD 32.0.21042.62) and RTX 3070 (NVIDIA 610.74), picked with LEONIDA_VK_DEVICE. Test programs built from f847748c (the PR changes no C++). Python 3.14.

  • Tests only, with the translator and lane_masks.py from main: python -m unittest discover -s tests/semantic -p test_wave64_saveexec_b32.py fails all 5 tests, for example s_and_saveexec_b32: AssertionError: 240 != 255, and test_lane_masks_tags_b32_saveexec_and_wrexec_as_mask_lo: {4: 'mask'} != {4: 'mask_lo'}.
  • Whole PR: the same file 5 tests OK; test_wrexec_b32.py 5 OK, test_saveexec_variants.py 4 OK, test_or_saveexec.py 4 OK, test_wave64_vcc_half_write.py 7 OK, tests/test_lane_masks.py OK.
  • Whole python -m unittest discover -s tests/semantic with the PR: 7327 tests ran, 1 expected failure. The only failures were four sub-cases of test_mutations.py ("mutation anchor must occur exactly once"), and those failed only because my patched copy of tools/rdna2spirv.py had CRLF line endings; with the PR's exact files test_mutations.py passes (2 tests OK), as it does on main. regen_fixtures.py --check clean.
  • Whole run_gpu_tests.py, per test against f847748c, native and with LEONIDA_W64_EMULATE=1: no status difference in any of the four runs.
PR main
Radeon iGPU, native (subgroup 32..64) 184/199 passed, 15 skipped 184/199, 15 skipped
Radeon iGPU, emulated 184/199, 15 skipped 184/199, 15 skipped
RTX 3070, native (subgroup 32..32) 152/199, 46 skipped, 1 failed 152/199, 46 skipped, 1 failed
RTX 3070, emulated 183/199, 15 skipped, 1 failed 183/199, 15 skipped, 1 failed

The one failure is ps_sdwa_f16_const on the RTX 3070, on main as well (#3220).

  • The GPU suite shows no regression but does not exercise the change: the only GPU fixture that contains a _saveexec_b32 or _wrexec_b32 instruction is the wave32 cs_w32_mask_imm. The new wave64 behaviour (EXEC_HI kept, SCC from the low half) is checked by the CPU interpreter only; no hardware run confirms it here.

Not checked: a wave64 GPU fixture for these instructions on the Radeon (none exists). GitHub reports the branch as mergeable.

@byPreaZy

Copy link
Copy Markdown

Tested d714ee8 on Windows 11, AMD Radeon RX 9060 XT (RDNA4, driver 32.0.32015.7029, native wave64: subgroup 32..64, native64 confirmed via tools/vk_subgroup_info.py), runtime built from this head (MSVC, RelWithDebInfo):

  • tests/semantic: test_wave64_saveexec_b32 5/5, test_wrexec_b32 5/5, test_saveexec_variants 4/4, test_or_saveexec 4/4, test_mask_src_sgpr_const 7/7, test_wave64_vcc_half_write 7/7 (CPU 64-lane interpreter + spirv-val).
  • scripts/run_gpu_tests.py (LLVM_MC: WSL Fedora llvm-mc 22.1.8, Vulkan SDK 1.4.363.0): 204 shaders translated, 204 pass spirv-val; 185/199 passed, 14 skipped (d3d12_* milestone tests, run by ctest), 0 failed.
  • All wave64 fixtures passed natively (no --wave64-emulate): every cs_w64x_*, cs_wqm_w64/cs_wqm_w64_half, cs_wave64_ballot, cs_wavemask (64-wide confirmed), ms_w64x_ballot, ps_w64x_readlane, ps_wqm.

First RDNA4 result for this PR (earlier checks: RDNA3.5 RADV, gfx1036 RDNA2 iGPU, RTX 5070/5080).

Corpus note (own work folder, counts only): wave64 is 23,841/26,503 shaders; only 11 contain a _b32 saveexec/wrexec op, and this head vs its parent emit identical SPIR-V on all 11 (the ops sit in regions the translator does not emit), so the fix reads as latent correctness rather than a corpus-visible change. AI-assisted (Devin).

@evilclanker9000

Copy link
Copy Markdown
Contributor

Correction to my earlier comment (Tested d714ee8): on this machine vk_texture_test, vk_sampler_test and vk_bindless_test ignore LEONIDA_VK_DEVICE and pick the RTX 5080. So in that "Radeon" run_gpu_tests.py run, the texture, sampler and bindless cases actually ran on the 5080. Rerun on the same head with the Radeon forced by VK_LOADER_DRIVERS_SELECT=*amd* (device line AMD Radeon(TM) Graphics): full run_gpu_tests.py 184/199 passed, 15 skipped, 0 failed, so the result stands.

AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit 7e6338d into ItsNotRexed:main Nov 23, 2026
2 of 4 checks passed
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.

7 participants