[PR #1803] lane_masks, rdna2spirv: wrap parked v_writelane/v_readlane slots mod 32 in wave32 (LANE-MASKS-WAVE32-SLOT) #1817

Open
opened 2026-11-26 21:19:04 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1803
Author: @ShotTechOp
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/lane-masks-wave32-slot


📝 Commits (1)

  • 87fde5c lane_masks, rdna2spirv: wrap parked v_writelane/v_readlane slots mod 32 in wave32 (LANE-MASKS-WAVE32-SLOT)

📊 Changes

4 files changed (+87 additions, -17 deletions)

View changed files

📝 tests/semantic/test_lane_masks_edge_cases.py (+29 -0)
📝 tests/test_lane_masks.py (+37 -0)
📝 tools/lane_masks.py (+18 -14)
📝 tools/rdna2spirv.py (+3 -3)

📄 Description

Summary

Claimed in #1608 as LANE-MASKS-WAVE32-SLOT: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162135689

In wave32 (wave64=False), RDNA2 v_writelane_b32 and v_readlane_b32 mask the lane selector by S1[4:0] (& 31, mod 32) — which tools/rdna2spirv.py already emits at lines 8818 and 8837 (self.cu(63 if self.wave64 else 31)). However, lane_masks.lane_slot() always masked by & 63 and lane_masks.parked() / rdna2spirv.py did not pass wave64:

  • Overwriting lane 32 (32 & 31 == 0) with plain data in wave32 failed to invalidate a mask parked in lane 0, so a subsequent v_readlane_b32 returned the stale parked mask ([0xffffffff, 0xffffffff, 0, 0]) instead of the written scalar ([0x55aa] * 4).
  • Parking a mask in lane 32 in wave32 and reading it back from lane 0 missed the parked slot and broadcast lane 0's bit across all lanes instead of restoring each lane's bit.

Changes

  • tools/lane_masks.py:
    • lane_slot(vgpr, lane, wave64=True): mask lane index by 63 if wave64 else 31, and reject multi-dword VGPRs (n != 1) or abs/neg-modified operands.
    • step() and parked(blocks, masks, wave64=True): thread wave64 into lane_slot() (default True preserves existing callers).
  • tools/rdna2spirv.py:
    • Pass wave64=self.wave64 to lane_masks.parked() (park_masks) and lane_masks.lane_slot() (v_readlane_b32 / v_writelane_b32).
  • tests/test_lane_masks.py & tests/semantic/test_lane_masks_edge_cases.py:
    • Unit tests for wave32 mod-32 aliasing, wave64 lane-0 vs lane-32 separation, and multi-dword/modified operand rejection.
    • End-to-end translated wave32 compute shader tests executed through spirv_mini_interp.run_workgroup.

Testing

Environment: Windows 11 x64, Python 3.12.10, CPU-only (no GPU or game files; based on 0d80bc5).

  • Negative control on unpatched main (0d80bc5):
    • python -I tests/test_lane_masks.py -> AssertionError in test_wave32_parked_lane_wraps_mod_32
    • python -m unittest discover -s tests/semantic -p test_lane_masks_edge_cases.py -> FAIL ([0xffffffff, 0xffffffff, 0, 0] != [0x55aa] * 4)
  • After fix:
    • python -I tests/test_lane_masks.py -> ok
    • python -m unittest discover -s tests/semantic -p "test_*lane_mask*.py" -> all OK
    • python -m compileall -q / scripts/check_no_game_data.py / git diff --check -> all clean

AI-assisted: yes (Antigravity). Synthetic inputs only; no game data.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1803 **Author:** [@ShotTechOp](https://github.com/ShotTechOp) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/lane-masks-wave32-slot` --- ### 📝 Commits (1) - [`87fde5c`](https://github.com/ubiquitarianism/leonida/commit/87fde5c8daccdb29ef6d78d8877bae15cab5eabb) lane_masks, rdna2spirv: wrap parked v_writelane/v_readlane slots mod 32 in wave32 (LANE-MASKS-WAVE32-SLOT) ### 📊 Changes **4 files changed** (+87 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `tests/semantic/test_lane_masks_edge_cases.py` (+29 -0) 📝 `tests/test_lane_masks.py` (+37 -0) 📝 `tools/lane_masks.py` (+18 -14) 📝 `tools/rdna2spirv.py` (+3 -3) </details> ### 📄 Description ## Summary Claimed in #1608 as `LANE-MASKS-WAVE32-SLOT`: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162135689 In wave32 (`wave64=False`), RDNA2 `v_writelane_b32` and `v_readlane_b32` mask the lane selector by `S1[4:0]` (`& 31`, mod 32) — which `tools/rdna2spirv.py` already emits at lines 8818 and 8837 (`self.cu(63 if self.wave64 else 31)`). However, `lane_masks.lane_slot()` always masked by `& 63` and `lane_masks.parked()` / `rdna2spirv.py` did not pass `wave64`: - Overwriting lane `32` (`32 & 31 == 0`) with plain data in wave32 failed to invalidate a mask parked in lane `0`, so a subsequent `v_readlane_b32` returned the stale parked mask (`[0xffffffff, 0xffffffff, 0, 0]`) instead of the written scalar (`[0x55aa] * 4`). - Parking a mask in lane `32` in wave32 and reading it back from lane `0` missed the parked slot and broadcast lane 0's bit across all lanes instead of restoring each lane's bit. ### Changes - `tools/lane_masks.py`: - `lane_slot(vgpr, lane, wave64=True)`: mask lane index by `63 if wave64 else 31`, and reject multi-dword VGPRs (`n != 1`) or `abs`/`neg`-modified operands. - `step()` and `parked(blocks, masks, wave64=True)`: thread `wave64` into `lane_slot()` (default `True` preserves existing callers). - `tools/rdna2spirv.py`: - Pass `wave64=self.wave64` to `lane_masks.parked()` (`park_masks`) and `lane_masks.lane_slot()` (`v_readlane_b32` / `v_writelane_b32`). - `tests/test_lane_masks.py` & `tests/semantic/test_lane_masks_edge_cases.py`: - Unit tests for wave32 mod-32 aliasing, wave64 lane-0 vs lane-32 separation, and multi-dword/modified operand rejection. - End-to-end translated wave32 compute shader tests executed through `spirv_mini_interp.run_workgroup`. ## Testing Environment: Windows 11 x64, Python 3.12.10, CPU-only (no GPU or game files; based on `0d80bc5`). - Negative control on unpatched `main` (`0d80bc5`): - `python -I tests/test_lane_masks.py` -> `AssertionError` in `test_wave32_parked_lane_wraps_mod_32` - `python -m unittest discover -s tests/semantic -p test_lane_masks_edge_cases.py` -> `FAIL` (`[0xffffffff, 0xffffffff, 0, 0]` != `[0x55aa] * 4`) - After fix: - `python -I tests/test_lane_masks.py` -> `ok` - `python -m unittest discover -s tests/semantic -p "test_*lane_mask*.py"` -> all OK - `python -m compileall -q` / `scripts/check_no_game_data.py` / `git diff --check` -> all clean AI-assisted: yes (Antigravity). Synthetic inputs only; no game data. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1817
No description provided.