D3D12-SHADER-DOUBLE-BUFFERED-EXCHANGE: double-buffer wave64 exchange banks to halve loop barriers #2688
Closed
leonida/mandy
bobcatchris wants to merge 0 commits from
feat/d3d12-shader-double-buffered-exchange into main
pull from: feat/d3d12-shader-double-buffered-exchange
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
1 participant
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!2688
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/d3d12-shader-double-buffered-exchange"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Claimed 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)
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).
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).
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).
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).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
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.
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.
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.
@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).
RTX 3090 / 621.47, 7efcddb21 merged onto main 393901a5b: 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.
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).
Posted after this pull request was closed for its conflict with
main, for whoever rebases and reopens it: the head measured is 7efcddb21.RUN (independent, Windows, RTX 3090): head 7efcddb21 merged with
git 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)