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

Open
vakaobr wants to merge 2 commits from upstream-pr/2363 into main
vakaobr commented 2026-11-25 16:41:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vakaobr on 2026-11-25T16:41:05Z.


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.

The default goes into main's safe_barrier_wanted(), so XCL_SAFE_BARRIER still decides the same way for both translators. The refusal of the split form's geometry ES phase (#1727's pattern) is unchanged on a Mac: only XCL_SAFE_BARRIER=0 lifts it, as on main.

Part of #258.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: safe_barrier_wanted(). XCL_SAFE_BARRIER=0 / 1 decides; by default the spin barrier everywhere except on a macOS host (util::mac_host, #2361). New safe_barrier_set_off(): whether XCL_SAFE_BARRIER=0 is set.
  • crates/xcl/src/gpu/recomp/pso.rs: the compute build key's safe_barrier comes from safe_barrier_wanted(). It read the variable on its own, so on a Mac a default run and an XCL_SAFE_BARRIER=1 run would have shared keys.
  • crates/xcl/src/gpu/dxil/kernel.rs: translate_geometry refuses the split ES phase unless safe_barrier_set_off(), which is main's behaviour. Its two tests (lower_mem.rs, geometry_tests.rs) ask the same.
  • 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). Two tests that read the variable themselves now ask safe_barrier_wanted().

Tested

  • M5 Pro, macOS 27.2.1, CrossOver 26.3 (Wine) with D3DMetal, Rust 1.100, x86_64-pc-windows-gnu, debug, DXC 1.9.2609; head e69da9d on #2361's 69c0b04 on main 9dfbe3e. Base: 69c0b04 with only this PR's tests.rs.
  • 57 tests: every test with barrier in its name, all of gpu::dxil::geometry_tests and gpu::dxil::robustness_tests, geometry_export_rejected, the compute build key tests, and the two that look for xcl_s_barrier() in the HLSL. Each ran in its own process (<lib test exe> --exact <test> --test-threads=1):
run passed failed ignored
base 54 2 1
this PR 55 1 1
this PR, XCL_SAFE_BARRIER=1 54 2 1
base, XCL_SAFE_BARRIER=0 55 1 1
this PR, XCL_SAFE_BARRIER=0 55 1 1
  • gpu_s_barrier_1024_threads_waits_for_working_waves: fails on the base (128 threads read their partner's LDS word before it was written); passes with this PR, and with XCL_SAFE_BARRIER=0 on either; fails with XCL_SAFE_BARRIER=1 (128 threads).
  • gpu::dxil::ops_tests::groupshared_barrier_and_atomics_run fails in all five runs on the same assertion (ops_tests.rs:398); this switch does not reach it.
  • The ignored test is programs_left_to_the_hlsl_path_for_their_barrier_translate_and_compile (XCL_SAMPLE_BARRIER). No SKIPPED tests.

Regression run

  • None: I have no title of my own to run scripts/smoke.ps1 on. On Windows mac_host() is false, so the default there is unchanged.

Not tested

  • Windows (any GPU); the whole suite; any title, including the #258 world-entry hang.
  • On a Mac, the direct translator's barrier with the new default is covered by the unit tests above only.
  • The translation cache does not key on XCL_SAFE_BARRIER (#1409); #1413 turns it off only while the variable is set. So on a Mac, switching between the default and XCL_SAFE_BARRIER=1 can reuse the other's translations until one of them lands.

AI use

  • Claude Code with Claude Opus 5.5 found the cause on D3DMetal, wrote the change and the test, rebased it onto current main, ran the tests above and wrote this description. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:issue:5495311633 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2363). Originally posted by [vakaobr](https://github.com/vakaobr) on 2026-11-25T16:41:05Z. --- Stacked on #2361; only the top commit belongs here. On a macOS host (CrossOver / D3DMetal), multi-wave Compute and Mesh `s_barrier`s 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. The default goes into `main`'s `safe_barrier_wanted()`, so `XCL_SAFE_BARRIER` still decides the same way for both translators. The refusal of the split form's geometry ES phase (#1727's pattern) is unchanged on a Mac: only `XCL_SAFE_BARRIER=0` lifts it, as on `main`. Part of #258. **What is in it** - `crates/xcl/src/gpu/recomp/emit.rs`: `safe_barrier_wanted()`. `XCL_SAFE_BARRIER=0` / `1` decides; by default the spin barrier everywhere except on a macOS host (`util::mac_host`, #2361). New `safe_barrier_set_off()`: whether `XCL_SAFE_BARRIER=0` is set. - `crates/xcl/src/gpu/recomp/pso.rs`: the compute build key's `safe_barrier` comes from `safe_barrier_wanted()`. It read the variable on its own, so on a Mac a default run and an `XCL_SAFE_BARRIER=1` run would have shared keys. - `crates/xcl/src/gpu/dxil/kernel.rs`: `translate_geometry` refuses the split ES phase unless `safe_barrier_set_off()`, which is `main`'s behaviour. Its two tests (`lower_mem.rs`, `geometry_tests.rs`) ask the same. - `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_readfirstlane`s, then reads the LDS word of the farthest wave after the barrier). Two tests that read the variable themselves now ask `safe_barrier_wanted()`. **Tested** - M5 Pro, macOS 27.2.1, CrossOver 26.3 (Wine) with D3DMetal, Rust 1.100, `x86_64-pc-windows-gnu`, debug, DXC 1.9.2609; head `e69da9d` on #2361's `69c0b04` on `main` `9dfbe3e`. Base: `69c0b04` with only this PR's `tests.rs`. - 57 tests: every test with `barrier` in its name, all of `gpu::dxil::geometry_tests` and `gpu::dxil::robustness_tests`, `geometry_export_rejected`, the compute build key tests, and the two that look for `xcl_s_barrier()` in the HLSL. Each ran in its own process (`<lib test exe> --exact <test> --test-threads=1`): | run | passed | failed | ignored | |---|---|---|---| | base | 54 | 2 | 1 | | this PR | 55 | 1 | 1 | | this PR, `XCL_SAFE_BARRIER=1` | 54 | 2 | 1 | | base, `XCL_SAFE_BARRIER=0` | 55 | 1 | 1 | | this PR, `XCL_SAFE_BARRIER=0` | 55 | 1 | 1 | - `gpu_s_barrier_1024_threads_waits_for_working_waves`: fails on the base (128 threads read their partner's LDS word before it was written); passes with this PR, and with `XCL_SAFE_BARRIER=0` on either; fails with `XCL_SAFE_BARRIER=1` (128 threads). - `gpu::dxil::ops_tests::groupshared_barrier_and_atomics_run` fails in all five runs on the same assertion (`ops_tests.rs:398`); this switch does not reach it. - The ignored test is `programs_left_to_the_hlsl_path_for_their_barrier_translate_and_compile` (`XCL_SAMPLE_BARRIER`). No SKIPPED tests. **Regression run** - None: I have no title of my own to run `scripts/smoke.ps1` on. On Windows `mac_host()` is false, so the default there is unchanged. **Not tested** - Windows (any GPU); the whole suite; any title, including the #258 world-entry hang. - On a Mac, the direct translator's barrier with the new default is covered by the unit tests above only. - The translation cache does not key on `XCL_SAFE_BARRIER` (#1409); #1413 turns it off only while the variable is set. So on a Mac, switching between the default and `XCL_SAFE_BARRIER=1` can reuse the other's translations until one of them lands. **AI use** - Claude Code with Claude Opus 5.5 found the cause on D3DMetal, wrote the change and the test, rebased it onto current `main`, ran the tests above and wrote this description. I checked it before posting.
DavidM1911 commented 2026-11-25 19:09:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T18:50:17Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7171469587 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2363#issuecomment-7171469587). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T18:50:17Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
github-actions[bot] commented 2026-11-30 08:39:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:39:16Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7273176338 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2363#issuecomment-7273176338). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-30T08:39:16Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
vakaobr commented 2026-11-30 13:22:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vakaobr on 2026-11-30T13:22:03Z.


Please keep this open: main now uses safe_barrier_wanted in the direct translator too, so changing its default on a Mac reaches further than this PR tested. I'll rework and re-test it on current main.

<!-- greyfinch-sync:ivall/xcl:comment:7279742464 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2363#issuecomment-7279742464). Originally posted by [vakaobr](https://github.com/vakaobr) on 2026-11-30T13:22:03Z. --- Please keep this open: `main` now uses `safe_barrier_wanted` in the direct translator too, so changing its default on a Mac reaches further than this PR tested. I'll rework and re-test it on current `main`.
vakaobr commented 2026-11-30 14:44:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vakaobr on 2026-11-30T14:44:10Z.


Reworked on current main (e69da9d): the default now goes through safe_barrier_wanted(), so it reaches both translators and the build key; the split-geometry refusal stays as on main. Description updated with the test runs.

<!-- greyfinch-sync:ivall/xcl:comment:7281847598 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2363#issuecomment-7281847598). Originally posted by [vakaobr](https://github.com/vakaobr) on 2026-11-30T14:44:10Z. --- Reworked on current `main` (`e69da9d`): the default now goes through `safe_barrier_wanted()`, so it reaches both translators and the build key; the split-geometry refusal stays as on `main`. Description updated with the test runs.
Foniass commented 2026-12-01 07:56:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:56:04Z.


Triage (#1607) – head e69da9d

Stacked on #2361 (mac_host). Only the top commit, e69da9d, belongs to this PR. No other open or merged PR changes the s_barrier default on a Mac. #1793 and #1413 touch the safe barrier but do not change its default.
The PR routes the compute build key (pso.rs) through safe_barrier_wanted(), which fixes a key that would otherwise not see the Mac default. A new safe_barrier_set_off() keeps translate_geometry's refusal of the split ES phase unchanged, and on Windows nothing changes.
XCL_MAC_HOST now changes the translated HLSL but is not in cache_allowed (pso.rs) or the shaders.rs env-var list, unlike XCL_SAFE_BARRIER.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7304664552 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2363#issuecomment-7304664552). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:56:04Z. --- **Triage (#1607)** – head e69da9d Stacked on #2361 (`mac_host`). Only the top commit, e69da9d, belongs to this PR. No other open or merged PR changes the `s_barrier` default on a Mac. #1793 and #1413 touch the safe barrier but do not change its default. The PR routes the compute build key (`pso.rs`) through `safe_barrier_wanted()`, which fixes a key that would otherwise not see the Mac default. A new `safe_barrier_set_off()` keeps `translate_geometry`'s refusal of the split ES phase unchanged, and on Windows nothing changes. `XCL_MAC_HOST` now changes the translated HLSL but is not in `cache_allowed` (pso.rs) or the `shaders.rs` env-var list, unlike `XCL_SAFE_BARRIER`. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2363:upstream-pr/2363'
git switch 'upstream-pr/2363'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2363'
git switch 'upstream-pr/2363'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2363'
git switch 'upstream-pr/2363'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2363'
git switch 'main'
git merge --squash 'upstream-pr/2363'
git switch 'main'
git merge --ff-only 'upstream-pr/2363'
git switch 'main'
git merge 'upstream-pr/2363'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2353
No description provided.