Recompiler: 64-bit image atomics keep all 64 bits #1541
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1551"
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?
Imported from ivall/xcl. Originally posted by youroot-code on 2026-11-24T17:33:08Z.
Fixes #1485.
A console image atomic whose DMASK covers two dwords works on 64 bits: VDATA[0:1] against the
texel's two dwords (LLVM's
SIISelLowering:DMask = Is64Bit ? 0x3 : 0x1,0xf : 0x3forcmpswap). Themimgatomic arms never read DMASK, so such an atomic ran as a 32-bit one on thelow dword, and the program still counted as translated: an add lost its carry, and a max ordered
by the low dword.
On a PC the operation needs SM 6.6 int64 atomics on a typed resource — a
uint64_tview of theconsole
32_32_UINTtexel'sR32G32_UINTformat — on a descriptor-heap resource as well, sincethe views come from
ResourceDescriptorHeap.What is in it
gpu/recomp/emit.rs: a newmimgarm ahead of the 32-bit ones, fordmask == 0x3(0xfforcmpswap). It packs VDATA[0:1] into oneuint64_tand emitsInterlockedAdd(also forsub,as an add of the negation),
InterlockedMin/Max/And/Or/Xor/Exchange, a 64-bitInterlockedCompareExchangeforcmpswap, and the 32-bit form's CAS loop onuint64_tforinc/dec(the hardware has neither). GLC returns the old value in VDATA[0:1].gpu/recomp/pso.rs:image_atomic64_for_device, askingD3D12_OPTIONS9::AtomicInt64OnTypedResourceSupportedand
D3D12_OPTIONS11::AtomicInt64OnDescriptorHeapResourceSupported; the result is kept in astatic (set once from
hle/d3d12x/real.rswhen the device is created) and read asOptions::image_atomic64by the compute / VS / PS, geometry and mesh translation paths.image_atomic_64, an unsupported entrywith its reason) instead of being run on the low dword.
gpu/recomp/runner.rs: the test GPU reports the two flags, andrunner::optionscarries them,so kernel tests translate as the adapter can.
gpu/recomp/tests.rs:gpu_image_atomics_64_bit(the program and expectations from the issue):image_atomic_addof0xFFFFFFFFper lane must carry into the high dword,image_atomic_umaxof
(l << 32) | (1000 - l)must pick lane 63. It also asserts that the refusal is only takenwhen the adapter reports no int64 typed atomics, so it cannot pass by refusing on hardware that
has them.
Not in it: 64-bit
smin/smax(signed view) andfmin/fmax/fcmpswap— there are no64-bit float atomics on a typed resource, and the signed view is a separate change; those are
refused with the same reason for now. The offline
xcl shaderspath has no device, so it refusesthese programs too (they show up in its unsupported list).
Tested
73e7403, rebased ontomain9e3831e(#680). The only conflict wasOptions::default, whereheap_windowsandimage_atomic64now sit side by side.26200; rustc 1.92.0 (
stable-x86_64-pc-windows-msvc), debug; DXC 1.9.2602.17 (SDK 10.0.28000.0).cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4on73e7403: 775 passed, 2 failed, 41 ignored. Both failures are this machine's, and both failon unmodified
mainhere as well:hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory: the test's[u8; 64]buffer is misaligned for
VirtualQueryEx(ERROR_NOACCESS998) — #650 / #656.test_title_draws_with_a_root_signature_under_the_debug_layer: no device is made with thedebug layer on here (
System32\d3d12SDKLayers.dll10.0.26100.1 againstD3D12Core.dll10.0.26100.7309), so XCL falls back to the null device.
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);set_predication_buffer_state_and_kickoff(no GPU).cargo test -p xcl --lib gpu_image_atomics_64_bit -- --test-threads=1: 1 passed; theadapter reports both capabilities, the program is translated and runs on the GPU, and both
results match.
b7aa9f3), thesame test fails with the values from the issue —
image_atomic_add 64-bit: 0x00000000ffffffc0, want 0x0000003fffffffc0andimage_atomic_umax 64-bit: 0x00000000000003e8, want 0x0000003f000003a9(0 passed, 1 failed).gpu_images_sample_load_store_atomic(the 32-bit paths) still passes.Not tested
cmpswap,inc/decand GLC 64-bit paths on a GPU (they are emitted, not exercised bythe test above).
Regression run
From
main(9e3831e):From this PR's head (
73e7403):Both are 60 s of the same title, release build,
XCL_NETWORK=0.AI use
Freebuff (Buffy) — the exact model name is not known to me. It wrote the change, ran the tests and
measured the failing case on the machine above; the failing test, the program and its expectations
come from the issue's reporter.
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T17:34:39Z.
Review: COMMENTED
AI-assisted review (GPT-6): I verified the bounded compare-exchange loop and post-loop handling in the current diff.
Imported from ivall/xcl. Originally posted by youroot-code on 2026-11-24T17:47:02Z.
Review: COMMENTED
No description provided.
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T17:48:00Z.
Note: #1485 already has #1533 and #1541, both opened earlier. Both pass on an RTX 3070, together with an extended test of mine (64-bit add / umax / smin, cmpswap with GLC, and a 32-bit cmpswap next to them that must leave the high dword alone): https://github.com/xcl-dev/xcl/pull/1533#issuecomment-7139403027, https://github.com/xcl-dev/xcl/pull/1541#issuecomment-7139403614. This PR is an implementation of its own, not a copy; I haven't run it. Only one of the three can land in the
mimgatomic arms.AI use: Claude Code (Claude Opus 5.5) compared the diffs and wrote this.
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T17:34:39Z.
Code review location:
crates/xcl/src/gpu/recomp/emit.rs; line 2527After 4096 failed compare-exchanges this loop exits and still reports
_cas the old value, so the 64-bit increment or decrement is silently dropped under sustained contention. Please retry until the compare-exchange succeeds, or report failure on exhaustion. AI-assisted review: I verified there is no success check after the bounded loop.Imported from ivall/xcl. Originally posted by youroot-code on 2026-11-24T17:47:02Z.
Code review location:
crates/xcl/src/gpu/recomp/emit.rs; line 2527You are right that the increment is dropped when the loop runs out, and that
_oldthen holds the last observed value rather than the old value of a completed write.The bound is deliberate and older than this PR.
rmw32(thecasclosure,emit.rs) and the 64-bit buffer path (rmw64, same file) both run the same[allow_uav_condition] for (uint i = 0u; i < 4096u; i++)compare-exchange loop, andHANDOFF.mdrecords the design as "a bounded CAS loop (4096)". Retrying without a bound on a typed atomic is a hang risk: a wave spinning on one texel can outlive the TDR timeout and you get a device removal instead — and the regression run measures device removals, so a hang is worse than a lost increment on a path that needs 4096 lost races in a row.Reporting the failure has no channel in the generated HLSL: the shader cannot return an error, and the only "report" would be a write to a debug buffer, which nothing reads on a title run.
So I kept 64-bit
inc/decbyte-for-byte with the existing loops rather than make one path behave differently. If the exhaustion should be handled, it is one change over all three loops (rmw32,rmw64, and this one) and I am happy to open it — but it changes paths this PR does not touch, and the repo asks for one logical change per PR.On coverage: the test does not exercise 64-bit
inc/decat all (it usesaddandumax), which the description lists under "Not tested".Imported from ivall/xcl. Originally posted by KainanP on 2026-11-24T18:27:30Z.
Read at
73e7403while doing the #1607 duplicate check (D9). The 64-bit arm seems to catch 32-bitimage_atomic_fcmpswap:fcmpswapis a compare-swap too: its 32-bit form already uses DMASK0x3(data + compare), like 32-bitcmpswap. Since only the exact string"cmpswap"gets0xF, a 32-bitfcmpswapwith0x3matches this arm and is refused withimage_atomic_64, wheremaintranslates it in the 32-bit path. Testingbase[7..].ends_with("cmpswap")(ormatches!(.., "cmpswap" | "fcmpswap")) for the0xFcase would keep it on the 32-bit path; a translation test of a 32-bitfcmpswapwould catch it.AI use: Claude Code (Claude Opus 5.5) read the diff; not run. Checked by the user before posting.
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T18:50:23Z.
Full-suite run, since this PR has no test report yet. Tested exact head
73e7403(on its base9e3831e).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form: 776 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.gpu_image_atomics_64_bit.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 777 passed, 0 failed, 41 ignored. SKIPPED:heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).heap_window_out_of_memory_falls_back_to_the_switch_formwas skipped with--skip. It fails on main9e3831etoo, not because of this PR: underXCL_REQUIRE_GPU=mesh,runner::skip_testturns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (XCL_HEAP_WINDOWSunset). Reported as #1651.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T19:19:19Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.Thanks!
Imported from ivall/xcl. Originally posted by ddaikodaiko on 2026-11-24T20:03:00Z.
The main fix reads right, but the new arm's guard has one hole around
fcmpswapthat I think you want to close before merge. The guard is:fcmpswapnever satisfies the0xFcase because the comparison is against"cmpswap"exactly, so:image_atomic_fcmpswap(DMASK 0x3, VDATA[0]=compare, VDATA[1]=value) takes theelse { 0x3 }branch, enters the new 64-bit arm, and is then refused bymatches!(op, "fmin" | "fmax" | "fcmpswap")asimage_atomic_64. That is a program the currentmaintranslates (the genericrmw32arm below already handlesfcmpswapwithends_with("cmpswap")in the dmask guard), so it turns into a new unsupported entry, not a refusal of a 64-bit form.fcmpswap(DMASK 0xF, if such an encoding ever appears) matches neither side of the guard and falls through to the same 32-bitrmw32arm, i.e. it still runs on the low dword rather than being refused as your description says.Using
ends_with("cmpswap")in both terms fixes both directions:which is also what the fork branch I have does; the same expression is in
gpu/dxil/lower_image.rsfor the direct translator.Two more things that may be useful:
crates/xcl/src/gpu/dxil/lower_image.rs, theatomic_arm) has the same original bug and this PR does not touch it, so withXCL_DIRECT_DXIL=1the issue remains. I have an unverified port for it inddaikodaiko/xclcontrib/int64-image-atomicsca1b79f(U64/I64 typed heap view,heap_typed_atomic64(),pack64/unpack64, same refusals); the existing test withXCL_DIRECT_DXIL=1should pin it.smin/smax: refusing them is a documented scope choice here, but the signed view is only anint64_tvariant of the sameuint64_tarm, and the HLSL fix I have runs them that way; worth a line in the "not in it" list saying the console op exists so the program is lost until then.AI use: written with OpenCode (DeepSeek V4.1 Flash); a person submitting any of this is responsible for running it.
Imported from ivall/xcl. Originally posted by winne42 on 2026-11-25T07:20:23Z.
The new arm in
mimgtakes the compare-swap DMASK (0xF) only forcmpswap, not forfcmpswap(LLVM'sSIISelLoweringgives both the0xf : 0x3form). Two effects at head73e7403:IMAGE_ATOMIC_FCMPSWAP(DMASK 0x3) now enters the 64-bit arm and is refused (image_atomic_fcmpswap), with or withoutimage_atomic64.maintranslates it.IMAGE_ATOMIC_FCMPSWAP(DMASK 0xF) does not enter the arm and still runs on the 32-bit path, counted as translated.maingained a test that uses the first case (gpu_float_cas_uses_ieee_equality,990b9d4, after this PR's base). With this PR merged ontomain568e7db(no textual conflict), it fails:mainalone passes it (1 / 0), and this PR's owngpu_image_atomics_64_bitpasses at its head and on the merge, on the 64-bit path (the adapter reports int64 typed atomics). The two cases above come from a translate-only probe on the head (a temporary test, not kept).Linux, Wine 10.0 + vkd3d-proton, NVIDIA RTX 3050 Laptop (driver 580.178.04), DXC 1.9.2609.5, Rust 1.98.1 (
x86_64-pc-windows-gnu), debug; part of the D9 check on #1607. Written with Claude Code (Claude Opus 5.5).Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T20:44:20Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:05:01Z.
Triage (#1607) – head
73e7403Same issue (#1485) as #1533 and #1541. #1533 emits the 64-bit atomics without a capability check. This PR and #1541 both probe OPTIONS9/OPTIONS11 and refuse the program without them, but #1541 also puts the capability into the translated-cache and in-memory keys. This PR does not:
pso.rs:translated::filestill keys on blob/stage/sampler_base/windows/split only, so a cache directory reused on an adapter without the capability can load a 64-bit-atomic DXIL.gpu_image_atomics_64_bitis the same test as #1533's.The branch predates the
{t}_okT# guard on main. On rebase, the new arm inemit.rsmust create the UAV underand({act}, {t}_ok)like the other image-atomic arms do.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.