Shaders: translate 64-bit image atomics #173

Closed
AlgoArtist06 wants to merge 1 commit from upstream-pr/173 into main
AlgoArtist06 commented 2026-11-24 01:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AlgoArtist06 on 2026-11-24T01:06:01Z.


What is in it

64-bit image atomics no longer stop the translation.
In the world run in #97, "a 64-bit image atomic" stopped five pixel programs, and their draws were dropped.

  • An image atomic with two data dwords per value (dmask 0x3, cmpswap 0xF) now lowers to atomicBinOp.i64 or atomicCompareExchange.i64.
    The dword pairs become i64 values, and with glc the returned value is split back into the pair.
    sub is the add of the i64 negation, as for 32-bit.
  • The shader then declares 64-bit integer ops, 64-bit atomics on typed resources and 64-bit atomics on heap resources (ShaderFlags bits 20, 27 and 32; SFI0 0x8000, 0x40_0000 and 0x1000_0000).
    Every image handle comes from ResourceDescriptorHeap, so both atomic bits are needed.
  • Any other dmask on an image atomic fails with "an image atomic of some channels".
  • Fix along the way, for 32-bit atomics too: descriptor_data creates the handle when it lowers the descriptor load, and it annotated an atomic's texture as four floats (0x409).
    The atomic reused that cached handle, so its own one-channel 32-bit uint annotation (0x105) never reached the DXIL.
    The load now picks 0x105 when the use is an image atomic.
    This is what DXC emits for both RWTexture2D<uint> and RWTexture2D<uint64_t>.
  • New helper join64, which src64 now uses too.
  • The binding notes in emit/mod.rs name the host requirements.

Refs #97.

Host requirements

The host view at the descriptor's index must be R32G32_UINT, which is the format the title creates for a 64-bit atomic target.
The device must also report AtomicInt64OnTypedResourceSupported and AtomicInt64OnDescriptorHeapResourceSupported.
Without them the host refuses the pipeline, which drops the same draws as before.
I did not add a capability check to victory-gpu.

Tested

The tests ran on macOS, which builds the shader crate only.
No GPU and no game data were involved.

  • cargo test -p victory-shader: 58 passed, 0 failed, including the two new tests:
    • a_64_bit_image_atomic_requires_64_bit_typed_atomics checks the SFI0 bits for image_atomic_umax (32-bit and 64-bit) and the 64-bit image_atomic_cmpswap. The programs are hand-written GFX10 words.
    • an_image_atomic_on_part_of_a_pair_is_refused checks that dmask 0x5 fails with a reason.
  • cargo clippy -p victory-shader --all-targets: no new warnings. constant_color is unused off Windows, as on main.
  • cargo fmt -p victory-shader -- --check: passed.
  • cargo xtask policy: asset policy: 151 files ok.
  • DXIL validation: I wrote the emitted containers for 32-bit umax, 64-bit umax, 64-bit cmpswap and 64-bit sub without glc to files.
    dxv from DXC v1.9.2609 (Linux release) reports "Validation succeeded" for all four.
  • Against DXC: I compiled InterlockedMax and InterlockedCompareExchange on a RWTexture2D<uint64_t> from ResourceDescriptorHeap with dxc -T ps_6_6.
    Our 64-bit output matches it in the shader flags (0x148100000), the SFI0 bits (0x12408000), the operations and their operand order, and the handle annotation ({0x1002, 0x105}).

Not tested: I could not create a pipeline or run the title on a GPU.
The --validate and --pipelines paths, diff_tests and the world itself still need a run on Windows.

Hardware / OS

macOS (Apple silicon), with DXC in an x86-64 Linux container.
No Windows machine and no D3D12 device.

AI-assisted

Yes. Claude Code (Claude Opus 5.5) wrote the change and ran the checks above.
No game data was used.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572240507 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/173). Originally posted by [AlgoArtist06](https://github.com/AlgoArtist06) on 2026-11-24T01:06:01Z. --- ## What is in it 64-bit image atomics no longer stop the translation. In the world run in #97, "a 64-bit image atomic" stopped five pixel programs, and their draws were dropped. - An image atomic with two data dwords per value (dmask `0x3`, cmpswap `0xF`) now lowers to `atomicBinOp.i64` or `atomicCompareExchange.i64`. The dword pairs become i64 values, and with `glc` the returned value is split back into the pair. `sub` is the add of the i64 negation, as for 32-bit. - The shader then declares 64-bit integer ops, 64-bit atomics on typed resources and 64-bit atomics on heap resources (`ShaderFlags` bits 20, 27 and 32; `SFI0` `0x8000`, `0x40_0000` and `0x1000_0000`). Every image handle comes from `ResourceDescriptorHeap`, so both atomic bits are needed. - Any other dmask on an image atomic fails with "an image atomic of some channels". - Fix along the way, for 32-bit atomics too: `descriptor_data` creates the handle when it lowers the descriptor load, and it annotated an atomic's texture as four floats (`0x409`). The atomic reused that cached handle, so its own one-channel 32-bit uint annotation (`0x105`) never reached the DXIL. The load now picks `0x105` when the use is an image atomic. This is what DXC emits for both `RWTexture2D<uint>` and `RWTexture2D<uint64_t>`. - New helper `join64`, which `src64` now uses too. - The binding notes in `emit/mod.rs` name the host requirements. Refs #97. ## Host requirements The host view at the descriptor's index must be `R32G32_UINT`, which is the format the title creates for a 64-bit atomic target. The device must also report `AtomicInt64OnTypedResourceSupported` and `AtomicInt64OnDescriptorHeapResourceSupported`. Without them the host refuses the pipeline, which drops the same draws as before. I did not add a capability check to `victory-gpu`. ## Tested The tests ran on macOS, which builds the shader crate only. No GPU and no game data were involved. - `cargo test -p victory-shader`: 58 passed, 0 failed, including the two new tests: - `a_64_bit_image_atomic_requires_64_bit_typed_atomics` checks the `SFI0` bits for `image_atomic_umax` (32-bit and 64-bit) and the 64-bit `image_atomic_cmpswap`. The programs are hand-written GFX10 words. - `an_image_atomic_on_part_of_a_pair_is_refused` checks that dmask `0x5` fails with a reason. - `cargo clippy -p victory-shader --all-targets`: no new warnings. `constant_color` is unused off Windows, as on `main`. - `cargo fmt -p victory-shader -- --check`: passed. - `cargo xtask policy`: `asset policy: 151 files ok`. - **DXIL validation:** I wrote the emitted containers for 32-bit `umax`, 64-bit `umax`, 64-bit `cmpswap` and 64-bit `sub` without `glc` to files. `dxv` from DXC v1.9.2609 (Linux release) reports "Validation succeeded" for all four. - **Against DXC:** I compiled `InterlockedMax` and `InterlockedCompareExchange` on a `RWTexture2D<uint64_t>` from `ResourceDescriptorHeap` with `dxc -T ps_6_6`. Our 64-bit output matches it in the shader flags (`0x148100000`), the `SFI0` bits (`0x12408000`), the operations and their operand order, and the handle annotation (`{0x1002, 0x105}`). **Not tested:** I could not create a pipeline or run the title on a GPU. The `--validate` and `--pipelines` paths, `diff_tests` and the world itself still need a run on Windows. ## Hardware / OS macOS (Apple silicon), with DXC in an x86-64 Linux container. No Windows machine and no D3D12 device. ## AI-assisted Yes. Claude Code (Claude Opus 5.5) wrote the change and ran the checks above. No game data was used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:51:40 +00:00
DaviTostes commented 2026-11-24 06:54:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:19:35Z.


Tested 6f84e86 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 58 passed, 0 failed (2 test binaries), including the 2 tests this PR adds.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118988726 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/173#issuecomment-7118988726). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:19:35Z. --- Tested `6f84e86` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **58 passed, 0 failed** (2 test binaries), including the 2 tests this PR adds. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used.
AlgoArtist06 commented 2026-11-24 06:54:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AlgoArtist06 on 2026-11-24T01:21:11Z.


Closing as a duplicate. #48 already translates 64-bit texture atomics and was opened first, and #177 fixes the reuse of a float-annotated handle by an image atomic. For whoever reviews #48: the shader flags (0x148100000), SFI0 bits (0x12408000) and handle annotation ({0x1002, 0x105}) that DXC v1.9.2609 emits for InterlockedMax / InterlockedCompareExchange on a RWTexture2D<uint64_t> from ResourceDescriptorHeap are a useful reference.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119014905 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/173#issuecomment-7119014905). Originally posted by [AlgoArtist06](https://github.com/AlgoArtist06) on 2026-11-24T01:21:11Z. --- Closing as a duplicate. #48 already translates 64-bit texture atomics and was opened first, and #177 fixes the reuse of a float-annotated handle by an image atomic. For whoever reviews #48: the shader flags (`0x148100000`), `SFI0` bits (`0x12408000`) and handle annotation (`{0x1002, 0x105}`) that DXC v1.9.2609 emits for `InterlockedMax` / `InterlockedCompareExchange` on a `RWTexture2D<uint64_t>` from `ResourceDescriptorHeap` are a useful reference.
Sunkiller-qc commented 2026-11-24 06:54:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T01:29:37Z.


Heads-up: #48 also translates 64-bit image atomics (SM 6.6, typed and heap capability bits), and the two conflict in lower.rs. The approach here looks fine: dmask 3/0xF for the wide forms, the old value taken from vals[0] under glc. It may still be worth agreeing with #48 on which one carries the atomics. One more note: this also changes the handle annotation of 32-bit image atomics from 0x409 to 0x105, which overlaps with #177 (handles keyed by element type) touching the same float/integer UAV handle issue.

Static review, not built or run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119152947 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/173#issuecomment-7119152947). Originally posted by [Sunkiller-qc](https://github.com/Sunkiller-qc) on 2026-11-24T01:29:37Z. --- Heads-up: #48 also translates 64-bit image atomics (SM 6.6, typed and heap capability bits), and the two conflict in `lower.rs`. The approach here looks fine: `dmask` 3/0xF for the wide forms, the old value taken from `vals[0]` under `glc`. It may still be worth agreeing with #48 on which one carries the atomics. One more note: this also changes the handle annotation of 32-bit image atomics from `0x409` to `0x105`, which overlaps with #177 (handles keyed by element type) touching the same float/integer UAV handle issue. Static review, not built or run.

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!173
No description provided.