Recompiler: split 64-bit atomics into 32-bit ones where the host drops them #1501
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!1501
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1501"
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?
@us3r40456 on GitHub · 2026-11-24 17:00 UTC · original
us3r40456:recompiler-split-int64-atomics→main· +217 −3 · 6 files · 4 commits · openOn D3DMetal, a program with a 64-bit atomic writes nothing at all (#983, #258), so a title shader with a global / buffer
*_x2atomic computes or draws nothing. This PR emits 32-bit atomics instead where they leave the same memory, on a host where a start-up probe finds 64-bit atomics dropped. Part of #258: it was proposed there, and Ahmet-Dedeler and vakaobr gave it a +1.What is in it
rmw64_split(emit.rs), used whenOptions::split_int64_atomicsis set and the old value is not returned (no GLC):add_x2/sub_x2become the low dword'sInterlockedAdd, then the high dword's with the carry (or borrow) that the low one's old value shows. Adds commute, so the end state is exact.and_x2/or_x2/xor_x2become one 32-bit op per dword.umin_x2/umax_x2become the 64-bit atomic without a returned value, which D3DMetal runs.swap,cmpswap, signed min / max,inc/decand the float ones keep the 64-bit form.runner::probe_int64_atomics: once, on the title's device, under Wine only, it runsInterlockedAdd64and a plain store. Where neither lands, it sets the option.XCL_SPLIT_INT64_ATOMICS=1/=0overrides it.pso.rs). With it off, the HLSL is unchanged.split_int64_atomics_emit_32_bit_atomics: the HLSL with and without the option, with GLC (unchanged by the option), with two memory windows and with the windows in the descriptor heap (heap_windows), compiled with DXC.gpu_split_int64_atomics: 64 lanes on one cell per op, covering carries, borrows, one bit per lane through and / or / xor, and the largest of 64 values.Tested
MacBook Pro, Apple M5 Pro (20-core GPU), 24 GB, macOS 27.2.1, Rosetta 2. CrossOver 26.3.0.39832 with D3DMetal 3.0. MSVC debug build, cross-built with cargo-xwin 0.24.1 (Rust 1.100.0, clang-cl / lld 23.1.6). DXC 1.9.2609.
lib unit tests, head
26105deagainst basemainb7aa9f3, one module group at a time; a group that hangs or crashes is rerun one test per process:gpu_split_int64_atomicsgets every value right on D3DMetal.The 16 integration binaries give the same outcome on both.
gpu::recompwithXCL_SPLIT_INT64_ATOMICS=1, every test one per process: the same outcomes as without it. The tests whose programs also hold acmpswap/inc/dec/ float*_x2still write nothing on D3DMetal (#983 skips them).The probe at start-up (
tests/e2e.rs, the test title on D3DMetal) logsrecompiler: a program with a 64-bit atomic writes nothing on this GPU (probe: [ffffffff, 1, 0]) – add / sub / and / or / xor and unsigned min / max without a returned value become 32-bit atomics; …. The title gets the same 29[PASS]as on the base.After merging
main9e3831e(itsheap_windowsoption, #680) and the GLC change: both tests pass on D3DMetal, and so doesgpu::recomp::heap_window_tests.Regression run
By @mikebuckets171 on a Mac (M5 Pro, CrossOver 26.3 / D3DMetal / Rosetta 2, release
x86_64-pc-windows-gnullvm, the same retail title for 60 s each), #1501. Plainmainon a Mac shows no frame of this title, so these show the probe and start-up, not the split atomics in a frame: on this PR's head the probe logsprobe: [ffffffff, 1, 0]and turns the split on, onmainit does not run. No crash, no device removal in any of the four. Windows does not take this path (the probe runs under Wine only), and the HLSL there is unchanged.main
9e3831e:PR
b24436b:The same on a stack of seven Mac PRs (
476c325) and that stack with this PR's diff (7fd3a25): the same blocks, 0 frames, no crash; the probe as above.Not tested
under_wine()), so the option stays off.AI use
@us3r40456 on GitHub · 2026-11-24 17:01 UTC · original
@mikebuckets171: this is the split-forms PR from #258. When you have the time, both pairs would help: on plain
main(baseb7aa9f3, head26105de), and stacked with the Mac port pieces you used there. As you said, the first shows nothing regressed; the second is where a wrong split or the torn GLC return would show up in the frames and draws. With this PR the start-up log should haverecompiler: a program with a 64-bit atomic writes nothing on this GPUon that host.@mikebuckets171 on GitHub · 2026-11-24 18:19 UTC · original
Mac
xcl-smokepairs (M5 Pro, CrossOver 26.3 / D3DMetal / Rosetta 2; release cross-buildcargo build --release --locked -p xcl --target x86_64-pc-windows-gnullvm; same retail title, 60 s each). The first pair is current base9e3831evs this PR's headb24436b. The second is the seven-PR Mac test stack vs that stack with this PR's current diff applied.Current
main9e3831e:This PR
b24436b:Seven-PR stack base
476c325(#89076d2ff7, #9573c43506, #9823a6f95a, #983ab7ce43, #996f242ea8, #1024699975b, #78746695ab):Stack plus #1501's current diff, temporary test tree
7fd3a25(not an upstream commit):On both PR heads the startup probe logged
probe: [ffffffff, 1, 0]and enabled the documented split for eligible atomics; neither baseline logged it. All four bounded runs exited cleanly, but showed 0 frames, so this verifies probe detection and startup only—not rendered atomic behavior or gameplay.peak commit: 0 MBwas reported by the harness and is unavailable as a memory measurement here.AI use: OpenCode, GPT-6 Luna ran the builds/smokes and wrote this report.
@DavidM1911 on GitHub · 2026-11-24 18:53 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 / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
@ -5068,0 +5089,4 @@"add" | "sub" => {let n = if op == "sub" { format!("((uint64_t)0 - {v})") } else { v.to_string() };format!("uint64_t {t}_n = {n}; uint {t}_l = 0u, {t}_h = 0u; mem.InterlockedAdd({a}, (uint){t}_n, {t}_l); mem.InterlockedAdd({a} + 4u, (uint)({t}_n >> 32) + (({t}_l + (uint){t}_n < {t}_l) ? 1u : 0u), {t}_h); {old} = (uint64_t){t}_l | ((uint64_t){t}_h << 32);"@gut0to on GitHub · 2026-11-24 17:05 UTC · original
When
glcrequests the old value, these two 32-bit return values are not one atomic 64-bit snapshot. For example, starting at0x00000000_FFFFFFFF, interleavingadd 1withadd 0x1_00000000can make the first operation return0x00000001_FFFFFFFF, although that value never existed. Please disable this split path when the old result is requested (or provide a truly atomic implementation) and cover the interleaving. AI-assisted review; I verified the generated sequence and interleaving.@ -5068,0 +5089,4 @@"add" | "sub" => {let n = if op == "sub" { format!("((uint64_t)0 - {v})") } else { v.to_string() };format!("uint64_t {t}_n = {n}; uint {t}_l = 0u, {t}_h = 0u; mem.InterlockedAdd({a}, (uint){t}_n, {t}_l); mem.InterlockedAdd({a} + 4u, (uint)({t}_n >> 32) + (({t}_l + (uint){t}_n < {t}_l) ? 1u : 0u), {t}_h); {old} = (uint64_t){t}_l | ((uint64_t){t}_h << 32);"@us3r40456 on GitHub · 2026-11-24 17:10 UTC · original
Right, thanks.
6a1fae4drops the split for every atomic whose old value is returned: with GLC the 64-bit form stays, so no value memory never held can come back. The split is now only for add / sub / and / or / xor and unsigned min / max without a returned value, where the end state is exact.split_int64_atomics_emit_32_bit_atomicschecks that with GLC the option leaves the HLSL unchanged. AI-assisted (Claude Code, Claude Opus 5.5).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.