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

Manually merged
github merged 1 commit from gh-pr/1118/head into gh-pr/1118/base 2026-11-26 09:39:12 +00:00
Owner

@⁠ambroseautomation on GitHub · 2026-11-24 18:49 UTC · original
ambroseautomation:carry/old-9829-ds-permute-guard → main · +38 −4 · 2 files · 1 commits · merged 2026-11-24 22:19 UTC

Claimed in the coordination issue as: OLD-9829 (#14)

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)
**@⁠ambroseautomation** on GitHub · 2026-11-24 18:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1118) `ambroseautomation:carry/old-9829-ds-permute-guard` → `main` · +38 −4 · 2 files · 1 commits · merged 2026-11-24 22:19 UTC Claimed in the coordination issue as: OLD-9829 (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:39:10 +00:00
github manually merged commit 2d4dce41e7 into gh-pr/1118/base 2026-11-26 09:39:12 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 18:56 UTC · original · approved these changes

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.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 18:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1118#pullrequestreview-6045430987) · **approved these changes** 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.
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-24 19:04 UTC · original · reviewed

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.

**@⁠KernelSmoker** on GitHub · 2026-11-24 19:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1118#pullrequestreview-6045546488) · **reviewed** 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.
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-24 19:04 UTC · original · reviewed

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.

**@⁠KernelSmoker** on GitHub · 2026-11-24 19:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1118#pullrequestreview-6045560340) · **reviewed** 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.
Author
Owner

@⁠madhyn on GitHub · 2026-11-24 19:24 UTC · original

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

**@⁠madhyn** on GitHub · 2026-11-24 19:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1118#issuecomment-7142062775) 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
Author
Owner

@⁠Deedlyy on GitHub · 2026-11-24 20:16 UTC · original

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

**@⁠Deedlyy** on GitHub · 2026-11-24 20:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1118#issuecomment-7143277650) **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
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 22:19 UTC · original

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

**@⁠QemmHD** on GitHub · 2026-11-24 22:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1118#issuecomment-7146087399) 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).
This discussion has been locked. Commenting is limited to contributors.
No description provided.