Skip to content

Recompiler: implement 64-bit MIMG image atomics (DMASK 0x3 / 0xF) with cap gating - #1541

Open
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:recomp/image-atomic-64bit
Open

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:recomp/image-atomic-64bit

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1485.

Em::mimg in crates/xcl/src/gpu/recomp/emit.rs ignored DMASK on IMAGE_ATOMIC_* instructions and always emitted 32-bit RWTexture<uint>/RWTexture<int> atomics on VDATA[0]. On RDNA2 (per LLVM SIISelLowering), DMASK == 0x3 (or 0xF for cmpswap/fcmpswap) selects 64-bit image atomics operating on VDATA[0:1] (and VDATA[2:3] as compare value for cmpswap), so 64-bit carries, upper-dword comparisons, and GLC 64-bit return values were silently truncated to 32 bits.

This adds 64-bit MIMG image atomic translation using SM 6.6 RWTexture<uint64_t> / RWTexture<int64_t> typed 64-bit atomics (InterlockedAdd, InterlockedAnd, InterlockedOr, InterlockedXor, InterlockedExchange, InterlockedMin, InterlockedMax, InterlockedCompareExchange, plus bounded CAS loops matching rmw32 for inc/dec), gated on D3D12_FEATURE_DATA_D3D12_OPTIONS9::AtomicInt64OnTypedResourceSupported && D3D12_FEATURE_DATA_D3D12_OPTIONS11::AtomicInt64OnDescriptorHeapResourceSupported. Adapters without those capabilities cleanly refuse 64-bit image atomics instead of failing at pipeline creation or silently truncating to 32 bits, and invalid DMASK values are also refused.

Since the review (@KainanP): a device without the capability no longer bypasses the shader caches. The capability is part of their keys instead — a field of the in-memory ShaderKey, and an identity of its own for the translations on disk (translated::identity_for_caps, which the rerouted direct entries keep too). A capable device's identity is unchanged, so its existing entries stay valid. The device is asked once, not for every translation.

On the current main: the mimg atomics were refactored while this PR waited (one rmw32 arm for the operations without an int view), and the disk cache now checks that a stored DXIL is a container. The width decode feeds a single dispatch that keeps that rmw32 arm for the 32-bit case and adds the 64-bit one beside it, and every atomic's ResourceDescriptorHeap[...] handle is made inside if (and(act, ok)) — what main's new mimg_view_and_sampler_heap_indices_are_guarded test requires.

#1533 and #1551 fix the same issue (#1607, group D9). The difference that is left: this PR asks the device first and refuses a program that uses 64-bit image atomics where the capabilities are missing; the other two always emit the 64-bit form. Merging any one of the three makes the others conflict in the same mimg arms.

What is in it

  • crates/xcl/src/gpu/recomp/mod.rs: add int64_typed_atomic: bool to Options (default true for standalone translation; adapter-probed in runtime and GPU test runner).
  • crates/xcl/src/gpu/recomp/emit.rs: atomic_width from DMASK (cmpswap/fcmpswap: 0x3 32-bit, 0xF 64-bit; the rest: 0x1 32-bit, 0x3 64-bit), refusal of anything else or of the 64-bit form without the capability, and the SM 6.6 64-bit typed UAV atomics with GLC 64-bit writeback; the existing rmw32 arm serves the 32-bit operations that have no int view.
  • crates/xcl/src/gpu/recomp/pso.rs: probe OPTIONS9/OPTIONS11 on the runtime device (once) and pass int64_typed_atomic into the recompiler's Options; the capability in ShaderKey and in the disk identity (identity_for_caps), for the compute and the mesh path; unit test a_device_without_int64_typed_atomics_has_its_own_disk_entries, and the changed-key case in shader_cache_checks_context_and_blob_bytes.
  • crates/xcl/src/gpu/recomp/runner.rs: probe the test adapter and expose int64_typed_atomic_supported().
  • crates/xcl/src/gpu/recomp/tests.rs: gpu_image_atomics_64_bit — capability refusal, invalid DMASK refusal, and GPU execution of 64-bit add (with GLC), umax, smin, cmpswap (with GLC, DMASK 0xF), and inc across a 32-bit carry. It skips with direct DXIL: no 64-bit image atomics under XCL_DIRECT_DXIL=1, since the direct translator lowers mimg itself and this PR does not change it.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1: 1173 passed, 2 failed, 26 ignored. The two failures are gpu::recomp::pso::shader_cache_tests::rerouted_disk_entries_follow_the_direct_translator and hle::d3d12x::device_x::tests::pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa; both fail the same way on unmodified main a7ec0db on this machine (checked with the same command), so they are not from this change.
  • cargo test -p xcl --lib -- gpu_image_atomics_64_bit: 1 passed (the 64-bit GPU run; this adapter has both capabilities)
  • gpu::dxil::lower_image::heap_bounds_tests::mimg_view_and_sampler_heap_indices_are_guarded: passes
  • cargo test -p xcl --lib -- a_device_without_int64_typed_atomics_has_its_own_disk_entries: 1 passed
  • @JJAutoCompare ran the same test on an Intel Arc A770, the first device here that lacks the capability (OPTIONS9.AtomicInt64OnTypedResourceSupported = 0, OPTIONS11.AtomicInt64OnDescriptorHeapResourceSupported = 1): both CPU assertions passed and the GPU part reported no int64 typed image atomics, as designed.

Regression run

main (a7ec0db, clean tree, no local changes):

xcl-smoke v1
commit: a7ec0db9b524ee08ca0b0b64071cd860878c16ba
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1600 (PresentX 1600)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15483 MB

PR (130815d, clean tree, no local changes):

xcl-smoke v1
commit: 130815daa7e948a219f830932e366939bbe94046
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1639 (PresentX 1639)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15166 MB

Not tested

  • a title or the full suite on an adapter lacking AtomicInt64OnTypedResourceSupported / AtomicInt64OnDescriptorHeapResourceSupported (the Arc A770 report above covers the translation-level refusal and the test's skip only)
  • the direct DXIL path (XCL_DIRECT_DXIL=1) for these instructions: this PR changes the HLSL path only
  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Claude Fable 5.2: implemented 64-bit MIMG image atomics and capability gating for Recompiler: 64-bit image atomics (DMASK 0x3) run as 32-bit atomics on the low dword #1485, switched smin/smax to native int64_t InterlockedMin/InterlockedMax and moved the capability into the cache keys per review feedback, merged the change into main's refactored mimg arms and heap guard, wrote the tests, ran the test suite and the scripts/smoke.ps1 runs, and drafted this PR description.

@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 failure path in the generated 64-bit compare-exchange loop.

let u = format!("{t}_U[{icoord}]");
let cas64 = |new: String| {
format!(
"uint64_t {t}_c = {u}; [allow_uav_condition] for (uint {t}_i = 0u; {t}_i < 4096u; {t}_i++) {{ uint64_t {t}_n = {new}; uint64_t {t}_p = 0; InterlockedCompareExchange({u}, {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.

Could this retry until the compare-exchange succeeds? If all 4096 attempts lose under contention, the loop exits without applying the atomic operation but still reports _c as the old value. That silently drops updates for 64-bit smin, smax, inc, or dec. Please handle exhaustion as a failure or keep retrying. AI-assisted review: I checked the generated loop and its failure path.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Checked on NVIDIA at head ec4c343: pass. Also a note that #1533 fixes the same issue.

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 passes.
  • An extra test of my own, added locally (not part of this PR), also passes. It has a 64-bit add with GLC, umax, smin over negative values, cmpswap with GLC (exactly one winner), and a 32-bit cmpswap (DMASK 0x3) in the same program that must leave the 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).

Compared with #1533 (same issue, opened earlier; both pass the test above here):

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

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

@b3IKK

b3IKK commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @gut0to and @upipibi — updated in \d9138ac\ to use native \RWTexture<int64_t>\ \InterlockedMin/\InterlockedMax\ directly for 64-bit \smin\ and \smax\ (no CAS loop needed at all for those two). For \inc\ and \dec\ (which have no HLSL wrap-at-limit intrinsic), the 4096-iteration bounded CAS loop matches the existing
mw32\ and
mw64\ helpers in \emit.rs\ so shaders cannot hang in an unbounded GPU loop and trigger TDR. Re-ran \gpu_image_atomics_64_bit, \scripts/test.ps1, and the 60 s \scripts/smoke.ps1\ run.

@Belox17

Belox17 commented Nov 24, 2026

Copy link
Copy Markdown

Test report for d9138ac2 on NVIDIA (RTX 3060 Ti, 32-lane waves): passes, and the GPU check catches the bug without the fix

Tested

  • NVIDIA GeForce RTX 3060 Ti 8 GB, driver 32.0.16.2124; Ryzen 5 5600X; Windows 11 build 26300; rustc 1.98.1 MSVC; DXC 1.8.2502.11 (Windows SDK 10.0.26100); debug build. Head d9138ac2 as is (base 9e3831e), clean tree; the previous head ec4c343f gave the same results.
  • cargo test -p xcl --lib gpu_image_atomics_64_bit: 1 passed. The GPU part ran (no SKIPPED, so the adapter has 64-bit typed atomics through the descriptor heap).
  • cargo test --workspace -- --test-threads=4: 777 passed, 0 failed, 41 ignored. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows). main 9e3831e on the same machine: 776 passed, 0 failed, 41 ignored, same three skips.
  • With emit.rs from 9e3831e (the rest of the PR kept), the test fails at its CPU check (64-bit image atomic must be refused when adapter lacks int64_typed_atomic). With the CPU checks also removed, its GPU part fails on this adapter: image_atomic_add 64-bit, left 4294967232 (0xFFFFFFC0), right 274877906880 (0x3FFFFFFFC0): the carry into the high dword is lost.

Not tested

  • AMD / wave64 hardware; an adapter without 64-bit typed atomics (the refusal only ran as the CPU check); any retail title (no smoke run).

AI use: Claude Code (Claude Opus 5.5) ran the commands and wrote this report; I checked it before posting.

@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. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

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)
@KainanP

KainanP commented Nov 24, 2026

Copy link
Copy Markdown

Thanks for the 64-bit atomics work. I read the diff at ec4c343 and rechecked d9138ac (not run); the line below is unchanged.

In console_to_dxil_in (pso.rs:146), || !int64_typed_atomic() sends every shader past ShaderCache and the translated disk cache on GPUs without 64-bit typed atomics, not only shaders that use them. On those machines, each boot re-translates the whole corpus (the module comment cites 0.1-0.3 s per program over ~2 800 programs on a retail title) and pipelines no longer share translations within a run. The DXIL cache still saves the DXC step.

Suggestion: keep the caches and add the capability bit to the keys instead, i.e. a field in ShaderKey and a component of the translated::file path/identity. Memoising int64_typed_atomic() in a OnceLock once the device exists would also avoid two CheckFeatureSupport calls per request.

AI use: Claude Code (Claude Opus 5.5) read the diff; not run. Checked by the user before posting.

@throny

throny commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #1533 #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.

b3IKK added a commit to b3IKK/xcl that referenced this pull request Nov 24, 2026
…h cap gating

The MIMG image atomic emitter ignored DMASK, silently lowering 64-bit
image atomics (DMASK 0x3 for add/sub/min/max/and/or/xor/swap/inc/dec,
DMASK 0xF for cmpswap/fcmpswap) as 32-bit atomics on the low dword only,
losing carries, ordering u64 values by their low 32 bits, and ignoring
VDATA[1] / VDATA[2:3].

Decode 32-bit vs 64-bit width from DMASK (rejecting invalid masks),
gate 64-bit typed image atomics on `Options::int64_typed_atomic`
(queried from `D3D12_OPTIONS9::AtomicInt64OnTypedResourceSupported` and
`D3D12_OPTIONS11::AtomicInt64OnDescriptorHeapResourceSupported`), and
emit SM 6.6 `RWTexture*<uint64_t>` Interlocked* / 64-bit CAS loops with
full 64-bit GLC return unpacking into VDATA[0:1]. When the adapter lacks
these capabilities, 64-bit image atomics are cleanly refused rather than
mistranslated as 32-bit.

The capability is part of the caches' keys instead of a reason to bypass
them: a field of the in-memory `ShaderKey`, and an identity of its own
for the translations on disk of a device without it (a capable device's
identity, and so its existing entries, is unchanged). Without that, a
device lacking the capability translated every program again at each
start (review of xcl-dev#1541). The device is asked once, not per translation.

Fixes xcl-dev#1485.

Assisted-by: OpenCode (Claude Fable 5.2)
@b3IKK
b3IKK force-pushed the recomp/image-atomic-64bit branch from d9138ac to a4f7834 Compare November 24, 2026 23:15
@b3IKK

b3IKK commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@KainanP you are right: || !int64_typed_atomic() took every shader past both caches on a device without the capability, not only the programs that use 64-bit image atomics. Pushed a4f7834 (rebased onto 689f2db):

  • The bypass is gone. The capability is a field of ShaderKey, and the translations on disk of a device without it live under an identity of their own (translated::identity_for_caps). With the capability the identity is the one main has, so existing entries stay valid.
  • int64_typed_atomic() asks the device once it exists and keeps the answer, instead of two CheckFeatureSupport calls per translation.
  • New unit test a_device_without_int64_typed_atomics_has_its_own_disk_entries: an entry stored for a capable device is a miss for one without, each reuses its own, and a disabled cache (identity 0) stays disabled.

Suite on this head: 977 passed, 0 failed, 45 ignored. Smoke for 689f2db and a4f7834: 1643 and 1642 frames, 0 crashes, 0 device removals.

Not tested: a device that lacks the capability. I have none here, so the cache behaviour on one is covered by the unit tests only.

On the #1607 hint (group D9, #1533 and #1551): the description now says what differs. This PR refuses a program that uses 64-bit image atomics where the device lacks them; the other two always emit the 64-bit form. I have not run either of them, so I am not claiming more than that.

Also corrected in the description: it listed a change in hle/d3d12x/real.rs that this PR does not have. The probe is in pso.rs.

AI use: OpenCode, Claude Fable 5.2 made the change, ran the tests and wrote this comment.

b3IKK added a commit to b3IKK/xcl that referenced this pull request Nov 25, 2026
…h cap gating

The MIMG image atomic emitter ignored DMASK, silently lowering 64-bit
image atomics (DMASK 0x3 for add/sub/min/max/and/or/xor/swap/inc/dec,
DMASK 0xF for cmpswap/fcmpswap) as 32-bit atomics on the low dword only,
losing carries, ordering u64 values by their low 32 bits, and ignoring
VDATA[1] / VDATA[2:3].

Decode 32-bit vs 64-bit width from DMASK (rejecting invalid masks),
gate 64-bit typed image atomics on `Options::int64_typed_atomic`
(queried from `D3D12_OPTIONS9::AtomicInt64OnTypedResourceSupported` and
`D3D12_OPTIONS11::AtomicInt64OnDescriptorHeapResourceSupported`), and
emit SM 6.6 `RWTexture*<uint64_t>` Interlocked* / 64-bit CAS loops with
full 64-bit GLC return unpacking into VDATA[0:1]. When the adapter lacks
these capabilities, 64-bit image atomics are cleanly refused rather than
mistranslated as 32-bit.

The capability is part of the caches' keys instead of a reason to bypass
them: a field of the in-memory `ShaderKey`, and an identity of its own
for the translations on disk of a device without it (a capable device's
identity, and so its existing entries, is unchanged). Without that, a
device lacking the capability translated every program again at each
start (review of xcl-dev#1541). The device is asked once, not per translation.

Fixes xcl-dev#1485.

Assisted-by: OpenCode (Claude Fable 5.2)

(The mesh-shader path's own cache key, added on main since the last rebase, carries the same capability.)
@b3IKK
b3IKK force-pushed the recomp/image-atomic-64bit branch from a4f7834 to 9e1e7d3 Compare November 25, 2026 00:24
@b3IKK

b3IKK commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto 80f4819 (main had moved the cache to shader_cache() and added a cache key to the mesh path, which now carries the capability too). Head 9e1e7d3: 995 passed, 0 failed, 45 ignored, and the two smoke blocks in the description are from 80f4819 and this head, run one after the other. AI use: OpenCode, Claude Fable 5.2.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Re-checked the rebased head 9e1e7d3 on the RTX 3070 (driver 616.56, Windows 11, debug). With XCL_DIRECT_DXIL=0, my extended 64-bit test passes, and so does the existing image_atomic GPU test. The extended test covers add with a carry between the halves, umax, smin of negative values, and cmpswap with GLC: one winner, and the other 63 lanes return the final value. Same result as at ec4c343.

AI-assisted (Claude Code).

@JJAutoCompare

JJAutoCompare commented Nov 25, 2026 •

Copy link
Copy Markdown

Tested

Independent Windows run for PR #1541 at clean detached 9e1e7d30e9a58de28a932675c5a5b1fc8e6e3a58. STOR-WINLAB, Windows 11 Enterprise Evaluation x64 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust/Cargo 1.100.0 x86_64-pc-windows-msvc, DXC/DXIL 1.9.2609.5. Unoptimized test profile with debug info and incremental compilation disabled.

cargo test --locked -p xcl --lib --no-run -j 2 --message-format=json ran outside the GPU lock and exited 0. Used XCL_ADAPTER=A770, XCL_DIRECT_DXIL=0, and the DXC directory %LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64.

& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
    & 'L:/XclTooling/verify-pr1523-1362129-t3-cf2e05e7/target/debug/build/xcl/77aca8ccb20e299f/out/xcl-77aca8ccb20e299f.exe' --exact gpu::recomp::tests::gpu_image_atomics_64_bit --nocapture --test-threads=1
}

Libtest reported 1 passed, 0 failed, 0 ignored, with 970 filtered out and 0.15 s elapsed. The two CPU translation assertions passed (capability disabled and invalid DMASK rejected). The fixture then reported 1 GPU skip with no int64 typed image atomics on this adapter and driver. No 64-bit atomic dispatched. The fixture and mutex wrapper exited 0, and the executable hash matched before waiting, under the lock, and after execution.

A separate Windows SDK 10.0.26100.0 D3D12 feature probe identified the gate on this adapter. Both queries returned S_OK. OPTIONS9.AtomicInt64OnTypedResourceSupported=0 and OPTIONS11.AtomicInt64OnDescriptorHeapResourceSupported=1. I built the standalone query with cl /nologo /W4 /WX /EHsc /std:c++17 atomic-capability.cpp d3d12.lib dxgi.lib in the probe directory, then ran atomic-capability.exe under the same Arc lock. The probe and wrapper exited 0. OPTIONS9 · OPTIONS11

Not tested

Live 64-bit atomic results, device cache behavior, direct DXIL, other adapters, the full suite, and title smoke runs.

AI use

T3 Code / Codex (gpt-6.2-sol) verified the checkout, ran the checked-in fixture and the standalone feature probe, and wrote this report.

@b3IKK

b3IKK commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@JJAutoCompare thank you — that is the first run of this test on a device without the capability, and it behaves as the PR says it should: the two CPU assertions pass and the GPU part skips with no int64 typed image atomics on the A770 (OPTIONS9.AtomicInt64OnTypedResourceSupported = 0). I added that to the description.

One thing this PR needs before it can move: main has since refactored the mimg emitter (an rmw32 helper and a separate arm for the operations that have no int view), and this head (9e1e7d3, based on 80f4819) conflicts with it. A mechanical rebase does not resolve that — the 64-bit DMASK dispatch has to be woven into the new arms — so I have left it unrebased rather than push a rushed merge, and said so under Not tested. AI use: OpenCode, Claude Fable 5.2.

b3IKK added a commit to b3IKK/xcl that referenced this pull request Nov 25, 2026
…h cap gating

The MIMG image atomic emitter ignored DMASK, silently lowering 64-bit
image atomics (DMASK 0x3 for add/sub/min/max/and/or/xor/swap/inc/dec,
DMASK 0xF for cmpswap/fcmpswap) as 32-bit atomics on the low dword only,
losing carries, ordering u64 values by their low 32 bits, and ignoring
VDATA[1] / VDATA[2:3].

Decode 32-bit vs 64-bit width from DMASK (rejecting invalid masks),
gate 64-bit typed image atomics on `Options::int64_typed_atomic`
(queried from `D3D12_OPTIONS9::AtomicInt64OnTypedResourceSupported` and
`D3D12_OPTIONS11::AtomicInt64OnDescriptorHeapResourceSupported`), and
emit SM 6.6 `RWTexture*<uint64_t>` Interlocked* / 64-bit CAS loops with
full 64-bit GLC return unpacking into VDATA[0:1]. When the adapter lacks
these capabilities, 64-bit image atomics are cleanly refused rather than
mistranslated as 32-bit.

The capability is part of the caches' keys instead of a reason to bypass
them: a field of the in-memory `ShaderKey`, and an identity of its own
for the translations on disk of a device without it (a capable device's
identity, and so its existing entries, is unchanged). Without that, a
device lacking the capability translated every program again at each
start (review of xcl-dev#1541). The device is asked once, not per translation.

Fixes xcl-dev#1485.

Assisted-by: OpenCode (Claude Fable 5.2)

(The mesh-shader path's own cache key, added on main since the last rebase, carries the same capability.)

(On the current main, the mimg emitter's atomics take the width from DMASK through one dispatch, which then keeps the
mw32 arm main extracted for the operations without an int view.)
@b3IKK
b3IKK force-pushed the recomp/image-atomic-64bit branch from 9e1e7d3 to 99d80ad Compare November 25, 2026 10:56
@b3IKK

b3IKK commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

The merge onto current main is done: head 99d80ad, based on 568e7db. main had since refactored the mimg atomics — one rmw32 arm for the operations without an int view — so the DMASK width decode now feeds a single dispatch that keeps that arm for the 32-bit case and adds the 64-bit one, instead of sitting beside it as before.

Two things that changed in the process:

  • main's new heap_bounds_tests::mimg_view_and_sampler_heap_indices_are_guarded requires the UAV handle to be made inside if (and(act, ok)); my earlier code declared it outside the guard. The guard now wraps the handle and the operation for the 64-bit path too, and that test passes.
  • gpu_image_atomics_64_bit now skips with direct DXIL: no 64-bit image atomics when XCL_DIRECT_DXIL=1, rather than failing on the direct translator's own mimg lowering, which this PR does not touch.

Suite: 1156 passed, 0 failed, 46 ignored. Smoke blocks for 568e7db and 99d80ad are in the description. The Arc A770 result from @JJAutoCompare is in Tested. AI use: OpenCode, Claude Fable 5.2.

…h cap gating

The MIMG image atomic emitter ignored DMASK, silently lowering 64-bit
image atomics (DMASK 0x3 for add/sub/min/max/and/or/xor/swap/inc/dec,
DMASK 0xF for cmpswap/fcmpswap) as 32-bit atomics on the low dword only,
losing carries, ordering u64 values by their low 32 bits, and ignoring
VDATA[1] / VDATA[2:3].

Decode 32-bit vs 64-bit width from DMASK (rejecting invalid masks),
gate 64-bit typed image atomics on `Options::int64_typed_atomic`
(queried from `D3D12_OPTIONS9::AtomicInt64OnTypedResourceSupported` and
`D3D12_OPTIONS11::AtomicInt64OnDescriptorHeapResourceSupported`), and
emit SM 6.6 `RWTexture*<uint64_t>` Interlocked* / 64-bit CAS loops with
full 64-bit GLC return unpacking into VDATA[0:1]. When the adapter lacks
these capabilities, 64-bit image atomics are cleanly refused rather than
mistranslated as 32-bit.

The capability is part of the caches' keys instead of a reason to bypass
them: a field of the in-memory `ShaderKey`, and an identity of its own
for the translations on disk of a device without it (a capable device's
identity, and so its existing entries, is unchanged). Without that, a
device lacking the capability translated every program again at each
start (review of xcl-dev#1541). The device is asked once, not per translation.

Fixes xcl-dev#1485.

Assisted-by: OpenCode (Claude Fable 5.2)

(The mesh-shader path's own cache key, added on main since the last rebase, carries the same capability.)

(On the current main, the mimg emitter's atomics take the width from DMASK through one dispatch, which then keeps the
mw32 arm main extracted for the operations without an int view.)
@b3IKK
b3IKK force-pushed the recomp/image-atomic-64bit branch from 99d80ad to 130815d Compare November 25, 2026 11:06
@b3IKK

b3IKK commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Merged again, onto a7ec0db — main moved another 80 commits in the hour the previous merge took, and this time it had also changed the translated-cache tests (a synthetic DXIL container with the marker at byte 67) and the mimg guard (the T# handle only inside if (and(act, ok))).

Head 130815d:

  • suite 1173 passed, 2 failed, 26 ignored. The two failures, rerouted_disk_entries_follow_the_direct_translator and pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa, fail identically on unmodified main a7ec0db on this machine, which I checked before posting; they are not from this PR.
  • the three tests this change is about (gpu_image_atomics_64_bit, mimg_view_and_sampler_heap_indices_are_guarded, a_device_without_int64_typed_atomics_has_its_own_disk_entries) pass.
  • smoke blocks for a7ec0db and 130815d are in the description (1600 / 1639 frames, 0 crashes, 0 device removals).

One caveat on the treadmill: main is taking ~80 commits an hour and has now touched this file twice. If it conflicts again before a reviewer gets to it, the merge is the same two hunks (the DMASK decode and the guarded handle) and I will redo it on request rather than chase every move. AI use: OpenCode, Claude Fable 5.2.

@thehollowedone

Copy link
Copy Markdown

Independent Windows run on 130815d. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11, debug.

On the exact revision, cargo build --offline --locked --workspace passed. cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --nocapture reported 1,236 passed, 2 failed, 46 ignored. The stock 64-bit image atomic and capability-cache tests passed. The only failures were the two stale assertions already addressed by #2245.

With this revision merged locally into 426a5a7, the same build and test commands reported 1,245 passed, 0 failed, 46 ignored. Both runs had 25 runtime skip notices included in Cargo's pass count.

I also fed the integrated HLSL path LLVM MC 23.1.6 gfx1030 encodings for 64-bit image_atomic_dec and image_atomic_sub with GLC. On the RTX, 64 lanes contended on each texel. Both final values and all 128 full-width old values matched, including decrement wrap and low-word borrow. The scratch check passed 1/0/0 with zero skips using cargo test --offline --locked -p xcl --lib scratch_llvm_image_atomic64_sub_and_dec -- --nocapture --test-threads=1, with XCL_DIRECT_DXIL=0 and XCL_ADAPTER=3080 Ti.

Synthetic HLSL-path coverage only. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote the fixture, ran the tests, and drafted this report.

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