Skip to content

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

Merged
MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
bobcatchris:feat/d3d12-shader-1d-wave-base-no-ticket
Nov 30, 2026
Merged

MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
bobcatchris:feat/d3d12-shader-1d-wave-base-no-ticket

Conversation

@bobcatchris

Copy link
Copy Markdown
Contributor

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

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

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

AI-assisted: Claude Code

@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

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 1d22590 + this PR (head 15478c9, 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

…r 1-D groups (D3D12-SHADER-1D-WAVE-BASE-NO-TICKET)

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)
@bobcatchris
bobcatchris force-pushed the feat/d3d12-shader-1d-wave-base-no-ticket branch from 15478c9 to 903e373 Compare November 30, 2026 11:20
@KelboLive

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

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

@MoonEyes

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator

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
MoonEyes merged commit 4da7792 into ProjectLeonida:main Nov 30, 2026
5 checks passed
djrolfes added a commit to djrolfes/leonida that referenced this pull request Nov 30, 2026
… 1D wave-base (ProjectLeonida#2685), NaN-exact, by_due texture queue, unlocked pool growth (ProjectLeonida#2693), pipeline wait queue (ProjectLeonida#2622)
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.

5 participants