d3d12-shader: one-thread LDS regions before the split form without skips (D3D12-LDS-EXACT-FIRST) #3126
Closed
github-bot
wants to merge 1 commit from
github-bot/gh-3126 into main
AGit
pull from: github-bot/gh-3126
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
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!3126
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3126"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@enlight3d on GitHub · 2026-12-02 12:43 UTC · original
enlight3d:lds-exact-first-pr→main· +742 −6 · 7 files · 1 commits · closed without mergingClaimed in the coordination issue as: D3D12-LDS-EXACT-FIRST (first claimed as D3D12-SPLIT-LDS-STORE-RUNS: #2570)
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, av_readfirstlanewith 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 unless0):=0gives the translation as before. The name joins the shader cache key through the translator's build script, andd3d12/docs/switches.mdis regenerated (tools/d3d12_switches.py --out, then--check; only the new row and the count line).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).Not in this pull request: the first plan of the claim (dropping the barrier between stores of a run at constant addresses). The 400 stores of those programs sit in a region thread 0 runs, which this change takes whole, so that rule would gain nothing here.
Tested
Offline, over the 2,734 compute programs of a pipeline book, with the NVIDIA host settings (waves of 32), on this branch against
main40ac04183: 10 change form, all from the split form without skips to the one-thread regions of the form without early-outs; none is refused and none newly translated, and all 10 make compute pipelines on the card in both forms. WithLEONIDA_LDS_EXACT_FIRST=0all 2,734 are byte-identical tomain. (Counted first on393901a5b, the base before the rebase, and again on the rebased branch: the same 10 programs, the same DXIL bytes.) Translating the 10 takes about a quarter longer (220 ms against 178 ms for the 10, three runs each), while making their pipelines on the card takes far less (the costliest: 68 against 294 ms).main/ this branchmain/ this branchThe other eight: five programs of 64 threads go from 7 to 5 barriers, one of 64 threads keeps 6 (DXIL 66.8 to 53.6 KB), and two twins of the costliest pair (1,024 threads) go as the pair (417 to 14, 427 to 24).
Hand-written console code (
wave64_tests.rs), red before and green after:s_barriers, one before each access every thread makes, the meetings on the region's edges), against 12 and 16 in the split form;Guard rails, which keep the split form byte for byte, each having reached the attempt: a column of a 2-D group, a first-lane read under a guard of its own, two threads reading and writing one dword, a thread id rewritten before the compare, and two threads in two host waves reading a first lane.
On the card (
one_thread_regions_store_the_consoles_bytes_and_every_group_ends): the clear-and-scan with lanes leaving early and the region's thread in either host wave and either console wave (s0, s1 = 128, 0; 128, 40; 128, 127; 100, 64; 100, 100; 32, 31), 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 runs in a thread with a 60 s limit (a group stuck at a barrier). WARP was tried and skipped: its waves have 4 lanes, so it takes no program in waves of 32.Mutations, each built and run against the targeted tests, are each caught: the switch inverted; the guard check dropped; the one-thread proof ignored; the early attempt taking the second kind of region; a scalar a loop changes accepted as picking one thread; a thread id rewritten before the compare taken as the thread id; the meetings on the edges of a one-thread region dropped. One is not caught: the first-lane rule also outside the early attempt (in the last-resort exact forms). No fixture reaches those forms with such a read (the approximate local-wave form takes them first), so it is kept as a guard by construction only.
Rust, on
1d08f28a9(this branch, rebased onmain40ac04183), fromd3d12/,--target x86_64-pc-windows-msvc:cargo test -p leonida-shader --lib -- one_thread first_lane_read_ keeps_its_formcargo test -p leonida-shadercargo test -p leonida-shader --features diagnosticscargo clippy -p leonida-shader --all-targets(and with--features diagnostics)valu_tests.rs, none in this changepython -I tools/d3d12_switches.py --check d3d12/docs/switches.mdThe rebase onto
40ac04183had one conflict, in the field list of the lowering's state inlower.rs(mainadded the ray-query fields beside the new one), andswitches.mdwas regenerated; no line of the change itself differs (git range-diffshows only those context lines). The executable measured in game below was built from the commit before the rebase,1bc00fe25.How red was shown: the new tests use two test hooks (
lds_exact::TEST_EXACT_FIRST,census::TEST_CENSUS), so they were first run on a seam that added only those hooks and the switch, unused; each failed for the reason it states (a first-lane read refused; 12 against 16 barriers).In-game
RTX 3090, NVIDIA 621.40, Series S settings, standing at the save, exe of
1bc00fe25(this change before the rebase; the rebase changed none of its lines, see Tested).LEONIDA_LDS_EXACT_FIRST=0)LEONIDA_GPU_TIMING=1, two shortened runs, ±30 %)How the cost in the frame was measured: in each arm, one run of 600 s with
LEONIDA_AB=10,LEONIDA_SKIP_TRY_Askipping 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 ofmain), 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 ofmainbuilt 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 onmainand 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 test, the pipelines of the 10 programs, the Rust suites and the in-game runs above. NVIDIA GeForce RTX 4070 Laptop 8 GB, driver 621.40 (run by OreoFR): the in-game A/B above.
AI-assisted: yes (Claude Code, Claude Opus 5.5; reviews by two independent agents, Claude Opus 5.5 and Claude Fable)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (That table describes the SPIR-V translator; the DX12 translator's rules are ind3d12/docs/findings.md, where this one is added with how it was confirmed.)🤖 Generated with Claude Code
@Kal0s-design on GitHub · 2026-12-02 14:35 UTC · original
Ran natively on Windows 11, head
1d08f28a9merged into currentmain(d0bf821fa, clean merge, no commit), fromd3d12/with the pinned toolchain and--locked. Machine shared with other builds, so the suite times are slow; nothing flaked.Suite and lint on the merge
cargo test -p leonida-shader --libcargo test -p leonida-shader --lib -- one_thread first_lane_read_ keeps_its_form --nocapture --test-threads=1cargo clippy -p leonida-shader --all-targetsvalu_tests.rs, none in files this PR touchesFrom the
--nocaptureoutput:group barriers: 6 with the switch, 12 and 16 without, the same numbers as the PR body.one_thread_regions_store_the_consoles_bytes_and_every_group_endsran on the card: "20 cases stored the console's bytes three times each". WARP reports "waves of 4..4 lanes" and skips both programs, as the PR says. So the dispatch part ran on one NVIDIA card here, not on WARP. The validator was present, sochain_resultvalidated every shader it built.Red on the merge. I reverse-applied only the behaviour hunks (the
mod.rsblock that callswith_exact_first, and thelower.rschanges) and kept the test hooks inlds_exact.rs/census.rs, so the tests still compile:a_first_lane_read_where_one_thread_runs_is_that_threads_ownErr("... a first-lane read where not every lane runs is not supported")againstOk(Some(32))a_one_thread_region_costs_no_group_barrier_per_accessa_program_with_no_one_thread_region_keeps_its_formone_thread_regions_store_the_consoles_bytes_and_every_group_endsAfter I put the hunks back, the diff against
mainwas again 7 files, +742/−6, the tree on which the 12 had passed.Extra shapes I tried (throwaway tests, not committed). Each one was translated with
LEONIDA_LDS_EXACT_FIRSTon and off throughemit, and where it builds, dispatched on the card 3 times per (s0, s1) in both forms and compared with the console result computed by hand. The "off" form is main's translation, so it is the control for my expected values.s_cbranch_execzaround the regionsone_wave_scanwithouts_cbranch_execzaround its regionone_wave_scan, extra threads 1, 33, 62, 63clear_and_scan(4)in a 96-thread group (second console wave half full); s1 = 0, 63, 64, 70, 95, and s0 = 80 with s1 = 79 / 90clear_and_scan(4), 128 threads, s1 = 63, 64, 95, 96, 200, and s0 = 64 with s1 = 63 / 64, and s0 = 0xFFFFFFFFone_wave_scanwiths_add_u32 s1, s1, 0before the compare (s1 no longer the input value)That makes 228 dispatches with 0 mismatches. The cross-half cases (31,32), (32,31), (0,63) and (63,0) are consistent with the meetings on the regions' edges ordering a write by one host wave before a first-lane read by the other. The last row shows that the input-only rule for the picking scalar is conservative: a scalar that is changed outside any loop also keeps the split form. That is a missed case, not a wrong one. Without the skip branch the program never reaches the split form, so this change does not touch it.
Not checked: the corpus counts (2,734 programs, the 10 that change form, byte identity with
=0);--features diagnostics; the in-game numbers; AMD or other cards; a region whose EXEC is widened inside it (the case the findings note leaves out).GPUs tested: one NVIDIA desktop card (WARP tried, skips these programs: 4-lane waves).
AI-assisted: yes (Claude Code).
@lixonik on GitHub · 2026-12-02 15:01 UTC · original
Verified PR #3126 (
1d08f28a9) merged cleanly ontomain(acc350745) on Windows 10 x64 (Rust 1.98.1):python -I scripts/check_no_game_data.pyPASS.python -I tools/d3d12_switches.py --check d3d12/docs/switches.mdPASS.LEONIDA_DXIL=none):cargo test -p leonida-shader --lib --locked wave64_tests::-- 38 passed, 0 failed (3.56 s), including all 7 new 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_one_thread_region_costs_no_group_barrier_per_access(group barriers: 6 with the switch, 12 and 16 without),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, andone_thread_regions_store_the_consoles_bytes_and_every_group_ends).dxil.dllis10.0.19041.0(predates SM 6.6) and the test binary runs against inbox D3D12 (SM 0x65 / WARP 0x62 without Agility SDK alongside the test executable), sodxil.dllvalidation and live SM 6.6 GPU dispatch insideone_thread_regions_store_the_consoles_bytes_and_every_group_endswere skipped; IR/lowering/barrier-count assertions all passed.Verdict: PASS (CPU/IR/lowering unit tests; SM 6.6
dxil.dll+ GPU dispatch not exercised on this Win10 test runner).AI-assisted: yes (Antigravity).
@MoonEyes on GitHub · 2026-12-02 18:13 UTC · original
Ran the crate's portable tests on Linux. The new tests are Windows-only (
#[cfg(all(test, windows))] mod wave64_tests), so red/green cannot be shown here. The Windows runs by Kal0s-design and lixonik are on this same head.python -I scripts/red_green.py pr/3126 --base origin/main --no-fetch --json(cargo test -p leonida-shader):So on Linux this shows that the merge builds and the 255 portable
leonida-shadertests stay green. It says nothing about the new behaviour.python -I tests/test_d3d12_switches.pyLEONIDA_LDS_EXACT_FIRSTis on the page)python -I tests/test_docs_*.py(links, repo paths, encoding, repeated lines, list items, env vars, design rows)python -I scripts/check_no_game_data.pyon the 7 filesRead in the diff:
emit/mod.rsnow tries "exact LDS regions" before the "without skips" form, both on the base form and "as it is", underlds_exact::with_exact_first.early()limits that pass to one-thread regions, andlower.rs::one_thread_blocklets areadfirstlaneinside such a block return the thread's own value.LEONIDA_LDS_EXACT_FIRSTis on by default (is_none_or(|v| v != "0")), so the translation of every program that used to reach "without skips" can change.Points for the author
Verdict: ready, given the two Windows runs, with an in-game run requested.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
@fiestorra on GitHub · 2026-12-02 23:24 UTC · original
VERIFY-3126 — Windows nativo:
red then greenen la forma de un solo hilo1d08f28a9—emit/lds_exact.rs(+59),emit/lower.rs(+31),emit/mod.rs,emit/bitcode/census.rsRan at the head
Negative control (synthetic): I made
early()false, so the one-thread-region form is never taken, rebuilt and ran:All three bite, and the message is the measurement: the region's group barrier count is what the form changes.
What the change is: when
emitwould otherwise keep a program in the split form without its skips, it now tries the one-thread-region form first (LEONIDA_LDS_EXACT_FIRST, on unless0). Inside a region one thread runs, av_readfirstlanewith no guard of its own is that thread's value — because on the console the wave's first lane is the only lane there — and the form drops the group barrier before every LDS access it would otherwise need. The tests are the three sides of that decision: the barrier count, the console bytes written, and a program with no such region keeping its form (the "no regression by default" case).Why I trust the control here more than usual: the failing assertion names the number of barriers, which is the property the commit claims to remove — a test that would still pass with the form disabled would have been measuring something else.
What I could not test
Written with an AI assistant.
@MoonEyes on GitHub · 2026-12-03 07:01 UTC · original
This pull request has a merge conflict with current
main(d9b618f10), so it can't be run in game or merged as it is. Could you merge the latestmaininto it (or rebase onto it) and resolve the conflict? Once the head is updated, the in-game gate run can be done on the new head.AI-assisted (Claude Code).
@fiestorra on GitHub · 2026-12-03 09:23 UTC · original
Rebasadas contra
d9b618f10, con el recuento calculado y no elegidoLas tres chocaban en la misma línea de
d3d12/docs/switches.md, y las tres están resueltas contando el fichero en vez de copiando el número demain(porque las tres añaden filas, o sea que la cabecera cambia):Ramas
pr-3009-rebased,pr-3126-rebasedypr-3140-rebasedempujadas al fork, y las tres con el árbol verificado:Y el detalle que conviene mirar antes de fusionar:
#3009toca 9 ficheros.rscon 1851 líneas y#3126toca 5 con 742 — y las dos dejanleonida-gpuen715, igual quemain. O sea que ninguna de las dos añade un solo test al crate. No es un fallo de ellas (pueden ser cambios de runtime que el juego ejercita), pero es la diferencia con#3225, que trae dos, y con#3306, que trae cinco. Quien fusione debería saber que estas dos se van sin red.Lo que no verifiqué: el comportamiento en el juego, que es donde se ejercitan las dos.
@MoonEyes on GitHub · 2026-12-03 18:02 UTC · original
Thanks for the work on this. This pull request has a merge conflict with the current
mainand has had no new commit, comment or review for more than 5 hours, so I am closing it to keep the list of open pull requests manageable. This is not a judgement of the change. Whenever you like, merge the latestmaininto your branch, resolve the conflict, and reopen it (or open a new pull request that links this one). Please re-run the relevant tests on the new head; a reviewer will look at it when time allows, with no guarantee of timing or outcome.Generated by Claude Code
Pull request closed