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

Closed
Tortoche wants to merge 1 commit from upstream-pr/865 into main
Tortoche commented 2026-11-24 14:48:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tortoche on 2026-11-24T14:48:38Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474443982 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/865). Originally posted by [Tortoche](https://github.com/Tortoche) on 2026-11-24T14:48:38Z. --- 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.
abnalstlll-byte commented 2026-11-24 14:52:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T14:52:56Z.

Review: APPROVED


Audited and verified. Emits true 64-bit SPIR-V atomics (OpCapability Int64Atomics) for global_atomic_x2 and uffer_atomic_x2 over PhysicalStorageBuffer instead of split 32-bit operations, correctly packing operands via pack_u64 and unpacking 64-bit atomic return values for glc destinations. Contract docs updated in docs/design.md. Approved.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041540374 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/865#pullrequestreview-6041540374). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:52:56Z. **Review:** APPROVED --- Audited and verified. Emits true 64-bit SPIR-V atomics (OpCapability Int64Atomics) for global_atomic_*_x2 and uffer_atomic_*_x2 over PhysicalStorageBuffer instead of split 32-bit operations, correctly packing operands via pack_u64 and unpacking 64-bit atomic return values for glc destinations. Contract docs updated in docs/design.md. Approved.
abnalstlll-byte commented 2026-11-24 14:53:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T14:53:58Z.

Review: APPROVED


Clean-Room Audit & Shader Architecture Review — PR #865 (OLD-9909)

True 64-bit atomic lowering for global and buffer addresses.

Technical Verification

  1. 64-bit Atomics:
    • Lowers global_atomic_*_x2 and buffer_atomic_*_x2 to native SPIR-V OpAtomic* with Int64Atomics capability, avoiding 32-bit split desynchronization.
    • Clean-room verified against RDNA2 specification.

Verdict: APPROVED

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041559497 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/865#pullrequestreview-6041559497). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:53:58Z. **Review:** APPROVED --- ### Clean-Room Audit & Shader Architecture Review — PR #865 (`OLD-9909`) True 64-bit atomic lowering for global and buffer addresses. #### Technical Verification 1. **64-bit Atomics**: - Lowers `global_atomic_*_x2` and `buffer_atomic_*_x2` to native SPIR-V `OpAtomic*` with `Int64Atomics` capability, avoiding 32-bit split desynchronization. - Clean-room verified against RDNA2 specification. **Verdict: APPROVED**
MoonEyes commented 2026-11-27 23:20:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:20:22Z.


Hi @Tortoche, thanks for this pull request. It currently conflicts with main (conflicting file(s): docs/design.md, tools/rdna2spirv.py), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230063495 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/865#issuecomment-7230063495). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:20:22Z. --- Hi @Tortoche, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `docs/design.md`, `tools/rdna2spirv.py`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 11:44:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:44:44Z.

Review: CHANGES_REQUESTED


This PR cannot merge in its current state:

  • Merge conflicts with main in docs/design.md and tools/rdna2spirv.py.
  • Failing CI (windows, linux-gpu-tools, stdlib-tests-linux, macos, macos-python, check).
  • Competing variant with #251: #865 emits OpCapability Int64Atomics unconditionally for all 11 *_atomic_*_x2 ops, whereas #251 gates 64-bit atomics behind --int64-atomics for devices lacking shaderBufferInt64Atomics. This design choice needs to be settled before landing so devices without Int64Atomics are not broken.

Please rebase onto current main, clarify/resolve the capability-gating approach with #251, and get a green CI run.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130567922 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/865#pullrequestreview-6130567922). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:44:44Z. **Review:** CHANGES_REQUESTED --- This PR cannot merge in its current state: - **Merge conflicts** with `main` in `docs/design.md` and `tools/rdna2spirv.py`. - **Failing CI** (`windows`, `linux-gpu-tools`, `stdlib-tests-linux`, `macos`, `macos-python`, `check`). - **Competing variant with `#251`**: `#865` emits `OpCapability Int64Atomics` unconditionally for all 11 `*_atomic_*_x2` ops, whereas `#251` gates 64-bit atomics behind `--int64-atomics` for devices lacking `shaderBufferInt64Atomics`. This design choice needs to be settled before landing so devices without `Int64Atomics` are not broken. Please rebase onto current `main`, clarify/resolve the capability-gating approach with `#251`, and get a green CI run. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 11:49:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:49:10Z.


Closing this PR in favor of #251 (SHADER-868) for 64-bit atomic lowering on global_atomic_*_x2 / buffer_atomic_*_x2.

Side-by-side comparison:

  • Portability & Vulkan contract: #865 unconditionally emits OpCapability Int64Atomics for all 11 global_atomic_*_x2 and buffer_atomic_*_x2 operations — even bitwise and/or/xor ops that do not tear under 2x32-bit — which breaks Vulkan devices without shaderBufferInt64Atomics (e.g., MoltenVK / older GPUs / llvmpipe). In addition, #865 does not record "Int64Atomics": "shaderBufferInt64Atomics" in shader_meta(), does not enable shaderBufferInt64Atomics in the Vulkan device (runtime/shims/d3d12_vulkan_device.cpp), and adds no multi-thread GPU tearing fixture.
  • #251: follows the opt-in --int64-atomics design requested during maintainer review, preserving default 2x32-bit portability while wiring --int64-atomics end-to-end across tools/rdna2spirv.py (including shader_meta()), make_game.py, runtime/shims/d3d12_vulkan_device.cpp (shaderBufferInt64Atomics feature enable + unit test), scripts/run_gpu_tests.py, and a 64-thread contention GPU tearing fixture (cs_atomic_swap_x2_int64.asm) independently verified on RDNA2 and RDNA3 hardware (0 torn swaps).

Thanks @Tortoche for the effort on OLD-9909.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7310189526 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/865#issuecomment-7310189526). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:49:10Z. --- Closing this PR in favor of **#251** (`SHADER-868`) for 64-bit atomic lowering on `global_atomic_*_x2` / `buffer_atomic_*_x2`. **Side-by-side comparison:** - **Portability & Vulkan contract:** `#865` unconditionally emits `OpCapability Int64Atomics` for all 11 `global_atomic_*_x2` and `buffer_atomic_*_x2` operations — even bitwise `and`/`or`/`xor` ops that do not tear under 2x32-bit — which breaks Vulkan devices without `shaderBufferInt64Atomics` (e.g., MoltenVK / older GPUs / llvmpipe). In addition, `#865` does not record `"Int64Atomics": "shaderBufferInt64Atomics"` in `shader_meta()`, does not enable `shaderBufferInt64Atomics` in the Vulkan device (`runtime/shims/d3d12_vulkan_device.cpp`), and adds no multi-thread GPU tearing fixture. - **#251**: follows the opt-in `--int64-atomics` design requested during maintainer review, preserving default 2x32-bit portability while wiring `--int64-atomics` end-to-end across `tools/rdna2spirv.py` (including `shader_meta()`), `make_game.py`, `runtime/shims/d3d12_vulkan_device.cpp` (`shaderBufferInt64Atomics` feature enable + unit test), `scripts/run_gpu_tests.py`, and a 64-thread contention GPU tearing fixture (`cs_atomic_swap_x2_int64.asm`) independently verified on RDNA2 and RDNA3 hardware (0 torn swaps). Thanks `@Tortoche` for the effort on `OLD-9909`. *(AI-assisted review.)*

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!865
No description provided.