rdna2spirv: redirect absent subgroup lanes before OpGroupNonUniformShuffle in ds_permute (OLD-9829) #1118

Merged
leonida/mandy
ambroseautomation merged 1 commit from carry/old-9829-ds-permute-guard into main 2026-11-24 22:19:27 +00:00

Pull request successfully merged and closed

ambroseautomation commented 2026-11-24 18:49:04 +00:00

Claimed in the coordination issue as: OLD-9829 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140912852)

What and why

Carries forward old-pr/9829 (draft #97, original commit author Lewandox preserved; indexed in #17), rebased cleanly onto current main.

Fixes undefined behavior in ds_permute (tools/rdna2spirv.py): previously, OpGroupNonUniformShuffle received raw source lane IDs even for absent invocations in partial waves, masking the result only afterward. In SPIR-V/Vulkan, shuffling from an absent invocation is undefined behavior even if the result is masked. This change redirects absent source lanes to the current invocation's own lane via OpSelect gated by OpGroupNonUniformBallotBitExtract before OpGroupNonUniformShuffle, matching ds_lane_read.

Adds test_shuffles_redirect_absent_lanes_via_ballot_select in tests/semantic/test_ds_permute.py covering compute wave32, compute wave64, pixel shaders, and a 7-lane partial-wave execution check.

Tested

  • python -m unittest discover -s tests/semantic -p test_ds_permute.py -v: 7 tests, OK.
  • python -I scripts/run_semantic_tests.py tests/semantic: 470 files, 6,169 tests, 0 files failed.
  • python -m compileall -q make_game.py tools tests: exit 0.
  • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_ds_permute.py: exit 0 (no game data).

GPUs tested: n/a (CPU SPIR-V interpreter semantic suite on Windows 11 Pro 64-bit, Python 3.12.10)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — UB guard on existing ds_permute rule)
Claimed in the coordination issue as: OLD-9829 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140912852) ### What and why Carries forward `old-pr/9829` (draft #97, original commit author `Lewandox` preserved; indexed in #17), rebased cleanly onto current `main`. Fixes undefined behavior in `ds_permute` (`tools/rdna2spirv.py`): previously, `OpGroupNonUniformShuffle` received raw source lane IDs even for absent invocations in partial waves, masking the result only afterward. In SPIR-V/Vulkan, shuffling from an absent invocation is undefined behavior even if the result is masked. This change redirects absent source lanes to the current invocation's own lane via `OpSelect` gated by `OpGroupNonUniformBallotBitExtract` before `OpGroupNonUniformShuffle`, matching `ds_lane_read`. Adds `test_shuffles_redirect_absent_lanes_via_ballot_select` in `tests/semantic/test_ds_permute.py` covering compute wave32, compute wave64, pixel shaders, and a 7-lane partial-wave execution check. ### Tested - `python -m unittest discover -s tests/semantic -p test_ds_permute.py -v`: 7 tests, OK. - `python -I scripts/run_semantic_tests.py tests/semantic`: 470 files, 6,169 tests, 0 files failed. - `python -m compileall -q make_game.py tools tests`: exit 0. - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_ds_permute.py`: exit 0 (no game data). GPUs tested: n/a (CPU SPIR-V interpreter semantic suite on Windows 11 Pro 64-bit, Python 3.12.10) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — UB guard on existing `ds_permute` rule)
abnalstlll-byte approved these changes 2026-11-24 18:56:26 +00:00
abnalstlll-byte left a comment

Reviewed and verified. Resolves SPIR-V undefined behavior in ds_permute lowering (tools/rdna2spirv.py) by redirecting absent source lanes to the current invocation lane using OpSelect gated by OpGroupNonUniformBallotBitExtract before calling OpGroupNonUniformShuffle. Verified with tests/semantic/test_ds_permute.py (7/7 PASS) and full semantic suite. 100% clean-room.

Reviewed and verified. Resolves SPIR-V undefined behavior in `ds_permute` lowering (`tools/rdna2spirv.py`) by redirecting absent source lanes to the current invocation lane using `OpSelect` gated by `OpGroupNonUniformBallotBitExtract` before calling `OpGroupNonUniformShuffle`. Verified with `tests/semantic/test_ds_permute.py` (7/7 PASS) and full semantic suite. 100% clean-room.
KernelSmoker reviewed 2026-11-24 19:04:00 +00:00
KernelSmoker left a comment
No description provided.
Additional independent RTX 3090 check on exact head 2d4dce41e751d55dfc88b20b60ae511e98d473c5. passes 7/7. On Bazzite 45 / NVIDIA 620.73.04 / Vulkan 1.4.357 (subgroup 32), the native fixture passed 1/1 with ; passed 1/1 with . Each generated module passed . This exercises partial-wave32 behavior and the wave64 emulation path on NVIDIA; it is not native wave64 or AMD hardware validation.
KernelSmoker reviewed 2026-11-24 19:04:53 +00:00
KernelSmoker left a comment
No description provided.
Correction to my previous review comment: shell expansion removed the test names and outputs there; disregard its blank result fields. The corrected independent RTX 3090 results are: focused test_ds_permute.py suite 7/7; native cs_w32_partial_permute 1/1 with output 0 29 127 0 1 0 134 113; LEONIDA_W64_EMULATE=1 cs_w64x_permute 1/1 with output 218 442 435 239 0 99 239 232. Both generated SPIR-V modules passed spirv-val. Device: Bazzite 45, NVIDIA RTX 3090, driver 620.73.04, Vulkan 1.4.357, subgroup 32. This exercises partial-wave32 and wave64 emulation on NVIDIA; it does not validate native wave64 or AMD hardware.
madhyn commented 2026-11-24 19:24:57 +00:00

Verified 2d4dce41e on Arch Linux (Python 3.14):

  • PYTHONPATH=tests/semantic python3 -m unittest tests/semantic/test_ds_permute.py: 7 tests passed (1.797 s)

AI-assisted: yes

Verified `2d4dce41e` on Arch Linux (Python 3.14): - `PYTHONPATH=tests/semantic python3 -m unittest tests/semantic/test_ds_permute.py`: **7 tests passed** (1.797 s) AI-assisted: yes
Deedlyy commented 2026-11-24 20:16:06 +00:00

Recommendation: [MERGE]

Reasoning: Carries #97: ds_permute redirects absent lanes before OpGroupNonUniformShuffle, removing SPIR-V undefined behaviour in partial waves. Small translator change with a test. Verified by madhyn (7/7) and KernelSmoker on an RTX 3090 (native fixture passes). CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 4/10

**Recommendation:** [MERGE] **Reasoning:** Carries #97: `ds_permute` redirects absent lanes before `OpGroupNonUniformShuffle`, removing SPIR-V undefined behaviour in partial waves. Small translator change with a test. Verified by madhyn (7/7) and KernelSmoker on an RTX 3090 (native fixture passes). CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 4/10
QemmHD commented 2026-11-24 22:19:24 +00:00

Merging.

Why merged: OLD-9829, carrying forward #97: in the ds_permute lowering, a shuffle from an absent lane is redirected to the lane itself, which removes undefined behaviour from the generated SPIR-V. madhyn and KernelSmoker (RTX 3090) checked it.

Why it's good: test_ds_permute: 7/7.

Tested on Windows 11 / RTX 4070 SUPER: merged alone onto main 4a50cafc7. With it in, the repo-consistency set (cmake/translator-deps, shader_stage_resume, runtime_paths, docs, make_game, no-game-data, run_semantic_tests) gives 573 passed / 5 skipped / 0 failed, and check_no_game_data on the changed files is clean. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls, new subprocesses, new env vars or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

Merging. **Why merged:** OLD-9829, carrying forward #97: in the ds_permute lowering, a shuffle from an absent lane is redirected to the lane itself, which removes undefined behaviour from the generated SPIR-V. madhyn and KernelSmoker (RTX 3090) checked it. **Why it's good:** test_ds_permute: 7/7. Tested on Windows 11 / RTX 4070 SUPER: merged alone onto main 4a50cafc7. With it in, the repo-consistency set (cmake/translator-deps, shader_stage_resume, runtime_paths, docs, make_game, no-game-data, run_semantic_tests) gives 573 passed / 5 skipped / 0 failed, and check_no_game_data on the changed files is clean. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls, new subprocesses, new env vars or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No description provided.