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

Merged
ambroseautomation merged 1 commit from upstream-pr/1118 into main 2026-11-24 22:19:27 +00:00
ambroseautomation commented 2026-11-24 18:49:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ambroseautomation on 2026-11-24T18:49:04Z.


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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5478296105 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1118). Originally posted by [ambroseautomation](https://github.com/ambroseautomation) on 2026-11-24T18:49:04Z. --- 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 commented 2026-11-24 18:56:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T18:56:26Z.

Review: APPROVED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6045430987 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1118#pullrequestreview-6045430987). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T18:56:26Z. **Review:** APPROVED --- 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 commented 2026-11-24 19:04:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KernelSmoker on 2026-11-24T19:04:00Z.

Review: COMMENTED


Additional independent RTX 3090 check on exact head 2d4dce41e7. 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6045546488 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1118#pullrequestreview-6045546488). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-24T19:04:00Z. **Review:** COMMENTED --- 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 commented 2026-11-24 19:04:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KernelSmoker on 2026-11-24T19:04:53Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6045560340 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1118#pullrequestreview-6045560340). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-24T19:04:53Z. **Review:** COMMENTED --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by madhyn on 2026-11-24T19:24:57Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7142062775 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1118#issuecomment-7142062775). Originally posted by [madhyn](https://github.com/madhyn) on 2026-11-24T19:24:57Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:16:06Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143277650 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1118#issuecomment-7143277650). Originally posted by [Deedlyy](https://github.com/Deedlyy) on 2026-11-24T20:16:06Z. --- **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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T22:19:24Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7146087399 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1118#issuecomment-7146087399). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T22:19:24Z. --- 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 reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1118
No description provided.