[PR #865] tools/rdna2spirv: native SPIR-V 64-bit atomics for global_atomic_*_x2 and buffer_atomic_*_x2 (OLD-9909) #903

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

📋 Pull Request Information

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

Base: main ← Head: feat/rdna2spirv-64bit-atomics


📝 Commits (1)

  • 46fc4d4 tools/rdna2spirv: native SPIR-V 64-bit atomics for global_atomic_x2 and buffer_atomic_x2

📊 Changes

6 files changed (+268 additions, -89 deletions)

View changed files

📝 docs/design.md (+3 -3)
📝 tests/semantic/spirv_mini_interp.py (+30 -13)
📝 tests/semantic/test_buffer_atomics_x2.py (+59 -12)
📝 tests/semantic/test_global_atomics.py (+1 -1)
📝 tests/semantic/test_global_atomics_x2.py (+67 -12)
📝 tools/rdna2spirv.py (+108 -48)

📄 Description

Claimed in the coordination issue as: OLD-9909 / SHADER-64BIT-ATOMICS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7134973876)
Completes and supersedes draft #174 (old-pr/9909).

What and why

Previously, global_atomic_add_x2/sub_x2 and buffer_atomic_add_x2/sub_x2 were rejected as Unsupported, while bitwise buffer atomics (and, or, xor, swap) were lowered as independent 32-bit dwords with known tearing approximations.

This PR provides full native SPIR-V 64-bit atomic support for all 11 operations on both global and buffer memory:

  • global_atomic_*_x2: add, sub, smin, smax, umin, umax, and, or, xor, swap, and cmpswap
  • buffer_atomic_*_x2: add, sub, smin, smax, umin, umax, and, or, xor, swap, and cmpswap

Key details:

  • Lowers 64-bit operations to native SPIR-V 64-bit atomic opcodes (OpAtomicIAdd, OpAtomicISub, OpAtomicUMin, OpAtomicUMax, OpAtomicSMin, OpAtomicSMax, OpAtomicAnd, OpAtomicOr, OpAtomicXor, OpAtomicExchange, OpAtomicCompareExchange) targeting PhysicalStorageBuffer %ulong and %long.
  • Eliminates multi-dword tearing under concurrency on bitwise and swap operations.
  • Emits OpCapability Int64Atomics whenever 64-bit atomics are used, and decorates %rt_ulong / %rt_long with ArrayStride 8.
  • Supports 4-VGPR operand layout for cmpswap_x2: {DATA[63:0], CMP[63:0]} as specified by AMD ISA.
  • Validates 8-byte natural alignment and whole-element bounds checking (fixed_fmt=62).
  • Updates spirv_mini_interp.py with 64-bit PSB atomic read/modify/writeback emulation.
  • Adds comprehensive regression suites to tests/semantic/test_global_atomics_x2.py and tests/semantic/test_buffer_atomics_x2.py (value verification, cmpswap match/mismatch, unaligned address handling, and rejected invalid forms).
  • Contract table row updated in docs/design.md.

Tested

  • Python isolated mode: scripts/check_no_game_data.py: Clean (0 violations).
  • Semantic unit tests:
    • python -I tests/semantic/test_global_atomics_x2.py: 6/6 passed.
    • python -I tests/semantic/test_buffer_atomics_x2.py: 7/7 passed.
    • python -I tests/semantic/test_global_atomics.py: 12/12 passed.
  • SPIR-V Validation: All 11 atomic operations assembled with spirv-as and validated with spirv-val: 0 errors.
  • Line endings compliant (newline="\n").
  • Zero retail game files or proprietary keys.

AI-assisted: yes.

Checklist

  • Based on current main and merges cleanly.
  • 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.

🔄 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/865 **Author:** [@Tortoche](https://github.com/Tortoche) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/rdna2spirv-64bit-atomics` --- ### 📝 Commits (1) - [`46fc4d4`](https://github.com/ubiquitarianism/leonida/commit/46fc4d427094c0d334b5f8f03a82196789da8d62) tools/rdna2spirv: native SPIR-V 64-bit atomics for global_atomic_*_x2 and buffer_atomic_*_x2 ### 📊 Changes **6 files changed** (+268 additions, -89 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+3 -3) 📝 `tests/semantic/spirv_mini_interp.py` (+30 -13) 📝 `tests/semantic/test_buffer_atomics_x2.py` (+59 -12) 📝 `tests/semantic/test_global_atomics.py` (+1 -1) 📝 `tests/semantic/test_global_atomics_x2.py` (+67 -12) 📝 `tools/rdna2spirv.py` (+108 -48) </details> ### 📄 Description Claimed in the coordination issue as: OLD-9909 / SHADER-64BIT-ATOMICS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7134973876) Completes and supersedes draft #174 (old-pr/9909). ### What and why Previously, `global_atomic_add_x2/sub_x2` and `buffer_atomic_add_x2/sub_x2` were rejected as `Unsupported`, while bitwise buffer atomics (`and, or, xor, swap`) were lowered as independent 32-bit dwords with known tearing approximations. This PR provides full native SPIR-V 64-bit atomic support for all 11 operations on both global and buffer memory: - `global_atomic_*_x2`: `add`, `sub`, `smin`, `smax`, `umin`, `umax`, `and`, `or`, `xor`, `swap`, and `cmpswap` - `buffer_atomic_*_x2`: `add`, `sub`, `smin`, `smax`, `umin`, `umax`, `and`, `or`, `xor`, `swap`, and `cmpswap` Key details: - Lowers 64-bit operations to native SPIR-V 64-bit atomic opcodes (`OpAtomicIAdd`, `OpAtomicISub`, `OpAtomicUMin`, `OpAtomicUMax`, `OpAtomicSMin`, `OpAtomicSMax`, `OpAtomicAnd`, `OpAtomicOr`, `OpAtomicXor`, `OpAtomicExchange`, `OpAtomicCompareExchange`) targeting `PhysicalStorageBuffer` `%ulong` and `%long`. - Eliminates multi-dword tearing under concurrency on bitwise and swap operations. - Emits `OpCapability Int64Atomics` whenever 64-bit atomics are used, and decorates `%rt_ulong` / `%rt_long` with `ArrayStride 8`. - Supports 4-VGPR operand layout for `cmpswap_x2`: `{DATA[63:0], CMP[63:0]}` as specified by AMD ISA. - Validates 8-byte natural alignment and whole-element bounds checking (`fixed_fmt=62`). - Updates `spirv_mini_interp.py` with 64-bit PSB atomic read/modify/writeback emulation. - Adds comprehensive regression suites to `tests/semantic/test_global_atomics_x2.py` and `tests/semantic/test_buffer_atomics_x2.py` (value verification, cmpswap match/mismatch, unaligned address handling, and rejected invalid forms). - Contract table row updated in `docs/design.md`. ### Tested - Python isolated mode: `scripts/check_no_game_data.py`: Clean (0 violations). - Semantic unit tests: - `python -I tests/semantic/test_global_atomics_x2.py`: 6/6 passed. - `python -I tests/semantic/test_buffer_atomics_x2.py`: 7/7 passed. - `python -I tests/semantic/test_global_atomics.py`: 12/12 passed. - SPIR-V Validation: All 11 atomic operations assembled with `spirv-as` and validated with `spirv-val`: 0 errors. - Line endings compliant (`newline="\n"`). - Zero retail game files or proprietary keys. AI-assisted: yes. ### Checklist - [x] Based on current main and merges cleanly. - [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. --- <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#903
No description provided.