Recompiler: implement 64-bit MIMG image atomics (DMASK 0x3 / 0xF) with cap gating #1541
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1541
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1541"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@b3IKK on GitHub · 2026-11-24 17:25 UTC · original
b3IKK:recomp/image-atomic-64bit→main· +314 −37 · 5 files · 1 commits · openFixes #1485.
Em::mimgincrates/xcl/src/gpu/recomp/emit.rsignoredDMASKonIMAGE_ATOMIC_*instructions and always emitted 32-bitRWTexture<uint>/RWTexture<int>atomics onVDATA[0]. On RDNA2 (per LLVMSIISelLowering),DMASK == 0x3(or0xFforcmpswap/fcmpswap) selects 64-bit image atomics operating onVDATA[0:1](andVDATA[2:3]as compare value forcmpswap), so 64-bit carries, upper-dword comparisons, andGLC64-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 matchingrmw32forinc/dec), gated onD3D12_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 invalidDMASKvalues 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: themimgatomics were refactored while this PR waited (onermw32arm 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 thatrmw32arm for the 32-bit case and adds the 64-bit one beside it, and every atomic'sResourceDescriptorHeap[...]handle is made insideif (and(act, ok))ÔÇö whatmain's newmimg_view_and_sampler_heap_indices_are_guardedtest 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
mimgarms.What is in it
crates/xcl/src/gpu/recomp/mod.rs: addint64_typed_atomic: booltoOptions(defaulttruefor standalone translation; adapter-probed in runtime and GPU test runner).crates/xcl/src/gpu/recomp/emit.rs:atomic_widthfromDMASK(cmpswap/fcmpswap:0x332-bit,0xF64-bit; the rest:0x132-bit,0x364-bit), refusal of anything else or of the 64-bit form without the capability, and the SM 6.6 64-bit typed UAV atomics withGLC64-bit writeback; the existingrmw32arm serves the 32-bit operations that have no int view.crates/xcl/src/gpu/recomp/pso.rs: probeOPTIONS9/OPTIONS11on the runtime device (once) and passint64_typed_atomicinto the recompiler'sOptions; the capability inShaderKeyand in the disk identity (identity_for_caps), for the compute and the mesh path; unit testa_device_without_int64_typed_atomics_has_its_own_disk_entries, and the changed-key case inshader_cache_checks_context_and_blob_bytes.crates/xcl/src/gpu/recomp/runner.rs: probe the test adapter and exposeint64_typed_atomic_supported().crates/xcl/src/gpu/recomp/tests.rs:gpu_image_atomics_64_bitÔÇö capability refusal, invalidDMASKrefusal, and GPU execution of 64-bitadd(withGLC),umax,smin,cmpswap(withGLC,DMASK 0xF), andincacross a 32-bit carry. It skips withdirect DXIL: no 64-bit image atomicsunderXCL_DIRECT_DXIL=1, since the direct translator lowersmimgitself and this PR does not change it.Tested
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 aregpu::recomp::pso::shader_cache_tests::rerouted_disk_entries_follow_the_direct_translatorandhle::d3d12x::device_x::tests::pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa; both fail the same way on unmodifiedmaina7ec0dbon 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: passescargo test -p xcl --lib -- a_device_without_int64_typed_atomics_has_its_own_disk_entries: 1 passedgpu_image_atomics_64_biton an RX 9070 XT (RDNA4, native wave64) and an RTX 3060: it runs, with no skip on either (both report the capabilities), and passes on both; the two failures in theirgpu::run are the #2115 fuzz seeds, the same onmainOPTIONS9.AtomicInt64OnTypedResourceSupported = 0,OPTIONS11.AtomicInt64OnDescriptorHeapResourceSupported = 1): both CPU assertions passed and the GPU part reportedno int64 typed image atomics, as designed.Regression run
main (
a7ec0db, clean tree, no local changes):PR (
130815d, clean tree, no local changes):Not tested
AtomicInt64OnTypedResourceSupported/AtomicInt64OnDescriptorHeapResourceSupported(the Arc A770 report above covers the translation-level refusal and the test's skip only)XCL_DIRECT_DXIL=1) for these instructions: this PR changes the HLSL path onlyAI use
smin/smaxto nativeint64_tInterlockedMin/InterlockedMaxand moved the capability into the cache keys per review feedback, merged the change intomain's refactoredmimgarms and heap guard, wrote the tests, ran the test suite and thescripts/smoke.ps1runs, and drafted this PR description.github-bot referenced this pull request2026-11-26 04:59:09 +00:00
@upipibi on GitHub · 2026-11-24 17:34 UTC · original
Checked on NVIDIA at head
ec4c343: pass. Also a note that #1533 fixes the same issue.Tested
cargo test -p xcl --lib -- image_atomic --test-threads=1:gpu_image_atomics_64_bitpasses.gpu_image_atomics_64_bitthere).Compared with #1533 (same issue, opened earlier; both pass the test above here):
D3D12_OPTIONS9/OPTIONS11), refuses the program where the caps are missing, and bypasses the shared cache then. #1533 always emits the 64-bit form, so such a device would refuse at pipeline creation instead.gpu_image_atomics_64_bit_cmpswap_smin_inc); here onlygpu_image_atomics_64_bitruns on the GPU.mimgarms.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 on GitHub · 2026-11-24 18:43 UTC · original
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 on GitHub · 2026-11-24 18:48 UTC · original
Test report for
d9138ac2on NVIDIA (RTX 3060 Ti, 32-lane waves): passes, and the GPU check catches the bug without the fixTested
d9138ac2as is (base9e3831e), clean tree; the previous headec4c343fgave the same results.cargo test -p xcl --lib gpu_image_atomics_64_bit: 1 passed. The GPU part ran (noSKIPPED, 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).main9e3831eon the same machine: 776 passed, 0 failed, 41 ignored, same three skips.emit.rsfrom9e3831e(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, left4294967232(0xFFFFFFC0), right274877906880(0x3FFFFFFFC0): the carry into the high dword is lost.Not tested
AI use: Claude Code (Claude Opus 5.5) ran the commands and wrote this report; I checked it before posting.
@DavidM1911 on GitHub · 2026-11-24 19:12 UTC · original
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 unmodifiedmain.)Thanks!
@KainanP on GitHub · 2026-11-24 19:35 UTC · original
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 pastShaderCacheand 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
ShaderKeyand a component of thetranslated::filepath/identity. Memoisingint64_typed_atomic()in aOnceLockonce the device exists would also avoid twoCheckFeatureSupportcalls per request.AI use: Claude Code (Claude Opus 5.5) read the diff; not run. Checked by the user before posting.
@throny on GitHub · 2026-11-24 19:55 UTC · original
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 on GitHub · 2026-11-24 23:15 UTC · original
@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. Pusheda4f7834(rebased onto689f2db):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 onemainhas, so existing entries stay valid.int64_typed_atomic()asks the device once it exists and keeps the answer, instead of twoCheckFeatureSupportcalls per translation.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
689f2dbanda4f7834: 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.rsthat this PR does not have. The probe is inpso.rs.AI use: OpenCode, Claude Fable 5.2 made the change, ran the tests and wrote this comment.
@b3IKK on GitHub · 2026-11-25 00:24 UTC · original
Rebased onto
80f4819(mainhad moved the cache toshader_cache()and added a cache key to the mesh path, which now carries the capability too). Head9e1e7d3: 995 passed, 0 failed, 45 ignored, and the two smoke blocks in the description are from80f4819and this head, run one after the other. AI use: OpenCode, Claude Fable 5.2.@upipibi on GitHub · 2026-11-25 00:34 UTC · original
Re-checked the rebased head
9e1e7d3on the RTX 3070 (driver 616.56, Windows 11, debug). WithXCL_DIRECT_DXIL=0, my extended 64-bit test passes, and so does the existingimage_atomicGPU test. The extended test covers add with a carry between the halves, umax, smin of negative values, and cmpswap withGLC: one winner, and the other 63 lanes return the final value. Same result as atec4c343.AI-assisted (Claude Code).
@JJAutoCompare on GitHub · 2026-11-25 07:37 UTC · original · edited 2026-11-25 07:40 UTC
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=jsonran outside the GPU lock and exited 0. UsedXCL_ADAPTER=A770,XCL_DIRECT_DXIL=0, and the DXC directory%LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64.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 atomicson 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=0andOPTIONS11.AtomicInt64OnDescriptorHeapResourceSupported=1. I built the standalone query withcl /nologo /W4 /WX /EHsc /std:c++17 atomic-capability.cpp d3d12.lib dxgi.libin the probe directory, then ranatomic-capability.exeunder the same Arc lock. The probe and wrapper exited 0. OPTIONS9 · OPTIONS11Not 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 on GitHub · 2026-11-25 10:49 UTC · original
@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 atomicson the A770 (OPTIONS9.AtomicInt64OnTypedResourceSupported = 0). I added that to the description.One thing this PR needs before it can move:
mainhas since refactored themimgemitter (anrmw32helper and a separate arm for the operations that have no int view), and this head (9e1e7d3, based on80f4819) 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 on GitHub · 2026-11-25 10:56 UTC · original
The merge onto current
mainis done: head99d80ad, based on568e7db.mainhad since refactored themimgatomics — onermw32arm 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 newheap_bounds_tests::mimg_view_and_sampler_heap_indices_are_guardedrequires the UAV handle to be made insideif (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_bitnow skips withdirect DXIL: no 64-bit image atomicswhenXCL_DIRECT_DXIL=1, rather than failing on the direct translator's ownmimglowering, which this PR does not touch.Suite: 1156 passed, 0 failed, 46 ignored. Smoke blocks for
568e7dband99d80adare in the description. The Arc A770 result from @JJAutoCompare is in Tested. AI use: OpenCode, Claude Fable 5.2.@b3IKK on GitHub · 2026-11-25 11:06 UTC · original
Merged again, onto
a7ec0db—mainmoved 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 themimgguard (the T# handle only insideif (and(act, ok))).Head
130815d:rerouted_disk_entries_follow_the_direct_translatorandpc_resource_desc_strips_uav_on_unsupported_formats_and_msaa, fail identically on unmodifiedmaina7ec0dbon this machine, which I checked before posting; they are not from this PR.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.a7ec0dband130815dare in the description (1600 / 1639 frames, 0 crashes, 0 device removals).One caveat on the treadmill:
mainis 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 on GitHub · 2026-11-25 11:37 UTC · original
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 --workspacepassed.cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --nocapturereported 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_decandimage_atomic_subwith 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 usingcargo test --offline --locked -p xcl --lib scratch_llvm_image_atomic64_sub_and_dec -- --nocapture --test-threads=1, withXCL_DIRECT_DXIL=0andXCL_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.
@DarkPanda69 on GitHub · 2026-11-25 13:42 UTC · original
AMD run, plus an RTX 3060:
gpu_image_atomics_64_bitruns (no skip, so both drivers report the 64-bit typed-resource atomic caps) and passes on both.Head
130815dapplied onmain379725a, debug, Windows 11 Pro 26200,cargo test -p xcl --lib -- gpu:: --test-threads=4:gpu_image_atomics_64_bitok. 631 passed, 2 failed, 22 ignored, 6 SKIPPED; the 2 failures are the AMD fuzz seeds tracked in #2115, the same onmain.Not tested: the direct DXIL path (
XCL_DIRECT_DXIL=1), an adapter without the caps, a title.AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
@b3IKK on GitHub · 2026-11-25 15:17 UTC · original
Thank you — that closes the AMD gap: gpu_image_atomics_64_bit runs and passes on an RX 9070 XT with native wave64, and on an RTX 3060, with no skip on either, so both adapters report AtomicInt64OnTypedResourceSupported and the descriptor-heap capability. I added that to Tested and dropped AMD from Not tested; the two failures in your run are the #2115 fuzz seeds and are the same on main.
Still untested here: an adapter without the capabilities (the Arc A770 report covers the translation-level refusal only) and the direct DXIL path. AI use: OpenCode, Claude Fable 5.2.
@ -2991,0 +2995,4 @@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;"@gut0to on GitHub · 2026-11-24 17:27 UTC · original
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
_cas the old value. That silently drops updates for 64-bitsmin,smax,inc, ordec. Please handle exhaustion as a failure or keep retrying. AI-assisted review: I checked the generated loop and its failure path.@DavidM1911 on GitHub · 2026-11-26 05:48 UTC · original
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.@gut0to on GitHub · 2026-11-24 17:27 UTC · original · reviewed
AI-assisted review (GPT-6): I verified the failure path in the generated 64-bit compare-exchange loop.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.