Shaders: drop group sync for race-free divergent single-wave barriers on narrow-wave hosts #2033
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2035"
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?
Imported from Marvisak/VIctory. Originally posted by rivaldodev on 2026-11-25T03:49:41Z.
Split out from #1133 and narrowed to address all triage and reviewer feedback.
Problem
On the console,
s_barrierwaits per wave: a wave whose lanes skip the barrier still arrives. In translated DXIL, control flow runs per lane, so a barrier inside a lane-dependent branch or in a loop with a lane-dependent exit is reached by only some threads. On a wave32 host (e.g. NVIDIA) or an unpinned shader on a 32–64 adapter, one 64-thread console wave spans two host waves, and a host wave that skipsGroupMemoryBarrierWithGroupSynchangs the GPU.Narrow, race-free approach (addressing triage,
@jeremygold02, and@akimfomin)WaveLaneCountMin, notWaveLaneCountMax):crates/victory-gpu/src/host.rsrecordsD3D12_OPTIONS1::WaveLaneCountMinviavictory_shader::emit::set_host_wave_min.Lower::barrier_unsynceduseslet effective_wave = self.s.wave_size.unwrap_or_else(super::host_wave_min);.WaveSize(64)keepeffective_wave == 64(never drop sync); unpinned shaders on 32–64 or 32-only adapters useWaveLaneCountMin(32); 64-only adapters use 64 (translate identically tomain).!has_shared_rw+ single console wave):should_drop_barrier_synconly dropsSyncThreadGroup(keeping memory fences2 | 8) when:effective_wave < console_wave, ANDgroup_threads <= console_wave), AND!has_shared_rw: the shader uses zero LDS (s.lds_dwords == 0) and does not both write and read memory across buffers, images, orFlatglobal memory (so no invocation can read data written by another invocation across the barrier — eliminating both LDS and UAV/Flat-global read-after-write races).SyncThreadGroup.lane_exit_loop_blocksgroups back-edges by loop header and only marks a loop when an exiting block (with a successor outside the loop body) has a lane-dependent branch.shader_cache::build()keys onhost_wave_min()and documents its side effect (initializingcrate::host::host()on first call soWaveLaneCountMinis known before the cache key is fixed).Tests & Hardware Proof
emit::lower::tests::divergent_single_wave_barrier_runs_on_narrow_wave_hardware(live GPU dispatch + DXIL validation):s_barrierinsideif (lane < below)(below = 1, 10, 32, 33, 64).WaveLaneCountMin=32, Max=32): completes without hanging and all 64 lanes write the exact reference output (19 + lane).emit::lower::tests::lane_loop_blocks_only_marks_loops_with_lane_dependent_exits: verifies uniform-exit loops with inner lane branches are NOT marked, while lane-dependent header exits and early breaks ARE marked.emit::lower::tests::narrow_wave_barrier_sync_only_drops_for_divergent_single_console_wave_groups: verifies 64-only /WaveSize(64)-pinned, uniform barriers,has_shared_rw(LDS / UAV+Flat R/W), multi-console-wave groups, and unknown group sizes all keepSyncThreadGroup.victory-gpushader_cache::tests:3 passed, 0 failed.Imported from Marvisak/VIctory. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T04:05:40Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T03:54:50Z.
Triage verdict — Keep as a draft and verify the selected wave width (
2a5fe15)Evidence
WaveLaneCountMaxis the maximum supported width. An unpinned shader on an adapter reporting a 32–64 range can still run with wave32, butbarrier_unsyncedtreats it like a 64-only adapter. In the other direction, the emitter already requests exactWaveSize(64)for certain console-wave64 compute shaders, including a group of at most one console wave with LDS. On a 32-only adapter, such a PSO can fail validation before the barrier executes. Barrier rule · Wave size emission · D3D12 WaveSize specificationChecks and limits
Next step
This verification was AI-assisted.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:25:59Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.146 passed / 0 failed / 2 ignored. Narrow-wave host barrier handling (+2 tests) — barrier lowering for sub-32-lane waves; mixed gpu+shader, gpu half Windows-only.
[PR #2035] Shaders: narrow-wave host barrier handlingto [PR #2035] Shaders: drop group sync only for divergent single-console-wave barriers on narrow-wave hostsImported from Marvisak/VIctory. Originally posted by akimfomin on 2026-11-25T04:18:58Z.
I used PortBridge to review the current
bfb7c39csource after the loop and multi-console-wave updates. Your revised detector preserves the converged diamond. A separate case remains for one 64-thread console wave split into two host wave32s, with zero LDS and a shared UAV dependency.A lane-dependent loop exit can mark a barrier that every thread reaches in the first iteration. If one host wave writes data before that first arrival and the other reads after it, the mode 11 → 10 change permits the read of the old value. The static control grants a completed store full visibility. The difference follows from the missing arrival dependency, separate from the selected-wave-capability question. The existing
writes_uavscheck also misses Flat global stores and atomics, so zero LDS and that predicate together cannot prove the path independent.Exact pinned source checks and finite schedule model. I did not build or dispatch a potentially nonuniform barrier shader. The narrow safe omission rule needs positive evidence that no other invocation can observe the ordering. For shared effects, #192 and #1433 already cover broader convergent approaches. AI-assisted PortBridge review (OpenAI Codex).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:18:33Z.
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main(conflict incrates/victory-shader/src/emit/lower.rs). It will be reviewed again once it is rebased.From the earlier needs-work note, still open: show what the new test does on
mainon wave32 hardware, and handle (or explain) write-only shaders where the barrier orders two waves' writes.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T09:45:31Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
bfb7c39contomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
[PR #2035] Shaders: drop group sync only for divergent single-console-wave barriers on narrow-wave hoststo [PR #2035] Shaders: drop group sync for race-free divergent single-wave barriers on narrow-wave hostsImported from Marvisak/VIctory. Originally posted by rivaldodev on 2026-11-25T12:14:53Z.
Addressed all points from triage,
@jeremygold02, and@akimfomin:WaveLaneCountMin+s.wave_size): Switched fromWaveLaneCountMaxtoWaveLaneCountMin(host_wave_min()) and keyedLower::barrier_unsyncedonself.s.wave_size.unwrap_or_else(super::host_wave_min)soWaveSize(64)-pinned shaders keep sync, unpinned shaders on 32–64 adapters are handled conservatively, and 64-only adapters are unchanged.!has_shared_rw): Restricted droppingSyncThreadGroupto shaders with zero LDS (s.lds_dwords == 0) that do not both write and read across buffers, images, orFlatglobal memory (including atomics). Any shader with LDS or shared read+write memory effects keepsSyncThreadGroup, leaving broader convergent synchronization to #192 / #1433.emit::lower::tests::divergent_single_wave_barrier_runs_on_narrow_wave_hardware, which validates DXIL and dispatches a 64-thread wave64 compute shader with a divergents_barrier(lane < belowforbelow = 1, 10, 32, 33, 64) on live wave32 hardware (RTX 4070 Ti SUPER,WaveLaneCountMin=32, Max=32), checking all 64 lanes against the exact reference output (19 + lane).shader_cache::buildside effect: Noted on bothuse_shader_cacheandbuildinshader_cache.rsand in the PR description.Ready for re-triage.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T02:08:49Z.
Review: APPROVED
LGTM — verified on Windows (RTX 5090 + WARP):
cargo test -p victory-shader --lib emit::barrier:: -- --nocapturepassed (3/3) on both RTX 5090 (WaveLaneCountMin=32, Max=32) andVICTORY_WARP=1(WaveLaneCountMin=4, Max=4)cargo test -p victory-gpu --lib shader_cache::passed (4/4)cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warningspassed with 0 warningscargo xtask policypassed (192 files ok)Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.