Recompiler: 64-bit image atomics keep all 64 bits #1551
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!1551
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@youroot-code on GitHub · 2026-11-24 17:33 UTC · original
youroot-code:recomp/image-atomics-64-bit→main· +168 −8 · 6 files · 1 commits · openFixes #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.
github-bot referenced this pull request2026-11-26 04:59:09 +00:00
@upipibi on GitHub · 2026-11-24 17:48 UTC · original
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): #1533, #1541. 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.
@KainanP on GitHub · 2026-11-24 18:27 UTC · original
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.
@futurepro62 on GitHub · 2026-11-24 18:50 UTC · original · edited 2026-11-24 18:51 UTC
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
@DavidM1911 on GitHub · 2026-11-24 19:19 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.Thanks!
@ddaikodaiko on GitHub · 2026-11-24 20:03 UTC · original
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.
@winne42 on GitHub · 2026-11-25 07:20 UTC · original
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).@ -2485,0 +2524,4 @@format!("({t}_c == (uint64_t)0 || {t}_c > {t}_v) ? {t}_v : {t}_c - (uint64_t)1")};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:34 UTC · original
After 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.@ -2485,0 +2524,4 @@format!("({t}_c == (uint64_t)0 || {t}_c > {t}_v) ? {t}_v : {t}_c - (uint64_t)1")};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;"@youroot-code on GitHub · 2026-11-24 17:47 UTC · original
You 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".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.