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

Manually merged
github merged 1 commit from github-bot/gh-2685 into main 2026-11-30 18:30:25 +00:00 AGit
Owner

@⁠bobcatchris on GitHub · 2026-11-30 02:34 UTC · original
bobcatchris:feat/d3d12-shader-1d-wave-base-no-ticket → main · +101 −13 · 2 files · 1 commits · merged 2026-11-30 18:28 UTC

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)

**@⁠bobcatchris** on GitHub · 2026-11-30 02:34 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2685) `bobcatchris:feat/d3d12-shader-1d-wave-base-no-ticket` → `main` · +101 −13 · 2 files · 1 commits · merged 2026-11-30 18:28 UTC 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)
Addresses the d3d12/docs/findings.md item ("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)").

For 1-D host groups (threads[1] == 1 && threads[2] == 1, including all
multi-wave paired groups which are lowered as [32 * waves, 1, 1]), each
host wave already receives a consecutive run of flat thread IDs. Derive
each wave's console thread base directly from
waveReadLaneFirst(flattenedThreadIdInGroup) & !(wave - 1) (shifted left
by 1 for paired groups) instead of allocating an LDS counter dword and
emitting an entry group_sync + atomicrmw add.

2-D and 3-D groups keep the LDS counter path unchanged.

AI-assisted: Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 02:38:36 +00:00
Author
Owner

@⁠OreoFR on GitHub · 2026-11-30 02:39 UTC · original

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** on GitHub · 2026-11-30 02:39 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7267198168) 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
Author
Owner

@⁠OreoFR on GitHub · 2026-11-30 07:09 UTC · original

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

**@⁠OreoFR** on GitHub · 2026-11-30 07:09 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7271421115) 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
github-bot force-pushed github-bot/gh-2685 from 15478c9392 to 903e3731ec 2026-11-30 11:25:15 +00:00 Compare
Author
Owner

@⁠KelboLive on GitHub · 2026-11-30 16:05 UTC · original

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).

**@⁠KelboLive** on GitHub · 2026-11-30 16:05 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7284105370) 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).
Author
Owner

@⁠merzleckeier on GitHub · 2026-11-30 16:48 UTC · original

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).

**@⁠merzleckeier** on GitHub · 2026-11-30 16:48 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7285259790) ### 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://git.gtahub.st/github/ubiquitarianism--leonida/pulls/2688) 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).
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-30 18:24 UTC · original

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** on GitHub · 2026-11-30 18:24 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7287805837) 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).
github manually merged commit 4da7792521 into main 2026-11-30 18:30:25 +00:00
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-30 18:28 UTC · original

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).

**@⁠MoonEyes** on GitHub · 2026-11-30 18:28 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2685#issuecomment-7287894092) 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).
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida!2685
No description provided.