shader: relax WaveSize(64) for uniform single-wave LDS compute shaders #3406
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!3406
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3406"
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?
@danielibabet on GitHub · 2026-11-26 22:45 UTC · original
danielibabet:pr/nvidia-wave-invariant→main· +434 −4 · 3 files · 6 commits · openWave32-only hosts (such as NVIDIA) reject any compute pipeline whose DXIL metadata specifies \WaveSize(64)\ (\E_INVALIDARG / 0x80070057).
Previously, \lower.rs\ forced \WaveSize(64)\ whenever a Wave64 compute shader used LDS with <= 64\ threads (without \console_lanes) because the console compiler omits \s_barrier\ inside a single 64-lane wave.
This PR relaxes \WaveSize(64)\ in two safe cases:
Tested on RTX 4070 (Windows 11):
@Dukestar69 on GitHub · 2026-11-26 22:47 UTC · original · approved these changes
LGTM — verified on RTX 5090 and
VICTORY_WARP=1(Windows / D3D12) againstorigin/main(63bcca4).WaveSize(64)for uniform single-wave LDS compute shaders enables them to run on 32-lane hosts (like NVIDIA RTX) without losing correctness.cargo test -p victory-shader --lib wave64_lds_tests:: -- --test-threads=1: all passed on RTX 5090 andVICTORY_WARP=1.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@Jackster on GitHub · 2026-11-26 23:02 UTC · original
Windows 11,
63bcca4+ this PR:cargo test -p victory-shader --lib --features host wave64_lds: 3 passed —wave64_lds_within_32_threads_drops_wave_size,wave64_lds_64_threads_uniform_drops_wave_size_and_emits_barriers,wave64_lds_64_threads_guarded_keeps_wave_size_64.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.These are translation-level tests, so they run on any host. Synthetic only. AI-assisted.
@fuzeofficlal on GitHub · 2026-11-26 23:13 UTC · original · requested changes
Thanks for looking at relaxing
WaveSize(64)on single-wave Wave64 compute shaders that share LDS on Wave32 hosts. There are three blocking correctness issues with the current barrier-insertion approach:crates/victory-shader/src/emit/lower.rs:25-48, 655-660, 3385-3388, 3488-3566):can_sync_wave64_ldsonly checksx.st.guards[b][i]. When LDS instructions sit inside a divergent branch block (e.g.,s_and_saveexec_b64+s_cbranch_execz,if/else, or a divergent loop),EXECis already narrowed by control flow so the structurizer leavesguard == None.can_sync_wave64_ldstreats those accesses as workgroup-uniform, dropsWaveSize(64), andemit_lds_barrier()emitsdx.op.barrier(80, 9)in divergent control flow — where one 32-lane wave can reach the barrier while the other skips it, violating DXIL/D3D12 rules and risking a GPU hang / TDR.crates/victory-shader/src/emit/lower.rs:3385-3388, 3486-3566):ds_readinserts a barrier before the read, andds_write/ds_*atomics insert a barrier after the write/atomic. Ads_readfollowed by ads_writeords_add_*(straight-line or across loop iterations) has no barrier between the read and the modifying operation, allowing wave 0 (0..31) to overwrite LDS slots before wave 1 (32..63) reads them.v_readfirstlane_b32changes behavior when split across two Wave32 waves (crates/victory-shader/src/emit/lower.rs:607-660, 6766-6778):Non-waterfall
v_readfirstlane_b32(waveReadLaneFirst.i32) is not included inconsole_lanes. Running 64 threads as two Wave32 waves causesv_readfirstlane_b32to broadcast two different values instead of one, which can corrupt LDS writes or causeAtom::Uniformscalar branches to diverge between the two waves (triggering the divergent-barrier hang above).crates/victory-shader/src/emit/wave64_lds_tests.rs:45-94):The new tests only assert
wave_sizeandlds_wave32_syncflags onLowered, without checking actual emitted barrier instructions/ordering, divergents_cbranch_execzbranches,dxil.dllvalidation, or hardware/WARP execution.To make this safe,
can_sync_wave64_ldsneeds to verify workgroup-uniform control-flow reachability for every LDS block (and reject non-waterfallv_readfirstlane_b32/ other cross-32-lane dependencies), ensure WAR ordering between reads and subsequent writes/atomics, and add end-to-end DXIL + GPU/WARP tests.@andrewpozdnakov7-jpg on GitHub · 2026-11-26 23:18 UTC · original
I found two gaps at
434f687with the same small Wave64 LDS exchange on app-local WARP. Each lane writes its ID, reads the opposite half, replaces its own slot, then reads the opposite half again.434f687434f6877ecac72At 64 threads a later store can get ahead of an earlier read. At 16 and 32 threads, dropping the fixed wave width can still leave multiple host waves without a fence. The follow-up inserts a group fence before each LDS instruction in the eligible uniform path. It also retains
WaveSize(64)when a branch can bring only some lanes to an LDS instruction, even when that instruction has no separate EXEC guard. That branch case was checked at translation only.The controls repeated in two WARP processes and the follow-up in three. The affected suites passed 60 tests with one ignored. Strict shader Clippy in both configurations and asset policy passed. The barrier flags match DXC's thread-group and shared-memory definitions.
@danielibabet, could you rerun the exchange test on the RTX 4070 and check the title pipeline count with this change? If you fold it in, please retain the Git author or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.@danielibabet on GitHub · 2026-11-26 23:19 UTC · original
Thanks @fuzeofficlal for the thorough review! Fixed all four points:
crates/victory-shader/src/emit/wave64_lds.rs):can_sync_wave64_ldsnow propagates divergence forward from any non-uniformLaneExit::Branch(wherewhenhas non-Atom::Uniformatoms) andLaneExit::Indirect, and rejects any LDS instruction sitting in a divergent block (divergent[b]) in addition to per-laneEXECguards (x.st.guards[b][i]).crates/victory-shader/src/emit/lower.rs):Lower::dsnow emitsemit_lds_barrier()both before and afterds_read*(covering both RAW and WAR hazards across straight-line and loop iterations) in addition to afterds_write*/ LDS atomics.v_readfirstlane_b32(wave64_lds.rs):can_sync_wave64_ldsnow rejects any non-waterfallv_readfirstlane_b32(not inx.res.waterfall.reads) soWaveSize(64)is preserved whenever wave-first broadcasts occur.crates/victory-shader/src/emit/wave64_lds_tests.rs):lds_barriers: u32(dx.op.barriercall count) onLoweredunder#[cfg(test)]and verified exact barrier counts (3fords_write+ds_read,0otherwise).wave64_lds_64_threads_divergent_branch_keeps_wave_size_64(s_and_saveexec_b64+s_cbranch_execz) andwave64_lds_64_threads_readfirstlane_keeps_wave_size_64.Validator::validateinwave64_lds_64_threads_uniform_drops_wave_size_and_emits_barriers(skipping only pre-SM 6.6Unknown shader modelon older localdxil.dll).Verified locally:
cargo test -p victory-shader wave64_lds_tests -- --test-threads=1(5 passed; 0 failed)cargo clippy -p victory-shader --all-targets -- -D warningscargo xtask policy(193 files ok)@danielibabet on GitHub · 2026-11-26 23:22 UTC · original
Great catch @andrewpozdnakov7-jpg — thanks for the app-local WARP repro!
Even with
threads <= 32, hosts whose native wave width is narrower than 32 lanes (like WARP) still split the group across multiple host waves and need group barriers around uniform LDS accesses.Updated
pr/nvidia-wave-invariant(HEADnow includesCo-authored-by: andrewpozdnakov7-jpg <[email protected]>):lds_wave32_sync(group barriers before/afterds_read*and afterds_write*/ LDS atomics) for all uniform single-waveWave64LDS shaders (threads <= 64, including16and32threads) instead of skipping<= 32.55ad0f3,can_sync_wave64_ldsalso enforces workgroup-uniform control-flow reachability and rejects non-waterfallv_readfirstlane_b32.Verified locally on RTX 4070 (Windows 11):
cargo test -p victory-shader wave64_lds_tests -- --test-threads=1(5 passed; 0 failed)cargo clippy -p victory-shader --all-targets -- -D warningscargo xtask policy(193 files ok)@fuzeofficlal on GitHub · 2026-11-26 23:35 UTC · original · requested changes
Thanks for adding
wave64_lds.rsreachability checks, wrappingds_readwith pre/post barriers (closing the WAR/read-to-atomic gap), and rejecting non-waterfallv_readfirstlane_b32! Two P0 divergent-barrier issues still remain in48cb3944:image_atomic_*emitsemit_lds_barrier()outsidecan_sync_wave64_lds's check (crates/victory-shader/src/emit/lower.rs:8647-8649,crates/victory-shader/src/emit/wave64_lds.rs:67-94):if self.lds_wave32_sync { self.emit_lds_barrier(); }is also inserted at the end ofimage_atomic_*(a texture UAV atomic, not aFields::DsLDS op), whereascan_sync_wave64_ldsonly checksFields::Ds { gds: false, .. }blocks. A 64-thread shader with a uniformds_writefollowed by animage_atomic_*inside a divergents_and_saveexec_b64+s_cbranch_execzbranch passescan_sync_wave64_lds, dropsWaveSize(64), and emits a workgroup barrier inside divergent control flow (hanging when only one Wave32 executes it). (image_atomic_*does not operate on LDS and shouldn't emit an LDS barrier here—or must be checked bycan_sync_wave64_lds.)waveActiveBallotcan diverge anAtom::Uniformbranch across Wave32s (crates/victory-shader/src/emit/wave64_lds.rs:12-25, 86-94,crates/victory-shader/src/structure.rs:1207-1225, 1364-1378,crates/victory-shader/src/emit/lower.rs:416-438, 1672-1680, 1850-1888):When
console_lanesis false, instructions likes_bitset1_b32 s20, 0on av_cmpmask can read awaveActiveBallotresult whose low 32-bit word differs between Wave64 and two contiguous Wave32s (0vs0xffffffff). A downstream scalar comparison such ass_cmp_eq_u32 s20, 1is still classified asAtom::Uniform, letting a divergent branch into an LDS block passcan_sync_wave64_lds.(Non-blocking note: existing compute
s_barrieroutsideFields::Dshas the same exposure ifWaveSize(64)is dropped ands_barriersits inside a divergent branch; also consider adding a hardware/WARP execution test covering WAR ordering and uniform loops.)@danielibabet on GitHub · 2026-11-26 23:49 UTC · original
Thanks @fuzeofficlal for catching both P0s! Fixed in
HEAD:image_atomic_*(crates/victory-shader/src/emit/lower.rs):if self.lds_wave32_sync { self.emit_lds_barrier(); }fromimage_atomic_*(image_atomic_*does not operate on LDS).s_barrier(crates/victory-shader/src/emit/wave64_lds.rs):can_sync_wave64_ldsnow rejects shaders where a non-EXEC-writing scalar instruction (Fields::Sop) reads alane_mask(x.st.masks), preventingwaveActiveBallotresults (e.g.s_bitset1_b32+s_cmp_eq_u32) from divergingAtom::Uniformbranches across two Wave32 waves.s_barrierinsidedivergent[b].crates/victory-shader/src/emit/wave64_lds_tests.rs):wave64_lds_64_threads_scalar_mask_mod_keeps_wave_size_64(s_bitset1_b32+s_cmp_eq_u32branch -> keepsWaveSize(64)andlds_barriers == 0).Verified locally:
cargo test -p victory-shader wave64_lds_tests -- --test-threads=1(6 passed; 0 failed)cargo clippy -p victory-shader --all-targets -- -D warningscargo xtask policy(193 files ok)@fuzeofficlal on GitHub · 2026-11-27 00:05 UTC · original · requested changes
Thanks for the quick turnaround in
9ca8096b— movingemit_lds_barrier()strictly intods()resolved theimage_atomic_*issue, andwave64_lds_tests(6 passed on both hardware and WARP),emit::lower::tests(33 passed),policy,clippy, and formatting on the touched hunks all pass (lower.rsis523,071 B, under 512 KiB).However, a few mask-escape paths remain in
can_sync_wave64_ldsthat can still cause the two Wave32 waves to diverge at anAtom::Uniformbranch or alter LDS values:Missing
x.st.highsand non-SOP mask-as-data paths (wave64_lds.rs:84-89,lower.rs:416-439):can_sync_wave64_ldsonly inspectsFields::Sopand only checksx.st.masks.contains_key(&r), missing reads ofx.st.highs(the upper dword of a 64-bit lane mask, including implicit destination reads/writes on the high dword).Fields::Smem(for examples_buffer_load_dwordusing a tracked mask SGPR as its offset) is skipped by bothcan_sync_wave64_ldsandreads_mask_as_data(lower.rs:433). That materializes a Wave32-onlywaveActiveBallotword inmask_dword(lower.rs:1852), which can then drive ans_cmp+s_cbranch_scc*(Atom::Uniform) branch so only one Wave32 executes an LDS op/barrier.v_cndmask_b32is wholly exempt fromreads_mask_as_data(lower.rs:428-430), so a tracked mask SGPR passed as a data operand (not the condition) can likewise materialize a Wave32 ballot before an LDS write.Test encoding mismatch (
wave64_lds_tests.rs:147):wave64_lds_64_threads_scalar_mask_mod_keeps_wave_size_64,0xBEB4_1D80encodess_bitset1_b32 s52, 0rather thans20(0xBE94_1D80). Becauses20is unmodified, the test currently passes vias_cmp_eq_u32 s20, 1hittingreads_mask_as_data, rather than exercising thes_bitset1_b32guard. Also consider adding a hardware/WARP execution test verifying cross-wave LDS visibility (not only barrier counts).@danielibabet on GitHub · 2026-11-27 00:11 UTC · original
@fuzeofficlal Thanks for catching those mask-escape paths and the encoding typo! Fixed in
ef308f5:eads_mask_as_data): now inspects \Fields::Smem\ (\data, \ase, \soffset) and checks the data operands (\.src.iter().take(2)) of \cndmask_b32\ and _co_ci\ rather than exempting those instructions entirely.
@upipibi on GitHub · 2026-11-27 00:29 UTC · original
Run of head
ef308f5eon an RTX 3070 8 GB (Ampere, wave32 only, SM 6.6), driver 616.56, Windows 11, withmain63bcca43as the control. No game files used.cargo test -p victory-shader --lib --features host --locked -- --test-threads=1 wave64_lds, 3 runs on head:9 passed; 0 failedeach time. All nineemit::lower::wave64_lds_testspass, including the three added inef308f5(cndmask_data,scalar_mask_mod,smem_mask_offsetkeep WaveSize(64)).Negative control: this head's
wave64_lds_tests.rsand itsmodline applied tomaindon't compile. There are 27 errors, all E0609: no fieldwave_size,lds_wave32_syncorlds_barriersonemit::lower::Lowered. So the tests need the PR's code.Full lib,
--skip heap_direct_texture_reads_mark_their_heap_indexon both trees (that test aborts with 0xC0000005 on this card onmaintoo):307 passed; 3 failed; 3 ignored298 passed; 3 failed; 3 ignoredstride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware). The +9 on head are the new tests.One limit: these tests lower the shader and run the
dxil.dllvalidator. They create no D3D12 device, so this doesn't show a WaveSize(64) pipeline being refused or accepted on wave32 hardware, or the LDS exchange result from the WARP repro. That would need a test that creates the pipeline on the card.AI-assisted (Claude Code, Claude Opus 5.5): ran the tests and wrote this.
@fuzeofficlal on GitHub · 2026-11-27 00:34 UTC · original · requested changes
Thanks for updating the tests and tightening the
x.st.highs,Fields::Smem, andv_cndmask_b32/_co_ci_checks —wave64_lds_tests(9/9 on hardware and WARP),emit::lower::tests(33/33),clippy, andxtask policyall pass, andwave64_lds_tests.rs:161now encodess_bitset1_b32 s20, 0(0xBE94_1D80).Two issues still block approval:
Multi-SGPR scalar operands only check the first register (
lower.rs:442-445) + uncoveredFieldsvariantsreads_mask_as_datachecksi.read(Reg::S(code)).is_some_and(is_mask), which only inspects the base register of a scalar pair (Operand::Scalar { code, count }withcount > 1). If the low word (s20) of a mask pairs[20:21]is overwritten while the high word (s21inx.st.highs) stays live and is read vias[20:21]in a 64-bit VALU instruction (reproduced withv_lshlrev_b64 v[2:3], v1, s[20:21]feedingds_write_b32),reads_mask_as_datareturnsfalseand lowering proceeds withwave_size = Noneandlds_wave32_sync = true. Checking all registerscode..code + countcloses this path.reads_mask_as_data(lower.rs:418-441) andcan_sync_wave64_lds(wave64_lds.rs:85) also omit other instructions that can carry scalar mask operands (such asFields::Buffer { soffset, .. }andFields::Flat { saddr, .. }).Formatting (
lower.rs:431)rustfmt --edition 2024 --checkfails on the newly editedFields::Valu(v) if matches!(i.name(), "v_cndmask_b32") || i.name().contains("_co_ci_") =>arm atcrates/victory-shader/src/emit/lower.rs:434-436(it fits on one line).@danielibabet on GitHub · 2026-11-27 00:36 UTC · original
Follow-up while testing on RTX 4070:
eads_mask_as_data, while still rejecting \x.st.highs\ and non-mask scalar/SMEM uses.
@zzm1234560621-prog on GitHub · 2026-11-27 00:49 UTC · original
Verification on a Wave32-only Intel host (Arc, Xe-LPG, driver 32.0.101.6127), which is the class of adapter the relaxation is for —
ef308f5on top of63bcca4:The seven failures are this adapter's standing set on unmodified
63bcca4(#3196: three BVH tests one ULP off,arithmetic_matches_the_hardwareand the MAD signed zero which #3212 fixes,image_atomics_of_64_bitsand the view-heap test covered by #3203/#3178, andfspx_…dot_products). So no new failure here, and the 304 over the 295 baseline includes the 9 new tests.cargo clippy … -D warnings: clean.cargo xtask policy: 193 files ok.Two things worth saying about the shape of the evidence, since they bound what this adds:
lowered.wave_size,lds_wave32_sync,lds_barriersand run the DXIL validator; no device is created (the whole selection finishes in 0.02 s). So what I have verified on the Intel side is that the metadata the relaxation emits is what the tests say, on a host that refusesWaveSize(64).[32, 1, 1], 16 dwords of LDS) throughHost::compute_pipeline/dispatchand asserts it creates and runs where an unrelaxedWaveSize(64)program does not — I can write and run that here if it is wanted, either in this PR or as a follow-up.No conflict with #3242 (that one only touches
synthetic_tests.rs's assertions about which waves a device can run; this one changes whatlower.rsemits).No game files. AI-assisted (Claude).
@fuzeofficlal on GitHub · 2026-11-27 01:11 UTC · original · requested changes
Thanks for fixing the
v_cndmask_b32encoding inwave64_lds_tests.rs:199(0x0202_0214).wave64_lds_tests(9/9 on RTX 5090 and WARP),emit::lower::tests(33/33),clippy, andxtask policypass.However, the two blockers in
lower.rsfrom the previous round are still present in174e8d9b, and the new!writes_maskexemption makes the saved-mask case easier to reach:Multi-SGPR scalar pairs and
Fields::Buffer/Fields::Flatstill bypassreads_mask_as_data(lower.rs:416-445)reads_mask_as_datastill checks onlyi.read(Reg::S(code)).is_some_and(is_mask)(lower.rs:442), skipping registerscode + 1..code + count. With the new!writes_maskexemption inwave64_lds.rs:86-93, a sequence likes_mov_b64 s[20:21], vcc; s_mov_b32 s20, 0; v_lshlrev_b64 v[2:3], v1, s[20:21]; ds_write_b32 ...now passescan_sync_wave64_ldsand dropsWaveSize(64)while readings21(x.st.highs) as data.Fields::Buffer { soffset, .. }andFields::Flat { saddr, .. }are also still unhandled inreads_mask_as_data(lower.rs:418-441) andcan_sync_wave64_lds(wave64_lds.rs:85).Formatting (
lower.rs:431)rustfmt --edition 2024 --checkstill reports formatting drift on theFields::Valu(v) if matches!(i.name(), "v_cndmask_b32") || i.name().contains("_co_ci_") =>arm atcrates/victory-shader/src/emit/lower.rs:434-436.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.