Skip to content

Recompiler: 64-bit image atomics keep all 64 bits (#1485) - #1533

Open
enderrr9 wants to merge 1 commit into
xcl-dev:mainfrom
enderrr9:recomp-image-atomics-64
Open

enderrr9 wants to merge 1 commit into
xcl-dev:mainfrom
enderrr9:recomp-image-atomics-64

Conversation

@enderrr9

Copy link
Copy Markdown

An image atomic with DMASK 0x3 (0xF for cmpswap) works on 64 bits: VDATA[0:1] against the texel's two dwords. The MIMG atomic arms never read DMASK, so XCL ran these on the low dword only. An add lost its carry, a max ordered by the low dword, and the program still counted as translated. They now run as SM 6.6 64-bit typed atomics on a uint64_t / int64_t view of the R32G32_UINT texel. Fixes #1485.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: a 64-bit arm ahead of the 32-bit atomic arms in mimg, picked by DMASK. It covers add, sub, and, or, xor, swap, umin/umax, smin/smax (int64 view), and cmpswap/fcmpswap (bitwise, compare value in VDATA[2:3]). inc/dec run as a compare-exchange loop. With GLC, the old value comes back in VDATA[0:1]. 64-bit float min/max have no typed HLSL form, so they are refused (image_atomic 64-bit float min/max) instead of mistranslated.
  • crates/xcl/src/gpu/recomp/tests.rs: gpu_image_atomics_64_bit is the test from Recompiler: 64-bit image atomics (DMASK 0x3) run as 32-bit atomics on the low dword #1485, written by its author and used unchanged. gpu_image_atomics_64_bit_cmpswap_smin_inc covers cmpswap with GLC (exactly one lane sees the initial texel, and the rest get the swapped one), a signed min decided by the high dwords, and an inc that carries past 2^32 with a limit above 2^32.

Tested

  • NVIDIA GeForce RTX 3050 Laptop GPU (4 GB, driver 621.24, 32-lane waves, so the split wave64 path), AMD Ryzen 5 4600H, Windows 11 build 26300, rustc 1.100.0 (MSVC), DXC 1.8.2502.11, debug build
  • cargo test --workspace -- --test-threads=4: 778 passed, 0 failed, 41 ignored. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows). This ran on the tree before one comment-only wording change in emit.rs. On the head commit 23d6656, cargo test -p xcl --lib gpu_image -- --test-threads=1 gives 5 passed, 0 failed.
  • Without the emit.rs change, both new tests fail. The first fails with the issue's numbers: image_atomic_add 64-bit: 0x00000000ffffffc0, want 0x0000003fffffffc0 and image_atomic_umax 64-bit: 0x00000000000003e8, want 0x0000003f000003a9. The second fails with image_atomic_cmpswap 64-bit: texel 0x0000000100000000 is no lane's new value.

Regression run
I have no title, so there is no smoke run. If someone with a title can run scripts/smoke.ps1 on main and on 23d6656, I'll add both blocks here.

main:

PR:

Not tested

  • any retail title (no smoke run, see above), so which 64-bit atomic programs a title reaches, and whether its picture changes, is unknown
  • AMD / native wave64, and Intel
  • a host without AtomicInt64OnTypedResourceSupported / AtomicInt64OnDescriptorHeapResourceSupported: the translation doesn't check these caps, and I haven't checked how such a host handles the pipeline
  • the and / or / xor / swap / sub / smax / dec / fcmpswap forms on the GPU (they are emitted but not exercised by the tests)

AI use

  • Claude Code with Claude Opus 5.5: wrote the emit.rs change, the second test and this description, and ran the tests above. The first test is from the issue.

An MIMG image atomic with DMASK 0x3 (0xF for cmpswap) works on the
texel's two dwords, VDATA[0:1] (cmpswap: compare value in VDATA[2:3]).
The atomic arms never read DMASK and ran a 32-bit atomic on the low
dword: an add lost the carry and a max ordered by the low dword.

They now run as SM 6.6 64-bit typed atomics on a uint64_t / int64_t
view of the R32G32_UINT texel (add, sub, and, or, xor, swap, u/s min,
u/s max, cmpswap, fcmpswap bitwise; inc / dec as a compare-exchange
loop), with GLC returning the old value in VDATA[0:1]. 64-bit float
min / max have no typed form and are refused.

Tests: gpu_image_atomics_64_bit (the issue's test, by
13hourstilliland) and gpu_image_atomics_64_bit_cmpswap_smin_inc. Both
fail on main and pass with the change on an RTX 3050 Laptop GPU.

Fixes xcl-dev#1485

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@gut0to gut0to left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted review (GPT-6): I verified the exhaustion path in the generated compare-exchange loop.

self.line(&format!("{vt} {t}_old = 0;"));
let texel = format!("{t}_U[{icoord}]");
let cas = |new: &str| {
format!("uint64_t {t}_c = 0; [allow_uav_condition] for (uint {t}_i = 0u; {t}_i < 4096u; {t}_i++) {{ uint64_t {t}_n = {new}; uint64_t {t}_p = 0; InterlockedCompareExchange({texel}, {t}_c, {t}_n, {t}_p); if ({t}_p == {t}_c) break; {t}_c = {t}_p; }} {t}_old = {t}_c;")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If every compare-exchange attempt loses to concurrent updates, this loop exits after 4096 iterations and then assigns _old = _c without recording whether any exchange succeeded. That silently drops the 64-bit inc or dec operation under contention. Please retry until the compare-exchange succeeds, or handle exhaustion as a failure. AI-assisted review: I checked the generated loop and its post-loop success handling.

@dcastell1

Copy link
Copy Markdown

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on main@9e3831e (baseline 776 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
778 passed; 0 failed; 41 ignored   (exit 0)

Two more passing tests than the baseline; keeping all 64 bits in 64-bit image atomics ships its cases and they run green.

Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

@DarkPanda69

Copy link
Copy Markdown

AMD run with 64-lane waves, which this PR lists as not tested (the other report here is NVIDIA).

Tested: pass, head 23d6656 applied on its base main 9e3831e, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.
cargo test -p xcl --lib -- gpu::recomp --test-threads=4:

  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010, native wave64: 194 passed, 0 failed, 18 ignored, 0 SKIPPED. gpu_image_atomics_64_bit and gpu_image_atomics_64_bit_cmpswap_smin_inc ok.
  • NVIDIA RTX 3060, driver 32.0.16.1088: 194 passed, 0 failed, 18 ignored, 2 SKIPPED (no wave64). Both ok.

Not tested: Intel; a host without 64-bit image atomics; the whole workspace suite; a title.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Checked on NVIDIA at head 23d6656: pass.

Tested

  • RTX 3070, driver 616.56 (32-lane waves, so the split form), Windows 11 Pro 26100, Rust 1.100.0 MSVC, DXC 1.8.2502.11, debug.
  • cargo test -p xcl --lib -- image_atomic --test-threads=1: gpu_image_atomics_64_bit and gpu_image_atomics_64_bit_cmpswap_smin_inc pass.
  • An extra test of my own, added locally (not part of this PR), also passes. It has a 64-bit add with GLC (each lane gets a distinct earlier sum), umax, smin over negative values, and cmpswap with GLC (exactly one lane sees the initial texel; the others get the winner's value). It also puts a 32-bit image_atomic_cmpswap (DMASK 0x3) in the same program, and that one must leave the texel's high dword alone. Test: https://github.com/upipibi/xcl/blob/fix/image-atomic-64/crates/xcl/src/gpu/recomp/tests.rs (gpu_image_atomics_64_bit there).

Not tested: the whole suite, AMD, a retail run.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this comment.

@eizispark

Copy link
Copy Markdown

Hardware test report — commit 23d6656

Checked 23d6656744935901eff8cc85ce3593da600ae82c (based on main 9e3831e1f570d3646e53ab753b19ec07eb8f1485): pass.

Tested

  • Hardware: Windows 11 x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT (RDNA4, native wave32 + wave64, driver 32.0.32015.16001), 32 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 778 passed, 0 failed, 41 ignored (1 skipped: heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows)
  • cargo test -p xcl --lib image_atomics_64_bit -- --nocapture: 2 passed, 0 failed, 0 ignored, 0 skipped (gpu::recomp::tests::gpu_image_atomics_64_bit and gpu::recomp::tests::gpu_image_atomics_64_bit_cmpswap_smin_inc executed natively in wave32 and wave64 on AMD RDNA4 RWTexture2D<uint64_t> over R32G32_UINT)

Regression run
main (9e3831e):

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1677 (PresentX 1677)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14728 MB

PR (23d6656):

xcl-smoke v1
commit: 23d6656744935901eff8cc85ce3593da600ae82c
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1677 (PresentX 1677)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14863 MB

Not tested

  • adapters without AtomicInt64OnTypedResourceSupported / AtomicInt64OnDescriptorHeapResourceSupported, NVIDIA/Intel GPUs, Wine/vkd3d-proton, XCL_SAMPLE_*

AI use

  • Antigravity (Google DeepMind, Gemini 4 Carbon) — ran the workspace test suite and 60 s retail smoke run on this commit and formatted the report.

@vitor127wt

Copy link
Copy Markdown

I ran the retail smoke comparison requested in #1243 on Proton. Both runs used the same Xbox title for 60 seconds, with fresh Proton prefixes and XCL caches.

Tested

Regression run

The title field omits a local folder suffix. All measurements are as emitted by the script.

main

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1193 (PresentX 1193)
presents per 2 s (last 3): 60 60 57
device removals: 0
crashes: 0
peak commit: 0 MB

PR head

xcl-smoke v1
commit: 23d6656744935901eff8cc85ce3593da600ae82c
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1192 (PresentX 1192)
presents per 2 s (last 3): 60 58 60
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

Native Windows with scripts/smoke.ps1 and the full workspace suite. Wine reported peak commit: 0 MB in both runs, so these blocks provide no usable peak memory comparison.

AI use

OpenAI Codex (GPT-6, exact variant unavailable) ran the tests and prepared this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

kacper-serewis pushed a commit to kacper-serewis/xcl that referenced this pull request Nov 24, 2026
Adapt xcl-dev#1541 and the signed views and contention fixtures from xcl-dev#1533. Key translation caches on the device capability. Five independent operations failed on the baseline and passed on the RTX 5070.

Co-authored-by: enderrr9 <178652333+enderrr9@users.noreply.github.com>
Assisted-by: OpenCode (Gemini 4 Neon)
Assisted-by: T3 Code (gpt-6.2-astra)
@throny

throny commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #1541 #1551 solves the same problem (for #1485) in a different way: #1607, group D9. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recompiler: 64-bit image atomics (DMASK 0x3) run as 32-bit atomics on the low dword

9 participants