d3d12-shader: one-thread LDS regions before the split form without skips (D3D12-LDS-EXACT-FIRST) #3420

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u  "lds-exact-first-b9f:underlight3d-lds-exact-first-b9f"
git switch "underlight3d-lds-exact-first-b9f"
Open
leonida/mandy
underlight3d wants to merge 4 commits from underlight3d/mandy:lds-exact-first-b9f into main

This branch is out-of-date with the base branch

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request is blocked because it's outdated.
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 'lds-exact-first-b9f:underlight3d-lds-exact-first-b9f'
git switch 'underlight3d-lds-exact-first-b9f'
Collaborator

Claimed in the coordination issue as: D3D12-LDS-EXACT-FIRST. This continues #3126, which the housekeeping bot closed on 2026-12-03 (a conflict in the count line of switches.md with main, and no activity for 5 hours; "not a judgement of the change"). It is the same change, ported to main b9f70bc748 (it merges cleanly into today's main), plus fixes from two new reviews (last section of What and why).

What and why

A console wave64 compute program runs on a host of 32-lane waves as two host waves per console wave. Where its LDS regions are taken only by the form without skips (ir::without_skips), every thread of the group walks a region that one thread runs on the console, with EXEC off, a group barrier before each LDS access in it, and an exchange of the halves for each first-lane read. Programs that clear group memory with thread 0 and then scan it in a loop of that thread pay for that in every pass: the two costliest compute programs of this form in the title carry 417 and 427 group barriers in the translated code where the console code has 3 and 2, and all 1,024 threads of the group run them for one thread's loads and stores. Skipping those two programs in a measured run (picture wrong meanwhile, so a ceiling only) took 1.64 ± 0.09 ms of card time a frame.

This change (d3d12/crates/leonida-shader/src/emit/):

  • mod.rs: where the form without skips takes a program, the forms before it (without early-outs, then as it is) are tried first with the lane-branch regions one thread runs (lds_exact::with_exact_first), and kept when they translate whole. Such a region has no barrier inside; the halves still meet on its way in and out (lds_meetings), so what came before reaches it and what it writes reaches the code after it.
  • lds_exact.rs: in that attempt only the first kind of region is taken (one thread runs it), not the second (reads and writes that cannot meet), which leans on the shortcut that two writes of a region do not meet. The thread must be picked by a constant or by a scalar the program starts with: a scalar a loop changes picks another thread each round, and the lanes a loop lets out one by one gather at its exit.
  • lower.rs: in that attempt only, in a block one thread of the group runs, a v_readfirstlane with no guard of its own is that thread's value: the console wave's first lane is the only lane there, and the other host wave has none. With a guard EXEC may be empty and the console reads lane 0, so that case keeps the exchange (and is refused there). The split form took the program, so the skip around the region is one the code after it cannot see; and no scalar the read makes may be read past the region (checked, see the review fixes below).
  • LEONIDA_LDS_EXACT_FIRST (on unless 0): =0 gives the translation as before. The name joins the shader cache key through the translator's build script, and d3d12/docs/switches.md is regenerated (tools/d3d12_switches.py --out, then --check; only the new row).
  • d3d12/docs/findings.md: the rule, how it was confirmed, and what it does not cover (EXEC widened inside a region to lanes that never entered it, hand-written code only, which no lane-branch form follows).
  • Review fixes since #3126:
    • lds_exact.rs: with_exact and with_exact_first put both switches back through a guard that drops, also when a translation panics. The pipeline workers catch a panic and go on with the next program on the same thread, so before this a panic in the attempt could leave the rule on for later programs on that thread, and their translation would be cached under the normal key.
    • lower.rs / lds_exact::stays_inside: the premise "no scalar the region makes is read past it" is now checked where the rule fires. If a scalar the first-lane read makes, or one made from it (phis included), is read past the blocks one thread runs, the read keeps the exchange. A vector register made from it is the lane's own and may leave.
    • New tests for both, for the rule staying off in the last-resort exact forms (the mutation #3126 listed as not caught), and for a first-lane value carried out of its region in a vector register.

Tested (on this branch, main b9f70bc748)

Offline, over the 2,734 compute programs of a pipeline book (NVIDIA host settings, waves of 32), the translator of b9f70bc748 against this branch:

  • 2,727 translate and 7 are refused, in every run (the same 7).
  • With LEONIDA_LDS_EXACT_FIRST=0, every program has the same result, DXIL size and FNV-1a-64 hash of its DXIL as on main; the two costliest were also compared byte for byte (61,348 and 63,240 bytes).
  • With the switch on, exactly 10 change form, all from the split form without skips to the one-thread regions of the form without early-outs; none refused, none newly translated. Their DXIL is the same as in #3126.
  • 81 programs reach the attempt. Besides the 10, 71 keep the split form after more translations that fail: two for 64 of them, one for the 7 that have no form without early-outs. Whole book with 8 shards: 49 s with the switch off, 36 s on (no single program timed here; #3126 timed the 10).
The two costliest programs group barriers in the code DXIL instructions
first, main / this branch 417 / 14 5,892 / 2,245
second, main / this branch 427 / 24 6,047 / 2,409

Hand-written console code (wave64_tests.rs), red before and green after. The tests of #3126, plus:

  • a panic inside either attempt leaves both switches off on its thread (red: left: (true, true) right: (false, false));
  • a first-lane read whose scalar is read past its region keeps the exchange in the attempt (red: it was lowered in waves of 32);
  • the first-lane rule stays off in the last-resort exact forms;
  • a first-lane value carried out of its region in a vector register reaches the attempt and keeps the one-thread region;
  • the test of a first-lane value that leaves its region now asserts that it never reaches the attempt (tried == 0), which is the premise it guards.

Mutations, each caught by a test: a check in ir::without_skips disabled; a with_exact_first try on the as-is form before the forms loop; the 1-D check in single_thread_compares removed; one_thread_block given a flat group size; the rule leaking into the last-resort forms; the switch inverted; the guard check dropped; the thread picker check; the second region kind in the early attempt; the early-only scope of the first-lane rule.

On the card (RTX 3090, NVIDIA 621.40): 30 cases store the console's bytes three times each, in both forms: the clear-and-scan with the region's thread in either host wave and either console wave, the one-wave running sum through first-lane reads by threads 0, 31, 32 and 63, and the vector case (by thread 0, 31, 32, 63 or none). Each dispatch runs with a 60 s limit. WARP takes no program in waves of 32 (its waves have 4 lanes).

Rust, from d3d12/, --target x86_64-pc-windows-msvc: cargo test -p leonida-shader: 441 passed, 0 failed, 6 ignored. cargo clippy -p leonida-shader --all-targets: 6 warnings, all in valu_tests.rs, none in this change. python -I tools/d3d12_switches.py --check d3d12/docs/switches.md: passes.

In-game

On this branch's head: not run in game yet. A GPU-timing series on the RTX 3090 is queued for tonight (same executable for both arms, one warm-up per arm because the switch is part of the shader cache key, then A B B A with LEONIDA_LDS_EXACT_FIRST=0 against the default). Its result will follow as a comment. The table below is from #3126 (executable of 1bc00fe25, the change before both rebases; the 10 programs' DXIL is the same here).

RTX 3090, NVIDIA 621.40, Series S settings, standing at the save, exe of 1bc00fe25 (see the note above).

old (LEONIDA_LDS_EXACT_FIRST=0) new new − old
the two programs, GPU timing (LEONIDA_GPU_TIMING=1, two shortened runs, ±30 %) 0.32 + 0.26 = 0.58 ms a frame 0.07 + 0.04 = 0.11 ms a frame −0.47 ms
the two programs' cost in the frame, measured in each arm within one run (below) 1.50 ± 0.03 ms of card time 1.28 ± 0.15 ms −0.22 ± 0.15 ms of card time a frame
whole runs, card busy (2 runs old, 1 run new; indicative only) 26.2 ms 25.9 ms inside the spread of whole runs
whole runs, frame median (indicative only) 25.5 ms 25.2 ms inside the spread of whole runs
captures at 120 s and 300 s same scene same scene, nothing broken 0 ‰ magenta or purple pixels

How the cost in the frame was measured: in each arm, one run of 600 s with LEONIDA_AB=10,LEONIDA_SKIP_TRY_A skipping the two programs every other 10 s (the picture is wrong while they are skipped), the first 60 s after reaching the world left out, 22 cycles; the cost is the card time a frame with them minus without them. This was chosen over comparing whole runs because two whole runs of the same executable differ from each other by 0.4 to 2 ms of card time a frame, more than the effect.

Another card (OreoFR: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Series S settings, moving, four parts of 450 s off/on/on/off, one shader folder per arm): 25.16 frames/s off against 25.23 on. No effect on the frame rate there: that card is limited by the submitting thread. No crash.

Stability, as observed: with this executable, 4 of 7 runs between 05:11 and 06:09 UTC ended in a crash, in both arms (including =0, whose translation is byte for byte that of main), with three different signatures; then 0 crashes in 4 runs with a clean rebuild of the same commit (byte-identical executable), and 0 in 7 runs with an executable of main built the same way on the same day. Not reproduced, and not attributed to this change. Offline, each of the 19,104 programs of the pipeline book translates on a thread of the runtime's default stack (2 MiB) with at most 68 KiB of stack, the same on main and on this branch, with the switch on or off.

GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40, Windows 11 Pro (build 26300): the dispatch tests, the Rust suites and the offline book on this branch; the in-game runs of #3126. NVIDIA GeForce RTX 4070 Laptop 8 GB, driver 621.40 (run by OreoFR): the in-game A/B of #3126.

AI-assisted: yes (Claude Code, Claude Opus 5.5 for the code and tests; two independent read-only reviewer agents, Claude Opus 5.5, one on the code and one on the evidence and mutations; the code reviewer re-reviewed the fixes and found them ready).

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request. (Open from review, not changed here because it changes another form's output: outside the early attempt, single_thread_compares still accepts a scalar a loop changes as the thread picker, in the last-resort exact forms.)
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (That table describes the SPIR-V translator; the DX12 translator's rules are in d3d12/docs/findings.md, where this one is added with how it was confirmed.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01WtKdZ5UBfzFHFUgnKaKoSc

Claimed in the coordination issue as: D3D12-LDS-EXACT-FIRST. This continues #3126, which the housekeeping bot closed on 2026-12-03 (a conflict in the count line of `switches.md` with `main`, and no activity for 5 hours; "not a judgement of the change"). It is the same change, ported to `main` `b9f70bc748` (it merges cleanly into today's `main`), plus fixes from two new reviews (last section of What and why). ### What and why A console wave64 compute program runs on a host of 32-lane waves as two host waves per console wave. Where its LDS regions are taken only by the form without skips (`ir::without_skips`), every thread of the group walks a region that one thread runs on the console, with EXEC off, a group barrier before each LDS access in it, and an exchange of the halves for each first-lane read. Programs that clear group memory with thread 0 and then scan it in a loop of that thread pay for that in every pass: the two costliest compute programs of this form in the title carry 417 and 427 group barriers in the translated code where the console code has 3 and 2, and all 1,024 threads of the group run them for one thread's loads and stores. Skipping those two programs in a measured run (picture wrong meanwhile, so a ceiling only) took 1.64 ± 0.09 ms of card time a frame. This change (`d3d12/crates/leonida-shader/src/emit/`): - `mod.rs`: where the form without skips takes a program, the forms before it (without early-outs, then as it is) are tried first with the lane-branch regions one thread runs (`lds_exact::with_exact_first`), and kept when they translate whole. Such a region has no barrier inside; the halves still meet on its way in and out (`lds_meetings`), so what came before reaches it and what it writes reaches the code after it. - `lds_exact.rs`: in that attempt only the first kind of region is taken (one thread runs it), not the second (reads and writes that cannot meet), which leans on the shortcut that two writes of a region do not meet. The thread must be picked by a constant or by a scalar the program starts with: a scalar a loop changes picks another thread each round, and the lanes a loop lets out one by one gather at its exit. - `lower.rs`: in that attempt only, in a block one thread of the group runs, a `v_readfirstlane` with no guard of its own is that thread's value: the console wave's first lane is the only lane there, and the other host wave has none. With a guard EXEC may be empty and the console reads lane 0, so that case keeps the exchange (and is refused there). The split form took the program, so the skip around the region is one the code after it cannot see; and no scalar the read makes may be read past the region (checked, see the review fixes below). - `LEONIDA_LDS_EXACT_FIRST` (on unless `0`): `=0` gives the translation as before. The name joins the shader cache key through the translator's build script, and `d3d12/docs/switches.md` is regenerated (`tools/d3d12_switches.py --out`, then `--check`; only the new row). - `d3d12/docs/findings.md`: the rule, how it was confirmed, and what it does not cover (EXEC widened inside a region to lanes that never entered it, hand-written code only, which no lane-branch form follows). - Review fixes since #3126: - `lds_exact.rs`: `with_exact` and `with_exact_first` put both switches back through a guard that drops, also when a translation panics. The pipeline workers catch a panic and go on with the next program on the same thread, so before this a panic in the attempt could leave the rule on for later programs on that thread, and their translation would be cached under the normal key. - `lower.rs` / `lds_exact::stays_inside`: the premise "no scalar the region makes is read past it" is now checked where the rule fires. If a scalar the first-lane read makes, or one made from it (phis included), is read past the blocks one thread runs, the read keeps the exchange. A vector register made from it is the lane's own and may leave. - New tests for both, for the rule staying off in the last-resort exact forms (the mutation #3126 listed as not caught), and for a first-lane value carried out of its region in a vector register. ### Tested (on this branch, `main` `b9f70bc748`) **Offline**, over the 2,734 compute programs of a pipeline book (NVIDIA host settings, waves of 32), the translator of `b9f70bc748` against this branch: - 2,727 translate and 7 are refused, in every run (the same 7). - With `LEONIDA_LDS_EXACT_FIRST=0`, every program has the same result, DXIL size and FNV-1a-64 hash of its DXIL as on `main`; the two costliest were also compared byte for byte (61,348 and 63,240 bytes). - With the switch on, exactly 10 change form, all from the split form without skips to the one-thread regions of the form without early-outs; none refused, none newly translated. Their DXIL is the same as in #3126. - 81 programs reach the attempt. Besides the 10, 71 keep the split form after more translations that fail: two for 64 of them, one for the 7 that have no form without early-outs. Whole book with 8 shards: 49 s with the switch off, 36 s on (no single program timed here; #3126 timed the 10). | The two costliest programs | group barriers in the code | DXIL instructions | |---|---|---| | first, `main` / this branch | 417 / 14 | 5,892 / 2,245 | | second, `main` / this branch | 427 / 24 | 6,047 / 2,409 | **Hand-written console code** (`wave64_tests.rs`), red before and green after. The tests of #3126, plus: - a panic inside either attempt leaves both switches off on its thread (red: `left: (true, true) right: (false, false)`); - a first-lane read whose scalar is read past its region keeps the exchange in the attempt (red: it was lowered in waves of 32); - the first-lane rule stays off in the last-resort exact forms; - a first-lane value carried out of its region in a vector register reaches the attempt and keeps the one-thread region; - the test of a first-lane value that leaves its region now asserts that it never reaches the attempt (`tried == 0`), which is the premise it guards. **Mutations**, each caught by a test: a check in `ir::without_skips` disabled; a `with_exact_first` try on the as-is form before the forms loop; the 1-D check in `single_thread_compares` removed; `one_thread_block` given a flat group size; the rule leaking into the last-resort forms; the switch inverted; the guard check dropped; the thread picker check; the second region kind in the early attempt; the early-only scope of the first-lane rule. **On the card** (RTX 3090, NVIDIA 621.40): 30 cases store the console's bytes three times each, in both forms: the clear-and-scan with the region's thread in either host wave and either console wave, the one-wave running sum through first-lane reads by threads 0, 31, 32 and 63, and the vector case (by thread 0, 31, 32, 63 or none). Each dispatch runs with a 60 s limit. WARP takes no program in waves of 32 (its waves have 4 lanes). **Rust**, from `d3d12/`, `--target x86_64-pc-windows-msvc`: `cargo test -p leonida-shader`: 441 passed, 0 failed, 6 ignored. `cargo clippy -p leonida-shader --all-targets`: 6 warnings, all in `valu_tests.rs`, none in this change. `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md`: passes. ### In-game On this branch's head: not run in game yet. A GPU-timing series on the RTX 3090 is queued for tonight (same executable for both arms, one warm-up per arm because the switch is part of the shader cache key, then A B B A with `LEONIDA_LDS_EXACT_FIRST=0` against the default). Its result will follow as a comment. The table below is from #3126 (executable of `1bc00fe25`, the change before both rebases; the 10 programs' DXIL is the same here). RTX 3090, NVIDIA 621.40, Series S settings, standing at the save, exe of `1bc00fe25` (see the note above). | | old (`LEONIDA_LDS_EXACT_FIRST=0`) | new | new − old | |---|---|---|---| | the two programs, GPU timing (`LEONIDA_GPU_TIMING=1`, two shortened runs, ±30 %) | 0.32 + 0.26 = 0.58 ms a frame | 0.07 + 0.04 = 0.11 ms a frame | −0.47 ms | | the two programs' cost in the frame, measured in each arm within one run (below) | 1.50 ± 0.03 ms of card time | 1.28 ± 0.15 ms | **−0.22 ± 0.15 ms of card time a frame** | | whole runs, card busy (2 runs old, 1 run new; indicative only) | 26.2 ms | 25.9 ms | inside the spread of whole runs | | whole runs, frame median (indicative only) | 25.5 ms | 25.2 ms | inside the spread of whole runs | | captures at 120 s and 300 s | same scene | same scene, nothing broken | 0 ‰ magenta or purple pixels | How the cost in the frame was measured: in each arm, one run of 600 s with `LEONIDA_AB=10,LEONIDA_SKIP_TRY_A` skipping the two programs every other 10 s (the picture is wrong while they are skipped), the first 60 s after reaching the world left out, 22 cycles; the cost is the card time a frame with them minus without them. This was chosen over comparing whole runs because two whole runs of the same executable differ from each other by 0.4 to 2 ms of card time a frame, more than the effect. Another card (OreoFR: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Series S settings, moving, four parts of 450 s off/on/on/off, one shader folder per arm): 25.16 frames/s off against 25.23 on. No effect on the frame rate there: that card is limited by the submitting thread. No crash. Stability, as observed: with this executable, 4 of 7 runs between 05:11 and 06:09 UTC ended in a crash, **in both arms** (including `=0`, whose translation is byte for byte that of `main`), with three different signatures; then 0 crashes in 4 runs with a clean rebuild of the same commit (byte-identical executable), and 0 in 7 runs with an executable of `main` built the same way on the same day. Not reproduced, and not attributed to this change. Offline, each of the 19,104 programs of the pipeline book translates on a thread of the runtime's default stack (2 MiB) with at most 68 KiB of stack, the same on `main` and on this branch, with the switch on or off. GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40, Windows 11 Pro (build 26300): the dispatch tests, the Rust suites and the offline book on this branch; the in-game runs of #3126. NVIDIA GeForce RTX 4070 Laptop 8 GB, driver 621.40 (run by OreoFR): the in-game A/B of #3126. AI-assisted: yes (Claude Code, Claude Opus 5.5 for the code and tests; two independent read-only reviewer agents, Claude Opus 5.5, one on the code and one on the evidence and mutations; the code reviewer re-reviewed the fixes and found them ready). ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. (Open from review, not changed here because it changes another form's output: outside the early attempt, `single_thread_compares` still accepts a scalar a loop changes as the thread picker, in the last-resort exact forms.) - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (That table describes the SPIR-V translator; the DX12 translator's rules are in `d3d12/docs/findings.md`, where this one is added with how it was confirmed.) 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WtKdZ5UBfzFHFUgnKaKoSc
A console wave64 program run as two host waves of 32 whose LDS regions only
the form without skips takes (ir::without_skips) runs every thread of the
group through a region that one thread runs on the console, with a group
barrier before each LDS access in it and an exchange of the halves for each
first-lane read. Programs that clear group memory with thread 0 and then scan
it in a loop of that thread paid for that in every pass: the two costliest of
the pipeline book's compute programs carry 417 and 427 group barriers in the
code, most of them run by all 1,024 threads of the group for one thread's
stores and loads.

- emit: where the form without skips takes a program, the forms before it
  (without early-outs, then as it is) are tried first with the lane-branch
  regions one thread runs (lds_exact::with_exact_first), and kept when they
  translate whole. Such a region then has no barrier inside; the halves still
  meet on its way in and out (lds_meetings), so what came before reaches it
  and what it writes reaches the code after it. Only the first kind of
  lds_exact region is taken there: the second (reads and writes that cannot
  meet) leans on the shortcut that two writes of a region do not meet, which
  the split form does not need. And the thread must be picked by a constant
  or a scalar the program starts with: a scalar a loop changes picks another
  thread each round, and the lanes a loop lets out one by one gather at its
  exit.
- lower: in that attempt only, in a block one thread of the group runs, a
  v_readfirstlane with no guard of its own is that thread's value: the
  console wave's first lane is the only lane there, and the other host wave
  has none. With a guard EXEC may be empty and the console reads lane 0, so
  that case keeps the exchange (and is refused there). The split form took
  the program, so the skip around the region is one the code after it cannot
  see, and no scalar the region makes is read past it.
- LEONIDA_LDS_EXACT_FIRST (on unless 0): =0 gives the translation as before;
  the name joins the shader cache key through the build script's list.

Tests (wave64_tests, hand-written console code): the group barriers of a
two-wave clear-and-scan no longer grow with its one-thread region (6 for 2
and for 6 pairs of stores: the two s_barriers, one before each access every
thread makes, the meetings on the region's edges; 12 and 16 in the split
form); a first-lane read where one thread runs lowers in waves of 32 (refused
with the switch off), and under a guard of its own still asks the other half;
two columns of 2-D groups (two threads each), a guard on the read, two threads
reading and writing one dword, two threads reading one dword and writing
another, a thread id rewritten before the compare, two threads in two host
waves reading a first lane, and a first-lane read after a loop each lane
leaves on a round of its own keep the split form byte for byte, each having
reached the attempt. On an RTX 3090 (NVIDIA 621.40) the clear-and-scan with
lanes leaving early and the region's thread in either host wave and either
console wave, and a one-wave running sum through first-lane reads by threads
0, 31, 32 and 63, store the console's bytes in both forms, three times each,
each dispatch watched by a timeout; WARP takes no waves of 32 (its waves have
4 lanes), so it runs neither form.

Offline over the 2,733 compute programs of a pipeline book (NVIDIA host
settings): 10 change form, all from the split form without skips to the
one-thread regions of the form without early-outs, none refused, none newly
translated; with LEONIDA_LDS_EXACT_FIRST=0 all 2,733 are byte-identical to
before. The two costliest go from 417 and 427 group barriers to 14 and 24,
and from 5,892 and 6,047 DXIL instructions to 2,245 and 2,409; all 10 create
pipelines on the card in both forms. Translating the 10 takes about a quarter
longer (the earlier forms are tried once more).

The contract table of docs/design.md describes the SPIR-V translator; the DX12
translator's rules are in d3d12/docs/findings.md, where this one is added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- lds_exact: with_exact and with_exact_first put ACTIVE and EARLY back
  through a guard that drops, also when a translation panics. The pipeline
  workers catch such a panic and go on with the next shader on the same
  thread, which before kept the regions (and the attempt's first-lane rule)
  on for it, under the normal cache key.
- lds_exact::stays_inside, lower: the first-lane rule of the attempt before
  the split form now also checks, for the region the read is in, what the
  split form having taken the program says of the skips it left out: no
  scalar the read makes, nor any made from it, is read past the blocks one
  thread runs, directly or through a join. A vector register made from it is
  the lane's own and may leave the region.

Tests (wave64_tests): a panic inside either attempt leaves both flags off
(failed before: both stayed on); a first-lane read whose scalar the join
after its region merges keeps the exchange when lowered straight in the
attempt (lowered in waves of 32 before); the program of that shape never
reaches the attempt in emit (asserted: the form without skips keeps its
skip); the rule is refused in the last forms emit tries; a first-lane value
that leaves its region in a vector register reaches the attempt, keeps the
one-thread region, and stores the console's bytes on the card in both forms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WtKdZ5UBfzFHFUgnKaKoSc
The findings paragraph now gives the book as 2,734 compute programs
measured on this main before and after the change. It says the switch-off
check compares result, DXIL size and FNV-1a-64 hash, with the two costliest
programs compared byte for byte. It counts the programs that reach the
attempt and pay for failed translations, and names the 64 x 2 column as the
only two-dimensional group in the keep-the-form test. Two claims are marked
as measured on an earlier main only: pipelines created on the card, and the
timing of the 10. It also describes the first-lane check where the rule
fires, the panic-safe switches and the new fixtures, the card case included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WtKdZ5UBfzFHFUgnKaKoSc
OreoFR referenced this pull request from a commit 2026-12-04 04:26:47 +00:00
OreoFR referenced this pull request from a commit 2026-12-04 04:26:47 +00:00
underlight3d force-pushed lds-exact-first-b9f from 6b3ad1688c to 6acc7ef76a 2026-12-04 16:05:55 +00:00 Compare
Author
Collaborator

Rebased onto main 44c480a5f. The head is now 6acc7ef76; it was 6b3ad1688 on b9f70bc748.

What changed

  • The three commits are rebased with no conflict, and there is one more docs commit.
  • A test-build fix, folded into the first commit. Since the old base, main's mesh-shader compute fallback added mesh_compute to lower::Parts. The new test helper (wave64_tests.rs) builds a Parts, so the Windows-only wave64_tests module no longer compiled on today's main. That is so even though this pull request still merged cleanly as text. The helper now sets mesh_compute: false, as main's own wave64 helpers do. It is folded into the commit that adds the helper, so no commit of the branch lacks the field (for git bisect; only the final tree was built and tested). Apart from that line, git range-diff shows the three commits unchanged.
  • The docs commit (findings.md).
    • The offline counts below were taken on both bases.
    • =0 gives main's translation except after a translation panic in the last forms. main's with_exact left the regions on for the later programs of that thread; the flags of this change are put back.
  • An independent review of the rebase, by a second agent working from the range-diff, found no blocker. Its three nits are the fold and the two docs points above.

Checked on the rebased tree (Windows 11, RTX 3090, driver 621.40, --target x86_64-pc-windows-msvc)

  • The two costliest programs of this form (the 417 and 427 of the description). Their translated code carries 417 and 427 group barriers on main and with LEONIDA_LDS_EXACT_FIRST=0, and 14 and 24 with it on (the translator's census). With the switch off, their DXIL is identical byte for byte to main's (61,348 and 63,240 bytes).
  • Every compute program of a pipeline book (2,734), translated through main and through this branch:
    • with the switch off, all 2,734 are identical to main in result, size and DXIL hash;
    • with it on, exactly 10 programs change form, the same 10 as on the old base, each from the split form without skips to the form without early-outs on 32-lane waves; no other program changes;
    • the same 7 programs are refused in all three runs.
  • Red, then green. The change adds 11 tests to wave64_tests. With its behaviour stubbed off (the attempt before the split form never runs, and no region is taken as one thread's), built in a target folder of its own: cargo test -p leonida-shader --lib -- emit::wave64_tests:: gives 36 passed, 6 failed. The 6 are the tests that need the attempt to take a program. The other 5 check what it must not take, and that a panic leaves no switch on; they pass either way, as do the 31 tests already there. On the branch, all 42 pass.
  • cargo test -p leonida-shader (the whole crate, with the tests that run on the card): 453 passed, 0 failed, 6 ignored. The 6 are main's own; this change marks none.
  • The docs tests (tests/test_docs_*.py, 59 tests): OK.
  • cargo clippy -p leonida-shader --all-targets: no warning in the files this touches. The 6 it prints are in valu_tests.rs, as before.
  • scripts/check_no_game_data.py on the 7 changed files: exit 0.
  • tools/d3d12_switches.py --check fails on this tree and on plain main 44c480a5f alike, with LEONIDA_WAIT_TEST_CHILD missing from the page. It is not from this change and is left to that page's owner.

The in-game measurement in the description was taken on the old base; it was not repeated for the rebase.

AI-assisted: yes (Claude Code, Claude Opus 5.5).

Rebased onto `main` `44c480a5f`. The head is now `6acc7ef76`; it was `6b3ad1688` on `b9f70bc748`. **What changed** - The three commits are rebased with no conflict, and there is one more docs commit. - **A test-build fix, folded into the first commit.** Since the old base, `main`'s mesh-shader compute fallback added `mesh_compute` to `lower::Parts`. The new test helper (`wave64_tests.rs`) builds a `Parts`, so the Windows-only `wave64_tests` module no longer compiled on today's `main`. That is so even though this pull request still merged cleanly as text. The helper now sets `mesh_compute: false`, as `main`'s own wave64 helpers do. It is folded into the commit that adds the helper, so no commit of the branch lacks the field (for `git bisect`; only the final tree was built and tested). Apart from that line, `git range-diff` shows the three commits unchanged. - **The docs commit (`findings.md`).** - The offline counts below were taken on both bases. - `=0` gives `main`'s translation except after a translation panic in the last forms. `main`'s `with_exact` left the regions on for the later programs of that thread; the flags of this change are put back. - An independent review of the rebase, by a second agent working from the range-diff, found no blocker. Its three nits are the fold and the two docs points above. **Checked on the rebased tree** (Windows 11, RTX 3090, driver 621.40, `--target x86_64-pc-windows-msvc`) - **The two costliest programs of this form** (the 417 and 427 of the description). Their translated code carries 417 and 427 group barriers on `main` and with `LEONIDA_LDS_EXACT_FIRST=0`, and 14 and 24 with it on (the translator's census). With the switch off, their DXIL is identical byte for byte to `main`'s (61,348 and 63,240 bytes). - **Every compute program of a pipeline book (2,734),** translated through `main` and through this branch: - with the switch off, all 2,734 are identical to `main` in result, size and DXIL hash; - with it on, exactly 10 programs change form, the same 10 as on the old base, each from the split form without skips to the form without early-outs on 32-lane waves; no other program changes; - the same 7 programs are refused in all three runs. - **Red, then green.** The change adds 11 tests to `wave64_tests`. With its behaviour stubbed off (the attempt before the split form never runs, and no region is taken as one thread's), built in a target folder of its own: `cargo test -p leonida-shader --lib -- emit::wave64_tests::` gives 36 passed, 6 failed. The 6 are the tests that need the attempt to take a program. The other 5 check what it must not take, and that a panic leaves no switch on; they pass either way, as do the 31 tests already there. On the branch, all 42 pass. - `cargo test -p leonida-shader` (the whole crate, with the tests that run on the card): 453 passed, 0 failed, 6 ignored. The 6 are `main`'s own; this change marks none. - The docs tests (`tests/test_docs_*.py`, 59 tests): OK. - `cargo clippy -p leonida-shader --all-targets`: no warning in the files this touches. The 6 it prints are in `valu_tests.rs`, as before. - `scripts/check_no_game_data.py` on the 7 changed files: exit 0. - `tools/d3d12_switches.py --check` fails on this tree and on plain `main` `44c480a5f` alike, with `LEONIDA_WAIT_TEST_CHILD` missing from the page. It is not from this change and is left to that page's owner. The in-game measurement in the description was taken on the old base; it was not repeated for the rebase. AI-assisted: yes (Claude Code, Claude Opus 5.5).
First-time contributor

Verification — Merge, Repo Checks & Partial leonida-shader Unit Tests (Windows 11)

(Corrected from an earlier script misparse of test counts.)

Tested PR head 6acc7ef76a merged cleanly onto main (f22b9fa64):

  • Merge onto f22b9fa64 — clean (7 files changed)
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md — PASS
  • python -I scripts/check_no_game_data.py — PASS
  • New emit::wave64_tests::* tests run individually with --exact:
    • PASS (6/6 non-validator tests):
      • a_first_lane_read_where_one_thread_runs_is_that_threads_own
      • a_first_lane_read_under_a_guard_of_its_own_still_asks_the_other_half
      • a_first_lane_read_in_a_two_dimensional_group_is_not_taken_as_one_threads
      • a_first_lane_read_whose_scalar_is_read_past_its_region_keeps_the_exchange_in_the_attempt
      • a_first_lane_read_where_one_thread_runs_is_refused_in_the_last_forms
      • a_panic_inside_the_lds_regions_leaves_them_off_on_its_thread
    • Blocked on this host (5 tests hitting 0xC0000005 in local dxil.dll / validation): a_one_thread_region_costs_no_group_barrier_per_access, a_program_with_no_one_thread_region_keeps_its_form, a_first_lane_read_whose_value_leaves_its_region_is_not_taken_as_one_threads, a_first_lane_value_that_leaves_its_region_in_a_vector_register_reaches_the_attempt, and one_thread_regions_store_the_consoles_bytes_and_every_group_ends. Confirmed pre-existing on untouched main (f22b9fa64), where emit::wave64_tests::a_16_bit_sum_rounds_to_nearest_when_asked_to fails with the same 0xC0000005.

Partial verification only (merge, repo checks, and 6/11 new unit tests confirmed green; DXIL-validated and GPU dispatch tests still need a host without the local dxil.dll 0xC0000005 issue).

AI-assisted.

### Verification — Merge, Repo Checks & Partial `leonida-shader` Unit Tests (Windows 11) *(Corrected from an earlier script misparse of test counts.)* Tested PR head `6acc7ef76a` merged cleanly onto `main` (`f22b9fa64`): - Merge onto `f22b9fa64` — **clean** (`7` files changed) - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md` — **PASS** - `python -I scripts/check_no_game_data.py` — **PASS** - New `emit::wave64_tests::*` tests run individually with `--exact`: - **PASS (`6/6` non-validator tests):** - `a_first_lane_read_where_one_thread_runs_is_that_threads_own` - `a_first_lane_read_under_a_guard_of_its_own_still_asks_the_other_half` - `a_first_lane_read_in_a_two_dimensional_group_is_not_taken_as_one_threads` - `a_first_lane_read_whose_scalar_is_read_past_its_region_keeps_the_exchange_in_the_attempt` - `a_first_lane_read_where_one_thread_runs_is_refused_in_the_last_forms` - `a_panic_inside_the_lds_regions_leaves_them_off_on_its_thread` - **Blocked on this host (`5` tests hitting `0xC0000005` in local `dxil.dll` / validation):** `a_one_thread_region_costs_no_group_barrier_per_access`, `a_program_with_no_one_thread_region_keeps_its_form`, `a_first_lane_read_whose_value_leaves_its_region_is_not_taken_as_one_threads`, `a_first_lane_value_that_leaves_its_region_in_a_vector_register_reaches_the_attempt`, and `one_thread_regions_store_the_consoles_bytes_and_every_group_ends`. Confirmed pre-existing on untouched `main` (`f22b9fa64`), where `emit::wave64_tests::a_16_bit_sum_rounds_to_nearest_when_asked_to` fails with the same `0xC0000005`. Partial verification only (merge, repo checks, and 6/11 new unit tests confirmed green; DXIL-validated and GPU dispatch tests still need a host without the local `dxil.dll` `0xC0000005` issue). AI-assisted.
Sign in to join this conversation.
No description provided.