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

Open
github-bot wants to merge 1 commit from github-bot/gh-1803 into main AGit
Owner

@⁠ShotTechOp on GitHub · 2026-11-25 12:19 UTC · original
ShotTechOp:fix/lane-masks-wave32-slot → main · +87 −17 · 4 files · 1 commits · open

Summary

Claimed in #1608 as LANE-MASKS-WAVE32-SLOT: #1608

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.

**@⁠ShotTechOp** on GitHub · 2026-11-25 12:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1803) `ShotTechOp:fix/lane-masks-wave32-slot` → `main` · +87 −17 · 4 files · 1 commits · open ## Summary Claimed in #1608 as `LANE-MASKS-WAVE32-SLOT`: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:06:06 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 12:20 UTC · original

Tested 87fde5c8d on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 0d80bc5df (translator/bookkeeping PR; binaries from the build at 66d4f5aa3):

  • python3 -I tests/test_lane_masks.py: ok at this head; on main it fails with an AssertionError in the parked-slot-32 case.
  • tests/semantic/test_lane_masks_edge_cases.py (from tests/semantic): OK at this head; on main 1 failure.
  • GPU smoke, --filter cs_w32_mask on MoltenVK 1.4.2: 1/1 PASS (cs_w32_mask_imm 2056 20 2 6152 2050 4112 258 32).
  • Not run: the full mask suite; the PR adds no fixture — the lane-mask parking is translator bookkeeping.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 12:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1803#issuecomment-7162233612) Tested `87fde5c8d` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `0d80bc5df` (translator/bookkeeping PR; binaries from the build at `66d4f5aa3`): - `python3 -I tests/test_lane_masks.py`: **ok** at this head; on `main` it fails with an `AssertionError` in the parked-slot-32 case. - `tests/semantic/test_lane_masks_edge_cases.py` (from `tests/semantic`): **OK** at this head; on `main` **1 failure**. - GPU smoke, `--filter cs_w32_mask` on **MoltenVK 1.4.2**: **1/1 PASS** (`cs_w32_mask_imm` `2056 20 2 6152 2050 4112 258 32`). - Not run: the full mask suite; the PR adds no fixture — the lane-mask parking is translator bookkeeping. AI-assisted; synthetic fixtures only, no game data.
Author
Owner

@⁠EvgHaze on GitHub · 2026-11-25 12:58 UTC · original

Apple check — no change on the GPU words, and one gap worth naming.

Machine:  Apple M3, 10-core (MacBook Air 13", Mac15,13), macOS 27.0 (26A5406e), arm64
Drivers:  MoltenVK 1.4.2 (Homebrew), ICD loaded directly, subgroup 4..32
          KosmicKrisp, Mesa 26.3.1 (Homebrew), through the Vulkan loader, subgroup 32..32
Base:     main `0d80bc5` + this diff (clean `git apply`)

scripts/run_gpu_tests.py --filter lane, identical on both drivers and on main:

Test Result
cs_w32_lane_wrap PASS 25 16 777 777
cs_w32_permlane_fi PASS 1000 0 4 1 1000 0 52 49
cs_w64x_readfirstlane, cs_w64x_readlane, cs_w64x_writelane SKIP (no 64-wide compute subgroup)
ps_w64x_readlane SKIP (cannot require a 64-wide fragment subgroup, 4..32)

2/6 passed, 4 skipped — before and after the diff, same words.

Semantic suite: main is 489 files, 6288 tests, 0 failed; with this diff 489 files, 6289 tests, 0 failed — the one extra test being this PR's.

The gap: cs_w32_lane32_overwrite and cs_w32_lane32_restore are built inside tests/semantic/test_lane_masks_edge_cases.py and never reach the GPU registry, so the wave32 slot wrap has no hardware fixture. A 32-wide host is exactly where those two programs run natively instead of being split, so if a GPU fixture ever gets added here, an Apple run is the one that would exercise it without emulation.

AI-assisted. No game data: hand-written programs, and the numbers above are test output.

**@⁠EvgHaze** on GitHub · 2026-11-25 12:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1803#issuecomment-7163121151) Apple check — no change on the GPU words, and one gap worth naming. ```text Machine: Apple M3, 10-core (MacBook Air 13", Mac15,13), macOS 27.0 (26A5406e), arm64 Drivers: MoltenVK 1.4.2 (Homebrew), ICD loaded directly, subgroup 4..32 KosmicKrisp, Mesa 26.3.1 (Homebrew), through the Vulkan loader, subgroup 32..32 Base: main `0d80bc5` + this diff (clean `git apply`) ``` `scripts/run_gpu_tests.py --filter lane`, identical on both drivers and on main: | Test | Result | |---|---| | `cs_w32_lane_wrap` | PASS `25 16 777 777` | | `cs_w32_permlane_fi` | PASS `1000 0 4 1 1000 0 52 49` | | `cs_w64x_readfirstlane`, `cs_w64x_readlane`, `cs_w64x_writelane` | SKIP (no 64-wide compute subgroup) | | `ps_w64x_readlane` | SKIP (cannot require a 64-wide fragment subgroup, 4..32) | 2/6 passed, 4 skipped — before and after the diff, same words. Semantic suite: main is `489 files, 6288 tests, 0 failed`; with this diff `489 files, 6289 tests, 0 failed` — the one extra test being this PR's. **The gap:** `cs_w32_lane32_overwrite` and `cs_w32_lane32_restore` are built inside `tests/semantic/test_lane_masks_edge_cases.py` and never reach the GPU registry, so the wave32 slot wrap has no hardware fixture. A 32-wide host is exactly where those two programs run natively instead of being split, so if a GPU fixture ever gets added here, an Apple run is the one that would exercise it without emulation. AI-assisted. No game data: hand-written programs, and the numbers above are test output.
Author
Owner

@⁠potatoe0100 on GitHub · 2026-11-25 13:50 UTC · original

Tested 87fde5c8d merged onto main 98c2f7777 (clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 (MSVC 19.44) RelWithDebInfo + Ninja, llvm-mc 21.1.8.

  • run_gpu_tests.py: 209/263 passed, 53 skipped, identical to main, so the wave32 slot wrap changes no fixture result on this 32-wide GPU.
  • Full ctest -j 6: 439 of 439 passed.

AI-assisted (Claude)

**@⁠potatoe0100** on GitHub · 2026-11-25 13:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1803#issuecomment-7164371096) Tested `87fde5c8d` merged onto `main` `98c2f7777` (clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 (MSVC 19.44) RelWithDebInfo + Ninja, llvm-mc 21.1.8. - `run_gpu_tests.py`: 209/263 passed, 53 skipped, identical to `main`, so the wave32 slot wrap changes no fixture result on this 32-wide GPU. - Full `ctest -j 6`: 439 of 439 passed. AI-assisted (Claude)
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-25 14:57 UTC · original

Hardware readback for the two parked-mask patterns in this PR, including slots close to the row and wave boundaries. On a desktop RTX 4060, Windows 11 Pro build 26300, NVIDIA 32.0.16.2114, the Vulkan harness reported a fixed 32-lane subgroup.

Translator GPU dispatches Matching lane words
Parent 0d80bc5df7c8 12 98/384
PR 87fde5c8dacc 12 384/384

I kept the same native vk_compute_test executable from the PR for both runs and changed the translator checkout. Each program used a 32×1×1 group. I tested 0↔32, 1↔33 and 31↔63 in both directions, both overwriting a parked mask with 0x55aa and restoring a compare mask for lanes 0–16. I checked all 32 output words each time. On the parent, every overwrite case failed all 32 words. On the PR, both operations matched throughout.

The standalone probe uses your translator, Python SPIR-V assembler and native Vulkan readback. Run python probes/leonida_lane_slots.py <leonida-checkout> <path-to-vk_compute_test> against each checkout. All inputs are hand-written. AI assistance: OpenAI Codex (GPT-6) prepared and ran the probe.

**@⁠tyr0nsur** on GitHub · 2026-11-25 14:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1803#issuecomment-7166084230) Hardware readback for the two parked-mask patterns in this PR, including slots close to the row and wave boundaries. On a desktop RTX 4060, Windows 11 Pro build 26300, NVIDIA 32.0.16.2114, the Vulkan harness reported a fixed 32-lane subgroup. | Translator | GPU dispatches | Matching lane words | | --- | ---: | ---: | | Parent `0d80bc5df7c8` | 12 | 98/384 | | PR `87fde5c8dacc` | 12 | 384/384 | I kept the same native `vk_compute_test` executable from the PR for both runs and changed the translator checkout. Each program used a 32×1×1 group. I tested 0↔32, 1↔33 and 31↔63 in both directions, both overwriting a parked mask with `0x55aa` and restoring a compare mask for lanes 0–16. I checked all 32 output words each time. On the parent, every overwrite case failed all 32 words. On the PR, both operations matched throughout. The [standalone probe](https://github.com/tyr0nsur/PortVI/blob/6578eff095f9cc01a948efd3ce44c15e406922a5/probes/leonida_lane_slots.py) uses your translator, Python SPIR-V assembler and native Vulkan readback. Run `python probes/leonida_lane_slots.py <leonida-checkout> <path-to-vk_compute_test>` against each checkout. All inputs are hand-written. AI assistance: OpenAI Codex (GPT-6) prepared and ran the probe.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1803/head:github-bot/gh-1803'
git switch 'github-bot/gh-1803'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1803'
git switch 'github-bot/gh-1803'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1803'
git switch 'github-bot/gh-1803'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1803'
git switch 'main'
git merge --squash 'github-bot/gh-1803'
git switch 'main'
git merge --ff-only 'github-bot/gh-1803'
git switch 'main'
git merge 'github-bot/gh-1803'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.