[PR #833] [MERGED] OLD-7450: restore old upstream PR 7450 - wave64 emulate: a cross-lane read of a missing lane in a partial wave gives 0 #871

Closed
opened 2026-11-26 20:19:20 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/833
Author: @aslan2142
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: wave64-partial-wave-zero


📝 Commits (4)

  • 5668f16 wave64 emulate: a cross-lane read of a missing lane in a partial wave gives 0
  • 721a3b8 Merge main into wave64-partial-wave-zero
  • 485e38f test_w64x_partial_swizzle: poison the prologue's OpAtomicStore zeroes
  • 0bae6f5 Merge main into wave64-partial-wave-zero

📊 Changes

8 files changed (+272 additions, -12 deletions)

View changed files

📝 docs/design.md (+1 -0)
📝 runtime/test/shaders/check.py (+2 -1)
➕ runtime/test/shaders/cs_w64x_partial_swizzle.asm (+78 -0)
📝 scripts/run_gpu_tests.py (+9 -6)
➕ tests/semantic/fixtures/disasm/cs_w64x_partial_swizzle.s (+59 -0)
➕ tests/semantic/fixtures/w64x_partial_swizzle.asm (+20 -0)
➕ tests/semantic/test_w64x_partial_swizzle.py (+77 -0)
📝 tools/rdna2spirv.py (+26 -5)

📄 Description

Claimed in the coordination issue as: OLD-7450 https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133918227

Restoration of my original pull request, old upstream PR 7450 in ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Ported onto main at d0da7dade; the translator change applied unchanged, and the port adds the subgroup-32 pin in scripts/run_gpu_tests.py (below) and the RX 7900 XTX measurements to the contract row.

Depends on: #793 (line-level, docs/design.md), #364, #366, #373 (line-level, scripts/run_gpu_tests.py)

What and why

  • With --wave64-emulate, a cross-lane read of another lane's exchange slot gives 0 when the source lane doesn't exist in a partial last wave. This covers ds_swizzle_b32, ds_bpermute_b32, ds_permute_b32, v_readlane_b32, v_readfirstlane_b32, DPP and the other reads behind Gen.x_round. A source lane that isn't running reads 0 on the hardware.
  • New helper Gen.x_lane_word: x_wbase + lane < threads, else 0. It is used by the five slot reads in x_round.
  • Why the prologue's zeroed slots weren't enough: RADV (Mesa 26.3.1) turns the store, barrier and load of an exchange behind a branch into masked_swizzle_amd with fetch_inactive. In a 40-thread group, lanes 32-39 of ds_swizzle_b32 offset:swizzle(SWAP,8) then read the missing lanes' registers: garbage that changes between runs.
  • Workgroups whose size is a multiple of 64 emit the same module as before.
  • New GPU fixture cs_w64x_partial_swizzle (40 threads: SWAP 8, BROADCAST 16,15 and ds_bpermute_b32 from lanes 40-47). Its 8 words were measured natively on gfx1036 through tools/hw_oracle.
  • New semantic test tests/semantic/test_w64x_partial_swizzle.py with a hand-written fixture. It covers 40 and 104 threads, with the prologue's zero stores replaced by a poison word in the workgroup interpreter.
  • Part of this change: scripts/run_gpu_tests.py now runs the partial-wave fixtures emulated at subgroup 32, as check.py's partial_wave_test already does.
    • Before, it left the size to the driver, and RADV picks 64 for compute.
    • At 64 the new fixture passes on main even without the fix, while check.py shows it wrong.
    • Without the pin the runner would not catch this bug.
  • New row in the docs/design.md contract table: "Wave64 emulation: cross-lane reads of missing lanes", with how it was confirmed.

Tested

Mesa 26.3.1 RADV on Linux. "Before" is main d0da7dade with only this PR's tests and runner change added.

  • test_w64x_partial_swizzle.py: before 2 fail and 1 error; after 3/3 OK.
  • Whole semantic suite (run_semantic_tests.py): before 465 files and 6,108 tests, after 466 files and 6,111 tests; 0 files fail on either.
  • cs_w64x_partial_swizzle, emulated at subgroup 32, 20 runs of vk_compute_test per device:
    • gfx1036 iGPU: before, words 2 and 3 wrong in 20/20 runs; after, 20/20 right.
    • RX 7900 XTX: before, words 2 and 3 wrong in 19/20 runs; after, 20/20 right.
    • Native wave64 and emulated at subgroup 64 were right before and after.
  • run_gpu_tests.py --filter cs_w64x_partial:
    • before, emulated: 2/3 on each GPU (cs_w64x_partial_swizzle fails);
    • after: 3/3 on each GPU, native and emulated.
  • check.py, emulated: cs_w64x_partial_swizzle fails on both GPUs before and is ok after.
  • Full run_gpu_tests.py, the same on both GPUs, native and LEONIDA_W64_EMULATE=1:
    • main: 231/249 passed, 16 skipped;
    • this branch: 232/250 passed, 16 skipped;
    • the same two failures on both, cs_imgload_tfe and cs_imgload_d16_tfe. They fail on main too and this change doesn't touch them.
  • crosslane_fuzz.py --wave 64 --ext --dpp --no-maskdata --programs 1000 --seed 48315 --modes emulate:
    • gfx1036 iGPU: before 993 match and 7 hyp_only; after 1000/1000.
    • RX 7900 XTX: before 995 match and 5 hyp_only; after 1000/1000.
  • Translator corpus, counts only:
    • --limit 2000 slice, native and --wave64-emulate: 2000 translated and 2000 pass spirv-val, before and after, with identical modules. That slice has no compute shaders.
    • The 40 wave64 compute/mesh shaders whose workgroup is not a multiple of 64, with --wave64-emulate: 40 translated and 40 pass spirv-val, before and after. 25 of the 40 modules change (the ones that read across lanes).
  • Other checks:
    • python -m compileall -q tools tests scripts is clean;
    • git diff --check is clean;
    • check_no_game_data.py passes on every changed file;
    • tests/test_shader_checks.py, tests/test_partial_wave_subgroup.py, tests/test_run_gpu_*.py and tests/test_text_write_line_endings.py pass.

GPUs tested: AMD Radeon RX 7900 XTX (RDNA3, RADV, Mesa 26.3.1, Linux); AMD Radeon Graphics iGPU of the Ryzen 9 7950X3D (gfx1036, RDNA2, RADV, Mesa 26.3.1, Linux)

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.

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


🔄 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/833 **Author:** [@aslan2142](https://github.com/aslan2142) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `wave64-partial-wave-zero` --- ### 📝 Commits (4) - [`5668f16`](https://github.com/ubiquitarianism/leonida/commit/5668f16b490a182452521fca3ccfc29e682eca2b) wave64 emulate: a cross-lane read of a missing lane in a partial wave gives 0 - [`721a3b8`](https://github.com/ubiquitarianism/leonida/commit/721a3b85aedebb52b00b6a34cc269ee72d62b8b6) Merge main into wave64-partial-wave-zero - [`485e38f`](https://github.com/ubiquitarianism/leonida/commit/485e38fb696d4f442f5e026b5dac3ae73c69b8ae) test_w64x_partial_swizzle: poison the prologue's OpAtomicStore zeroes - [`0bae6f5`](https://github.com/ubiquitarianism/leonida/commit/0bae6f545a6d0630d46b8e61298134b69bc2155c) Merge main into wave64-partial-wave-zero ### 📊 Changes **8 files changed** (+272 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -0) 📝 `runtime/test/shaders/check.py` (+2 -1) ➕ `runtime/test/shaders/cs_w64x_partial_swizzle.asm` (+78 -0) 📝 `scripts/run_gpu_tests.py` (+9 -6) ➕ `tests/semantic/fixtures/disasm/cs_w64x_partial_swizzle.s` (+59 -0) ➕ `tests/semantic/fixtures/w64x_partial_swizzle.asm` (+20 -0) ➕ `tests/semantic/test_w64x_partial_swizzle.py` (+77 -0) 📝 `tools/rdna2spirv.py` (+26 -5) </details> ### 📄 Description Claimed in the coordination issue as: OLD-7450 https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133918227 Restoration of my original pull request, old upstream PR 7450 in `ItsNotRexed/Leonida`, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Ported onto main at d0da7dade; the translator change applied unchanged, and the port adds the subgroup-32 pin in `scripts/run_gpu_tests.py` (below) and the RX 7900 XTX measurements to the contract row. Depends on: #793 (line-level, docs/design.md), #364, #366, #373 (line-level, scripts/run_gpu_tests.py) ### What and why - With `--wave64-emulate`, a cross-lane read of another lane's exchange slot gives 0 when the source lane doesn't exist in a partial last wave. This covers `ds_swizzle_b32`, `ds_bpermute_b32`, `ds_permute_b32`, `v_readlane_b32`, `v_readfirstlane_b32`, DPP and the other reads behind `Gen.x_round`. A source lane that isn't running reads 0 on the hardware. - New helper `Gen.x_lane_word`: `x_wbase + lane < threads`, else 0. It is used by the five slot reads in `x_round`. - Why the prologue's zeroed slots weren't enough: RADV (Mesa 26.3.1) turns the store, barrier and load of an exchange behind a branch into `masked_swizzle_amd` with `fetch_inactive`. In a 40-thread group, lanes 32-39 of `ds_swizzle_b32 offset:swizzle(SWAP,8)` then read the missing lanes' registers: garbage that changes between runs. - Workgroups whose size is a multiple of 64 emit the same module as before. - New GPU fixture `cs_w64x_partial_swizzle` (40 threads: SWAP 8, BROADCAST 16,15 and `ds_bpermute_b32` from lanes 40-47). Its 8 words were measured natively on gfx1036 through `tools/hw_oracle`. - New semantic test `tests/semantic/test_w64x_partial_swizzle.py` with a hand-written fixture. It covers 40 and 104 threads, with the prologue's zero stores replaced by a poison word in the workgroup interpreter. - **Part of this change: `scripts/run_gpu_tests.py` now runs the partial-wave fixtures emulated at subgroup 32**, as `check.py`'s `partial_wave_test` already does. - Before, it left the size to the driver, and RADV picks 64 for compute. - At 64 the new fixture passes on main even without the fix, while `check.py` shows it wrong. - Without the pin the runner would not catch this bug. - New row in the `docs/design.md` contract table: "Wave64 emulation: cross-lane reads of missing lanes", with how it was confirmed. ### Tested Mesa 26.3.1 RADV on Linux. "Before" is main d0da7dade with only this PR's tests and runner change added. - **`test_w64x_partial_swizzle.py`:** before 2 fail and 1 error; after 3/3 OK. - **Whole semantic suite** (`run_semantic_tests.py`): before 465 files and 6,108 tests, after 466 files and 6,111 tests; 0 files fail on either. - **`cs_w64x_partial_swizzle`, emulated at subgroup 32,** 20 runs of `vk_compute_test` per device: - gfx1036 iGPU: before, words 2 and 3 wrong in 20/20 runs; after, 20/20 right. - RX 7900 XTX: before, words 2 and 3 wrong in 19/20 runs; after, 20/20 right. - Native wave64 and emulated at subgroup 64 were right before and after. - **`run_gpu_tests.py --filter cs_w64x_partial`:** - before, emulated: 2/3 on each GPU (`cs_w64x_partial_swizzle` fails); - after: 3/3 on each GPU, native and emulated. - **`check.py`, emulated:** `cs_w64x_partial_swizzle` fails on both GPUs before and is `ok` after. - **Full `run_gpu_tests.py`,** the same on both GPUs, native and `LEONIDA_W64_EMULATE=1`: - main: 231/249 passed, 16 skipped; - this branch: 232/250 passed, 16 skipped; - the same two failures on both, `cs_imgload_tfe` and `cs_imgload_d16_tfe`. They fail on main too and this change doesn't touch them. - **`crosslane_fuzz.py --wave 64 --ext --dpp --no-maskdata --programs 1000 --seed 48315 --modes emulate`:** - gfx1036 iGPU: before 993 match and 7 hyp_only; after 1000/1000. - RX 7900 XTX: before 995 match and 5 hyp_only; after 1000/1000. - **Translator corpus, counts only:** - `--limit 2000` slice, native and `--wave64-emulate`: 2000 translated and 2000 pass `spirv-val`, before and after, with identical modules. That slice has no compute shaders. - The 40 wave64 compute/mesh shaders whose workgroup is not a multiple of 64, with `--wave64-emulate`: 40 translated and 40 pass `spirv-val`, before and after. 25 of the 40 modules change (the ones that read across lanes). - **Other checks:** - `python -m compileall -q tools tests scripts` is clean; - `git diff --check` is clean; - `check_no_game_data.py` passes on every changed file; - `tests/test_shader_checks.py`, `tests/test_partial_wave_subgroup.py`, `tests/test_run_gpu_*.py` and `tests/test_text_write_line_endings.py` pass. GPUs tested: AMD Radeon RX 7900 XTX (RDNA3, RADV, Mesa 26.3.1, Linux); AMD Radeon Graphics iGPU of the Ryzen 9 7950X3D (gfx1036, RDNA2, RADV, Mesa 26.3.1, Linux) 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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. AI-assisted (Claude Code, Claude Opus 5.5). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:20 +01:00
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#871
No description provided.