Opt-in Wave32 cross-half LDS barrier reduction (DARNER_WAVE32_LDS_OPT) #546
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
hle
input
INTEL
lighting
linux-proton
memory
MULDER
needs-info
needs-logs
needs-rebase
NVIDIA
performance
post-merge
pr-diagnostics
pr-docs
pre-merge
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
relevance
high
relevance
low
relevance
medium
relevance
very-high
rendering
report
roadmap-proposal
saves
series-s
shaders
startup
status
blocked-by-rework
status
needs-test-report
status
needs-triage
status
ready-for-review
status
stale
status
superseded
status
wip
tools
ui
upstream
wontfix
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
TrustNo1/Darner!546
Loading…
Reference in a new issue
No description provided.
Delete branch "davetheshrew/Darner:pr/wave32-lds-barrier-opt"
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?
Contributor role (optional)
What it changes
GroupMemoryBarrierWithGroupSync()pairs around each LDS handoff even when a phase has no intervening LDS writes/atomics or when two 32-bit half-exchanges can be coalesced, adding unnecessary workgroup synchronization stalls on Wave32 compute/lighting shaders.Adds an opt-in shader lowering switch
DARNER_WAVE32_LDS_OPT=1(off by default, and always a no-op on 64-lane/AMD hosts wherehost_max_wave() != 32):darner-shader(lower.rs,lower/analysis.rs,lower/tests.rs):exchange_halves) into a single barrier pair instead of two.lower/analysis.rsso acyclic cross-half exchanges can omit redundant trailing barriers when no conflicting LDS access follows.wave32_lds_opt_reduces_barriers_on_wave32_and_is_noop_on_amd_wave64andwave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchange) covering Wave32 reduction and Wave64 no-op behavior.darner-gpu(shader_cache.rs):DARNER_WAVE32_LDS_OPTinKEYEDso shaders compiled with the switch on/off are cached separately.host/menu.rs,locales/en.json,locales/zh-CN.json):DARNER_WAVE32_LDS_OPT, default OFF, restart-required) under F1 → ADVANCED with English and Simplified Chinese help text.How it was tested
Tested revision:
e7f5d8bCommands and results: built release binary locally on Windows (
cargo build --releasesucceeded after keyingKEYED: [&str; 61]).Changes a default: no (off by default; opt-in via
DARNER_WAVE32_LDS_OPT=1or F1 → ADVANCED → WAVE32 LDS BARRIER OPT; always disabled on Wave64 hosts).A/B result: tested in-game with the switch OFF vs ON (restart between runs so shaders recompile). Frame pacing felt slightly smoother when running around, with no noticeable average FPS jump on a non-GPU-bound setup (as expected for a shader-barrier-only optimization when CPU/submit-bound).
Gates run on that revision (the three in AGENTS.md; there is no CI), or "none": none
Gameplay, when relevant:
Shader wave sizes tested, when relevant: 32 lanes (NVIDIA); 64-lane path is guarded by
host_max_wave() == 32and covered by unit test.Hardware dependence: Wave32 hosts (NVIDIA) only; intentionally a no-op on AMD Wave64 GPUs.
Coverage gaps: AMD Wave64 hardware not runtime-tested (verified by code guard and unit test); needs GPU-bound Wave32 benchmarking before considering changing the default.
Checklist
main.docs/asset-policy.md.Checked for overlap
ive ran it, changing the setting live does effect latency but i have to go out today if someone could please do a/b test id be most greatful. Thankyou
e7f5d8b694to908d22ebd2Source review of
908d22eb. One correctness case could complement the barrier-count tests before interpreting the performance A/B. On the non-paired Wave32 path, a 128-thread workgroup needs eight free LDS dwords for the coalesced private allocation inexchange_halves_two. With four to seven free, it falls back to two calls toexchange_halves: the first can still allocate four private dwords and the second uses shared scratch. With fewer than four, both use shared scratch (lower.rs:5514–5565and5582–5601).For a synthetic test, I would exercise 3, 4, 7 and 8 dwords of remaining capacity and use distinct marker pairs for each half of both console waves. The coalesced private offsets are 0–3 and 4–7. Comparing both output pairs against the opt-off path on Wave32 would cover cross-wave separation and the mixed private/shared fallback, in addition to counting barriers. I checked the index formula offline and have no build or GPU result for this head.
For the performance A/B, use fresh processes for each arm. At this revision,
wave32_lds_optcaches the switch in aOnceLock.Source review with Codex and Claude Code.
I ran the CPU shader-lowering tests at
908d22eb. The currentwave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchangefixture fails withNoneversusSome(32)for the wave-size assertion. The onlyv_readlane_b32writess14and the program ends immediately. Keeping that result live made the existing Wave32 and Wave64 assertions pass.This small fixture change worked for me. Insert these words before
S_ENDPGMand usersrc2: 1 << 15to declare LDS.I also exercised
exchange_halves_twoon a 128-thread synthetic fixture with the same live read, no paired meetings and an acyclic site. I primedwave_base()before counting and set the prior private allocation to leave the requested free space.cargo test --locked --offline -p darner-shader --lib wave32_ldspassed both PR tests with the fixture change and the additional threshold test. The Linux runner also needed an independent test-only guard around the Windows validator incard_cost_tests.rs. These are CPU lowering and allocation checks. GPU scheduling and performance remain to be measured. Reviewed and tested with Claude Code and Codex.Thanks for this, and thanks to tyr0nsur for the test run and the fixed fixture. I read the diff at
908d22eb(source only; we have not built or run it yet). I won't repeat his points: the failing readlane fixture and the 3/4/7/8-dword threshold test are what I'd fix first.A few things on top of his:
Is
pure_unorderedand the acyclic check safe for loops the lowering adds?exchange_acyclic(emit/lower.rs:5570) decides "runs at most once" fromblocks_in_cycle(emit/lower/analysis.rs:1171), which only followsst.exits. The translator also runs some loops per host wave (loops_wave,emit/mod.rs:2015; the per-half loops noted atanalysis.rs:1040) and has waterfall loops over descriptors. If one of those can hold an exchange site and is not a cycle inst.exits, the trailing barrier would be dropped inside a loop. I could not show that this happens. Can you say why it can't, or add a test with an exchange inside such a loop?An output-equivalence test. The current tests count barriers. Please add one that lowers the same exchange cases with the switch off and on and checks that both write the same results (both halves of both console waves, distinct markers), including the mixed private/shared case. That is the thing that would catch a dropped barrier that matters.
Cache key.
DARNER_WAVE32_LDS_OPTis added toKEYED(shader_cache.rs:113), which is right. As far as I can tell from the hashing loop (:202), everyKEYEDname goes into the key, so merging this changes the key for everyone, so the first run after the update recompiles shaders even with the switch off. That is fine for an opt-in, but please say so in the PR text and add a line todocs/findings.mdor the README if the switch is documented there.Base. The PR is based on current
main(c8258f95) and merges cleanly for me, so no rebase is needed yet. Ifmainmoves before it lands, a rebase will be needed. The most likely conflict is theKEYEDarray.Testing. The PR text says the gates were not run. Please run
cargo test --workspace --lockedand the two clippy gates and put the results and commit in the description. The F2 table is still empty.Once these are addressed, we'll A/B it on an RTX 2070 SUPER (Turing, wave32, 8 GB, ReBAR off). That means a fresh process per arm, per-shader card times and a replay picture comparison, and we'll post the numbers here. We have not run it yet, so we have no result either way.
Source review only, no build or run.
Written with AI assistance (Claude Code).
Follow-up on
908d22ebwith native D3D12 dispatches on an RTX 4060 (driver 621.40). The Windows SDK DXIL validator accepted both arms.For the loop question,
structure_wide_hostpreserves the IR branch targets, and the descriptor waterfall recognizer starts from a guest back edge. Ray-query lowering does emit a callback loop of its own. Both callback recognizers source their body blocks from the detected guest loop inemit/rayquery.rs. An exchange inside a ray-query callback is still a separate hardware case to cover.The test-only reproduction at cf82733 is based on this PR head. The two ignored hardware tests are
wave32_divergent_loop_outputs_match_on_hardwareandwave32_firstlane_outputs_match_for_two_console_waves_at_the_lds_limits. The GPU crate's disk-cache test iswave32_lds_opt_separates_disk_cache_entries. These measurements cover correctness on the RTX 4060. Gameplay frame times and AMD/Intel hardware are still open. Reviewed with Claude Code and Codex.I ran the standalone A/B requested above on an RTX 3060 12 GB (driver 621.40, Core Ultra 5 225F, Windows 11 build 26100). On this scene I found no repeatable speedup.
Same fast build of
908d22eb, Chapter II save, fixed camera, Series S 960×540 to 1080p, DLSS Performance, FSR 3 ×2, RT off. Two warm-up runs per setting, then two alternating runs per setting with copies of the corresponding warm cache. I used the 10–50 s window after the gameplay anchor because the draw count drops near the end of the 70 s capture. FPS below comes from rendered frames in the CSV.All four runs completed with zero lost CSV rows. The final pipeline summary gave zero host pipeline failures and one untranslated shader in each run, the same refusal in both modes. This gameplay check covers performance in one scene. Visual parity and cold loading time were outside its scope.
wave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchange(@tyr0nsur,@Jesper-A): addedv_mov_b32 v1, s14+ds_write_b32 v0, v1withrsrc2: 1 << 15sos14stays live and lowers through Wave32 emulation.@Jesper-A#1): audited all translator-created loops inemit/(buffer_atomic_fmin/fmax,meet_pair,zero_meet_slots, andlds_float_min_maxnever lower guest IR;structure_wide_hostand waterfall loops preserve cyclic edges inst.exits). Added an explicitin_synthetic_loopguard onLowerset aroundRayQuerycallback lowering (emit/rayquery.rs), routedv_readlane_b32throughexchange_acyclic, and addedwave32_lds_opt_keeps_trailing_barrier_in_loops_and_synthetic_loops.@Jesper-A#3): movedDARNER_WAVE32_LDS_OPTout ofKEYEDinto conditional keying inshader_cache::build()(matchingDARNER_PORT_CBV/DARNER_HW_RT) so unset and=0keep existing cached shaders valid while=1uses a distinct key, covered bywave32_lds_opt_changes_the_shader_cache_key.@tyr0nsur,@Jesper-A#2):wave32_lds_opt_exchange_halves_two_respects_lds_capacity_thresholdschecks3 / 4 / 7 / 8free LDS dwords on a 128-thread group (+0/+4/+4/+8private dwords and4/3/3/1exchange barriers).wave32_lds_opt_matches_default_across_two_console_waves_and_lds_fallback(wave64_tests.rs) validates DXIL and compares off vs on outputs across two 64-lane console waves (128threads) with distinct per-half values, covering coalesced private, mixed private+shared fallback (free=7), and full shared fallback (free=3) in one shader.On performance (
@SmallDevBigNothing): acknowledged that the fresh-process warm-cache A/B on RTX 3060 showed no repeatable speedup (within run-to-run noise). Keeping this opt-in (DARNER_WAVE32_LDS_OPT=1, default off) unless another Wave32 card shows a repeatable win.[pr-performance][shader] Opt-in Wave32 cross-half LDS barrier reduction (DARNER_WAVE32_LDS_OPT)to Opt-in Wave32 cross-half LDS barrier reduction (DARNER_WAVE32_LDS_OPT)Test needed — commit
f300eaa5; what to check:GroupMemoryBarrierWithGroupSync()pairs around each LDS handoff even when a phase has no intervening LDS writes/atomics or when two 32-bit half-exchanges can be coalesced, adding unnecessary workgroup synchronization stalls on Wave32 compute/lighting shaders.Adds an opt-in shader lowering switch
DARNER_WAVE32_LDS_OPT=1(off by default, and always a no-op on 64-lane/AMD hosts wherehost_max_wave() != 32):darner-shader(lower.rs,lower/analysis.rs,lower/tests.rs):exchange_halves) into a single barrier pair instead of two.lower/analysis.rsso acyclic cross-half exchanges can omit redundant trailing barriers when no conflicting LDS access follows.wave32_lds_opt_reduces_barriers_on_wave32_and_is_noop_on_amd_wave64andwave32_lds_opt_omits_trailing_barrier_on_acyclic_readlane_exchange) covering Wave32 reduction and Wave64 no-op behavior.darner-gpu(shader_cache.rs):Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.
Reply
testingto take this run; it's free again after 24 h with no results.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.