rdna2spirv: wave64 emulation resets shared words with OpAtomicStore (SHADER-W64-SINK-RACE-CARRY) #1110

Manually merged
github merged 1 commit from gh-pr/1110/head into gh-pr/1110/base 2026-11-26 09:38:41 +00:00
Owner

@⁠klikso on GitHub · 2026-11-24 18:42 UTC · original
klikso:carry/shader-w64-sink-race → main · +83 −16 · 3 files · 1 commits · merged 2026-11-25 02:38 UTC

Claimed in the coordination issue as: SHADER-W64-SINK-RACE-CARRY

What and why

This carries #382 by @⁠natterman12 onto current main: one commit, 5cb32c2b3, cherry-picked with its author kept and no change of mine. #382 was closed by its author on 24 November along with his other open pull requests, after three independent GPU verifications (RTX 3080 Ti Laptop, RTX 4080, Radeon RX 6900 XT on RADV). main still has the plain stores, and no open pull request carries the fix.

The wave64 emulation resets words of %x_buf every round. The lane that owns a word stores to it and every other lane aims the same store at one sink word, so several invocations write one Workgroup word at once. The word is never read, but GPU-assisted validation reports the race in every emulated shader, which hides any real one. Those 16 stores become OpAtomicStore (Workgroup scope, relaxed), the same operands as the OpAtomicOr already used on the buffer. The values written do not change.

@⁠natterman12: this is your work. If you reopen #382 or want this branch, say so and I will close this.

Tested

Windows 11 26200.9974, Python 3.13.14, llvm-mc 23.1.6 (conda-forge, AMDGPU target), SPIRV-Tools v2026.4. Runtime test programs built from main 3aa975421 with MSVC 19.44; this change does not touch runtime/.

main with this commit
tests/semantic/test_wave64_emulate_opt.py with the new SharedWordStoresTests 33 run, 2 fail (the plain OpStore lines) 33 pass
tests/semantic/test_loop_ballot_barrier.py not rerun 15 pass
scripts/run_semantic_tests.py tests/semantic not rerun 470 files, 6170 tests, 0 files failed
run_gpu_tests.py, native 261/261 translated and valid; 203/252 passed, 49 skipped, 0 failed the same
run_gpu_tests.py, LEONIDA_W64_EMULATE=1 235/252 passed, 17 skipped, 0 failed the same

The first row's main column is the new test file run against main's translator. I do not have VK_LAYER_KHRONOS_validation installed, so the GPU-assisted validation count (44 failed fixtures down to 12 on the author's RTX 3080 Ti) is the original measurement, not mine; what I measured is that the emulated run is unchanged on a 32-wide-subgroup device.

  • python -I scripts/check_no_game_data.py on the three changed files: no hits. git diff --check: clean.

GPUs tested: NVIDIA GeForce RTX 3060 Ti (Ampere), driver 621.14, Vulkan 1.4.357, Windows 11 26200

AI-assisted: yes (Claude Code; run and measured on the machine above)

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 (no new rule; the stores write the same values).

🤖 Generated with Claude Code

**@⁠klikso** on GitHub · 2026-11-24 18:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1110) `klikso:carry/shader-w64-sink-race` → `main` · +83 −16 · 3 files · 1 commits · merged 2026-11-25 02:38 UTC Claimed in the coordination issue as: SHADER-W64-SINK-RACE-CARRY ### What and why This carries #382 by @⁠natterman12 onto current `main`: one commit, `5cb32c2b3`, cherry-picked with its author kept and no change of mine. #382 was closed by its author on 24 November along with his other open pull requests, after three independent GPU verifications (RTX 3080 Ti Laptop, RTX 4080, Radeon RX 6900 XT on RADV). `main` still has the plain stores, and no open pull request carries the fix. The wave64 emulation resets words of `%x_buf` every round. The lane that owns a word stores to it and every other lane aims the same store at one sink word, so several invocations write one Workgroup word at once. The word is never read, but GPU-assisted validation reports the race in every emulated shader, which hides any real one. Those 16 stores become `OpAtomicStore` (Workgroup scope, relaxed), the same operands as the `OpAtomicOr` already used on the buffer. The values written do not change. @⁠natterman12: this is your work. If you reopen #382 or want this branch, say so and I will close this. ### Tested Windows 11 26200.9974, Python 3.13.14, `llvm-mc` 23.1.6 (conda-forge, AMDGPU target), SPIRV-Tools v2026.4. Runtime test programs built from `main` `3aa975421` with MSVC 19.44; this change does not touch `runtime/`. | | `main` | with this commit | |---|---|---| | `tests/semantic/test_wave64_emulate_opt.py` with the new `SharedWordStoresTests` | 33 run, 2 fail (the plain `OpStore` lines) | 33 pass | | `tests/semantic/test_loop_ballot_barrier.py` | not rerun | 15 pass | | `scripts/run_semantic_tests.py tests/semantic` | not rerun | 470 files, 6170 tests, 0 files failed | | `run_gpu_tests.py`, native | 261/261 translated and valid; 203/252 passed, 49 skipped, 0 failed | the same | | `run_gpu_tests.py`, `LEONIDA_W64_EMULATE=1` | 235/252 passed, 17 skipped, 0 failed | the same | The first row's `main` column is the new test file run against `main`'s translator. I do not have `VK_LAYER_KHRONOS_validation` installed, so the GPU-assisted validation count (44 failed fixtures down to 12 on the author's RTX 3080 Ti) is the original measurement, not mine; what I measured is that the emulated run is unchanged on a 32-wide-subgroup device. - `python -I scripts/check_no_game_data.py` on the three changed files: no hits. `git diff --check`: clean. GPUs tested: NVIDIA GeForce RTX 3060 Ti (Ampere), driver 621.14, Vulkan 1.4.357, Windows 11 26200 AI-assisted: yes (Claude Code; run and measured on the machine above) ### 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: n/a (no new rule; the stores write the same values). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The emulated scheduler resets %x_buf words every round. The lane that owns
a word stores to it and every other lane aims the same store at one sink
word; the prologue's zeroing clamps its index the same way. Several
invocations therefore store to one Workgroup word at once: a data race,
harmless because the word is never read, but GPU-assisted validation
reports it in every emulated shader and so hides any real race.

Those 16 stores are now OpAtomicStore (Workgroup scope, relaxed), the same
operands as the OpAtomicOr already used on this buffer. The values written
are unchanged.

On an RTX 3080 Ti, run_gpu_tests.py with LEONIDA_W64_EMULATE=1 under
GPU-assisted validation goes from 44 failed fixtures to 12; without it the
result is unchanged (229/248).

Two test-local interpreters learn OpAtomicStore, and a new case checks that
no plain OpStore targets a shared %x_buf word.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:38:40 +00:00
github manually merged commit 19e42d6de7 into gh-pr/1110/base 2026-11-26 09:38:41 +00:00
Author
Owner

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

Reviewed and verified. Eliminates Vulkan validation layer data race errors by using OpAtomicStore (Workgroup scope, relaxed semantics) when zeroing the %x_buf sink word across multiple lanes during wave64 emulation. Verified with ests/semantic/test_wave64_emulate_opt.py and semantic suite. 100% clean-room compliant.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 18:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1110#pullrequestreview-6045328311) · **approved these changes** Reviewed and verified. Eliminates Vulkan validation layer data race errors by using OpAtomicStore (Workgroup scope, relaxed semantics) when zeroing the %x_buf sink word across multiple lanes during wave64 emulation. Verified with ests/semantic/test_wave64_emulate_opt.py and semantic suite. 100% clean-room compliant.
Author
Owner

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

Recommendation: [MERGE]

Reasoning: Carries #382: wave64 emulation resets shared %x_buf words with OpAtomicStore, removing a data race where several lanes store to one sink word. The original was verified on RTX 3080 Ti, RTX 4080 and RX 6900 XT (RADV); it is cherry-picked unchanged with author kept and a regression test added. A correctness fix in a hot translator path. 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: 5/10

**@⁠Deedlyy** on GitHub · 2026-11-24 20:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1110#issuecomment-7143299005) **Recommendation:** [MERGE] **Reasoning:** Carries #382: wave64 emulation resets shared `%x_buf` words with `OpAtomicStore`, removing a data race where several lanes store to one sink word. The original was verified on RTX 3080 Ti, RTX 4080 and RX 6900 XT (RADV); it is cherry-picked unchanged with author kept and a regression test added. A correctness fix in a hot translator path. 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:** 5/10
Author
Owner

@⁠klikso on GitHub · 2026-11-24 21:52 UTC · original

Follow-up measurement: the description says I had no validation layer and quoted the author's GPU-assisted validation count. I have the layer now (VK_LAYER_KHRONOS_validation 1.4.357 from conda-forge), so here is the count on this machine.

run_gpu_tests.py with LEONIDA_W64_EMULATE=1, the layer loaded for every test program through VK_INSTANCE_LAYERS, VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1, on current main 4a50cafc7, and the same with this commit cherry-picked onto it (clean, no conflict). Test programs built from that main with MSVC 19.44.

main 4a50cafc7 main + this commit
GPU tests 236/253 passed, 17 skipped, 0 failed the same
Test program runs that print a validation error 40 of 277 8 of 277
SharedMemoryDataRace-RaceOnStore messages 197, in 33 fixtures 5, in 1 fixture (cs_w32_lds_wide)

The 32 fixtures that become clean are the wave64-emulated ones (cs_w64x_*, cs_wm_*, cs_wqm_w64*, cs_w64_mask_*, cs_w64_exec_computed, cs_wave64_ballot, cs_wavemask, cs_exec64, cs_dpp_w64), six RaceOnStore messages each on main.

The 8 that remain are the same 8 a native run (no emulation) reports on main, so they are not the sink: cs_pk_mul_lo_const (VUID-RuntimeSpirv-PhysicalStorageBuffer64-11819, which #481 addresses), cs_w32_lds_wide (equal-address LDS stores), and RaceOnLoadStoreVsAtomic once each in cs_lds_atomics_ext, cs_lds_b64_cmpst, cs_lds_xchg64_ext, cs_w32_fcmpswap, cs_w32_misc_ext and cs_w32_new_ops.

A control run confirmed the setup reports errors: a compute module given to vk_harness as a vertex shader prints VUID-VkShaderModuleCreateInfo-pCode-08740. In a native run, core and synchronization validation without GPU-AV print nothing for any of the 277 runs.

GPU: NVIDIA GeForce RTX 3060 Ti, driver 621.14, Vulkan 1.4.357, Windows 11 26200 (32-wide subgroups). AI-assisted (Claude Code); measured on that machine.

**@⁠klikso** on GitHub · 2026-11-24 21:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1110#issuecomment-7145504620) Follow-up measurement: the description says I had no validation layer and quoted the author's GPU-assisted validation count. I have the layer now (`VK_LAYER_KHRONOS_validation` 1.4.357 from conda-forge), so here is the count on this machine. `run_gpu_tests.py` with `LEONIDA_W64_EMULATE=1`, the layer loaded for every test program through `VK_INSTANCE_LAYERS`, `VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1`, on current `main` `4a50cafc7`, and the same with this commit cherry-picked onto it (clean, no conflict). Test programs built from that `main` with MSVC 19.44. | | `main` `4a50cafc7` | `main` + this commit | |---|---|---| | GPU tests | 236/253 passed, 17 skipped, 0 failed | the same | | Test program runs that print a validation error | 40 of 277 | 8 of 277 | | `SharedMemoryDataRace-RaceOnStore` messages | 197, in 33 fixtures | 5, in 1 fixture (`cs_w32_lds_wide`) | The 32 fixtures that become clean are the wave64-emulated ones (`cs_w64x_*`, `cs_wm_*`, `cs_wqm_w64*`, `cs_w64_mask_*`, `cs_w64_exec_computed`, `cs_wave64_ballot`, `cs_wavemask`, `cs_exec64`, `cs_dpp_w64`), six `RaceOnStore` messages each on `main`. The 8 that remain are the same 8 a native run (no emulation) reports on `main`, so they are not the sink: `cs_pk_mul_lo_const` (`VUID-RuntimeSpirv-PhysicalStorageBuffer64-11819`, which #481 addresses), `cs_w32_lds_wide` (equal-address LDS stores), and `RaceOnLoadStoreVsAtomic` once each in `cs_lds_atomics_ext`, `cs_lds_b64_cmpst`, `cs_lds_xchg64_ext`, `cs_w32_fcmpswap`, `cs_w32_misc_ext` and `cs_w32_new_ops`. A control run confirmed the setup reports errors: a compute module given to `vk_harness` as a vertex shader prints `VUID-VkShaderModuleCreateInfo-pCode-08740`. In a native run, core and synchronization validation without GPU-AV print nothing for any of the 277 runs. GPU: NVIDIA GeForce RTX 3060 Ti, driver 621.14, Vulkan 1.4.357, Windows 11 26200 (32-wide subgroups). AI-assisted (Claude Code); measured on that machine.
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 02:38 UTC · original

Merged. Thanks for carrying this, and to natterman12 for the original (#382).

  • Claim: SHADER-W64-SINK-RACE-CARRY, valid.
  • The change: the wave64 emulation's reset stores of shared words become OpAtomicStore. They write the same values; the author measured data-race validation messages falling from 197 to 5.
  • Tests: two checks fail on main; all pass with the change.
  • On the user's own shader corpus (counts only): a --wave64-emulate slice of 60 shaders translates and validates the same as on main.
  • Checked again on main 85ece6847 + 19e42d6de: the semantic suite passes (485 files, 6,272 tests, 0 files failed); the 14 docs and writer tests pass; check_no_game_data.py is clean on the 3 changed files.

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

**@⁠aslan2142** on GitHub · 2026-11-25 02:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1110#issuecomment-7150978233) Merged. Thanks for carrying this, and to natterman12 for the original (#382). - **Claim:** `SHADER-W64-SINK-RACE-CARRY`, valid. - **The change:** the wave64 emulation's reset stores of shared words become `OpAtomicStore`. They write the same values; the author measured data-race validation messages falling from 197 to 5. - **Tests:** two checks fail on `main`; all pass with the change. - **On the user's own shader corpus (counts only):** a `--wave64-emulate` slice of 60 shaders translates and validates the same as on `main`. - **Checked again on `main` `85ece6847` + `19e42d6de`:** the semantic suite passes (485 files, 6,272 tests, 0 files failed); the 14 docs and writer tests pass; `check_no_game_data.py` is clean on the 3 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.