Shaders: drop group sync for race-free divergent single-wave barriers on narrow-wave hosts #2035
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2035
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@rivaldodev on GitHub · 2026-11-25 03:49 UTC · original
rivaldodev:nvidia/narrow-wave-barriers→main· +478 −9 · 5 files · 1 commits · openSplit 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.@jeremygold02 on GitHub · 2026-11-25 03:54 UTC · original
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.
@akimfomin on GitHub · 2026-11-25 04:18 UTC · original
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).
@Marvisak on GitHub · 2026-11-25 09:18 UTC · original · edited 2026-11-25 22:19 UTC
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
@sinan-cmyk on GitHub · 2026-11-25 09:45 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head bfb7c39c onto
main940d32f(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).
@rivaldodev on GitHub · 2026-11-25 12:14 UTC · original
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.
c61da5c700todca7588655@copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 04:05 UTC · original · reviewed
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.
@catminou4 on GitHub · 2026-11-25 04:25 UTC · original · approved these changes
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.
dca7588655to00018fa140View 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.