[PR #522] SHADER-LDS-MSKOR-ATOMIC: preserve masked-OR atomicity under contention #570

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/522
Author: @csmith105
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: codex/lds-mskor-atomic


📝 Commits (1)

  • a509b37 Make LDS masked-OR updates atomic under contention

📊 Changes

3 files changed (+82 additions, -11 deletions)

View changed files

📝 docs/design.md (+1 -1)
📝 tests/semantic/test_lds_mskor.py (+61 -3)
📝 tools/rdna2spirv.py (+20 -7)

📄 Description

Claimed as SHADER-LDS-MSKOR-ATOMIC.

Depends on: #413 (documentation-row overlap only; no code dependency). Whichever merges second should retain that PR's fixture attribution and this corrected atomicity contract. Draft #173 adds a separate single-active-lane fixture and is not a dependency.

What and why

The operation is specified in the AMD RDNA2 ISA guide, section 12.13. Two lanes updating the same LDS word with ds_mskor[_rtn]_b32 can currently produce a value no atomic execution permits. From zero, lane 0 clears bit 0 and sets bit 1, while lane 1 clears bit 1 and sets bit 0. A complete masked-OR operation must leave 1 or 2. The translator's separate atomic AND and OR leave 3; both lanes return zero.

Replace the split operations with a Workgroup-scope atomic load/compare-exchange loop. A failed exchange supplies the next old word, and the loop recomputes the entire update. The returning form exposes the old word of its successful exchange. Existing EXEC and LDS-bound guards remain around the operation; address/mask/data are captured before a potentially aliasing destination is written.

The regression checks both valid serial orders, both instruction forms and offsets 0/12. Additional coverage checks destination aliasing and inactive lanes. Update the existing contract row with measured translator results and the limitation that host atomic ordering does not promise the lane order measured on native RDNA2.

Tested

Native RTX 3080, one hand-written 32-thread wave with two active update lanes; fields below are [old0, final0, old1, final1]:

Translation Output Valid atomic result
Main / split AND+OR [0,3,0,3] No
CAS loop [0,1,2,1] Yes

Both modules translated, assembled and passed spirv-val for Vulkan 1.2. Both native dispatches completed with GPU-assisted validation enabled and zero validation errors; only the old translation violated the result oracle. Used SPIRV-Tools 2026.4, Khronos validation layers 1.4.357.0, LEONIDA_VK_VALIDATION=1, VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 and subgroup size 32.

  • New contention regression fails on main in all four form/offset cases; all seven focused tests pass after the fix.
  • Fifteen shared-memory bounds tests pass.
  • Six generated modules pass SPIR-V validation: both forms with unbounded, bounded in-range and bounded out-of-range access. Independent review executed all six through the CPU interpreter and confirmed results.
  • Full semantic suite: 465 files, 6,108 tests, zero failed files (397 seconds, eight jobs).
  • Compile, CLI-help, documentation-row, changed-file data-policy and whitespace checks pass.

No retail/game data was used. These measurements establish synthetic shader translation behavior, not a retail-game rendering result.

GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 610.88, Windows 11 build 26300.

AI-assisted: yes (Codex); independently reviewed by a second agent.

Checklist

  • Based on current main; code and tests merge cleanly. Documentation overlap with #413 noted above.
  • One topic.
  • No game data, keys or decryption.
  • Existing translator contract row updated with confirmation and limits.

🔄 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/522 **Author:** [@csmith105](https://github.com/csmith105) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `codex/lds-mskor-atomic` --- ### 📝 Commits (1) - [`a509b37`](https://github.com/ubiquitarianism/leonida/commit/a509b37575562b91d0315c60204c2a7d45bb19ef) Make LDS masked-OR updates atomic under contention ### 📊 Changes **3 files changed** (+82 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) 📝 `tests/semantic/test_lds_mskor.py` (+61 -3) 📝 `tools/rdna2spirv.py` (+20 -7) </details> ### 📄 Description Claimed as [SHADER-LDS-MSKOR-ATOMIC](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7124151261). Depends on: #413 (documentation-row overlap only; no code dependency). Whichever merges second should retain that PR's fixture attribution and this corrected atomicity contract. Draft #173 adds a separate single-active-lane fixture and is not a dependency. ### What and why The operation is specified in the [AMD RDNA2 ISA guide, section 12.13](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content). Two lanes updating the same LDS word with `ds_mskor[_rtn]_b32` can currently produce a value no atomic execution permits. From zero, lane 0 clears bit 0 and sets bit 1, while lane 1 clears bit 1 and sets bit 0. A complete masked-OR operation must leave 1 or 2. The translator's separate atomic AND and OR leave 3; both lanes return zero. Replace the split operations with a Workgroup-scope atomic load/compare-exchange loop. A failed exchange supplies the next old word, and the loop recomputes the entire update. The returning form exposes the old word of its successful exchange. Existing EXEC and LDS-bound guards remain around the operation; address/mask/data are captured before a potentially aliasing destination is written. The regression checks both valid serial orders, both instruction forms and offsets 0/12. Additional coverage checks destination aliasing and inactive lanes. Update the existing contract row with measured translator results and the limitation that host atomic ordering does not promise the lane order measured on native RDNA2. ### Tested Native RTX 3080, one hand-written 32-thread wave with two active update lanes; fields below are `[old0, final0, old1, final1]`: | Translation | Output | Valid atomic result | |---|---|---| | Main / split AND+OR | `[0,3,0,3]` | No | | CAS loop | `[0,1,2,1]` | Yes | Both modules translated, assembled and passed `spirv-val` for Vulkan 1.2. Both native dispatches completed with GPU-assisted validation enabled and zero validation errors; only the old translation violated the result oracle. Used SPIRV-Tools 2026.4, Khronos validation layers 1.4.357.0, `LEONIDA_VK_VALIDATION=1`, `VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1` and subgroup size 32. - New contention regression fails on main in all four form/offset cases; all seven focused tests pass after the fix. - Fifteen shared-memory bounds tests pass. - Six generated modules pass SPIR-V validation: both forms with unbounded, bounded in-range and bounded out-of-range access. Independent review executed all six through the CPU interpreter and confirmed results. - Full semantic suite: 465 files, 6,108 tests, zero failed files (397 seconds, eight jobs). - Compile, CLI-help, documentation-row, changed-file data-policy and whitespace checks pass. No retail/game data was used. These measurements establish synthetic shader translation behavior, not a retail-game rendering result. GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 610.88, Windows 11 build 26300. AI-assisted: yes (Codex); independently reviewed by a second agent. ### Checklist - [x] Based on current `main`; code and tests merge cleanly. Documentation overlap with #413 noted above. - [x] One topic. - [x] No game data, keys or decryption. - [x] Existing translator contract row updated with confirmation and limits. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#570
No description provided.