D3D12-SHADER-DOUBLE-BUFFERED-EXCHANGE: double-buffer wave64 exchange banks to halve loop barriers #2688
Closed
github-bot
wants to merge 4 commits from
github-bot/gh-2688 into main
AGit
pull from: github-bot/gh-2688
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!2688
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2688"
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?
@bobcatchris on GitHub · 2026-11-30 02:43 UTC · original
bobcatchris:feat/d3d12-shader-double-buffered-exchange→main· +222 −1 · 2 files · 4 commits · closed without mergingClaimed in #2570 as
D3D12-SHADER-DOUBLE-BUFFERED-EXCHANGE(#issuecomment-7267219686).What and why
Addresses the open shader-performance item in
d3d12/docs/findings.md:Previously,
exchange_many()ind3d12/crates/leonida-shader/src/emit/lower.rsemitted twogroup_syncbarriers for every exchange inside a cyclic IR block (one after storing into the shared pair, and a second after loading so the next exchange would not overwrite a slow reader).This change allocates a second shared exchange bank (
2 * wavesextra LDS dwords whenexchange_sites() > 0and LDS has room) and threads a per-thread 1-bitbankparity SSA value (i32in{0, 1}) across reachable IR blocks:kstores into bankk & 1, executes onegroup_sync, loads both halves from bankk & 1, and flipsbank ^= 1.k - 1after finishing their reads of bank(k - 2) & 1 == k & 1, storing to bankk & 1is race-free without a post-load barrier.bankphis in shaders with no shared-bank exchanges are eliminated byopt.rs(FOLD | DEAD).LEONIDA_EXCHANGE_SITES=0or LDS has no room for the second bank.Verification (Red -> Green)
Hardware / OS: native Windows 11 Pro (
10.0.26200) + AMD Radeon RX 7900 XTX (gfx1100, driver32.0.32029.2010), pinned toolchainrustc 1.98.1.exchanges_in_a_loop_meet_once_with_double_buffered_banksemitted3barriers both withLEONIDA_EXCHANGE_SITES=24and0(3 vs 3).main40e7fe69d):3barriers to2(1 barrier per loop exchange instead of 2), DXIL validates viadxil.dll, and live GPU dispatch on RX 7900 XTX matches the exact 8-iteration wave OR sum bit-for-bit.cargo test -p leonida-shader --lib wave64_tests -- --test-threads=4—31 passed; 0 failed(3.87s).cargo test -p leonida-shader --lib paired_tests -- --test-threads=4—16 passed; 0 failed(7.30s).python -I scripts/check_no_game_data.pyon both touched files — PASS.AI-assisted: Antigravity (Gemini 4 Neon)
Addresses the d3d12/docs/findings.md item ("exchanges inside loops (two barriers each: about 110 of the 134 barriers of the 8 x 8 material program 1f1fbd86759b3da2 are in loops)" / "What would make it cheap: one barrier per exchange (two dwords used by turns)"). When exchange_sites() > 0 and LDS has room for a second shared bank (2 * waves extra dwords), allocate two alternating shared exchange banks and thread a per-thread 1-bit bank parity SSA value (i32 in {0, 1}) across IR blocks. Every shared-bank exchange (including inside loops) alternates banks with one group_sync after its stores and flips bank ^= 1, eliminating the second post-load barrier while keeping bank reads and next-iteration stores strictly separated by the preceding barrier. Falls back cleanly to the 2-barrier single-bank path when LEONIDA_EXCHANGE_SITES=0 or when LDS is too full for the second bank. AI-assisted: Antigravity (Gemini 4 Neon)@ecox982745 on GitHub · 2026-11-30 02:53 UTC · original
Independent RTX 4090 exchange verification. Native Windows 11, NVIDIA 616.64, MSVC, Rust 1.98.1, and SDK 26100 DXIL validation.
52e1a0cf2merged cleanly onto182d0c174(tree083796dbb). The exactwave64_testsandpaired_testsfilters passed 31/31 and 16/16 respectively.ab78da371merged cleanly (tree864726660). The same exact filters passed 31/31 and 22/22.Synthetic input only. AI-assisted with OpenAI Codex (GPT-6.2 Sol).
52e1a0cf2ato2ef9796f0c@KelboLive on GitHub · 2026-11-30 15:57 UTC · original
Independent check on Windows (not the author), at
2ef9796f0.cargo test --locked --jobs 8 -p leonida-shader --lib -- --test-threads=8: 386 passed, 0 failed, 4 ignored in 251.6 s.Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned.
The behavioural claims (fewer loop barriers / same exchange results) are covered by the crate's own paired/wave64 tests; I did not measure the performance change on a GPU.
AI-assisted: yes (opencode).
@merzleckeier on GitHub · 2026-11-30 16:45 UTC · original
Test-only merge overlap with #2685
MEASURED. This head (
2ef9796f0) and #2685 (903e3731e) each merge cleanly intomain08e42a516. Combining the two resulting trees withgit merge-tree --write-treeconflicts only ind3d12/crates/leonida-shader/src/emit/wave64_tests.rs. Both patches append a different test at the same location. Keepone_d_wave64_group_skips_entry_ticket_barrier_and_keeps_thread_idsandexchanges_in_a_loop_meet_once_with_double_buffered_banksas separate functions.lower.rsmerges automatically.This checks the merge hunks. The combined shader behavior needs a separate test run. AI-assisted: Codex (GPT-6.2 Sol).
@ecox982745 on GitHub · 2026-11-30 17:12 UTC · original
Native Windows follow-up to the combined Wine test. I merged
2ef9796f0(#2688) and903e3731e(#2685) with1d4949d58, which includes #2710. The only conflict was the test-file overlap noted above. Keeping both tests gives tree00d85c8d8. No production source was changed during conflict resolution.MSVC Rust 1.98.1 release, Windows 11, NVIDIA 616.64. I made the two fixtures require Windows SDK 26100 DXIL validation, native hardware PSO creation and dispatch. DXGI confirmed the RTX 4090 for every case. Results held in three fresh runs per fixture:
1..128in both modesAll 11 stock
emit::wave::testspassed, including the merged #2710 regression. Synthetic inputs only. AI-assisted with OpenAI Codex (GPT-6.2 Sol).@bobcatchris on GitHub · 2026-11-30 18:43 UTC · original
Merged main (#2685 landed in wave64_tests.rs); kept both tests, no production change. cargo test -p leonida-shader --release emit:: after the merge: 269 passed, 0 failed, 5 ignored.
AI-assisted: Claude Sonnet 5.5
@lixonik on GitHub · 2026-12-01 03:25 UTC · original
Independent game-run A/B test with a freshly rebuilt shader cache on Windows 10 + NVIDIA RTX 5070 12 GB (driver 621.40) + Ryzen 9 5950X (
MEASURED,PROVISIONAL (n=2 balanced BAAB pairs: B1/A1, A2/B2), Series X dynamic 1080-1440p-NoFrameGen, same save restored before every run,d3d12/target/diagbuilt withdiagnostics,dlss,mimalloc).Verdict:
samein play frame rate on this CPU-bound PC (gpu_wait0.1-0.2 ms),betteron cold NVIDIA PSO compile time, and clean shader/runtime parity (0 translation regressions, 0 runtime errors, 0 device losses).MEASURED, fresh isolated cache dir for #2688):main(a596adfac):25,687shaders translated,202untranslated (133 s); coldwarm --used:3,209pipelines compiled in371 s(0 failures; per-PSO median669.0 ms, p906050.4 ms, p9918343.8 ms, max26496 ms, sum6922 s).#2688(d0a9bb041):25,687shaders translated,202untranslated (133 s); coldwarm --used:3,231pipelines compiled in328 s(0 failures; per-PSO median514.7 ms, p904951.9 ms, p9917508.2 ms, max24996 ms, sum6182 s) -- ~12% faster wall time / ~23% lower median driver PSO compile time with 22 more pipelines.Series X,-NoFrameGen, CPU-bound on RTX 5070):main):51.3 ms(49.1 / 53.5 ms), mean GPU busy68.3%(71.5% / 65.0%),gpu_wait0.1 / 0.2 ms.#2688):52.0 ms(54.4 / 49.6 ms), mean GPU busy69.5%(67.0% / 72.0%),gpu_wait0.1 / 0.2 ms.gpu_wait0.1-0.2 ms), GPU shader frame-time gains are hidden behind CPU preparation (~33-35 ms) and the two arms are within run-to-run spread (~4 ms). A GPU-bound card/resolution is still needed to isolate pure GPU frame-time speedup, while full shader corpus translation, PSO compilation, and play stability on RTX 5070 (621.40) are verified clean.AI-assisted: Antigravity.
@aslan2142 on GitHub · 2026-12-01 11:11 UTC · original · requested changes
Nice barrier reduction for cyclic/shared wave64 exchanges, and the end-of-
lower()bank_inphi wiring handles lateballot_of/wave_anyemissions onself.tail[b]cleanly.One correctness edge case to guard before merging:
d3d12/crates/leonida-shader/src/emit/lower.rs(exchange_many, lines 6018-6060 in the diff): whenself.double_bank.is_some()andirresolves toNone, execution falls back to the single-bank path targeting bank0(store(0); group_sync; load(0); group_sync). That fallback can be reached ifat == self.s.entry(e.g.,ballot_oforwave_anyfor entryEXECwithdef_block == None) after IR block 0 already emitted a double-bank exchange on bank0(which intentionally omits the trailinggroup_sync) and then splitself.s.entry(self.tail[0] != Some(self.s.entry)), e.g., withLEONIDA_EXCHANGE_SITES=1or >24 exchanges before a guarded memory op in block 0. Because the fallback writes bank0immediately after the preceding bank-0load with no intervening barrier, the two halves can race on bank0.Adding
if self.double_bank.is_some() { self.group_sync(at); }before the single-bank fallback loop (or ensuring every fallback underdouble_bankfences first) closes this race cleanly. Please also update the branch so the newd3d12 (windows-latest)CI workflow runs.(AI-assisted review.)
@merzleckeier on GitHub · 2026-12-01 11:59 UTC · original
Independent offscreen A/B check of
d0a9bb041on21e6bbf4b. I made the existing eight-iteration exchange test require DXIL validation, PSO creation, and GPU readback in both settings. On the base, exchange sites 0 and 24 both emitted two group barriers. With the PR, they emitted two and one respectively. Both settings returned the expected952on AMD Raphael (RADV 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.4), under Wine and vkd3d-proton 3.1.0.This covers the single exchange in the checked-in loop fixture. The multi-site case raised in the other review and in-game frame time remain open.
AI-assisted with OpenAI Codex.
@merzleckeier on GitHub · 2026-12-01 12:42 UTC · original
Follow-up with two distinct exchanges per loop iteration on
d0a9bb041merged onto6c7f6b60c. The synthetic fixture runs two cross-half reductions with different inputs in each of eight iterations. I built the same fixture with the base emitter and with the PR emitter and forced host-wave32 lowering. For exchange-site budgets 0 / 1 / 24, the base emitted 4 / 4 / 4 group barriers and the PR emitted 4 / 2 / 2. Each variant passed DXIL validation and returned the expected 1968 from a real dispatch via Wine/vkd3d-proton on AMD RADV and RTX 4070 SUPER. This covers two cyclic exchange sites. The split-entry fallback from the review still needs its own fixture.AI-assisted with OpenAI Codex.
@bobcatchris on GitHub · 2026-12-01 18:25 UTC · original
@aslan2142 Addressed in
7efcddb21(mergedmainfirst, no rebase/force-push, so thed3d12 (windows-latest)CI workflow runs):if self.double_bank.is_some() && !mine.is_empty() { self.group_sync(at); }before the single-bank fallback inexchange_many(lower.rs).double_bank_single_bank_fallback_fences_before_reusing_bank_zeroinwave64_tests.rs(confirmed red without the guard:off=6, on=4; green with it:off=6, on=5).cargo test --locked -p leonida-shader --lib wave64_tests(33 passed, 0 failed) andpython -I scripts/check_no_game_data.py(clean).AI-assisted: Gemini 4 Neon (including an independent read-only reviewer pass).
@ammonium231 on GitHub · 2026-12-02 03:36 UTC · original
RTX 3090 / 621.47,
7efcddb21merged onto main393901a5b: wave64_tests is 31 passed on main and 33 on the merge (0 failed), both new double-bank tests ok. paired_tests 22/22 on both. 32-lane hardware cases ran; wave64-only programs still not run, same as main.@MoonEyes on GitHub · 2026-12-02 12:18 UTC · original
Closing: this pull request no longer applies to current
main(merge conflict ind3d12/crates/leonida-shader/src/emit/lower.rs), and open pull requests that have fallen out of step withmainare being closed so the list stays workable. If you still want this change, rebase it on currentmainand reopen it (or open a new pull request); it will be looked at again.AI-assisted (Claude Code).
@enlight3d on GitHub · 2026-12-02 13:05 UTC · original
Posted after this pull request was closed for its conflict with
main, for whoever rebases and reopens it: the head measured is7efcddb21.RUN (independent, Windows, RTX 3090): head
7efcddb21merged withgit merge --no-ffontomaind741a9f8f; both sides built the same way (diagnostics,dlss,mimalloc, targetx86_64-pc-windows-msvc). RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro (build 26300).Off the game (
cargo test -p leonida-shader; some of these tests dispatch on the card):main+ this pull request's testsexchanges_in_a_loop_meet_once_with_double_buffered_banksdouble-buffered loop exchange should emit fewer barriers: 2 vs 2double_bank_single_bank_fallback_fences_before_reusing_bank_zeroOn this
mainthe loop case already counts 2 barriers, not the 3 the description quotes, somainhas moved since the base this was written on; the test still fails there because it asks for fewer than the single-bank path gives. The second test is a guard (it passes onmaintoo).In game, Series S settings, standing at the save, 600 s each, measured, nothing else built meanwhile. Whole runs of one build differ from each other by 0.4 to 2 ms of card time a frame on this card, more than the effect sought, so the cost was measured inside each run instead: with
LEONIDA_AB=10,LEONIDA_SKIP_TRY_Askipping, every other 10 s, the three compute programs of this title whose translated code has exchanges inside loops (the picture is wrong while they are skipped), first 60 s after reaching the world left out:mainNo crash, no device loss, and no magenta or purple pixels in the captures at 120 and 300 s in either build.
Verdict for this card: PASS, no regression, no measurable gain. The tests are red then green as described and the merged build runs cleanly; on an NVIDIA card these three programs cost the same with one barrier per exchange as with two. The description's measurements are from an AMD RX 7900 XTX, where barriers may weigh more.
AI-assisted: Claude Code (Claude Opus 5.5)
Pull request closed