Shaders: replace single-wave Wave64 LDS lockstep with barriers and lower 32-lane swizzle/DPP at WaveSize(32) #192
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!192
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-192"
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?
@kxiserino on GitHub · 2026-11-24 01:16 UTC · original
kxiserino:shader/wave64-lds-barriers-and-local-swizzle→main· +875 −23 · 1 files · 2 commits · openSummary
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 withoutE_INVALIDARG:Single-wave LDS barrier synchronization (
threads 33..=64):32 < total_threads <= 64) can omits_barrierbetween LDS writes and reads because all 64 lanes execute in lockstep on the console. Previously,lower.rspreserved that lockstep by forcingWaveSize(64), which Wave32-only devices refuse.plan_lds_barriers(p, st)incrates/victory-shader/src/emit/lower.rs:v_readfirstlane_b32of a lane-varying VGPR or scalar phis across divergent branches) so only genuinely threadgroup-uniformAtom::Uniformbranches are treated as uniform.WaveSize(64)).dx.op.barrier(1 | 8)(GroupMemoryBarrierWithGroupSync) only in threadgroup-uniform control flow (lds_barrier_beforeandlds_barrier_end) and dropsWaveSize(64).32-lane-local
ds_swizzle_b32andDPPatWaveSize(32):console_lanesintocross_32_lanes(permute,v_mbcnt,v_readlane_b32,v_writelane_b32, lane-mask data reads, opaque/constant lane masks) vslocal_32_lanes(ds_swizzle_b32andDPP, which never cross the 32-lane half-wave boundary).local_32_lanes(and passes LDS barrier planning if it uses LDS), emitWaveSize(32)instead ofWaveSize(64).Lower::console_flat()soDpp::Rowwithrow_mask != 0xFcomputes the 4-row index (0..3) from the console lane (console_flat >> 4 & 3) rather than hostlane_index >> 4, preserving upper half-wave rows 2 and 3 atWaveSize(32).Testing
crates/victory-shader/src/emit/lower.rs:wave64_single_wave_lds_adds_barriers_and_drops_wave_size(cross-half-wavetid ^ 32LDS exchange with nos_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-divergentv_readfirstlane_b32branch)wave64_local_swizzle_and_dpp_row_mask_uses_wave_size_32(ds_swizzle_b32XOR-16 +v_mov_b32_dpprow_shr:1withrow_mask:0xC)cargo test --workspaceon 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.dxil.dll: 22 of 106 previously-refused runtime compute pipelines now validate cleanly withdxil.dlland succeed inCreateComputePipelineState(0 new validation failures across 1,151 Wave64 compute shaders).@juliptree on GitHub · 2026-11-24 01:29 UTC · original
Independently validated
a6782ee25bon 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 on GitHub · 2026-11-24 01:30 UTC · original
Tested
a6782eeon Arch Linux x86_64, rustc 1.98.1: pass.cargo test -p victory-shader: 62 passed, 0 failed (2 test binaries), including the {adds} test{'s' if adds != 1 else ''} this PR adds.victory-gpuE0425.No game data used.
@Raxstreams on GitHub · 2026-11-24 02:27 UTC · original
Tested the PR head at
a6782eeon 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 on GitHub · 2026-11-24 02:45 UTC · original
Test report on a machine with a 32-lane and a 64-lane adapter, with one wrong result.
Tested
a6782ee.cargo test -p victory-shader: 75 passed, 0 failed.split_tests.rsplus two more), each lane's output checked against the console's result, five runs each with identical results:ds_swizzlexor 16 + DPProw_mirror, 64 and 128 threadsrow_mask:0x3s_barrier: every lane writes dword t, lanes below 20 then read dword t + 40v_readfirstlanes_bcnt1of a 64-bit mask;v_readlane 40mainmainThe wrong one. All 64 lanes active:
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), andv_readfirstlanethen reads the first lane of the host wave, which for the upper half is console lane 32. On the Radeon this program is exact onmaind2a4bae(WaveSize(64)), so it is a regression there.#233 had the same result on the RTX 5070 and fixed it in
3098672by not giving the 32-lane form to a program withv_readfirstlane. The same condition would work here; on hosts that run 64-lane waves such a program could simply keepWaveSize(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 on GitHub · 2026-11-24 02:57 UTC · original
@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.@kxiserino on GitHub · 2026-11-24 03:20 UTC · original
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 usesv_readfirstlane_b32or a whole-waveActive/Prefixreduction now keepsWaveSize(64)instead of being lowered atWaveSize(32)or havingWaveSize(64)swapped for LDS barriers. Plainv_readfirstlane_b32-only shaders (no DPP /ds_swizzle/ single-wave LDS) still get no fixed wave size, same asmain.New synthetic tests:
wave64_dpp_with_readfirstlane_keeps_wave_size_64(your repro: identityquad_permDPP +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_64wave64_readfirstlane_only_keeps_no_wave_sizeThe 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 failedVICTORY_WARP=1: 78 passed, 0 failedcargo clippy -p victory-shader -- -D warnings(also--all-targets): cleancargo xtask policy: ok@r4tedx on GitHub · 2026-11-24 05:46 UTC · original
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 on GitHub · 2026-11-24 05:57 UTC · original
Verified
4a365e3on the RTX 5080 / Windows 11 setup: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).
@Marvisak on GitHub · 2026-11-25 00:20 UTC · original
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
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.