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
pull from: underlight3d/mandy:lds-exact-first-b9f
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
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
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!3420
Loading…
Reference in a new issue
No description provided.
Delete branch "underlight3d/mandy:lds-exact-first-b9f"
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?
This branch is out-of-date with the base branch
Reviewers 0 approvals
Details
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.mdwithmain, and no activity for 5 hours; "not a judgement of the change"). It is the same change, ported tomainb9f70bc748(it merges cleanly into today'smain), 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, 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 read makes may be read past the region (checked, see the review fixes below).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).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).lds_exact.rs:with_exactandwith_exact_firstput 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.Tested (on this branch,
mainb9f70bc748)Offline, over the 2,734 compute programs of a pipeline book (NVIDIA host settings, waves of 32), the translator of
b9f70bc748against this branch:LEONIDA_LDS_EXACT_FIRST=0, every program has the same result, DXIL size and FNV-1a-64 hash of its DXIL as onmain; the two costliest were also compared byte for byte (61,348 and 63,240 bytes).main/ this branchmain/ this branchHand-written console code (
wave64_tests.rs), red before and green after. The tests of #3126, plus:left: (true, true) right: (false, false));tried == 0), which is the premise it guards.Mutations, each caught by a test: a check in
ir::without_skipsdisabled; awith_exact_firsttry on the as-is form before the forms loop; the 1-D check insingle_thread_comparesremoved;one_thread_blockgiven 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 invalu_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=0against the default). Its result will follow as a comment. The table below is from #3126 (executable of1bc00fe25, 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).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 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
mainand merges cleanly.single_thread_comparesstill accepts a scalar a loop changes as the thread picker, in the last-resort exact forms.)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
https://claude.ai/code/session_01WtKdZ5UBfzFHFUgnKaKoSc
6b3ad1688cto6acc7ef76aRebased onto
main44c480a5f. The head is now6acc7ef76; it was6b3ad1688onb9f70bc748.What changed
main's mesh-shader compute fallback addedmesh_computetolower::Parts. The new test helper (wave64_tests.rs) builds aParts, so the Windows-onlywave64_testsmodule no longer compiled on today'smain. That is so even though this pull request still merged cleanly as text. The helper now setsmesh_compute: false, asmain's own wave64 helpers do. It is folded into the commit that adds the helper, so no commit of the branch lacks the field (forgit bisect; only the final tree was built and tested). Apart from that line,git range-diffshows the three commits unchanged.findings.md).=0givesmain's translation except after a translation panic in the last forms.main'swith_exactleft the regions on for the later programs of that thread; the flags of this change are put back.Checked on the rebased tree (Windows 11, RTX 3090, driver 621.40,
--target x86_64-pc-windows-msvc)mainand withLEONIDA_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 tomain's (61,348 and 63,240 bytes).mainand through this branch:mainin result, size and DXIL hash;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 aremain's own; this change marks none.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 invalu_tests.rs, as before.scripts/check_no_game_data.pyon the 7 changed files: exit 0.tools/d3d12_switches.py --checkfails on this tree and on plainmain44c480a5falike, withLEONIDA_WAIT_TEST_CHILDmissing 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).
Verification — Merge, Repo Checks & Partial
leonida-shaderUnit Tests (Windows 11)(Corrected from an earlier script misparse of test counts.)
Tested PR head
6acc7ef76amerged cleanly ontomain(f22b9fa64):f22b9fa64— clean (7files changed)python -I tools/d3d12_switches.py --check d3d12/docs/switches.md— PASSpython -I scripts/check_no_game_data.py— PASSemit::wave64_tests::*tests run individually with--exact:6/6non-validator tests):a_first_lane_read_where_one_thread_runs_is_that_threads_owna_first_lane_read_under_a_guard_of_its_own_still_asks_the_other_halfa_first_lane_read_in_a_two_dimensional_group_is_not_taken_as_one_threadsa_first_lane_read_whose_scalar_is_read_past_its_region_keeps_the_exchange_in_the_attempta_first_lane_read_where_one_thread_runs_is_refused_in_the_last_formsa_panic_inside_the_lds_regions_leaves_them_off_on_its_thread5tests hitting0xC0000005in localdxil.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, andone_thread_regions_store_the_consoles_bytes_and_every_group_ends. Confirmed pre-existing on untouchedmain(f22b9fa64), whereemit::wave64_tests::a_16_bit_sum_rounds_to_nearest_when_asked_tofails with the same0xC0000005.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.dll0xC0000005issue).AI-assisted.