Shaders: 64-bit image atomics as DXIL's 64-bit typed atomics #1466

Closed
paulomatias97-create wants to merge 2 commits from upstream-pr/1467 into main
paulomatias97-create commented 2026-11-24 18:15:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by paulomatias97-create on 2026-11-24T18:15:59Z.


The README lists 64-bit image atomics among what world shaders still need. This adds them.

An image atomic with two data dwords (four for cmpswap) is a 64-bit atomic on an R32G32 view. It used to stop the program with "a 64-bit image atomic". DXIL does these in SM 6.6 on a texture of 64-bit integers. On D3D12 that texture is viewed as R32G32_UINT too (there is no R64 DXGI format), so only the shader changes:

  • the value (and the compare value) is joined from its two dwords, low first;
  • atomicBinOp.i64 / atomicCompareExchange.i64 run on a handle annotated RWTexture2D<U64> (element properties 0x107);
  • with glc, the old value is split back into the data VGPRs;
  • the module declares Int64Ops and 64-bit atomics on typed and on heap resources: shader flags bits 20, 27 and 32, and SFI0 0x8000, 0x400000 and 0x10000000. These are the flags DXC's DxilShaderFlags.cpp sets for a 64-bit atomic on a typed resource from the heap.

Second commit: handle cache key

The handle cache was keyed by the first word of the resource properties only. An access that wanted different element properties on a descriptor already used therefore reused the earlier handle. In the new test, the image atomic came after the size query, so its texture was annotated as RWTexture2D<4xF32>. The key now includes both words. The same bug affected 32-bit image atomics.

Tests

  • New test emit::tests::a_64_bit_image_atomic_is_a_64_bit_atomic: a hand-assembled wave32 compute program running image_atomic_umax (64-bit, no return), image_atomic_cmpswap (64-bit, glc) and image_atomic_swap of the returned value on a 2D UAV. The test checks the SFI0 bits. Without the change it fails with the old error.
  • Validated with dxv (DXC built from source, main branch): "Validation succeeded". dxc -dumpbin shows the three atomics as i64 operations on a RWTexture2D<U64> handle. On Windows the test also runs dxil.dll when present.
  • cargo test -p victory-shader passes. cargo clippy -p victory-shader --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings is clean.

Not verified

  • Nothing was run on a GPU, and I don't have the title. The host must report AtomicInt64OnTypedResourceSupported (D3D12 options 9); I did not add a check for that.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CL4QZxTrzfn3nkthzLyAtV

<!-- greyfinch-sync:Marvisak/VIctory:issue:6588449717 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1467). Originally posted by [paulomatias97-create](https://github.com/paulomatias97-create) on 2026-11-24T18:15:59Z. --- The README lists 64-bit image atomics among what world shaders still need. This adds them. An image atomic with two data dwords (four for `cmpswap`) is a 64-bit atomic on an R32G32 view. It used to stop the program with "a 64-bit image atomic". DXIL does these in SM 6.6 on a texture of 64-bit integers. On D3D12 that texture is viewed as `R32G32_UINT` too (there is no R64 DXGI format), so only the shader changes: - the value (and the compare value) is joined from its two dwords, low first; - `atomicBinOp.i64` / `atomicCompareExchange.i64` run on a handle annotated `RWTexture2D<U64>` (element properties `0x107`); - with `glc`, the old value is split back into the data VGPRs; - the module declares Int64Ops and 64-bit atomics on typed and on heap resources: shader flags bits 20, 27 and 32, and SFI0 `0x8000`, `0x400000` and `0x10000000`. These are the flags DXC's `DxilShaderFlags.cpp` sets for a 64-bit atomic on a typed resource from the heap. ### Second commit: handle cache key The handle cache was keyed by the first word of the resource properties only. An access that wanted different element properties on a descriptor already used therefore reused the earlier handle. In the new test, the image atomic came after the size query, so its texture was annotated as `RWTexture2D<4xF32>`. The key now includes both words. The same bug affected 32-bit image atomics. ## Tests - New test `emit::tests::a_64_bit_image_atomic_is_a_64_bit_atomic`: a hand-assembled wave32 compute program running `image_atomic_umax` (64-bit, no return), `image_atomic_cmpswap` (64-bit, `glc`) and `image_atomic_swap` of the returned value on a 2D UAV. The test checks the SFI0 bits. Without the change it fails with the old error. - **Validated with `dxv`** (DXC built from source, main branch): "Validation succeeded". `dxc -dumpbin` shows the three atomics as `i64` operations on a `RWTexture2D<U64>` handle. On Windows the test also runs `dxil.dll` when present. - `cargo test -p victory-shader` passes. `cargo clippy -p victory-shader --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings` is clean. ## Not verified - Nothing was run on a GPU, and I don't have the title. The host must report `AtomicInt64OnTypedResourceSupported` (D3D12 options 9); I did not add a check for that. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01CL4QZxTrzfn3nkthzLyAtV
catminou4 commented 2026-11-24 19:03:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T18:42:14Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 97 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and were not run here; lowering/structure coverage only.

64-bit image atomics lowered to DXIL 64-bit typed atomics (SM 6.6): wide detection accepts dmask 3 (plain) / 0xF (cmpswap) and rejects everything else; values are joined low-dword-first into i64; cmpswap emits atomicCompareExchange.i64; sub negates in the wide type; per-dword old-value reads preserved with glc; handle keys now carry the full (u32, u32) properties instead of just props.0, fixing a dedup collision. Flags INT64/ATOMIC_INT64_TYPED/ATOMIC_INT64_HEAP set. 97 passed on macOS.

<!-- greyfinch-sync:Marvisak/VIctory:review:6045234128 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1467#pullrequestreview-6045234128). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T18:42:14Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), `cargo test -p victory-shader --locked` → 97 passed, 0 failed. Execution/valu tests are `#[cfg(all(test, windows))]` and were not run here; lowering/structure coverage only. 64-bit image atomics lowered to DXIL 64-bit typed atomics (SM 6.6): `wide` detection accepts dmask 3 (plain) / 0xF (cmpswap) and rejects everything else; values are joined low-dword-first into i64; cmpswap emits `atomicCompareExchange.i64`; `sub` negates in the wide type; per-dword old-value reads preserved with `glc`; handle keys now carry the full `(u32, u32)` properties instead of just `props.0`, fixing a dedup collision. Flags INT64/ATOMIC_INT64_TYPED/ATOMIC_INT64_HEAP set. 97 passed on macOS.
geiyiliyabumo commented 2026-11-24 19:04:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T18:21:23Z.


Verified commit \4d4834d\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, SM 6.6) + WARP:

  • \cargo test -p victory-shader --lib: 121/121 passed (1 ignored), including \emit::tests::a_64_bit_image_atomic_is_a_64_bit_atomic.
  • Including both \props\ words in \HandleKey\ cleanly avoids handle-cache aliasing between 32-bit (\
<!-- greyfinch-sync:Marvisak/VIctory:comment:7140527690 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1467#issuecomment-7140527690). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T18:21:23Z. --- Verified commit \4d4834d\ on **Windows 11 / AMD Radeon RX 9060 XT (RDNA4, SM 6.6)** + **WARP**: - \cargo test -p victory-shader --lib\: **121/121 passed** (1 ignored), including \emit::tests::a_64_bit_image_atomic_is_a_64_bit_atomic\. - Including both \props\ words in \HandleKey\ cleanly avoids handle-cache aliasing between 32-bit (\
0xKaji commented 2026-11-24 20:03:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-24T19:40:55Z.


Verified 4d4834d on NVIDIA — Linux + Wine 11.22 + vkd3d-proton 3.2.0 (GE-Proton11-14) + RTX 3060 8 GB (Ampere, driver 620.73.04), cross-built with cargo xwin (x86_64-pc-windows-msvc, VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains). Complements the RDNA4/WARP check above with an NVIDIA driver and a whole-corpus host-pipeline sweep.

GPU test

  • a_64_bit_image_atomic_is_a_64_bit_atomic --test-threads=1: 1 passed, 0 failed on Ampere + vkd3d-proton 3.2.0.

Full shaders.rpf offline sweep (translate --pipelines --jobs 4)

Compared against ffe310e + #177 on the same machine and driver stack:

  • Exit code 0, no SPIR-V compiler crashes in the NVIDIA driver (26,084 programs translated, 22,406 emitted and handed to the driver) — covers both the 64-bit typed image atomic lowering and the HandleKey change.
  • emit: a 64-bit image atomic failures: 653 → 0.
  • Emitted / host pipelines accepted by vkd3d-proton 3.2.0 + NVIDIA 620.73.04:
    • Vertex + pixel: 12,231 → 12,749 emitted (+518), all 12,749 host pipelines created
    • Compute: 1,441 → 1,443 emitted (+2), 1,123 host pipelines (+2)
    • Mesh: 8,214 → 8,214 (unchanged, all created)
    • Total host pipelines: 21,566 → 22,086 (+520)
  • Host pipeline refusals: 320, all pre-existing Ampere Wave64 refusals (Required WaveSize range [64, 64], but supported range is [32, 32], #817); none from the new 64-bit image atomics.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7142440252 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1467#issuecomment-7142440252). Originally posted by [0xKaji](https://github.com/0xKaji) on 2026-11-24T19:40:55Z. --- Verified `4d4834d` on **NVIDIA** — Linux + Wine `11.22` + `vkd3d-proton 3.2.0` (`GE-Proton11-14`) + RTX 3060 8 GB (Ampere, driver `620.73.04`), cross-built with `cargo xwin` (`x86_64-pc-windows-msvc`, `VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains`). Complements the RDNA4/WARP check above with an NVIDIA driver and a whole-corpus host-pipeline sweep. ### GPU test - `a_64_bit_image_atomic_is_a_64_bit_atomic --test-threads=1`: **1 passed, 0 failed** on Ampere + `vkd3d-proton 3.2.0`. ### Full `shaders.rpf` offline sweep (`translate --pipelines --jobs 4`) Compared against `ffe310e + #177` on the same machine and driver stack: - **Exit code `0`**, no SPIR-V compiler crashes in the NVIDIA driver (26,084 programs translated, 22,406 emitted and handed to the driver) — covers both the 64-bit typed image atomic lowering and the `HandleKey` change. - **`emit: a 64-bit image atomic` failures: `653` → `0`**. - Emitted / host pipelines accepted by `vkd3d-proton 3.2.0` + NVIDIA `620.73.04`: - Vertex + pixel: `12,231` → **`12,749` emitted (`+518`), all `12,749` host pipelines created** - Compute: `1,441` → **`1,443` emitted (`+2`), `1,123` host pipelines (`+2`)** - Mesh: `8,214` → `8,214` (unchanged, all created) - **Total host pipelines: `21,566` → `22,086` (`+520`)** - **Host pipeline refusals:** `320`, all pre-existing Ampere Wave64 refusals (`Required WaveSize range [64, 64], but supported range is [32, 32]`, #817); **none** from the new 64-bit image atomics.
sinan-cmyk commented 2026-11-24 20:03:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T19:50:20Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: +520 programs over main, 0 lost.

Offline. I merged head 4d4834d onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 22,244 with this PR.

Failure on main Gained
emit: a 64-bit image atomic 520

All 520 are the same programs that #1127 gains, and the same ones that #1402 gains through #305 (64-bit image atomics). So #305, #539, #1127 and #1467 cover one set. On this data, review can pick between them on correctness and coverage alone.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142660708 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1467#issuecomment-7142660708). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T19:50:20Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: +520 programs over `main`, 0 lost.** **Offline.** I merged head 4d4834d onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 22,244 with this PR. | Failure on `main` | Gained | |---|---| | emit: a 64-bit image atomic | 520 | All 520 are the same programs that #1127 gains, and the same ones that #1402 gains through #305 (64-bit image atomics). So #305, #539, #1127 and #1467 cover one set. On this data, review can pick between them on correctness and coverage alone. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
paulomatias97-create commented 2026-11-24 22:02:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by paulomatias97-create on 2026-11-24T22:01:23Z.


Superseded by the 64-bit atomics in main; the remaining fix is in the new PR.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145698051 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1467#issuecomment-7145698051). Originally posted by [paulomatias97-create](https://github.com/paulomatias97-create) on 2026-11-24T22:01:23Z. --- Superseded by the 64-bit atomics in main; the remaining fix is in the new PR.
upstream-sync closed this pull request 2026-11-24 23:04:37 +00:00

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
Marvisak/VIctory!1466
No description provided.