D3D12-SHADER-1D-WAVE-BASE-NO-TICKET: skip entry ticket barrier and LDS atomic for 1-D groups #2685

Merged
bobcatchris merged 1 commit from upstream-pr/2685 into main 2026-11-30 18:28:11 +00:00
bobcatchris commented 2026-11-30 02:34:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-11-30T02:34:21Z.


Claimed in #2570 as D3D12-SHADER-1D-WAVE-BASE-NO-TICKET (#issuecomment-7267081456).

What and why

Addresses the open shader-performance item in d3d12/docs/findings.md:

"the entry ticket of every console wave64 program with lane code (a group barrier and an LDS atomic, also for groups of one dimension, where the host's waves are runs of consecutive ids)"

In d3d12/crates/leonida-shader/src/emit/lower.rs, every 1-D wave64/console-lanes compute shader (including multi-wave paired shaders, whose host group shape is always [32 * waves, 1, 1]) previously allocated an LDS counter dword and emitted an entry group_sync + atomicrmw add unless its LDS was already full (>= 8192 dwords).

Because 1-D host groups already assign each host wave a consecutive run of flattenedThreadIdInGroup values:

  • Paired multi-wave ([32 * waves, 1, 1]): set halves = Some(NO_COUNTER) and compute base = (waveReadLaneFirst(flat_id) & !31) << 1 in console_thread().
  • Non-paired 1-D (cs.threads[1] == 1 && cs.threads[2] == 1): use halves = Some(NO_COUNTER) / skip ticket, using the existing flat-ID console_thread() path (also setting flags::WAVE_OPS).
  • 2-D / 3-D groups: unchanged (continue using the LDS counter because host waves may be tiled).

Verification (Red -> Green)

Hardware / OS: native Windows 11 Pro (10.0.26200) + AMD Radeon RX 7900 XTX (gfx1100, driver 32.0.32029.2010), pinned toolchain rustc 1.98.1.

  • Red (before fix): one_d_wave64_group_skips_entry_ticket_barrier_and_keeps_thread_ids on [128, 1, 1] emitted 2 group barriers in halves mode (entry ticket + v_mbcnt exchange) and 1 in paired mode (entry ticket).
  • Green (after fix, on main 40e7fe69d):
    • Halves mode drops to 1 barrier (entry ticket eliminated); paired mode drops to 0 barriers; DXIL validated; GPU dispatch verified all 128 console thread IDs [1..=128] exact.
    • cargo test -p leonida-shader --lib wave64_tests -- --test-threads=4 — 31 passed; 0 failed (3.81s, including all 2D/3D group tests).
    • cargo test -p leonida-shader --lib paired_tests -- --test-threads=4 — 16 passed; 0 failed (7.56s).
    • python -I scripts/check_no_game_data.py on both touched files — PASS.

AI-assisted: Antigravity (Gemini 4 Neon)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5557943242 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2685). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-11-30T02:34:21Z. --- Claimed in #2570 as `D3D12-SHADER-1D-WAVE-BASE-NO-TICKET` (`#issuecomment-7267081456`). ### What and why Addresses the open shader-performance item in `d3d12/docs/findings.md`: > *"the entry ticket of every console wave64 program with lane code (a group barrier and an LDS atomic, also for groups of one dimension, where the host's waves are runs of consecutive ids)"* In `d3d12/crates/leonida-shader/src/emit/lower.rs`, every 1-D wave64/console-lanes compute shader (including multi-wave paired shaders, whose host group shape is always `[32 * waves, 1, 1]`) previously allocated an LDS counter dword and emitted an entry `group_sync` + `atomicrmw add` unless its LDS was already full (`>= 8192` dwords). Because 1-D host groups already assign each host wave a consecutive run of `flattenedThreadIdInGroup` values: - **Paired multi-wave (`[32 * waves, 1, 1]`):** set `halves = Some(NO_COUNTER)` and compute `base = (waveReadLaneFirst(flat_id) & !31) << 1` in `console_thread()`. - **Non-paired 1-D (`cs.threads[1] == 1 && cs.threads[2] == 1`):** use `halves = Some(NO_COUNTER)` / skip `ticket`, using the existing flat-ID `console_thread()` path (also setting `flags::WAVE_OPS`). - **2-D / 3-D groups:** unchanged (continue using the LDS counter because host waves may be tiled). ### Verification (Red -> Green) Hardware / OS: native Windows 11 Pro (`10.0.26200`) + **AMD Radeon RX 7900 XTX** (`gfx1100`, driver `32.0.32029.2010`), pinned toolchain `rustc 1.98.1`. - **Red (before fix):** `one_d_wave64_group_skips_entry_ticket_barrier_and_keeps_thread_ids` on `[128, 1, 1]` emitted `2` group barriers in halves mode (entry ticket + `v_mbcnt` exchange) and `1` in paired mode (entry ticket). - **Green (after fix, on `main` `40e7fe69d`):** - Halves mode drops to `1` barrier (entry ticket eliminated); paired mode drops to `0` barriers; DXIL validated; GPU dispatch verified all 128 console thread IDs `[1..=128]` exact. - `cargo test -p leonida-shader --lib wave64_tests -- --test-threads=4` — **`31 passed; 0 failed`** (`3.81s`, including all 2D/3D group tests). - `cargo test -p leonida-shader --lib paired_tests -- --test-threads=4` — **`16 passed; 0 failed`** (`7.56s`). - `python -I scripts/check_no_game_data.py` on both touched files — **PASS**. AI-assisted: Antigravity (Gemini 4 Neon)
OreoFR commented 2026-11-30 02:39:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T02:39:31Z.


Checked by OreoFR on macOS 27.2.1, Apple M5, Rust 1.98.1, cargo test -p leonida-shader, main 182d0c174, PR head 15478c939. MEASURED, partial:

  • main 224 passed / 2 ignored; main + only emit/wave64_tests.rs from this PR: 224 / 2; main + this PR: 224 / 2. No regression in the crate's host-independent tests.
  • The new tests do not run here: mod wave64_tests is #[cfg(all(test, windows))] (emit/mod.rs 120-121), so neither the red nor the green of this PR's own test is covered on macOS. It needs a Windows cargo test (and dxil.dll / a 32-lane GPU for the validated and dispatched parts).
  • Merges cleanly with main and with #2566.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7267198168 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7267198168). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T02:39:31Z. --- Checked by OreoFR on macOS 27.2.1, Apple M5, Rust 1.98.1, `cargo test -p leonida-shader`, main 182d0c174, PR head 15478c939. MEASURED, partial: - main 224 passed / 2 ignored; main + only `emit/wave64_tests.rs` from this PR: 224 / 2; main + this PR: **224 / 2**. No regression in the crate's host-independent tests. - **The new tests do not run here:** `mod wave64_tests` is `#[cfg(all(test, windows))]` (`emit/mod.rs` 120-121), so neither the red nor the green of this PR's own test is covered on macOS. It needs a Windows `cargo test` (and `dxil.dll` / a 32-lane GPU for the validated and dispatched parts). - Merges cleanly with main and with #2566. AI-assisted: Claude Code
OreoFR commented 2026-11-30 07:09:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T07:09:37Z.


Windows numbers for the part I could not run on macOS, measured by mooneyes-agent (MoonEyes's agent) and relayed here with their OK: Windows 11, d3d12/rust-toolchain.toml, CPU only, main 1d22590b9 + this PR (head 15478c939, merge without commit). MEASURED:

  • cargo test -p leonida-shader: main 370 ok, main + this PR 371 ok, 0 failed, 4 ignored. The cfg(windows) test this PR adds compiles and passes.
  • clippy: 5 warnings on both sides, none added by this PR.
  • Still not done: a red (this PR's test against main's lower.rs).

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7271421115 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7271421115). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T07:09:37Z. --- Windows numbers for the part I could not run on macOS, **measured by mooneyes-agent (MoonEyes's agent)** and relayed here with their OK: Windows 11, `d3d12/rust-toolchain.toml`, CPU only, main 1d22590b9 + this PR (head 15478c939, merge without commit). MEASURED: - `cargo test -p leonida-shader`: main **370 ok**, main + this PR **371 ok**, 0 failed, 4 ignored. The `cfg(windows)` test this PR adds compiles and passes. - clippy: 5 warnings on both sides, none added by this PR. - Still not done: a red (this PR's test against main's `lower.rs`). AI-assisted: Claude Code
KelboLive commented 2026-11-30 16:05:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T16:05:45Z.


Independent check on Windows (not the author), at 903e3731e.

  • cargo test --locked -p leonida-shader --lib: 386 passed, 0 failed, 4 ignored in 328 s.

Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned.

The skipped ticket/barrier path is covered by the crate's own emit tests; I did not independently measure the performance change on a GPU.

AI-assisted: yes (opencode).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7284105370 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7284105370). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-30T16:05:45Z. --- Independent check on Windows (not the author), at `903e3731e`. - `cargo test --locked -p leonida-shader --lib`: **386 passed, 0 failed, 4 ignored** in 328 s. Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned. The skipped ticket/barrier path is covered by the crate's own emit tests; I did not independently measure the performance change on a GPU. AI-assisted: yes (opencode).
merzleckeier commented 2026-11-30 16:48:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T16:48:30Z.


Hardware readback on RTX 4070 SUPER and Radeon 610M

MEASURED. Tested 903e3731e against main 08e42a516 (merge tree 6f2354b8e) with the PR's one_d_wave64_group_skips_entry_ticket_barrier_and_keeps_thread_ids fixture. The baseline uses the same fixture with its original expected barrier counts. The local fixture requires both hardware PSOs and both dispatches to complete. Rust 1.98.1 targeting MSVC x64, Wine 11.22 and VKD3D-Proton 3.2.0. The RTX 4070 SUPER used NVIDIA 620.73.04 and the Radeon 610M used RADV 26.3.1.

On each GPU and in all three runs per tree, emitted group barriers went from 2 to 1 in halves mode and 1 to 0 in paired mode. Both modes returned the exact 128 words 1..128 on both trees.

I also locally merged #2685 and #2688 (2ef9796f0), resolving the test-file overlap by keeping both tests (tree 7246c4c48). Both exact fixtures then passed three times per GPU. The 1-D fixture still returned 1..128 with 1/0 barriers. The loop-exchange fixture returned 952 with each bank setting, with 2 barriers for single banking and 1 for double buffering.

Scope: synthetic hardware dispatch and readback under Wine. Separate Microsoft SDK DXIL validation and gameplay measurements are outside these runs. AI-assisted: Codex (GPT-6.2 Sol).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7285259790 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7285259790). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-30T16:48:30Z. --- ### Hardware readback on RTX 4070 SUPER and Radeon 610M **MEASURED.** Tested `903e3731e` against `main` `08e42a516` (merge tree `6f2354b8e`) with the PR's `one_d_wave64_group_skips_entry_ticket_barrier_and_keeps_thread_ids` fixture. The baseline uses the same fixture with its original expected barrier counts. The local fixture requires both hardware PSOs and both dispatches to complete. Rust 1.98.1 targeting MSVC x64, Wine 11.22 and VKD3D-Proton 3.2.0. The RTX 4070 SUPER used NVIDIA 620.73.04 and the Radeon 610M used RADV 26.3.1. On each GPU and in all three runs per tree, emitted group barriers went from **2 to 1** in halves mode and **1 to 0** in paired mode. Both modes returned the exact 128 words `1..128` on both trees. I also locally merged #2685 and #2688 (`2ef9796f0`), resolving the [test-file overlap](https://github.com/ProjectLeonida/mandy/pull/2688#issuecomment-7285190149) by keeping both tests (tree `7246c4c48`). Both exact fixtures then passed three times per GPU. The 1-D fixture still returned `1..128` with 1/0 barriers. The loop-exchange fixture returned `952` with each bank setting, with 2 barriers for single banking and 1 for double buffering. Scope: synthetic hardware dispatch and readback under Wine. Separate Microsoft SDK DXIL validation and gameplay measurements are outside these runs. AI-assisted: Codex (GPT-6.2 Sol).
MoonEyes commented 2026-11-30 18:24:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T18:24:33Z.


RUN · VERIFY-2685-RTX4060 · by MoonEyes (another person than the author) on head 903e3731e, together with #2684 (bb68c6e19), #2685 (903e3731e) and #2757 (fe7c76d3b) merged into main 99167bcaf. Windows 11 Pro 26300, RTX 4060 8 GB, -SeriesS -FrameGen 2, diag build.

  • cargo test -p leonida-shader --locked: 392 passed, 0 failed.
  • Game: two runs of the same build, the person walking in the world from 345 s. First with the shaders translated again (795 s before the title, about 185 s of steady frames), then warm: the steady world after 165 s, about 425 s of it, about 98 m walked, no device loss, no unhandled exception, the process alive at the end. PASS for the gate of 300 s.
  • The three pull requests were in one build, so a fault of one could have been hidden by another only if they cancel out; none was seen. No frame rate is claimed, other work ran on the PC and there is no arm without them.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7287805837 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7287805837). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T18:24:33Z. --- RUN · VERIFY-2685-RTX4060 · by MoonEyes (another person than the author) on head `903e3731e`, together with #2684 (`bb68c6e19`), #2685 (`903e3731e`) and #2757 (`fe7c76d3b`) merged into `main` `99167bcaf`. Windows 11 Pro 26300, RTX 4060 8 GB, `-SeriesS -FrameGen 2`, diag build. - `cargo test -p leonida-shader --locked`: 392 passed, 0 failed. - Game: two runs of the same build, the person walking in the world from 345 s. First with the shaders translated again (795 s before the title, about 185 s of steady frames), then warm: the steady world after 165 s, about 425 s of it, about 98 m walked, no device loss, no unhandled exception, the process alive at the end. PASS for the gate of 300 s. - The three pull requests were in one build, so a fault of one could have been hidden by another only if they cancel out; none was seen. No frame rate is claimed, other work ran on the PC and there is no arm without them. AI-assisted (Claude Code).
MoonEyes commented 2026-11-30 18:28:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T18:28:08Z.


Merging. Head 903e3731e merges cleanly with main 8c8ab1783 and does not force a rebase of #2566. Two runs in the game (RTX 4060, the second 425 s steady, no device loss) with #2684, #2685 and #2757 together; cargo test 392 passed; checked by other people too. The shaders are translated again at the first start. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7287894092 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7287894092). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T18:28:08Z. --- Merging. Head `903e3731e` merges cleanly with `main` `8c8ab1783` and does not force a rebase of #2566. Two runs in the game (RTX 4060, the second 425 s steady, no device loss) with #2684, #2685 and #2757 together; cargo test 392 passed; checked by other people too. The shaders are translated again at the first start. Merged by MoonEyes. AI-assisted (Claude Code).
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
ProjectLeonida/mandy!2685
No description provided.