You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(shader): use hardware group_sync for uniform pair meetings (#282) - #310
Implements the Lower::meet LDS spin-barrier optimization from Audit #282 (Pass 4, Item 4): when lowering wave64 compute shaders for 32-lane hosts with with_pair_meetings (pairs mode), threadgroup-uniform IR blocks now emit a single hardware GroupMemoryBarrierWithGroupSync (group_sync, barrier(9)) instead of the 4,096-iteration LDS atomic counter spin-poll loop (barrier(8)), while divergent/non-uniform blocks continue to use the per-console-wave LDS spin-poll.
Computed in Lower::new (lower.rs:2009-2042) alongside fence_only so the reverse_postorder / cut_short / all_lane_blocks_of(x.st, pairs.is_some()) analysis runs whenever pairs.is_some() || insts().any(|i| i.name() == "s_barrier").
group_uniform_blocks is Some(all) only when pairs.is_some() && !cut_short, where all is all_lane_blocks_of(x.st, true) (marks an IR block true iff it is not inside any per-lane branch region, any wave-wide branch region Structured::wide, or any loop-closing branch region). When cut_short is true (a plain-jump loop where lanes can abort early via abort_block), group_uniform_blocks is None so every block safely stays on the per-console-wave LDS spin-poll.
Returns true iff self.pairs.is_some() and self.group_uniform_blocks marks self.cur_ir as true.
Lower::meet(&mut self) (lower.rs:4934-4938):
Changed guard from if self.pairs.is_none() to if self.pairs.is_none() || self.group_uniform_meet(), dispatching uniform blocks directly to self.group_sync(c).
Double-Buffered Exchange Race-Freedom (Lower::exchange_pairs at lower.rs:5028-5047 & v_readlane_b32 at lower.rs:9975-9981):
Critical invariant: In pairs mode, exchange_dword() selects exchange buffer 0 or 1 via (counter >> 1) & 1, where counter is only incremented by the divergent LDS spin-poll inside Lower::meet(). A uniform group_sync does not increment counter.
Consequently, two consecutive uniform exchanges (or a uniform exchange followed by a divergent exchange) observe the same counter value and select the same exchange buffer slot.
To keep buffer reuse race-free without touching counter, both exchange_pairs() and v_readlane_b32 capture let uniform_pair = self.group_uniform_meet(); before self.meet(), and emit a second self.meet() (group_sync) after loading from the exchange buffer when uniform_pair is true (matching the self.pairs.is_none() double-barrier protocol).
crates/victory-shader/src/emit/lower_tests.rs — Cross-Platform Unit Test Coverage
Added pair_meetings_use_group_sync_in_uniform_blocks_and_spin_in_divergent_loops (lower_tests.rs:1054-1206) using super::TEST_HOST_WAVE (32), super::with_pair_meetings, and bitcode::census::barrier_modes:
Mixed shader (128 threads, widened divergent loop with ds_write_b32/ds_read_b32 + reconverged uniform post-loop block with v_readlane_b32): verifies wave_size == Some(32), presence of barrier(8) from the divergent loop's LDS spin-poll, and >= 3barrier(9) hardware group_sync barriers (entry + post-loop v_readlane_b32).
CPU: Linux workstation (offline unit tests, DXIL barrier census, and clippy only)
GPU & VRAM: N/A (not executed on live Windows D3D12 hardware)
System RAM: N/A
OS & GPU Driver: Linux (x86_64) — Windows x86_64-pc-windows-msvc full workspace clippy, wave64_tests GPU execution, and live title frame-time validation deferred to GitHub Actions (windows-latest) / maintainer run
Run Settings & Profile
Build & Commit SHA:victory-shader changes on top of origin/main (c7d3102)
Automated triage for the maintainers (not an approval).
Verdict:needs-gpu-test · CI (check):passing
Review Summary
The change in crates/victory-shader/src/emit/lower.rs cleanly optimizes Lower::meet under pairs (with_pair_meetings) mode by emitting a hardware group_sync (barrier(9)) instead of the per-console-wave LDS spin-poll (barrier(8)) when self.cur_ir is threadgroup-uniform.
Verification
Uniformity analysis (Lower::new, Lower::group_uniform_meet): Reuses the same cut_short (plain-jump back-edge) and all_lane_blocks_of(x.st, pairs.is_some()) analysis already used on main to classify fence_only for s_barrier. Blocks inside per-lane branches, wave-wide branches, divergent loops, or shaders with cut-short loops stay on the LDS spin-poll.
Double-buffered exchange race-freedom (Lower::exchange_pairs, v_readlane_b32): Because a uniform group_sync does not advance the LDS meeting counter that exchange_dword() uses to alternate exchange buffers, capturing let uniform_pair = self.group_uniform_meet() and emitting a second self.meet() after loading from LDS prevents subsequent uniform or divergent exchanges from overwriting the slot before all lanes finish reading. v_readfirstlane_b32 routes through exchange_halves / exchange_pairs, so all pair-exchange callers are covered.
Tests (crates/victory-shader/src/emit/lower_tests.rs): pair_meetings_use_group_sync_in_uniform_blocks_and_spin_in_divergent_loops verifies both a mixed divergent-loop + uniform post-loop shader and a purely uniform shader via bitcode::census::barrier_modes, and cleanly restores TEST_HOST_WAVE.
CI: Passing.
Why needs-gpu-test
This modifies DXIL barrier emission for wave64-on-wave32 compute shaders (Lower::meet, exchange_pairs, v_readlane_b32) and has only been validated with offline compiler/census tests so far. A local real-GPU smoke test on a 32-lane host (with pair meetings active) is warranted to confirm no TDRs/deadlocks or LDS exchange corruption before merging.
(Automated technical triage review; not a formal maintainer approval.)
CI run 46844652097 failed on a single clippy::manual-contains lint in the new unit test:
crates/victory-shader/src/emit/lower_tests.rs:1163:9: replace mixed_modes.iter().any(|&m| m == 8) with mixed_modes.contains(&8).
Everything else compiled cleanly (victory-shader + workspace). Once fixed + green CI + real-GPU A/B & diagnostics visual PNG check, this is in the immediate priority merge wave.
Fixed the clippy::manual_contains lint in crates/victory-shader/src/emit/lower_tests.rs (commit 4005603 pushed to perf/shader-uniform-pair-meet) and ran real-GPU verification merged cleanly onto main (3230974):
victory-shaderlower::tests (22 passed, 0 failed, 1 ignored) and real-GPU wave64_tests (19 passed, 0 failed) PASS (352 passed overall; the 3 Pipeline State Validation failures in rect::tests x2 and barycentric_tests::first_half_values_render_on_hardware_and_warp fail identically on unmodified main3230974 on this host's dxil.dll)
Warm-Cache Paired Same-Path Plain---release A/B vs main (3230974, after 20s 1440p warmup, Series X + DLSS quality, RTX 4060 Ti 8 GB, 0 crashes/DRED):
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
area: shaderShader translator, wave lowering, or DXIL emittertriage: needs gpu testSecurity & logic checks passed; requires local real-GPU smoke test
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the
Lower::meetLDS spin-barrier optimization from Audit #282 (Pass 4, Item 4): when lowering wave64 compute shaders for 32-lane hosts withwith_pair_meetings(pairsmode), threadgroup-uniform IR blocks now emit a single hardwareGroupMemoryBarrierWithGroupSync(group_sync,barrier(9)) instead of the 4,096-iteration LDS atomic counter spin-poll loop (barrier(8)), while divergent/non-uniform blocks continue to use the per-console-wave LDS spin-poll.Refs #282
AI-Ready Context & Change Map
For downstream coding/review agents, here is the exact scope, invariant set, and symbol map of this PR:
crates/victory-shader/src/emit/lower.rs— Uniform vs. Divergent Pair MeetingsLower::group_uniform_blocks: Option<Vec<bool>>(lower.rs:355):Lower::new(lower.rs:2009-2042) alongsidefence_onlyso thereverse_postorder/cut_short/all_lane_blocks_of(x.st, pairs.is_some())analysis runs wheneverpairs.is_some() || insts().any(|i| i.name() == "s_barrier").group_uniform_blocksisSome(all)only whenpairs.is_some() && !cut_short, whereallisall_lane_blocks_of(x.st, true)(marks an IR blocktrueiff it is not inside any per-lane branch region, any wave-wide branch regionStructured::wide, or any loop-closing branch region). Whencut_shortis true (a plain-jump loop where lanes can abort early viaabort_block),group_uniform_blocksisNoneso every block safely stays on the per-console-wave LDS spin-poll.Lower::group_uniform_meet(&self) -> bool(lower.rs:4917-4923):trueiffself.pairs.is_some()andself.group_uniform_blocksmarksself.cur_irastrue.Lower::meet(&mut self)(lower.rs:4934-4938):if self.pairs.is_none()toif self.pairs.is_none() || self.group_uniform_meet(), dispatching uniform blocks directly toself.group_sync(c).Lower::exchange_pairsatlower.rs:5028-5047&v_readlane_b32atlower.rs:9975-9981):pairsmode,exchange_dword()selects exchange buffer0or1via(counter >> 1) & 1, wherecounteris only incremented by the divergent LDS spin-poll insideLower::meet(). A uniformgroup_syncdoes not incrementcounter.countervalue and select the same exchange buffer slot.counter, bothexchange_pairs()andv_readlane_b32capturelet uniform_pair = self.group_uniform_meet();beforeself.meet(), and emit a secondself.meet()(group_sync) after loading from the exchange buffer whenuniform_pairis true (matching theself.pairs.is_none()double-barrier protocol).crates/victory-shader/src/emit/lower_tests.rs— Cross-Platform Unit Test Coveragepair_meetings_use_group_sync_in_uniform_blocks_and_spin_in_divergent_loops(lower_tests.rs:1054-1206) usingsuper::TEST_HOST_WAVE(32),super::with_pair_meetings, andbitcode::census::barrier_modes:ds_write_b32/ds_read_b32+ reconverged uniform post-loop block withv_readlane_b32): verifieswave_size == Some(32), presence ofbarrier(8)from the divergent loop's LDS spin-poll, and>= 3barrier(9)hardwaregroup_syncbarriers (entry + post-loopv_readlane_b32).ds_write_b32/ds_read_b32+v_readlane_b32, no branches): verifieswave_size == Some(32),0barrier(8)spin-polls emitted, and>= 3barrier(9)hardwaregroup_syncbarriers.Rig Specs Tested On
x86_64-pc-windows-msvcfull workspace clippy,wave64_testsGPU execution, and live title frame-time validation deferred to GitHub Actions (windows-latest) / maintainer runRun Settings & Profile
victory-shaderchanges on top oforigin/main(c7d3102)VICTORY_*Overrides: N/AMeasurements & Verification
cargo clippy --workspace --all-targets --locked -- -D warnings(requiresx86_64-pc-windows-msvc; verified on GitHub Actionswindows-latestCI)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings(requiresx86_64-pc-windows-msvc; verified on GitHub Actionswindows-latestCI)cargo clippy --locked -p victory-shader --lib -- -D warnings-> 0 warnings, exit 0cargo test --locked -p victory-shader pair_meetings_use_group_sync -- --nocapture-> 1 passed, 0 failedcargo test --locked -p victory-shader -- --test-threads=1-> 253 passed, 0 failed, 2 ignoredcargo test --locked -p xtask-> 8 passed, 0 failedcargo xtask policy->asset policy: 321 files ok