Opt-in Wave32 cross-half LDS barrier reduction (DARNER_WAVE32_LDS_OPT) #546

Open
davetheshrew wants to merge 3 commits from davetheshrew/Darner:pr/wave32-lds-barrier-opt into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: read from the code only — when emulating Wave64 shaders on 32-lane hosts (NVIDIA), cross-half exchanges emit GroupMemoryBarrierWithGroupSync() pairs around each LDS handoff even when a phase has no intervening LDS writes/atomics or when two 32-bit half-exchanges can be coalesced, adding unnecessary workgroup synchronization stalls on Wave32 compute/lighting shaders.

Adds an opt-in shader lowering switch DARNER_WAVE32_LDS_OPT=1 (off by default, and always a no-op on 64-lane/AMD hosts where host_max_wave() != 32):

  • darner-shader (lower.rs, lower/analysis.rs, lower/tests.rs):
    • Coalesces paired 32-bit cross-half exchanges (exchange_halves) into a single barrier pair instead of two.
    • Tracks LDS writes / returning atomics per phase in lower/analysis.rs so acyclic cross-half exchanges can omit redundant trailing barriers when no conflicting LDS access follows.
    • Adds unit tests (wave32_lds_opt_reduces_barriers_on_wave32_and_is_noop_on_amd_wave64 and wave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchange) covering Wave32 reduction and Wave64 no-op behavior.
  • darner-gpu (shader_cache.rs):
    • Keys DARNER_WAVE32_LDS_OPT in KEYED so shaders compiled with the switch on/off are cached separately.
  • F1 menu & locales (host/menu.rs, locales/en.json, locales/zh-CN.json):
    • Exposes WAVE32 LDS BARRIER OPT (DARNER_WAVE32_LDS_OPT, default OFF, restart-required) under F1 → ADVANCED with English and Simplified Chinese help text.

How it was tested

  • Tested revision: e7f5d8b

  • Commands and results: built release binary locally on Windows (cargo build --release succeeded after keying KEYED: [&str; 61]).

  • Changes a default: no (off by default; opt-in via DARNER_WAVE32_LDS_OPT=1 or F1 → ADVANCED → WAVE32 LDS BARRIER OPT; always disabled on Wave64 hosts).

  • A/B result: tested in-game with the switch OFF vs ON (restart between runs so shaders recompile). Frame pacing felt slightly smoother when running around, with no noticeable average FPS jump on a non-GPU-bound setup (as expected for a shader-barrier-only optimization when CPU/submit-bound).

    A (off) B (on)
    Scene / FPS / frame time
  • Gates run on that revision (the three in AGENTS.md; there is no CI), or "none": none

  • Gameplay, when relevant:

  • Shader wave sizes tested, when relevant: 32 lanes (NVIDIA); 64-lane path is guarded by host_max_wave() == 32 and covered by unit test.

  • Hardware dependence: Wave32 hosts (NVIDIA) only; intentionally a no-op on AMD Wave64 GPUs.

  • Coverage gaps: AMD Wave64 hardware not runtime-tested (verified by code guard and unit test); needs GPU-bound Wave32 benchmarking before considering changing the default.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: <!-- paste your Fluxer ID if you want the Contributor role, or delete this section --> ## What it changes - The problem on main: read from the code only — when emulating Wave64 shaders on 32-lane hosts (NVIDIA), cross-half exchanges emit `GroupMemoryBarrierWithGroupSync()` pairs around each LDS handoff even when a phase has no intervening LDS writes/atomics or when two 32-bit half-exchanges can be coalesced, adding unnecessary workgroup synchronization stalls on Wave32 compute/lighting shaders. Adds an opt-in shader lowering switch `DARNER_WAVE32_LDS_OPT=1` (off by default, and always a no-op on 64-lane/AMD hosts where `host_max_wave() != 32`): - **`darner-shader` (`lower.rs`, `lower/analysis.rs`, `lower/tests.rs`):** - Coalesces paired 32-bit cross-half exchanges (`exchange_halves`) into a single barrier pair instead of two. - Tracks LDS writes / returning atomics per phase in `lower/analysis.rs` so acyclic cross-half exchanges can omit redundant trailing barriers when no conflicting LDS access follows. - Adds unit tests (`wave32_lds_opt_reduces_barriers_on_wave32_and_is_noop_on_amd_wave64` and `wave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchange`) covering Wave32 reduction and Wave64 no-op behavior. - **`darner-gpu` (`shader_cache.rs`):** - Keys `DARNER_WAVE32_LDS_OPT` in `KEYED` so shaders compiled with the switch on/off are cached separately. - **F1 menu & locales (`host/menu.rs`, `locales/en.json`, `locales/zh-CN.json`):** - Exposes **WAVE32 LDS BARRIER OPT** (`DARNER_WAVE32_LDS_OPT`, default OFF, restart-required) under **F1 → ADVANCED** with English and Simplified Chinese help text. ## How it was tested - Tested revision: `e7f5d8b` - Commands and results: built release binary locally on Windows (`cargo build --release` succeeded after keying `KEYED: [&str; 61]`). <!-- Replace or add `cargo test` results if you run them locally --> - Changes a default: no (off by default; opt-in via `DARNER_WAVE32_LDS_OPT=1` or **F1 → ADVANCED → WAVE32 LDS BARRIER OPT**; always disabled on Wave64 hosts). - A/B result: tested in-game with the switch OFF vs ON (restart between runs so shaders recompile). Frame pacing felt slightly smoother when running around, with no noticeable average FPS jump on a non-GPU-bound setup (as expected for a shader-barrier-only optimization when CPU/submit-bound). <!-- Fill in exact F2 numbers if you capture a side-by-side GPU-bound scene --> | | A (off) | B (on) | |---|---|---| | Scene / FPS / frame time | <!-- e.g. X fps / Y ms --> | <!-- e.g. X fps / Y ms --> | - Gates run on that revision (the three in AGENTS.md; there is no CI), or "none": none <!-- Run `cargo fmt --check`, `cargo clippy`, and `cargo test` locally and update this line if desired --> - Gameplay, when relevant: <!-- fill in your GPU, Series X or S profile, resolution, DLSS, frame generation, ray tracing --> - Shader wave sizes tested, when relevant: 32 lanes (NVIDIA); 64-lane path is guarded by `host_max_wave() == 32` and covered by unit test. - Hardware dependence: Wave32 hosts (NVIDIA) only; intentionally a no-op on AMD Wave64 GPUs. - Coverage gaps: AMD Wave64 hardware not runtime-tested (verified by code guard and unit test); needs GPU-bound Wave32 benchmarking before considering changing the default. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [ ] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found - Replaces or overlaps: none found
Author
Contributor

ive ran it, changing the setting live does effect latency but i have to go out today if someone could please do a/b test id be most greatful. Thankyou

ive ran it, changing the setting live does effect latency but i have to go out today if someone could please do a/b test id be most greatful. Thankyou
davetheshrew force-pushed pr/wave32-lds-barrier-opt from e7f5d8b694 to 908d22ebd2 2026-12-05 11:16:10 +00:00 Compare
Contributor

Source review of 908d22eb. One correctness case could complement the barrier-count tests before interpreting the performance A/B. On the non-paired Wave32 path, a 128-thread workgroup needs eight free LDS dwords for the coalesced private allocation in exchange_halves_two. With four to seven free, it falls back to two calls to exchange_halves: the first can still allocate four private dwords and the second uses shared scratch. With fewer than four, both use shared scratch (lower.rs:5514–5565 and 5582–5601).

For a synthetic test, I would exercise 3, 4, 7 and 8 dwords of remaining capacity and use distinct marker pairs for each half of both console waves. The coalesced private offsets are 0–3 and 4–7. Comparing both output pairs against the opt-off path on Wave32 would cover cross-wave separation and the mixed private/shared fallback, in addition to counting barriers. I checked the index formula offline and have no build or GPU result for this head.

For the performance A/B, use fresh processes for each arm. At this revision, wave32_lds_opt caches the switch in a OnceLock.

Source review with Codex and Claude Code.

Source review of `908d22eb`. One correctness case could complement the barrier-count tests before interpreting the performance A/B. On the non-paired Wave32 path, a 128-thread workgroup needs eight free LDS dwords for the coalesced private allocation in `exchange_halves_two`. With four to seven free, it falls back to two calls to `exchange_halves`: the first can still allocate four private dwords and the second uses shared scratch. With fewer than four, both use shared scratch (`lower.rs:5514–5565` and `5582–5601`). For a synthetic test, I would exercise 3, 4, 7 and 8 dwords of remaining capacity and use distinct marker pairs for each half of both console waves. The coalesced private offsets are 0–3 and 4–7. Comparing both output pairs against the opt-off path on Wave32 would cover cross-wave separation and the mixed private/shared fallback, in addition to counting barriers. I checked the index formula offline and have no build or GPU result for this head. For the performance A/B, use fresh processes for each arm. At this revision, `wave32_lds_opt` caches the switch in a `OnceLock`. Source review with Codex and Claude Code.
Contributor

I ran the CPU shader-lowering tests at 908d22eb. The current wave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchange fixture fails with None versus Some(32) for the wave-size assertion. The only v_readlane_b32 writes s14 and the program ends immediately. Keeping that result live made the existing Wave32 and Wave64 assertions pass.

This small fixture change worked for me. Insert these words before S_ENDPGM and use rsrc2: 1 << 15 to declare LDS.

0x7E02_020E, // v_mov_b32 v1, s14
0x36 << 26 | 0x0D << 18, 1 << 8, // ds_write_b32 v0, v1

I also exercised exchange_halves_two on a 128-thread synthetic fixture with the same live read, no paired meetings and an acyclic site. I primed wave_base() before counting and set the prior private allocation to leave the requested free space.

Free LDS dwords Added private dwords Exchange barriers
3 0 4
4 4 3
7 4 3
8 8 1

cargo test --locked --offline -p darner-shader --lib wave32_lds passed both PR tests with the fixture change and the additional threshold test. The Linux runner also needed an independent test-only guard around the Windows validator in card_cost_tests.rs. These are CPU lowering and allocation checks. GPU scheduling and performance remain to be measured. Reviewed and tested with Claude Code and Codex.

I ran the CPU shader-lowering tests at `908d22eb`. The current `wave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchange` fixture fails with `None` versus `Some(32)` for the wave-size assertion. The only `v_readlane_b32` writes `s14` and the program ends immediately. Keeping that result live made the existing Wave32 and Wave64 assertions pass. This small fixture change worked for me. Insert these words before `S_ENDPGM` and use `rsrc2: 1 << 15` to declare LDS. ```rust 0x7E02_020E, // v_mov_b32 v1, s14 0x36 << 26 | 0x0D << 18, 1 << 8, // ds_write_b32 v0, v1 ``` I also exercised `exchange_halves_two` on a 128-thread synthetic fixture with the same live read, no paired meetings and an acyclic site. I primed `wave_base()` before counting and set the prior private allocation to leave the requested free space. | Free LDS dwords | Added private dwords | Exchange barriers | |---:|---:|---:| | 3 | 0 | 4 | | 4 | 4 | 3 | | 7 | 4 | 3 | | 8 | 8 | 1 | `cargo test --locked --offline -p darner-shader --lib wave32_lds` passed both PR tests with the fixture change and the additional threshold test. The Linux runner also needed an independent test-only guard around the Windows validator in `card_cost_tests.rs`. These are CPU lowering and allocation checks. GPU scheduling and performance remain to be measured. Reviewed and tested with Claude Code and Codex.
Collaborator

Thanks for this, and thanks to tyr0nsur for the test run and the fixed fixture. I read the diff at 908d22eb (source only; we have not built or run it yet). I won't repeat his points: the failing readlane fixture and the 3/4/7/8-dword threshold test are what I'd fix first.

A few things on top of his:

  1. Is pure_unordered and the acyclic check safe for loops the lowering adds? exchange_acyclic (emit/lower.rs:5570) decides "runs at most once" from blocks_in_cycle (emit/lower/analysis.rs:1171), which only follows st.exits. The translator also runs some loops per host wave (loops_wave, emit/mod.rs:2015; the per-half loops noted at analysis.rs:1040) and has waterfall loops over descriptors. If one of those can hold an exchange site and is not a cycle in st.exits, the trailing barrier would be dropped inside a loop. I could not show that this happens. Can you say why it can't, or add a test with an exchange inside such a loop?

  2. An output-equivalence test. The current tests count barriers. Please add one that lowers the same exchange cases with the switch off and on and checks that both write the same results (both halves of both console waves, distinct markers), including the mixed private/shared case. That is the thing that would catch a dropped barrier that matters.

  3. Cache key. DARNER_WAVE32_LDS_OPT is added to KEYED (shader_cache.rs:113), which is right. As far as I can tell from the hashing loop (:202), every KEYED name goes into the key, so merging this changes the key for everyone, so the first run after the update recompiles shaders even with the switch off. That is fine for an opt-in, but please say so in the PR text and add a line to docs/findings.md or the README if the switch is documented there.

  4. Base. The PR is based on current main (c8258f95) and merges cleanly for me, so no rebase is needed yet. If main moves before it lands, a rebase will be needed. The most likely conflict is the KEYED array.

  5. Testing. The PR text says the gates were not run. Please run cargo test --workspace --locked and the two clippy gates and put the results and commit in the description. The F2 table is still empty.

Once these are addressed, we'll A/B it on an RTX 2070 SUPER (Turing, wave32, 8 GB, ReBAR off). That means a fresh process per arm, per-shader card times and a replay picture comparison, and we'll post the numbers here. We have not run it yet, so we have no result either way.

Source review only, no build or run.

Written with AI assistance (Claude Code).

Thanks for this, and thanks to tyr0nsur for the test run and the fixed fixture. I read the diff at `908d22eb` (source only; we have not built or run it yet). I won't repeat his points: the failing readlane fixture and the 3/4/7/8-dword threshold test are what I'd fix first. A few things on top of his: 1. **Is `pure_unordered` and the acyclic check safe for loops the lowering adds?** `exchange_acyclic` (`emit/lower.rs:5570`) decides "runs at most once" from `blocks_in_cycle` (`emit/lower/analysis.rs:1171`), which only follows `st.exits`. The translator also runs some loops per host wave (`loops_wave`, `emit/mod.rs:2015`; the per-half loops noted at `analysis.rs:1040`) and has waterfall loops over descriptors. If one of those can hold an exchange site and is not a cycle in `st.exits`, the trailing barrier would be dropped inside a loop. I could not show that this happens. Can you say why it can't, or add a test with an exchange inside such a loop? 2. **An output-equivalence test.** The current tests count barriers. Please add one that lowers the same exchange cases with the switch off and on and checks that both write the same results (both halves of both console waves, distinct markers), including the mixed private/shared case. That is the thing that would catch a dropped barrier that matters. 3. **Cache key.** `DARNER_WAVE32_LDS_OPT` is added to `KEYED` (`shader_cache.rs:113`), which is right. As far as I can tell from the hashing loop (`:202`), every `KEYED` name goes into the key, so merging this changes the key for everyone, so the first run after the update recompiles shaders even with the switch off. That is fine for an opt-in, but please say so in the PR text and add a line to `docs/findings.md` or the README if the switch is documented there. 4. **Base.** The PR is based on current `main` (`c8258f95`) and merges cleanly for me, so no rebase is needed yet. If `main` moves before it lands, a rebase will be needed. The most likely conflict is the `KEYED` array. 5. **Testing.** The PR text says the gates were not run. Please run `cargo test --workspace --locked` and the two clippy gates and put the results and commit in the description. The F2 table is still empty. Once these are addressed, we'll A/B it on an RTX 2070 SUPER (Turing, wave32, 8 GB, ReBAR off). That means a fresh process per arm, per-shader card times and a replay picture comparison, and we'll post the numbers here. We have not run it yet, so we have no result either way. Source review only, no build or run. Written with AI assistance (Claude Code).
Contributor

Follow-up on 908d22eb with native D3D12 dispatches on an RTX 4060 (driver 621.40). The Windows SDK DXIL validator accepted both arms.

  • 128 threads, two console waves. A synthetic first-lane shader activates either the lower or the upper half of both waves, with distinct per-wave markers. All 128 UAV values matched the independent expected values and matched off vs. on for each of the eight cases. The allocator trace confirms shared scratch at 3 free LDS dwords, mixed private/shared at 4 and 7, and coalesced private storage at 8.
  • Divergent loops. Reduction, first-lane read and ballot matched the independent 64-value oracle in the one-block and two-block cases. The first-lane pairs emitted different DXIL with the switch on. The reduction and ballot pairs emitted identical DXIL.
  • Disk cache. Two synthetic inputs shared one temporary cache across five fresh processes. Off cold gave 2 misses, off warm gave 2 hits, on cold gave 2 misses, on warm gave 2 hits, and returning to off gave 2 hits. The control with unchanged output also missed on the flip. The shared build key includes the new name even when unset, so the first run after the key changes rebuilds translations.

For the loop question, structure_wide_host preserves the IR branch targets, and the descriptor waterfall recognizer starts from a guest back edge. Ray-query lowering does emit a callback loop of its own. Both callback recognizers source their body blocks from the detected guest loop in emit/rayquery.rs. An exchange inside a ray-query callback is still a separate hardware case to cover.

The test-only reproduction at cf82733 is based on this PR head. The two ignored hardware tests are wave32_divergent_loop_outputs_match_on_hardware and wave32_firstlane_outputs_match_for_two_console_waves_at_the_lds_limits. The GPU crate's disk-cache test is wave32_lds_opt_separates_disk_cache_entries. These measurements cover correctness on the RTX 4060. Gameplay frame times and AMD/Intel hardware are still open. Reviewed with Claude Code and Codex.

Follow-up on `908d22eb` with native D3D12 dispatches on an RTX 4060 (driver 621.40). The Windows SDK DXIL validator accepted both arms. - **128 threads, two console waves.** A synthetic first-lane shader activates either the lower or the upper half of both waves, with distinct per-wave markers. All 128 UAV values matched the independent expected values and matched off vs. on for each of the eight cases. The allocator trace confirms shared scratch at 3 free LDS dwords, mixed private/shared at 4 and 7, and coalesced private storage at 8. - **Divergent loops.** Reduction, first-lane read and ballot matched the independent 64-value oracle in the one-block and two-block cases. The first-lane pairs emitted different DXIL with the switch on. The reduction and ballot pairs emitted identical DXIL. - **Disk cache.** Two synthetic inputs shared one temporary cache across five fresh processes. Off cold gave 2 misses, off warm gave 2 hits, on cold gave 2 misses, on warm gave 2 hits, and returning to off gave 2 hits. The control with unchanged output also missed on the flip. The shared build key includes the new name even when unset, so the first run after the key changes rebuilds translations. For the loop question, `structure_wide_host` preserves the IR branch targets, and the descriptor waterfall recognizer starts from a guest back edge. Ray-query lowering does emit a callback loop of its own. Both callback recognizers source their body blocks from the detected guest loop in `emit/rayquery.rs`. An exchange inside a ray-query callback is still a separate hardware case to cover. The [test-only reproduction at cf82733](https://git.gtahub.st/tyr0nsur/Darner/commit/cf8273361b06979a5c8fb70ba5ca54f750fcee28) is based on this PR head. The two ignored hardware tests are `wave32_divergent_loop_outputs_match_on_hardware` and `wave32_firstlane_outputs_match_for_two_console_waves_at_the_lds_limits`. The GPU crate's disk-cache test is `wave32_lds_opt_separates_disk_cache_entries`. These measurements cover correctness on the RTX 4060. Gameplay frame times and AMD/Intel hardware are still open. Reviewed with Claude Code and Codex.
Contributor

I ran the standalone A/B requested above on an RTX 3060 12 GB (driver 621.40, Core Ultra 5 225F, Windows 11 build 26100). On this scene I found no repeatable speedup.

Same fast build of 908d22eb, Chapter II save, fixed camera, Series S 960×540 to 1080p, DLSS Performance, FSR 3 ×2, RT off. Two warm-up runs per setting, then two alternating runs per setting with copies of the corresponding warm cache. I used the 10–50 s window after the gameplay anchor because the draw count drops near the end of the 70 s capture. FPS below comes from rendered frames in the CSV.

Off 1 On 1 Off 2 On 2
Rendered FPS 23.06 22.84 23.44 23.34
p95 frame time, ms 45.16 46.57 52.08 51.55
p99 frame time, ms 62.31 68.46 64.96 65.90
GPU busy ms/frame, mid-scene 600-frame sample 39.6 40.4 38.9 38.8

All four runs completed with zero lost CSV rows. The final pipeline summary gave zero host pipeline failures and one untranslated shader in each run, the same refusal in both modes. This gameplay check covers performance in one scene. Visual parity and cold loading time were outside its scope.

I ran the standalone A/B requested above on an RTX 3060 12 GB (driver 621.40, Core Ultra 5 225F, Windows 11 build 26100). On this scene I found no repeatable speedup. Same fast build of `908d22eb`, Chapter II save, fixed camera, Series S 960×540 to 1080p, DLSS Performance, FSR 3 ×2, RT off. Two warm-up runs per setting, then two alternating runs per setting with copies of the corresponding warm cache. I used the 10–50 s window after the gameplay anchor because the draw count drops near the end of the 70 s capture. FPS below comes from rendered frames in the CSV. | | Off 1 | On 1 | Off 2 | On 2 | |---|---:|---:|---:|---:| | Rendered FPS | 23.06 | 22.84 | 23.44 | 23.34 | | p95 frame time, ms | 45.16 | 46.57 | 52.08 | 51.55 | | p99 frame time, ms | 62.31 | 68.46 | 64.96 | 65.90 | | GPU busy ms/frame, mid-scene 600-frame sample | 39.6 | 40.4 | 38.9 | 38.8 | All four runs completed with zero lost CSV rows. The final pipeline summary gave zero host pipeline failures and one untranslated shader in each run, the same refusal in both modes. This gameplay check covers performance in one scene. Visual parity and cold loading time were outside its scope.
Author
Contributor
  1. Fixed wave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchange (@tyr0nsur, @Jesper-A): added v_mov_b32 v1, s14 + ds_write_b32 v0, v1 with rsrc2: 1 << 15 so s14 stays live and lowers through Wave32 emulation.
  2. Hardened synthetic-loop safety (@Jesper-A #1): audited all translator-created loops in emit/ (buffer_atomic_fmin/fmax, meet_pair, zero_meet_slots, and lds_float_min_max never lower guest IR; structure_wide_host and waterfall loops preserve cyclic edges in st.exits). Added an explicit in_synthetic_loop guard on Lower set around RayQuery callback lowering (emit/rayquery.rs), routed v_readlane_b32 through exchange_acyclic, and added wave32_lds_opt_keeps_trailing_barrier_in_loops_and_synthetic_loops.
  3. Preserved default shader cache key when off (@Jesper-A #3): moved DARNER_WAVE32_LDS_OPT out of KEYED into conditional keying in shader_cache::build() (matching DARNER_PORT_CBV / DARNER_HW_RT) so unset and =0 keep existing cached shaders valid while =1 uses a distinct key, covered by wave32_lds_opt_changes_the_shader_cache_key.
  4. Added LDS threshold & output-equivalence tests (@tyr0nsur, @Jesper-A #2):
    • wave32_lds_opt_exchange_halves_two_respects_lds_capacity_thresholds checks 3 / 4 / 7 / 8 free LDS dwords on a 128-thread group (+0/+4/+4/+8 private dwords and 4/3/3/1 exchange barriers).
    • wave32_lds_opt_matches_default_across_two_console_waves_and_lds_fallback (wave64_tests.rs) validates DXIL and compares off vs on outputs across two 64-lane console waves (128 threads) with distinct per-half values, covering coalesced private, mixed private+shared fallback (free=7), and full shared fallback (free=3) in one shader.

On performance (@SmallDevBigNothing): acknowledged that the fresh-process warm-cache A/B on RTX 3060 showed no repeatable speedup (within run-to-run noise). Keeping this opt-in (DARNER_WAVE32_LDS_OPT=1, default off) unless another Wave32 card shows a repeatable win.

1. **Fixed `wave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchange`** (`@tyr0nsur`, `@Jesper-A`): added `v_mov_b32 v1, s14` + `ds_write_b32 v0, v1` with `rsrc2: 1 << 15` so `s14` stays live and lowers through Wave32 emulation. 2. **Hardened synthetic-loop safety** (`@Jesper-A` #1): audited all translator-created loops in `emit/` (`buffer_atomic_fmin`/`fmax`, `meet_pair`, `zero_meet_slots`, and `lds_float_min_max` never lower guest IR; `structure_wide_host` and waterfall loops preserve cyclic edges in `st.exits`). Added an explicit `in_synthetic_loop` guard on `Lower` set around `RayQuery` callback lowering (`emit/rayquery.rs`), routed `v_readlane_b32` through `exchange_acyclic`, and added `wave32_lds_opt_keeps_trailing_barrier_in_loops_and_synthetic_loops`. 3. **Preserved default shader cache key when off** (`@Jesper-A` #3): moved `DARNER_WAVE32_LDS_OPT` out of `KEYED` into conditional keying in `shader_cache::build()` (matching `DARNER_PORT_CBV` / `DARNER_HW_RT`) so unset and `=0` keep existing cached shaders valid while `=1` uses a distinct key, covered by `wave32_lds_opt_changes_the_shader_cache_key`. 4. **Added LDS threshold & output-equivalence tests** (`@tyr0nsur`, `@Jesper-A` #2): - `wave32_lds_opt_exchange_halves_two_respects_lds_capacity_thresholds` checks `3 / 4 / 7 / 8` free LDS dwords on a 128-thread group (`+0/+4/+4/+8` private dwords and `4/3/3/1` exchange barriers). - `wave32_lds_opt_matches_default_across_two_console_waves_and_lds_fallback` (`wave64_tests.rs`) validates DXIL and compares off vs on outputs across two 64-lane console waves (`128` threads) with distinct per-half values, covering coalesced private, mixed private+shared fallback (`free=7`), and full shared fallback (`free=3`) in one shader. On performance (`@SmallDevBigNothing`): acknowledged that the fresh-process warm-cache A/B on RTX 3060 showed no repeatable speedup (within run-to-run noise). Keeping this opt-in (`DARNER_WAVE32_LDS_OPT=1`, default off) unless another Wave32 card shows a repeatable win.
TrustNo1 changed title from [pr-performance][shader] Opt-in Wave32 cross-half LDS barrier reduction (DARNER_WAVE32_LDS_OPT) to Opt-in Wave32 cross-half LDS barrier reduction (DARNER_WAVE32_LDS_OPT) 2026-12-06 03:27:28 +00:00
Owner

Test needed — commit f300eaa5; what to check:

  • The problem on main: read from the code only — when emulating Wave64 shaders on 32-lane hosts (NVIDIA), cross-half exchanges emit GroupMemoryBarrierWithGroupSync() pairs around each LDS handoff even when a phase has no intervening LDS writes/atomics or when two 32-bit half-exchanges can be coalesced, adding unnecessary workgroup synchronization stalls on Wave32 compute/lighting shaders.

Adds an opt-in shader lowering switch DARNER_WAVE32_LDS_OPT=1 (off by default, and always a no-op on 64-lane/AMD hosts where host_max_wave() != 32):

  • darner-shader (lower.rs, lower/analysis.rs, lower/tests.rs):
    • Coalesces paired 32-bit cross-half exchanges (exchange_halves) into a single barrier pair instead of two.
    • Tracks LDS writes / returning atomics per phase in lower/analysis.rs so acyclic cross-half exchanges can omit redundant trailing barriers when no conflicting LDS access follows.
    • Adds unit tests (wave32_lds_opt_reduces_barriers_on_wave32_and_is_noop_on_amd_wave64 and wave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchange) covering Wave32 reduction and Wave64 no-op behavior.
  • darner-gpu (shader_cache.rs):
    • Keys `DARNER_WAVE3

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `f300eaa5`; what to check: - The problem on main: read from the code only — when emulating Wave64 shaders on 32-lane hosts (NVIDIA), cross-half exchanges emit `GroupMemoryBarrierWithGroupSync()` pairs around each LDS handoff even when a phase has no intervening LDS writes/atomics or when two 32-bit half-exchanges can be coalesced, adding unnecessary workgroup synchronization stalls on Wave32 compute/lighting shaders. Adds an opt-in shader lowering switch `DARNER_WAVE32_LDS_OPT=1` (off by default, and always a no-op on 64-lane/AMD hosts where `host_max_wave() != 32`): - **`darner-shader` (`lower.rs`, `lower/analysis.rs`, `lower/tests.rs`):** - Coalesces paired 32-bit cross-half exchanges (`exchange_halves`) into a single barrier pair instead of two. - Tracks LDS writes / returning atomics per phase in `lower/analysis.rs` so acyclic cross-half exchanges can omit redundant trailing barriers when no conflicting LDS access follows. - Adds unit tests (`wave32_lds_opt_reduces_barriers_on_wave32_and_is_noop_on_amd_wave64` and `wave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchange`) covering Wave32 reduction and Wave64 no-op behavior. - **`darner-gpu` (`shader_cache.rs`):** - Keys `DARNER_WAVE3 Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr/wave32-lds-barrier-opt:davetheshrew-pr/wave32-lds-barrier-opt'
git switch 'davetheshrew-pr/wave32-lds-barrier-opt'

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 'davetheshrew-pr/wave32-lds-barrier-opt'
git switch 'davetheshrew-pr/wave32-lds-barrier-opt'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'davetheshrew-pr/wave32-lds-barrier-opt'
git switch 'davetheshrew-pr/wave32-lds-barrier-opt'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'davetheshrew-pr/wave32-lds-barrier-opt'
git switch 'Main'
git merge --squash 'davetheshrew-pr/wave32-lds-barrier-opt'
git switch 'Main'
git merge --ff-only 'davetheshrew-pr/wave32-lds-barrier-opt'
git switch 'Main'
git merge 'davetheshrew-pr/wave32-lds-barrier-opt'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
5 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!546
No description provided.