Repository navigation
Conversation
…s them On Apple's D3DMetal (CrossOver), a program with a 64-bit atomic other than a non-returning unsigned min / max writes nothing at all, its other stores included, though the device reports 64-bit atomics (xcl-dev#983, xcl-dev#258). A title shader with a global / buffer `*_x2` atomic then computes or draws nothing. Where 32-bit atomics leave the same memory, emit those (`Options::split_int64_atomics`): - add_x2 / sub_x2: the low dword's InterlockedAdd, then the high dword's with the carry (or borrow) its old value shows. Adds commute, so the end state is exact. - and_x2 / or_x2 / xor_x2: one 32-bit op per dword. - umin_x2 / umax_x2 without GLC: the 64-bit atomic without a returned value, which D3DMetal runs. With GLC the returned old value is the two dwords' old values, which another lane's update can come between. swap, cmpswap, signed min / max, inc / dec, the float ones and umin / umax with GLC keep the 64-bit form. The option is set once per process by a probe on the title's device (InterlockedAdd64 plus a plain store; under Wine only), or by XCL_SPLIT_INT64_ATOMICS=1 / =0. It keys the translated-shader disk cache. Off (Windows drivers), the HLSL is unchanged. The window accessors get the non-returning 64-bit min / max overloads the split forms call. Tests: split_int64_atomics_emit_32_bit_atomics (the HLSL, with and without the option and with two memory windows; DXC-compiled) and gpu_split_int64_atomics (64 lanes on one cell per op: carries, borrows, one bit per lane through and / or / xor, the largest of 64 values).
|
@mikebuckets171: this is the split-forms PR from #258. When you have the time, both pairs would help: on plain |
gut0to
left a comment
There was a problem hiding this comment.
AI-assisted review; I verified the split-atomic interleaving described in the inline comment against the generated sequence.
| "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);" |
There was a problem hiding this comment.
When glc requests the old value, these two 32-bit return values are not one atomic 64-bit snapshot. For example, starting at 0x00000000_FFFFFFFF, interleaving add 1 with add 0x1_00000000 can make the first operation return 0x00000001_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.
There was a problem hiding this comment.
Right, thanks. 6a1fae4 drops 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_atomics checks that with GLC the option leaves the HLSL unchanged. AI-assisted (Claude Code, Claude Opus 5.5).
With GLC the split forms returned the two dwords' old values, which are not one 64-bit snapshot: another lane's update can come between them and give a value memory never held (gut0to's review on xcl-dev#1501: from 0x00000000_FFFFFFFF, `add 1` interleaved with `add 0x1_00000000` can return 0x00000001_FFFFFFFF). A 64-bit atomic whose old value is returned now keeps its 64-bit form, so the split forms only cover add / sub / and / or / xor and unsigned min / max without a returned value, whose end state is exact. split_int64_atomics_emit_32_bit_atomics checks that with GLC the option leaves the HLSL unchanged.
…4-atomics # Conflicts: # crates/xcl/src/gpu/recomp/mod.rs
… heap heap_windows (from main) reaches window k through the descriptor heap; the split forms go through the same accessors there.
|
Mac Current This PR Seven-PR stack base Stack plus #1501's current diff, temporary test tree On both PR heads the startup probe logged AI use: OpenCode, GPT-6 Luna ran the builds/smokes and wrote this report. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
On 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 26105de against base
mainb7aa9f3, 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 (Tests: GPU tests of 64-bit atomics skip where those atomics write nothing #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, Recompiler: memory windows from the descriptor heap (no per-access switch) #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 (comment). 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