Shaders: 64-bit texture atomics as one i64 atomic #2241

Closed
github-bot wants to merge 1 commit from github-bot/gh-2241 into main AGit
Owner

@⁠FoxxoOwO on GitHub · 2026-11-25 08:35 UTC · original
FoxxoOwO:shader/64-bit-image-atomics → main · +265 −9 · 1 files · 1 commits · closed without merging

The console's MIMG image_atomic instructions with dmask 3 (or 0xF for cmpswap) carry two data dwords: the low and high halves of an i64. Previously they lowered to two separate 32-bit atomics, so a carry from the low dword was lost. Now they lower to one i64 atomic on an R32G32 integer texture UAV (SM 6.6).

Changes:

  • emit/lower.rs: fn image() detects width from dmask, builds an i64 atomic with join64/split64, and emits atomicBinOp.i64 / atomicCompareExchange.i64 (dx.op 78/79). Handle props stay (kind | 0x1000, 0x105) as the 32-bit path used.
  • emit/shader.rs: new module flags ATOMIC_INT64_ON_TYPED_RESOURCE = 1 << 27 and ATOMIC_INT64_ON_HEAP_RESOURCE = 1 << 32; SFI0 feature bits 22 and 28 mapped.
  • emit/host.rs: View::Uint2TextureUav (R32G32_UINT) added; one arm handles both U32 and U64 texture UAVs, format and pitch chosen by words (1/2).
  • emit/valu_tests.rs: helpers s_load_dwordx8, s_load_dwordx4_at, image_atomic64; builder build_atomic_cs + runner run_atomic_cases; tests wide_image_atomic_add (add with carry) and wide_image_atomic_cmpswap (compare-exchange); both run on hardware and WARP.

Validator errors fixed: "Flags must match usage" (missing bits 27/32) then "Container part 'Feature Info' does not match" (missing SFI0 bits 22/28). Authoritative table: llvm/include/llvm/BinaryFormat/DXContainerConstants.def SHADER_FEATURE_FLAG(sfi0, module, name) — 22/27 AtomicInt64OnTypedResource, 28/32 AtomicInt64OnHeapResource.

Not exercised: signed/unsigned min/max i64 atomics (same path, untested).
Rebased onto origin/main 940d32f.

**@⁠FoxxoOwO** on GitHub · 2026-11-25 08:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2241) `FoxxoOwO:shader/64-bit-image-atomics` → `main` · +265 −9 · 1 files · 1 commits · closed without merging The console's MIMG image_atomic instructions with `dmask` 3 (or 0xF for cmpswap) carry two data dwords: the low and high halves of an i64. Previously they lowered to two separate 32-bit atomics, so a carry from the low dword was lost. Now they lower to one i64 atomic on an R32G32 integer texture UAV (SM 6.6). Changes: - `emit/lower.rs`: `fn image()` detects width from `dmask`, builds an i64 atomic with `join64`/`split64`, and emits `atomicBinOp.i64` / `atomicCompareExchange.i64` (dx.op 78/79). Handle props stay `(kind | 0x1000, 0x105)` as the 32-bit path used. - `emit/shader.rs`: new module flags `ATOMIC_INT64_ON_TYPED_RESOURCE = 1 << 27` and `ATOMIC_INT64_ON_HEAP_RESOURCE = 1 << 32`; SFI0 feature bits 22 and 28 mapped. - `emit/host.rs`: `View::Uint2TextureUav` (R32G32_UINT) added; one arm handles both U32 and U64 texture UAVs, format and pitch chosen by `words` (1/2). - `emit/valu_tests.rs`: helpers `s_load_dwordx8`, `s_load_dwordx4_at`, `image_atomic64`; builder `build_atomic_cs` + runner `run_atomic_cases`; tests `wide_image_atomic_add` (add with carry) and `wide_image_atomic_cmpswap` (compare-exchange); both run on hardware and WARP. Validator errors fixed: "Flags must match usage" (missing bits 27/32) then "Container part 'Feature Info' does not match" (missing SFI0 bits 22/28). Authoritative table: llvm/include/llvm/BinaryFormat/DXContainerConstants.def SHADER_FEATURE_FLAG(sfi0, module, name) — 22/27 AtomicInt64OnTypedResource, 28/32 AtomicInt64OnHeapResource. Not exercised: signed/unsigned min/max i64 atomics (same path, untested). Rebased onto origin/main 940d32f.
The console's MIMG image_atomic instructions with `dmask` 3 (or 0xF for
cmpswap) carry two data dwords: the low and high halves of an i64.
Previously they lowered to two separate 32-bit atomics, so a carry from
the low dword was lost. Now they lower to one i64 atomic on an R32G32
integer texture UAV (SM 6.6).

- `emit/lower.rs`: `fn image()` detects width from `dmask` (3 for add/sub/or/xor/min/max/swap, 0xF for cmpswap), builds an i64 atomic with `join64`/`split64`, and emits `atomicBinOp.i64` / `atomicCompareExchange.i64` (dx.op 78/79). The handle props stay `(kind | 0x1000, 0x105)` as the 32-bit path used.
- `emit/shader.rs`: new module flags `ATOMIC_INT64_ON_TYPED_RESOURCE = 1 << 27` and `ATOMIC_INT64_ON_HEAP_RESOURCE = 1 << 32`; SFI0 feature bits 22 and 28 mapped.
- `emit/host.rs`: `View::Uint2TextureUav` (R32G32_UINT) added; one arm handles both U32 and U64 texture UAVs, format and pitch chosen by `words` (1/2).
- `emit/valu_tests.rs`: helpers `s_load_dwordx8`, `s_load_dwordx4_at`, `image_atomic64`; builder `build_atomic_cs` + runner `run_atomic_cases`; tests `wide_image_atomic_add` (add with carry) and `wide_image_atomic_cmpswap` (compare-exchange); both run on hardware and WARP.

Validator errors fixed: "Flags must match usage" (missing bits 27/32) then "Container part 'Feature Info' does not match" (missing SFI0 bits 22/28). Authoritative table: llvm/include/llvm/BinaryFormat/DXContainerConstants.def SHADER_FEATURE_FLAG(sfi0, module, name) — 22/27 AtomicInt64OnTypedResource, 28/32 AtomicInt64OnHeapResource.

Not exercised: signed/unsigned min/max i64 atomics (same path, untested).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:59:40 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 09:14 UTC · original · edited 2026-11-25 10:23 UTC

Automated triage for the maintainers.

Needs work. Now merges cleanly into main, but the lowering this PR describes is already in main. Commit 0b35b7f added the 64-bit image atomics: in emit/lower.rs (the image atomic lowering), a two-dword dmask becomes an i64 atomic with ATOMIC64_TYPED/ATOMIC64_HEAP and View::Uint2TextureUav. The image_atomics_of_64_bits test in valu_tests.rs covers umax, swap and cmpswap. After the rebase, this PR's diff touches only valu_tests.rs, and the description no longer matches it.

To be mergeable:

  • Drop the rustfmt-only changes to unrelated tests (scalar_quad_masks_pack_nibbles_and_set_scc, a_branch_to_fallthrough_keeps_both_values_at_a_join, v_cvt_off_f32_i4_uses_the_signed_low_nibble).
  • Drop wide_image_atomic_cmpswap, which image_atomics_of_64_bits already covers.
  • Keep the add-with-carry test (wide_image_atomic_add), which main does not cover. Ideally build it with the existing image_atomic helper instead of the new duplicate helpers.
  • Update the description.

CI passes.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 09:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2241#issuecomment-7158059954) · edited 2026-11-25 10:23 UTC <!-- victory-triage v1 head=00bd40bb3e2cbc6a4014d422039e4d5109a133d4 verdict=needs-work at=2026-11-25T10:22:51Z --> Automated triage for the maintainers. **Needs work.** Now merges cleanly into `main`, but the lowering this PR describes is already in `main`. Commit `0b35b7f` added the 64-bit image atomics: in `emit/lower.rs` (the image atomic lowering), a two-dword `dmask` becomes an i64 atomic with `ATOMIC64_TYPED`/`ATOMIC64_HEAP` and `View::Uint2TextureUav`. The `image_atomics_of_64_bits` test in `valu_tests.rs` covers umax, swap and cmpswap. After the rebase, this PR's diff touches only `valu_tests.rs`, and the description no longer matches it. To be mergeable: - Drop the rustfmt-only changes to unrelated tests (`scalar_quad_masks_pack_nibbles_and_set_scc`, `a_branch_to_fallthrough_keeps_both_values_at_a_join`, `v_cvt_off_f32_i4_uses_the_signed_low_nibble`). - Drop `wide_image_atomic_cmpswap`, which `image_atomics_of_64_bits` already covers. - Keep the add-with-carry test (`wide_image_atomic_add`), which `main` does not cover. Ideally build it with the existing `image_atomic` helper instead of the new duplicate helpers. - Update the description. CI passes. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠iGoldenNinja on GitHub · 2026-11-25 09:16 UTC · original

I tested clean head e2624b3384813a444067fe9ba93dfd131473a63c and its direct parent ffe310eb2098e52169f4c44db5ffdabf43a72622 on an RTX 5080, driver 617.14, and Windows 11 Pro 25H2 build 26200.9974, using Rust 1.98.1 MSVC and dxil.dll 1.9.2609.5.

  • Both original add and compare-swap fixtures passed with hardware and WARP and no skips. An added synthetic fixture passed signed and unsigned min and max on both adapters. It orders 0x8000000000000002 and 0x7ffffffffffffffe differently across signed and unsigned operations and verifies the returned old texel in each case. Synthetic fixture patch
  • On 168 unique matching pixel programs with two-dword image_atomic_umax, the direct parent refused all 168 at emission with a 64-bit image atomic. The PR head emitted and validated 162 and created 162 D3D12 pipelines. Six still refused during emission with barycentrics read directly. The matched-program check reached offline pipeline creation. Pinned report
**@⁠iGoldenNinja** on GitHub · 2026-11-25 09:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2241#issuecomment-7158115586) I tested clean head `e2624b3384813a444067fe9ba93dfd131473a63c` and its direct parent `ffe310eb2098e52169f4c44db5ffdabf43a72622` on an RTX 5080, driver 617.14, and Windows 11 Pro 25H2 build 26200.9974, using Rust 1.98.1 MSVC and `dxil.dll` 1.9.2609.5. - Both original add and compare-swap fixtures passed with hardware and WARP and no skips. An added synthetic fixture passed signed and unsigned min and max on both adapters. It orders `0x8000000000000002` and `0x7ffffffffffffffe` differently across signed and unsigned operations and verifies the returned old texel in each case. [Synthetic fixture patch](https://github.com/iGoldenNinja/victory-fork/blob/a08152888c521b73d6f64b7b369f49f9705f1338/docs/fixtures/victory-pr2241-minmax.patch) - On 168 unique matching pixel programs with two-dword `image_atomic_umax`, the direct parent refused all 168 at emission with `a 64-bit image atomic`. The PR head emitted and validated 162 and created 162 D3D12 pipelines. Six still refused during emission with `barycentrics read directly`. The matched-program check reached offline pipeline creation. [Pinned report](https://github.com/iGoldenNinja/victory-fork/blob/9938e07dc6bfd7eac3c3aa380d6842a9e485578e/docs/victory-pr2241-5080.md)
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 10:37 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head 00bd40bb onto main 940d32f (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: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

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

**@⁠sinan-cmyk** on GitHub · 2026-11-25 10:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2241#issuecomment-7159950856) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 00bd40bb onto `main` 940d32f (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: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
github-bot closed this pull request 2026-11-26 11:09:53 +00:00
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 08:48 UTC · original · reviewed

This PR no longer merges cleanly into main 940d32f69b (git merge origin/main conflicts locally). Please rebase; I will re-test the 64-bit texture atomics lowering on macOS afterwards (shader lowering/unit tests are the portable part; execution tests are Windows-gated).

**@⁠catminou4** on GitHub · 2026-11-25 08:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2241#pullrequestreview-6054378071) · **reviewed** This PR no longer merges cleanly into main 940d32f69b (`git merge origin/main` conflicts locally). Please rebase; I will re-test the 64-bit texture atomics lowering on macOS afterwards (shader lowering/unit tests are the portable part; execution tests are Windows-gated).
Author
Owner

@⁠FoxxoOwO on GitHub · 2026-11-26 09:42 UTC · original

Split into #3135 with only the add-with-carry test, as the triage asked: the lowering is already on main (0b35b7f), the rustfmt-only churn and the cmpswap test are dropped, and the test is built with the existing image_atomic/lower_cs32 helpers.

**@⁠FoxxoOwO** on GitHub · 2026-11-26 09:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2241#issuecomment-7188368071) Split into #3135 with only the add-with-carry test, as the triage asked: the lowering is already on `main` (0b35b7f), the rustfmt-only churn and the cmpswap test are dropped, and the test is built with the existing `image_atomic`/`lower_cs32` helpers.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2241
No description provided.