[PR #382] [CLOSED] rdna2spirv: wave64 emulation resets shared words with OpAtomicStore (SHADER-W64-SINK-RACE) #434

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/382
Author: @natterman12
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: rdna2spirv/w64-emulate-atomic-sink


📝 Commits (1)

  • 5cb32c2 rdna2spirv: wave64 emulation resets shared words with OpAtomicStore

📊 Changes

3 files changed (+83 additions, -16 deletions)

View changed files

📝 tests/semantic/test_loop_ballot_barrier.py (+3 -0)
📝 tests/semantic/test_wave64_emulate_opt.py (+60 -0)
📝 tools/rdna2spirv.py (+20 -16)

📄 Description

Claimed in the coordination issue as: SHADER-W64-SINK-RACE (#14)

What and why

Under --wave64-emulate the scheduler resets words of %x_buf every round. The lane that owns a word stores to it; every other lane aims the same store at one sink word:

%x_m5  = OpSelect %uint %x_ml %x_m3 <sink>
%x_mp5 = OpAccessChain %_ptr_WG_uint_x %x_buf %x_m5
         OpStore %x_mp5 %c0

x_prologue zeroes the mask and schedule words with an index clamped by UMin, which lands several invocations on the last word in the same way.

So several invocations store to one Workgroup word with no synchronization between them. That is a data race. It is harmless in effect, because the sink is never read and the clamped stores all write 0, but GPU-assisted validation reports it in every emulated shader:

vkCmdDispatch(): A data race was detected on the shared memory variable "[No OpName found, ID 5]" in local
invocation index 1 while performing a store operation. (Likely against local invocation index 63)
This race is between two invocations executing the same instruction.
SPIR-V Instruction: OpStore %273 %44

docs/testing.md documents this run (LEONIDA_VK_VALIDATION=1 VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 python scripts/run_gpu_tests.py) as the way to see what the translated shaders do at run time. With 30+ fixtures failing on this one report, a real race in the emulation would not stand out.

The 16 stores (in Gen.x_round_pre, x_round_head, x_mini_scheduler and x_prologue) become OpAtomicStore with Workgroup scope and relaxed semantics, the operands the OpAtomicOr on the same buffer already uses. The values written, the buffer layout and the control flow are unchanged, and native wave64 translation is untouched (a test pins that). No contract-table row: no instruction's translation rule changes, only how the emulation's own bookkeeping stores are emitted; say so if you want a row anyway.

Tests

  • tests/semantic/test_wave64_emulate_opt.py, new SharedWordStoresTests: for one wave and for two, no plain OpStore may target a %x_buf element whose index comes from an OpSelect (the sink) or the prologue's UMin, and the atomic ones must carry the expected operands. Fails on main with the four OpStore %x_mp5 / %x_mp6 / ... lines.
  • The interpreters local to test_wave64_emulate_opt.py and test_loop_ballot_barrier.py (the latter also used by test_lds_addtid.py) did not know OpAtomicStore; they execute it as a store. tests/semantic/spirv_mini_interp.py already did.

Tested

Windows 11 10.0.26300.9974, NVIDIA GeForce RTX 3080 Ti (subgroup 32..32), driver 621.24, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, Python 3.15.2. main d478a92d. No game files.

run_gpu_tests.py, LEONIDA_W64_EMULATE=1 before after
no validation 229/248 passed, 17 skipped 229/248 passed, 17 skipped
LEONIDA_VK_VALIDATION=1 229/248 229/248
plus VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 187/248, 44 failed 219/248, 12 failed

All 257 fixtures translate and pass spirv-val in each run. The two failures without GPU-assisted validation are cs_imgload_tfe and cs_imgload_d16_tfe (#31).

The 12 left under GPU-assisted validation are not this report: those two, nine LDS fixtures (cs_lds_atomics_ext, cs_lds_b64_cmpst, cs_lds_xchg64_ext, cs_w32_fcmpswap, cs_w32_lds_subdword, cs_w32_lds_u8_d16, cs_w32_lds_wide, cs_w32_misc_ext, cs_w32_new_ops), where the layer reports a race between an OpAtomicLoad and a plain OpLoad of the LDS variable, and cs_pk_mul_lo_const, which I have not looked into. I am posting those as a finding rather than widening this change.

  • python -I scripts/run_semantic_tests.py tests/semantic: 463 files, 6075 tests, 1 file failed: test_image_cube_store_glc (FileNotFoundError in its llvm-mc round trip), which fails the same way on main here.
  • python -I tests/test_text_write_line_endings.py, test_text_encoding.py: OK.
  • Not run: the pytest-based files (tests/test_translate.py and others; no pytest on this machine), any other GPU, and the game's own shader corpus (no game files here), so I have no translated/valid counts for it before and after.

AI-assisted: yes (Claude Code)

Checklist

  • 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. (no new rule; see above)

🤖 Generated with Claude Code


🔄 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/382 **Author:** [@natterman12](https://github.com/natterman12) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `rdna2spirv/w64-emulate-atomic-sink` --- ### 📝 Commits (1) - [`5cb32c2`](https://github.com/ubiquitarianism/leonida/commit/5cb32c2b34f8674aadbd83b888aaa77849498c47) rdna2spirv: wave64 emulation resets shared words with OpAtomicStore ### 📊 Changes **3 files changed** (+83 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `tests/semantic/test_loop_ballot_barrier.py` (+3 -0) 📝 `tests/semantic/test_wave64_emulate_opt.py` (+60 -0) 📝 `tools/rdna2spirv.py` (+20 -16) </details> ### 📄 Description Claimed in the coordination issue as: SHADER-W64-SINK-RACE (#14) ### What and why Under `--wave64-emulate` the scheduler resets words of `%x_buf` every round. The lane that owns a word stores to it; every other lane aims the same store at one sink word: ``` %x_m5 = OpSelect %uint %x_ml %x_m3 <sink> %x_mp5 = OpAccessChain %_ptr_WG_uint_x %x_buf %x_m5 OpStore %x_mp5 %c0 ``` `x_prologue` zeroes the mask and schedule words with an index clamped by `UMin`, which lands several invocations on the last word in the same way. So several invocations store to one Workgroup word with no synchronization between them. That is a data race. It is harmless in effect, because the sink is never read and the clamped stores all write 0, but GPU-assisted validation reports it in every emulated shader: ``` vkCmdDispatch(): A data race was detected on the shared memory variable "[No OpName found, ID 5]" in local invocation index 1 while performing a store operation. (Likely against local invocation index 63) This race is between two invocations executing the same instruction. SPIR-V Instruction: OpStore %273 %44 ``` `docs/testing.md` documents this run (`LEONIDA_VK_VALIDATION=1 VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 python scripts/run_gpu_tests.py`) as the way to see what the translated shaders do at run time. With 30+ fixtures failing on this one report, a real race in the emulation would not stand out. The 16 stores (in `Gen.x_round_pre`, `x_round_head`, `x_mini_scheduler` and `x_prologue`) become `OpAtomicStore` with Workgroup scope and relaxed semantics, the operands the `OpAtomicOr` on the same buffer already uses. The values written, the buffer layout and the control flow are unchanged, and native wave64 translation is untouched (a test pins that). No contract-table row: no instruction's translation rule changes, only how the emulation's own bookkeeping stores are emitted; say so if you want a row anyway. ### Tests - `tests/semantic/test_wave64_emulate_opt.py`, new `SharedWordStoresTests`: for one wave and for two, no plain `OpStore` may target a `%x_buf` element whose index comes from an `OpSelect` (the sink) or the prologue's `UMin`, and the atomic ones must carry the expected operands. Fails on `main` with the four `OpStore %x_mp5 / %x_mp6 / ...` lines. - The interpreters local to `test_wave64_emulate_opt.py` and `test_loop_ballot_barrier.py` (the latter also used by `test_lds_addtid.py`) did not know `OpAtomicStore`; they execute it as a store. `tests/semantic/spirv_mini_interp.py` already did. ### Tested Windows 11 10.0.26300.9974, NVIDIA GeForce RTX 3080 Ti (subgroup 32..32), driver 621.24, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, Python 3.15.2. `main` d478a92d. No game files. | `run_gpu_tests.py`, `LEONIDA_W64_EMULATE=1` | before | after | |---|---|---| | no validation | 229/248 passed, 17 skipped | 229/248 passed, 17 skipped | | `LEONIDA_VK_VALIDATION=1` | 229/248 | 229/248 | | plus `VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1` | 187/248, 44 failed | 219/248, 12 failed | All 257 fixtures translate and pass `spirv-val` in each run. The two failures without GPU-assisted validation are `cs_imgload_tfe` and `cs_imgload_d16_tfe` (#31). The 12 left under GPU-assisted validation are not this report: those two, nine LDS fixtures (`cs_lds_atomics_ext`, `cs_lds_b64_cmpst`, `cs_lds_xchg64_ext`, `cs_w32_fcmpswap`, `cs_w32_lds_subdword`, `cs_w32_lds_u8_d16`, `cs_w32_lds_wide`, `cs_w32_misc_ext`, `cs_w32_new_ops`), where the layer reports a race between an `OpAtomicLoad` and a plain `OpLoad` of the LDS variable, and `cs_pk_mul_lo_const`, which I have not looked into. I am posting those as a finding rather than widening this change. - `python -I scripts/run_semantic_tests.py tests/semantic`: 463 files, 6075 tests, 1 file failed: `test_image_cube_store_glc` (`FileNotFoundError` in its llvm-mc round trip), which fails the same way on `main` here. - `python -I tests/test_text_write_line_endings.py`, `test_text_encoding.py`: OK. - Not run: the pytest-based files (`tests/test_translate.py` and others; no pytest on this machine), any other GPU, and the game's own shader corpus (no game files here), so I have no translated/valid counts for it before and after. AI-assisted: yes (Claude Code) ### Checklist - [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. (no new rule; see above) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:17:52 +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#434
No description provided.