Skip to content

Recompiler: on a macOS host, s_barrier is the native group barrier by default - #2363

Draft
vakaobr wants to merge 2 commits into
xcl-dev:mainfrom
vakaobr:recompiler/mac-native-barrier
Draft

vakaobr wants to merge 2 commits into
xcl-dev:mainfrom
vakaobr:recompiler/mac-native-barrier

Conversation

@vakaobr

@vakaobr vakaobr commented Nov 25, 2026

Copy link
Copy Markdown

Stacked on #2361; only the top commit belongs here.

On a macOS host (CrossOver / D3DMetal), multi-wave Compute and Mesh s_barriers now use the native GroupMemoryBarrierWithGroupSync by default instead of the emulated spin barrier xcl_s_barrier. On D3DMetal, in a 1024-thread group in the split form, the waves spinning in xcl_s_barrier starve the one wave still working (its loop ran about 1000 times slower) until the spin's 2^20-poll bound gives up and threads read LDS before it is written: wrong output, or the hang at world entry reported in #258. The native barrier was correct in every case I tried, including waves that already ran s_endpgm, LDS exchange across the split-wave64 halves, barriers in loops and partial console waves. Windows keeps the spin barrier.

Part of #258.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: safe_barrier_enabled(). XCL_SAFE_BARRIER=0 / 1 decides; by default the spin barrier everywhere except on a macOS host (util::mac_host, Memory: detect a macOS host under Wine (mac_host) #2361).
  • crates/xcl/src/gpu/recomp/tests.rs: new GPU test gpu_s_barrier_1024_threads_waits_for_working_waves (1024 threads, every wave runs 1000 v_readfirstlanes, then reads the LDS word of the farthest wave after the barrier); gpu_safe_s_barrier_multi_warp_and_early_endpgm asks safe_barrier_enabled() whether to expect xcl_s_barrier().

Tested

  • MacBook Pro M5 Pro, macOS 27.2.1, CrossOver 26.3.0, D3DMetal 3.0, Rust 1.100.0 x86_64-pc-windows-gnu, debug, DXC 1.9.2609, at c917219 (on Memory: detect a macOS host under Wine (mac_host) #2361's 6d6a3e3, on main 65fc114).
  • Built with cargo test -p xcl --lib --target x86_64-pc-windows-gnu --no-run; each test in its own process: wine --bottle xcl-test <exe> --exact <test> --test-threads=1 --nocapture.
  • The 4 tests with barrier in their name, on the base commit (with only the new test added) and on this commit:
    • gpu_s_barrier_1024_threads_waits_for_working_waves: base fails (64 threads read their partner's LDS word before it was written), this commit passes. With XCL_SAFE_BARRIER=1 on this commit it fails again (128 threads).
    • gpu_safe_s_barrier_multi_warp_and_early_endpgm: passes on both, and with XCL_SAFE_BARRIER=1.
    • split_wave64_dead_scc_skips_exchange_barrier: passes on both.
    • gpu::dxil::ops_tests::groupshared_barrier_and_atomics_run: fails on both, with the same assertion (ops_tests.rs:398); it does not go through the HLSL emitter.
  • No SKIPPED tests.

Regression run

  • None: I have no title of my own to run scripts/smoke.ps1 on.

Not tested

AI use

  • Claude Code with Claude Opus 5.5 found the cause on D3DMetal, wrote the change and the test, ported them onto main, checked open PRs for overlap, ran the tests above and wrote this description.

util::mac_host(): the process runs under Wine on a Mac (CrossOver or the
Game Porting Toolkit), where D3D12 is Apple's D3DMetal and the title's
code runs through Rosetta 2. ntdll's wine_get_host_version names the
host's system; "Darwin" is a Mac. XCL_MAC_HOST=1 / 0 overrides it.

Nothing calls it yet. The Mac changes that need to know they run there
(the barrier default, title textures on shared pages) build on it; until
now only Ahmet-Dedeler's mac7 branch had it. Part of xcl-dev#258.
… default

xcl_s_barrier (the LDS spin barrier for multi-wave Compute / Mesh groups)
starves the waves it waits for on D3DMetal: in a 1024-thread group in the
split form, the one wave still working ran about 1000 times slower while
the others spun, until the 2^20-poll bound gave up and the barrier let
threads read LDS early (wrong output; a hang at world entry was reported
in xcl-dev#258).  D3DMetal's GroupMemoryBarrierWithGroupSync is correct in every
case tried, including waves that already ran s_endpgm, LDS exchange
across the two halves, barriers in loops and partial console waves.

safe_barrier_enabled(): XCL_SAFE_BARRIER=0 / 1 decides; by default the
spin barrier everywhere but on a macOS host (util::mac_host).  Windows is
unchanged.

gpu_s_barrier_1024_threads_waits_for_working_waves fails without this on
the Mac (64 of 1024 threads read their partner's LDS word before it was
written) and passes with it; with XCL_SAFE_BARRIER=1 it fails again.

Part of xcl-dev#258.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant