Recompiler: 64-bit image atomics (DMASK 0x3) run as 32-bit atomics on the low dword #1485
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#1485
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@13hourstilliland on GitHub · 2026-11-24 16:50 UTC · original
What happens. An MIMG image atomic with DMASK 0x3 (0xF for
image_atomic_cmpswap) works on 64 bits: VDATA[0:1] against the texel's two dwords. That's LLVM'sSIISelLowering.cpp:10634-10638at7292bcac6ac8:DMask = Is64Bit ? 0xf : 0x3for cmpswap,Is64Bit ? 0x3 : 0x1for the others.The image atomic arms in
mimgnever read DMASK (crates/xcl/src/gpu/recomp/emit.rs:2485-2517atb7aa9f3;dmaskis read at:2069and used only by the load/sample and gather paths). Each atomic:RWTexture<uint>/<int>view (:2511)self.vreg(vdata)(:2508)Interlocked*or 32-bit CAS loop, and with GLC returns one dword (:2514-2516)The program counts as translated, so nothing shows up in the unsupported list or the shader statistics.
Measured on main. A GPU test in
tests.rs, next togpu_images_sample_load_store_atomicand in the same style (patch below). 64 lanes runimage_atomic_addandimage_atomic_umaxwith DMASK 0x3 on one texel of a 1x1R32G32_UINTtexture (console 32_32_UINT, format 62,desc.rs:111):(l << 32) | (1000 - l)per lane, so the largest u64 is lane 63's, not the largest low dwordOn
b7aa9f3:So the add drops the carry, and the max picks the lane with the largest low dword (1000, lane 0) instead of the largest 64-bit value.
The test passes if the program is refused, or if both 64-bit results are right. I checked both outcomes with temporary
emit.rsedits, reverted afterwards:Interlocked*arm (auint64_tview, VDATA[0:1] packed into one value): passes on the GPUThe rough version is not a fix: no GLC return, no CAS arm, no capability check.
Where it matters (from another project's count, not measured here). VIctory refuses these programs explicitly (
crates/victory-shader/src/emit/lower.rs:5674-5681, "a 64-bit image atomic"). Its census of the same retail shader pack, 26,503 records like ours, counts 653 programs that stop there (Marvisak/VIctory#748, Marvisak/VIctory#885). I haven't counted them in XCL. If they are the same programs, XCL translates them with the 32-bit form.What a fix needs (inferred).
uint64_t/int64_tview of formatR32G32_UINT(SM 6.6 int64 atomics). That's already the view XCL makes for 32_32_UINT.D3D12_OPTIONS9.AtomicInt64OnTypedResourceSupported. Because the views come fromResourceDescriptorHeap, they also needD3D12_OPTIONS11.AtomicInt64OnDescriptorHeapResourceSupported. The RTX 3070 below reports both, and groupshared, as supported.The fix is runtime code, so it needs a smoke run on a title. I can't do that one, but I can run the test on a fix branch.
Tested
x86_64-pc-windows-gnu(GNU toolchain, not MSVC), DXC 1.9.2609.5, debug buildb7aa9f3plus the test patch only (tests.rs)cargo test -p xcl --lib gpu_image_atomics_64_bit -- --nocapture --test-threads=1: 0 passed, 1 failed (output above). With each temporary edit: 1 passed.gpu_images_sample_load_store_atomicon the same tree: 1 passedNot tested. AMD / native wave64; the cmpswap and GLC paths; the full suite; any retail run. Which of the programs above affect the picture is unknown.
The test (patch on
b7aa9f3, tests.rs only)AI use. Hermes Agent with Claude Opus 5.5 compared the code with VIctory's, wrote the test and the temporary checks, ran them on my PC and wrote this issue.
github-bot referenced this issue2026-11-26 04:57:15 +00:00
github-bot referenced this issue2026-11-26 04:59:09 +00:00
@youroot-code on GitHub · 2026-11-24 17:32 UTC · original
Claiming this one, measured on the RTX 4060 here.
Plan:
emit.rs: a new arm ahead of the 32-bit ones forDMASK 0x3(0xf forcmpswap) — VDATA[0:1] packed into oneuint64_tagainst aRWTexture<D3D12>view of the console32_32_UINTtexel, withInterlockedAdd/Min/Max/And/Or/Xor/ExchangeandInterlockedCompareExchange, auint64_tCAS loop forinc/dec, and the GLC return in VDATA[0:1].D3D12_OPTIONS9::AtomicInt64OnTypedResourceSupportedandD3D12_OPTIONS11::AtomicInt64OnDescriptorHeapResourceSupported, asked once when the device is created and carried inOptions::image_atomic64. Without them the program is refused (image_atomic_64) instead of run on the low dword, as you suggest.gpu_image_atomics_64_bit, extended so it also asserts the refusal case is the one taken when the adapter reports no int64 typed atomics.Not in it: 64-bit
smin/smax/fmin/fmax(refused for now), and the offlinexcl shaderspath has no device, so it refuses these programs too.I have an unpacked retail title here, so the smoke run is possible; I'll post the
xcl-smokeblock once the PR is up.AI use: Freebuff (Buffy) — the exact model name is not known to me; the measurement and this comment were produced with it.
@youroot-code on GitHub · 2026-11-24 17:33 UTC · original
Draft PR for this: #1551 (
recomp/image-atomics-64-bit).The regression run (
scripts/smoke.ps1) is still pending; I will paste thexcl-smokeblock here and on the PR once it is done.@ddaikodaiko on GitHub · 2026-11-24 18:57 UTC · original · edited 2026-11-24 19:37 UTC
Test report + local fix for #1485 — 64-bit image atomics (DMASK 0x3)
Tested
32.0.16.108810.0.19045.78461.620.2(%LOCALAPPDATA%\XCL\D3D12)1.8.2502.11(Windows SDK10.0.26100.0)1.100.0x86_64-pc-windows-msvc, releasemainc160d86+ local commit615a4f5(fix branchlocal/int64-image-atomics, rebased after the repo moved toxcl-dev/xcl)cargo test -p xcl --lib --release gpu_image_atomics_64_bit -- --nocapture: 1 passed, 0 failed. The issue's own test (add + umax on a 1x1R32G32_UINTUAV, every lane hitting the same texel) now gives0x0000003fffffffc0/0x0000003f000003a9.D3D12: 64-bit typed image atomics: supported.cargo test --workspace --release -- --test-threads=4: 859 passed, 0 failed, 42 ignored, 2 SKIPPED (no wave64). The existinggpu_images_sample_load_store_atomic(32-bit atomics, including the 32-bit cmpswap DMASK 0x3 path) still passes.mainthe issue's test fails exactly as reported on the RTX 3070 (add loses the carry, umax orders by the low dword); that measurement is the issue's, not repeated here.What the local fix does
Options::int64_image_atomics, set once inreal::initfromD3D12_OPTIONS9::AtomicInt64OnTypedResourceSupportedandD3D12_OPTIONS11::AtomicInt64OnDescriptorHeapResourceSupported(the views come fromResourceDescriptorHeap).Options::defaultreads it, so VS / PS / CS / mesh / geometry all get it.emit.rs, MIMG atomics: DMASK 0x3 (non-cmpswap) and 0xF (cmpswap) are no longer silently 32-bit. The non-cmpswap ops (add,sub,smin/umin,smax/umax,and,or,xor,swap,inc,dec) declare auint64_t/int64_ttyped view, pack VDATA[0:1], useInterlocked*, and put the GLC old value back in VDATA[0:1]. Without the device caps the program is refused (image_atomic 64-bit (no int64 typed atomics)), not mistranslated.fcmpswap/fmin/fmax) and2DMSare refused with a reason; 32-bit cmpswap (DMASK 0x3) and every other 32-bit atomic keep their existing path. Any other DMASK is refused instead of guessed.Not tested
fmin/fmax64-bit (refused), AMD / native wave64, a retail title /xcl-smoke.XCL_DIRECT_DXIL=1); the HLSL path is the default. The patch is prepared locally for a human / frontier-model contributor to submit under the project rules.AI use: OpenCode with DeepSeek V4.1 Flash wrote the fix and the GPU test, ran them on the machine above and drafted this report; every number is from those runs.
@ddaikodaiko on GitHub · 2026-11-24 23:48 UTC · original
Direct-DXIL path verified on the Windows GPU box (RTX 3060 Ti 8 GB, driver 32.0.16.1088, DXC 1.8.2502.11), branch
contrib/int64-image-atomicsrebased onmainb9b6ea6:gpu_image_atomics_64_bitpasses.XCL_DIRECT_DXIL=1(the opt-in translator from #1426): passes.3a5f88a) reverted and everything else kept, the same test fails attests.rs:2507- so it really goes through the DMASK 0x3 64-bit typed-atomic path and not the old behaviour.The first version of my verification script used
upstream/mainas the negative control; that is not valid, because the test only exists on the branch (cargo test <name>ran 0 tests and exited 0). Reverting just the port is the correct control, and it fails as it should.Note for whoever can open the PR: I cannot submit one myself (the project does not accept PRs produced with DeepSeek models), but the branch and the per-commit patches are ready to be picked up.
@iGoldenNinja on GitHub · 2026-11-25 00:12 UTC · original · edited 2026-11-25 02:58 UTC
I measured this on an RTX 5080, NVIDIA 617.14, Windows 11 build 26200, using XCL
e9e94ceand DXC 1.9.2609.5.In a selected subset of the 1.0.2.1 shader pack, I found 169 pixel-shader records with this form of 2D unsigned max, representing 168 distinct containers and 259 instruction sites after deduplication. Each site had DMASK 3 and GLC clear. This is a lower bound from the readable subset at the time of collection.
Stock XCL marked all 168 complete. A local change limited to that 2D UMAX form packed both source words and used a 64-bit typed UAV. All 168 then compiled as ps_6_6, and each shader's count of i64 UMAX calls in DXIL matched its native site count. In one example the upper word comes from pixel depth, so two fragments with different depths can exchange order when that word is dropped.
I also replayed that example’s stock and corrected emitted instruction blocks in single-thread D3D12 kernels, using the supported UAV format for each width. With an initial key of
0x3E800000FFFFFFFFand candidate0x3F40000000000003, the stock 32-bit operation kept0xFFFFFFFF; the corrected one wrote0x3F40000000000003. This measured the selected instruction under controlled inputs. Scene rendering and the proposed PR branches were outside this test.AI-assisted testing with OpenAI Codex (GPT-6).
Update after the verified download completed. My named-record scanner successfully unpacked 26,503 records. Filtering for reachable 2D image UMAX with two words and GLC clear yielded 682 pixel records, 676 distinct pixel containers, and 945 instruction sites across those distinct containers. All 168 previously tested containers are in that set. The 945 is a native instruction count. The earlier per-container DXIL validation covered the original 168.
I also ran an original two-instruction synthetic test on both XCL translation routes, with a narrow control and wide cases with GLC clear and set. On main at
80f48190both wide cases compiled to i32 on both routes. At #1541 (a4f78345) they compiled to i64 on the HLSL route. At #1948 (1e4f2bda) they compiled to i64 on the direct DXIL route. The narrow control stayed i32 on all six combinations, and all 18 modules passed DXIL validation. This measures the emitted atomic width. Reproducible fixture, exact commits and disassemblies.Re-ran the public synthetic fixture against main
cbc296abwith DXC and the DXIL validator 1.9.2609.5. All six modules validated. TheDMASK=1control is still i32. BothDMASK=3cases (GLC 0 and 1) still emit i32 in the HLSL and direct DXIL backends where i64 is expected. Observed emitted width and validation; this rerun did not perform GPU readback. Revision-specific result. AI-assisted with OpenAI Codex.