Skip to content

Shaders: replace single-wave Wave64 LDS lockstep with barriers and lower 32-lane swizzle/DPP at WaveSize(32) - #192

Open
kxiserino wants to merge 2 commits into
Marvisak:mainfrom
kxiserino:shader/wave64-lds-barriers-and-local-swizzle
Open

kxiserino wants to merge 2 commits into
Marvisak:mainfrom
kxiserino:shader/wave64-lds-barriers-and-local-swizzle

Conversation

@kxiserino

Copy link
Copy Markdown

Summary

Reduces unnecessary WaveSize(64) requirements on translated Wave64 compute shaders so Wave32-only GPUs (e.g. NVIDIA Ampere/Ada/Blackwell) can create and execute them without E_INVALIDARG:

  1. Single-wave LDS barrier synchronization (threads 33..=64):

    • Console single-wave Wave64 compute shaders (32 < total_threads <= 64) can omit s_barrier between LDS writes and reads because all 64 lanes execute in lockstep on the console. Previously, lower.rs preserved that lockstep by forcing WaveSize(64), which Wave32-only devices refuse.
    • Added plan_lds_barriers(p, st) in crates/victory-shader/src/emit/lower.rs:
      • Computes post-dominators (with a virtual exit node so divergent early returns keep everything after them non-uniform) and forward-propagates lane-varying values (including scalars derived from v_readfirstlane_b32 of a lane-varying VGPR or scalar phis across divergent branches) so only genuinely threadgroup-uniform Atom::Uniform branches are treated as uniform.
      • Rejects any shader where a non-uniform region has a RAW or WAR LDS hazard without reconverging (conservatively preserving WaveSize(64)).
      • Runs a forward RAW/WAR dataflow pass to insert dx.op.barrier(1 | 8) (GroupMemoryBarrierWithGroupSync) only in threadgroup-uniform control flow (lds_barrier_before and lds_barrier_end) and drops WaveSize(64).
  2. 32-lane-local ds_swizzle_b32 and DPP at WaveSize(32):

    • Split console_lanes into cross_32_lanes (permute, v_mbcnt, v_readlane_b32, v_writelane_b32, lane-mask data reads, opaque/constant lane masks) vs local_32_lanes (ds_swizzle_b32 and DPP, which never cross the 32-lane half-wave boundary).
    • When a Wave64 compute shader only needs local_32_lanes (and passes LDS barrier planning if it uses LDS), emit WaveSize(32) instead of WaveSize(64).
    • Added Lower::console_flat() so Dpp::Row with row_mask != 0xF computes the 4-row index (0..3) from the console lane (console_flat >> 4 & 3) rather than host lane_index >> 4, preserving upper half-wave rows 2 and 3 at WaveSize(32).

Testing

  • Added 6 synthetic GFX10 compute shader unit + D3D12 execution tests in crates/victory-shader/src/emit/lower.rs:
    • wave64_single_wave_lds_adds_barriers_and_drops_wave_size (cross-half-wave tid ^ 32 LDS exchange with no s_barrier)
    • wave64_single_wave_lds_uniform_loop_syncs_raw_and_war (4-iteration uniform loop verifying both RAW and WAR barriers)
    • wave64_divergent_write_reconverging_before_read_adds_barrier (divergent write reconverging before uniform read)
    • wave64_divergent_lds_hazard_keeps_wave_size_64 (negative safety test)
    • wave64_readfirstlane_of_tid_branch_keeps_wave_size_64 (negative safety test for half-wave-divergent v_readfirstlane_b32 branch)
    • wave64_local_swizzle_and_dpp_row_mask_uses_wave_size_32 (ds_swizzle_b32 XOR-16 + v_mov_b32_dpp row_shr:1 with row_mask:0xC)
  • cargo test --workspace on RTX 3090 (Wave32-only): all passed (victory-shader: 75 passed, 0 failed).
  • VICTORY_WARP=1 cargo test -p victory-shader wave64_ -- --test-threads=1: 6 passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: asset policy: 151 files ok.
  • Tested locally against a Wave64 compute shader corpus on RTX 3090 + dxil.dll: 22 of 106 previously-refused runtime compute pipelines now validate cleanly with dxil.dll and succeed in CreateComputePipelineState (0 new validation failures across 1,151 Wave64 compute shaders).

@juliptree

Copy link
Copy Markdown

Independently validated a6782ee on an RTX 5060 Ti, NVIDIA driver 616.92, and pinned Rust 1.98.1. Using only synthetic fixtures, I ran cargo test -p victory-shader wave64_ -- --test-threads=1. I verified the D3D12 adapter by LUID: all four GPU dispatches ran on the 5060 Ti and passed their readback assertions. The other two cases were CPU-only checks.

With VICTORY_WARP=1, three dispatches passed and two CPU-only checks passed. The fixed WaveSize(32) swizzle/DPP case passed its CPU checks and skipped dispatch after WARP rejected pipeline creation. Cargo reported 6 passed in both runs.

(Disclosure: ChatGPT 6.2 Sol used to test this and write this)

@DaviTostes

Copy link
Copy Markdown

Tested a6782ee on Arch Linux x86_64, rustc 1.98.1: pass.

No game data used.

@Raxstreams

Copy link
Copy Markdown

Tested the PR head at a6782ee on an RTX 3080 Ti. Of 96 distinct compute shaders that previously validated but failed D3D12 pipeline creation, 16 passed both checks with this PR alone. These 16 were still failing on our local integration of #233, so the fixes cover complementary cases. On this PR alone, the three 8×8 depth-pyramid shaders still validated and returned E_INVALIDARG at pipeline creation.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
v_readfirstlane reads the console wave's first lane. A wave64 program
with DPP or ds_swizzle and a v_readfirstlane was split into two 32-lane
waves, where the upper half read its own first lane: with all 64 lanes
active, lanes 32 to 63 got lane 32's value where the console gives
lane 0's (measured on an RTX 5070).

Such programs now take the console flow, which reads the first lane in
EXEC of the whole console wave (groups of at most 64 threads, no LDS),
or stop with the reason as they did before the split existed.

New test, exact on an RTX 5070 and a Radeon iGPU. Found by running the
same program against Marvisak#192, which has the same result on both adapters.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Test report on a machine with a 32-lane and a 64-lane adapter, with one wrong result.

Tested

  • NVIDIA RTX 5070 (D3D12 wave range 32..32) and an AMD Radeon iGPU (RDNA2, 32..64); Windows 11; Rust 1.98.1; debug.
  • This PR at a6782ee. cargo test -p victory-shader: 75 passed, 0 failed.
  • Hand-assembled wave64 GFX10 compute programs (the ones in Shaders: wave64 compute on 32-lane hosts, in halves and in the console flow #233's split_tests.rs plus two more), each lane's output checked against the console's result, five runs each with identical results:
Program (64 threads unless noted) RTX 5070 Radeon iGPU
ds_swizzle xor 16 + DPP row_mirror, 64 and 128 threads exact exact
DPP row_mask:0x3 exact exact
LDS without s_barrier: every lane writes dword t, lanes below 20 then read dword t + 40 exact exact
DPP + v_readfirstlane wrong wrong
s_bcnt1 of a 64-bit mask; v_readlane 40 no pipeline, as on main exact, as on main

The wrong one. All 64 lanes active:

v_mov_b32_dpp v3, v0 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf
v_readfirstlane_b32 s9, v0        ; v0 = thread id
v_mov_b32 v2, s9                  ; stored per lane

The console stores 0 in every lane (lane 0's thread id). Here lanes 32-63 store 32, on both adapters. The program has only DPP as a cross-lane read, so it gets WaveSize(32), and v_readfirstlane then reads the first lane of the host wave, which for the upper half is console lane 32. On the Radeon this program is exact on main d2a4bae (WaveSize(64)), so it is a regression there.

#233 had the same result on the RTX 5070 and fixed it in 3098672 by not giving the 32-lane form to a program with v_readfirstlane. The same condition would work here; on hosts that run 64-lane waves such a program could simply keep WaveSize(64).

Not tested: the LDS case is exact in five runs with two groups, which does not rule out a race; release build; the title (no game files used).

AI-assisted.

@kxiserino

Copy link
Copy Markdown
Author

@Raxstreams thanks for testing on the 3080 Ti. Good to hear that 16 of the 96 now pass both checks and that they don't overlap with what #233 fixes. The three 8×8 depth-pyramid shaders are expected to still fail here: they exchange data across the two 32-lane halves, so they need the full cross-half Wave64 emulation in #189 / #233, which this PR doesn't do. It only drops WaveSize(64) where barriers or 32-lane-local swizzle/DPP are enough.

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
A wave64 program split over two 32-lane waves took the DPP row index
from the host lane, so the upper half (console rows 2 and 3) read
row_mask bits 0 and 1. The row now comes from the console lane there.
New test: v_mov_b32_dpp with row_mask:0x3 writes lanes 0 to 31 only,
exact on an RTX 5070 (split) and a Radeon iGPU (native).

Found in review against #189 and #192, which both get this right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he whole wave

A Wave64 compute program with DPP/ds_swizzle or single-wave LDS that also
uses v_readfirstlane_b32 or a whole-wave Active/Prefix reduction was lowered
at WaveSize(32) (or had WaveSize(64) replaced by LDS barriers), so lanes
32..63 read their own half-wave's first lane or reduced over half the wave.

Such programs now keep the console wave size. Plain v_readfirstlane_b32
shaders without DPP, ds_swizzle or single-wave LDS still get no fixed wave
size. Test runs skip WaveSize(64) pipelines that a Wave32-only adapter
rejects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kxiserino

Copy link
Copy Markdown
Author

Thanks @r4tedx, good catch — confirmed and fixed in 4a365e3.

A Wave64 CS that needs wave-sized execution (DPP / ds_swizzle, or single-wave LDS) and also uses v_readfirstlane_b32 or a whole-wave Active/Prefix reduction now keeps WaveSize(64) instead of being lowered at WaveSize(32) or having WaveSize(64) swapped for LDS barriers. Plain v_readfirstlane_b32-only shaders (no DPP / ds_swizzle / single-wave LDS) still get no fixed wave size, same as main.

New synthetic tests:

  • wave64_dpp_with_readfirstlane_keeps_wave_size_64 (your repro: identity quad_perm DPP + v_readfirstlane_b32 s9, v0 → WaveSize(64), every lane stores 0 when run on a 64-lane adapter)
  • wave64_single_wave_lds_with_readfirstlane_keeps_wave_size_64
  • wave64_readfirstlane_only_keeps_no_wave_size

The test runner now skips (instead of panicking on) WaveSize(64) pipelines a Wave32-only adapter rejects.

Results:

  • cargo test -p victory-shader -- --test-threads=2: 78 passed, 0 failed
  • same with VICTORY_WARP=1: 78 passed, 0 failed
  • cargo clippy -p victory-shader -- -D warnings (also --all-targets): clean
  • cargo xtask policy: ok

@r4tedx

r4tedx commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the quick fix in 4a365e3, and for turning the repro into tests. I have not rerun it or reviewed the diff here, so take this as an acknowledgement, not a second confirmation.

AI-assisted (Claude Code).

@miniongk

Copy link
Copy Markdown

Verified 4a365e3 on the RTX 5080 / Windows 11 setup:

  • All nine wave64_ tests pass serially, including the positive LDS cases and the negative readfirstlane/divergent-hazard cases.
  • cargo test --workspace: 264 passed, 0 failed, 4 ignored.

I also checked stacking with #320 in the broader local test tree: the two branches overlap in the LDS and console-flow selection logic, not just in adjacent text. I did not force that combination or claim a real-title result for it; the LDS strategy needs to be coordinated explicitly.

No game data used. AI-assisted (Kimi Code).

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
A wave64 program split over two 32-lane waves took the DPP row index
from the host lane, so the upper half (console rows 2 and 3) read
row_mask bits 0 and 1. The row now comes from the console lane there.
New test: v_mov_b32_dpp with row_mask:0x3 writes lanes 0 to 31 only,
exact on an RTX 5070 (split) and a Radeon iGPU (native).

Found in review against Marvisak#189 and Marvisak#192, which both get this right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
v_readfirstlane reads the console wave's first lane. A wave64 program
with DPP or ds_swizzle and a v_readfirstlane was split into two 32-lane
waves, where the upper half read its own first lane: with all 64 lanes
active, lanes 32 to 63 got lane 32's value where the console gives
lane 0's (measured on an RTX 5070).

Such programs now take the console flow, which reads the first lane in
EXEC of the whole console wave (groups of at most 64 threads, no LDS),
or stop with the reason as they did before the split existed.

New test, exact on an RTX 5070 and a Radeon iGPU. Found by running the
same program against Marvisak#192, which has the same result on both adapters.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
A wave64 program split over two 32-lane waves took the DPP row index
from the host lane, so the upper half (console rows 2 and 3) read
row_mask bits 0 and 1. The row now comes from the console lane there.
New test: v_mov_b32_dpp with row_mask:0x3 writes lanes 0 to 31 only,
exact on an RTX 5070 (split) and a Radeon iGPU (native).

Found in review against Marvisak#189 and Marvisak#192, which both get this right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
v_readfirstlane reads the console wave's first lane. A wave64 program
with DPP or ds_swizzle and a v_readfirstlane was split into two 32-lane
waves, where the upper half read its own first lane: with all 64 lanes
active, lanes 32 to 63 got lane 32's value where the console gives
lane 0's (measured on an RTX 5070).

Such programs now take the console flow, which reads the first lane in
EXEC of the whole console wave (groups of at most 64 threads, no LDS),
or stop with the reason as they did before the split existed.

New test, exact on an RTX 5070 and a Radeon iGPU. Found by running the
same program against Marvisak#192, which has the same result on both adapters.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
A wave64 program split over two 32-lane waves took the DPP row index
from the host lane, so the upper half (console rows 2 and 3) read
row_mask bits 0 and 1. The row now comes from the console lane there.
New test: v_mov_b32_dpp with row_mask:0x3 writes lanes 0 to 31 only,
exact on an RTX 5070 (split) and a Radeon iGPU (native).

Found in review against Marvisak#189 and Marvisak#192, which both get this right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
v_readfirstlane reads the console wave's first lane. A wave64 program
with DPP or ds_swizzle and a v_readfirstlane was split into two 32-lane
waves, where the upper half read its own first lane: with all 64 lanes
active, lanes 32 to 63 got lane 32's value where the console gives
lane 0's (measured on an RTX 5070).

Such programs now take the console flow, which reads the first lane in
EXEC of the whole console wave (groups of at most 64 threads, no LDS),
or stop with the reason as they did before the split existed.

New test, exact on an RTX 5070 and a Radeon iGPU. Found by running the
same program against Marvisak#192, which has the same result on both adapters.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
A wave64 program split over two 32-lane waves took the DPP row index
from the host lane, so the upper half (console rows 2 and 3) read
row_mask bits 0 and 1. The row now comes from the console lane there.
New test: v_mov_b32_dpp with row_mask:0x3 writes lanes 0 to 31 only,
exact on an RTX 5070 (split) and a Radeon iGPU (native).

Found in review against Marvisak#189 and Marvisak#192, which both get this right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
v_readfirstlane reads the console wave's first lane. A wave64 program
with DPP or ds_swizzle and a v_readfirstlane was split into two 32-lane
waves, where the upper half read its own first lane: with all 64 lanes
active, lanes 32 to 63 got lane 32's value where the console gives
lane 0's (measured on an RTX 5070).

Such programs now take the console flow, which reads the first lane in
EXEC of the whole console wave (groups of at most 64 threads, no LDS),
or stop with the reason as they did before the split existed.

New test, exact on an RTX 5070 and a Radeon iGPU. Found by running the
same program against Marvisak#192, which has the same result on both adapters.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
A wave64 program split over two 32-lane waves took the DPP row index
from the host lane, so the upper half (console rows 2 and 3) read
row_mask bits 0 and 1. The row now comes from the console lane there.
New test: v_mov_b32_dpp with row_mask:0x3 writes lanes 0 to 31 only,
exact on an RTX 5070 (split) and a Radeon iGPU (native).

Found in review against #189 and #192, which both get this right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
v_readfirstlane reads the console wave's first lane. A wave64 program
with DPP or ds_swizzle and a v_readfirstlane was split into two 32-lane
waves, where the upper half read its own first lane: with all 64 lanes
active, lanes 32 to 63 got lane 32's value where the console gives
lane 0's (measured on an RTX 5070).

Such programs now take the console flow, which reads the first lane in
EXEC of the whole console wave (groups of at most 64 threads, no LDS),
or stop with the reason as they did before the split existed.

New test, exact on an RTX 5070 and a Radeon iGPU. Found by running the
same program against #192, which has the same result on both adapters.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
itsonlysimbo pushed a commit to itsonlysimbo/VIctory that referenced this pull request Nov 24, 2026
A wave64 program split over two 32-lane waves took the DPP row index
from the host lane, so the upper half (console rows 2 and 3) read
row_mask bits 0 and 1. The row now comes from the console lane there.
New test: v_mov_b32_dpp with row_mask:0x3 writes lanes 0 to 31 only,
exact on an RTX 5070 (split) and a Radeon iGPU (native).

Found in review against Marvisak#189 and Marvisak#192, which both get this right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
itsonlysimbo pushed a commit to itsonlysimbo/VIctory that referenced this pull request Nov 24, 2026
v_readfirstlane reads the console wave's first lane. A wave64 program
with DPP or ds_swizzle and a v_readfirstlane was split into two 32-lane
waves, where the upper half read its own first lane: with all 64 lanes
active, lanes 32 to 63 got lane 32's value where the console gives
lane 0's (measured on an RTX 5070).

Such programs now take the console flow, which reads the first lane in
EXEC of the whole console wave (groups of at most 64 threads, no LDS),
or stop with the reason as they did before the split existed.

New test, exact on an RTX 5070 and a Radeon iGPU. Found by running the
same program against Marvisak#192, which has the same result on both adapters.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants