fix(shader): track wave width and parked-lane restores in wave barriers #3348
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!3348
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3348"
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?
@legayclightning22 on GitHub · 2026-11-26 19:30 UTC · original
legayclightning22:fix/narrow-wave-barrier-and-unspill→main· +617 −26 · 7 files · 1 commits · openSummary
Tracks wave width and parked-lane restores across shader wave barriers and unspill handling (
5794ccc), updating shader cache keys and barrier gating/relaxation logic.Changes
+463/-23)[cite: 26].Verification
cargo test -p victory-shader --lib(297 passed, 6 new tests passing; 11 known baseline hardware failures, 3 ignored)[cite: 26]cargo test -p victory-gpu --libcache tests[cite: 26]cargo clippy --locked --all-targets -- -D warnings[cite: 26]cargo xtask policy[cite: 26]@Dukestar69 on GitHub · 2026-11-26 19:49 UTC · original · approved these changes
LGTM — verified on RTX 5090 (Windows / D3D12) against
origin/main(63bcca4).cargo test -p victory-shader --lib ir:: -- --test-threads=1: 12 passed, 0 failed.cargo test -p victory-shader --lib structure:: -- --test-threads=1: 13 passed, 0 failed (1 ignored).cargo test -p victory-shader --lib emit::tests:: -- --test-threads=1: 20 passed, 0 failed (barrier_modes_keep_the_shared_and_uav_fences,divergent_barriers_drop_group_sync_in_one_wave,wave64_on_32_lane_host_is_gated).cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1: 5 passed, 0 failed (wave_settings_have_distinct_cache_keys).cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@cloph-dsp on GitHub · 2026-11-26 19:55 UTC · original
Independent local verification of PR #3348 (
fix(shader): track wave width and parked-lane restores in wave barriers), head5794ccca63.cargo test --locked,CARGO_BUILD_JOBS=2, per-worktreeCARGO_TARGET_DIR(D:\Victory-Contrib\target-3348).cargo test --locked -p victory-shader --lib -- --exact ir::tests::parked_lane_restores_look_past_other_registers-> 1 passed, 0 failed, 310 filtered, exit 0.git diff --check origin/main HEAD-> clean.63bcca43..., so it is genuinely added by this PR.AI-assisted (Hy4 flash). GPU/driver: N/A for this CPU test. No game data used.
@fuzeofficlal on GitHub · 2026-11-26 20:38 UTC · original · requested changes
Tested locally merged onto
origin/main(63bcca43) at PR head5794cccaacross three adapters on Windows 11 x64 (NVIDIA GeForce RTX 5090, AMD Radeon Graphicsgfx1036, Microsoft WARP;VICTORY_D3D12_DEBUG=1).Baseline build checks pass (
cargo xtask policy: 191 files ok,emit/lower.rsis 522,803 B < 524,288 B; clippy default &--all-featuresclean;shader_cachekey hashing covershost_lanes/wide64/group_sync), but there are three blocking correctness bugs reproduced locally:1. Unconditional rejection of all
wave64programs on 32-lane hosts (emit/lower.rs:250, 290,shader_cache.rs:74)On NVIDIA adapters (
WaveLaneCountMax == 32,VICTORY_WAVE_WIDEunset),wave64_unsupported = x.native.wave64 && wave.host_lanes < 64 && !wave.wide64rejects everywave64shader before lowering — including completely unrestrictedwave64programs with no wave ops and no LDS (which already lower to unrestricted DXIL and run natively in Wave32 onmain).Reproduced locally with a minimal unrestricted
wave64compute shader (rsrc2 = 0,s_endpgm) underWaveMode::with(32, false, GroupSync::Auto):Err(Unsupported { offset: 0, what: "a wave64 program on a 32-lane host (VICTORY_WAVE_WIDE=1)" }).Any 32-lane host gating should only apply to programs that actually require 64-lane wave semantics, not every
native.wave64shader.2. Unsound
single_wavebarrier relaxation fromWaveLaneCountMax(host.rs:19-34,emit/lower.rs:257-272)host.rsderivesmax_wave_lanesfromWaveLaneCountMax(clamping values< 32up to32), andlower.rsdropsSYNC_THREAD_GROUP(bit 1) from divergents_barriers whenevergroup_lanes <= wave.host_lanes.Measured
D3D12_FEATURE_DATA_D3D12_OPTIONS1across three real adapters on this machine:WaveLaneCountMin = 32, WaveLaneCountMax = 32(host_lanes = 32)WaveLaneCountMin = 32, WaveLaneCountMax = 64(host_lanes = 64)WaveLaneCountMin = 4, WaveLaneCountMax = 4(clamped up tohost_lanes = 32)On AMD RDNA2/3 (
host_lanes = 64), a[64, 1, 1]wave32(or unrestricted) compute shader executes as two 32-lane waves, yet64 <= 64markssingle_wave = trueand stripsSYNC_THREAD_GROUP(reproduced locally:barrier_modes = [8]instead of[9]). Likewise on WARP (Min = Max = 4),[32, 1, 1]is eight 4-lane waves, yet32 <= 32strips group sync. DroppingSYNC_THREAD_GROUPis only sound whengroup_lanes <= WaveLaneCountMin(or when DXIL explicitly declares a fixedWaveSize >= group_lanes).3. Soundness bugs in
ir.rs::restores(crates/victory-shader/src/ir.rs:599-643)v_writelane_b32(L599-L607): Whenv_writelane_b32writes a non-SGPR value (e.g. an inline constant/literal) or uses a dynamic lane operand,parked_scalar/operand_numberreturnsNoneand the earlycontinueatL606skips invalidatingparked. Reproduced locally withv_writelane_b32 v1, s0, 0followed byv_writelane_b32 v1, 0, 0andv_readlane_b32 s5, v1, 0:p.restoredstill mapss5to the overwrittens0(Some(Value(4))).v_movrels_b32/v_movreld_b32/v_swaprel_b32(L620-L638): These are per-lane VGPR vector moves, not scalar broadcasts of one parked lane (andv_movreld_b32indexes the destinationv[dst + m0], notv.src[0], nor does the loop atL639-L643invalidatev[dst + m0]). Reproduced locally withv_writelane_b32 v7, s0, 3(only lane 3 parked) +s_mov_b32 m0, 3+v_movrels_b32 v0, v4:p.restoredfalsely maps the entire vector resultv0to scalars0(Some(Value(255))), which then propagates intoresource.rsandstructure.rs(l.restored).Synthetic tests only.
5794ccca63to8013170d80@legayclightning22 on GitHub · 2026-11-26 22:30 UTC · original
Pushed
d4bfcbdfixing all three blocking issues:wave64shaders without 64-lane wave semantics lower normally on 32-lane hosts, with a unit test underWaveMode::with(32, false, GroupSync::Auto).single_wavebarrier relaxation to checkgroup_lanes <= WaveLaneCountMin(without clamping values< 32up to32) so AMD (Min=32, Max=64) and WARP (Min=Max=4) preserveSYNC_THREAD_GROUP, with regression tests for both.ir.rs::restoresto invalidateparkedentries on non-SGPR/dynamic-lanev_writelane_b32writes and removed the unsound scalar-broadcast mapping onv_movrels_b32/v_movreld_b32/v_swaprel_b32with proper VGPR invalidation and regression tests.Re-verified
victory-shadertests,shader_cache::,clippy --all-features -- -D warnings, andcargo xtask policy.@fuzeofficlal on GitHub · 2026-11-26 23:02 UTC · original · requested changes
Thanks for updating
ir::restores(crates/victory-shader/src/ir.rs:317-364) and narrowing thewave64rejection to programs that actually sets.wave_size == Some(64)(emit/lower.rs:650-653). Verified on three live D3D12 adapters (RTX 5090, AMDgfx1036iGPU, and WARP withVICTORY_D3D12_DEBUG=1): both previousir::restoressoundness bugs are resolved and unrestrictedwave64compute shaders now compile and create PSOs cleanly on all three adapters with 0 Debug Layer errors.However, two blocking issues remain on the updated head (
d4bfcbd6):1.
declared_wave_size(c)trusts the console container'sPSV0as the host's wave size, strippingSYNC_THREAD_GROUPfrom multi-wave threadgroups (emit/mod.rs:454-459, 536+emit/lower.rs:585-598)emit_with_wave(crates/victory-shader/src/emit/mod.rs:536) extractsPSV0bytes20..28from the console input containercand passes it aswave.fixed_wave_size.Lower::new(crates/victory-shader/src/emit/lower.rs:585-598) then computessingle_wavebefores.wave_size(lower.rs:647) using:Because this inspects the console container's
PSV0rather than the emitted host DXIL'ss.wave_size(and never checkssize <= wave.host_lanes), a compute shader whose emitted host DXIL declares noWaveSize(PSV0 = 0..=4294967295) still hasSYNC_THREAD_GROUP(bit 0) stripped whenever the console container hadmin == max:min=32, max=32), consolewave64CS (threads=[64, 1, 1], consolePSV0=64, divergents_barrierwiths_and_saveexec_b64,s.wave_size = None): lowers tobarrier_modes = [8](bit 0 stripped) and emitted hostPSV0 = (0..=4294967295), even though 64 threads execute as 2 waves of 32 lanes on RTX 5090.min=4, max=4), consolewave32CS (threads=[32, 1, 1], consolePSV0=32, divergents_barrier,s.wave_size = None): lowers tobarrier_modes = [8]with emitted hostPSV0 = (0..=4294967295), even though WARP runs 8 waves of 4 lanes.gfx1036(min=32, max=64), consolewave64CS (threads=[64, 1, 1], consolePSV0=64, divergents_barrier,s.wave_size = None): lowers tobarrier_modes = [8]with emitted hostPSV0 = (0..=4294967295), where the driver is free to dispatch 2× Wave32 waves.Suggested fix: Do not derive
single_wavefrom the console input container'sPSV0. Computesingle_waveafters.wave_size(lower.rs:647) and only relax divergent barriers when the host is genuinely guaranteed to run one wave:n <= wave.min_lanes || s.wave_size.is_some_and(|w| w >= n && w <= wave.host_lanes).2.
VICTORY_WAVE_WIDE=1still emits DXILWaveSize(64)(rejected by 32-lane/4-lane adapters) andhost.rs:24-32misclamps WARP'sWaveLaneCountMax = 4to32wave64shader setss.wave_size = Some(64)on a host withhost_lanes < 64,lower.rs:1349directs the user toVICTORY_WAVE_WIDE=1. However, settingwide64 = trueonly clearswave64_unsupported(lower.rs:650-653) whilelower.rs:647still setss.wave_size = Some(64)(writingWaveSize(64)andPSV0 min=64, max=64) without any wave64 emulation.CreateComputePipelineStateverification withVICTORY_D3D12_DEBUG=1on the loweredwide64 = trueDXIL (v_readlane_b32+s_endpgm,wave64 = true):WaveLaneCountMin=32, WaveLaneCountMax=32):Err(E_INVALIDARG / 0x80070057)—ID3D12Device::CreateComputeShader: Shader wants wave lane count of 64 but maximum wave lane count for device is 32.WaveLaneCountMin=4, WaveLaneCountMax=4):Err(E_INVALIDARG / 0x80070057)—ID3D12Device::CreateComputeShader: Shader wants wave lane count of 64 but maximum wave lane count for device is 4.gfx1036) (WaveLaneCountMin=32, WaveLaneCountMax=64):Ok(0 Debug Layer messages).crates/victory-gpu/src/host.rs:24-32, whenWaveLaneCountMax < 32(observed on WARP:WaveLaneCountMin=4, WaveLaneCountMax=4),max_wave_lanesis clamped up to32(Hostreportedmin_wave_lanes=4, max_wave_lanes=32). Please preserve the actual reportedWaveLaneCountMax(e.g.,wave_options.WaveLaneCountMaxwhenlanes.is_ok() && wave_options.WaveLaneCountMax > 0) and either implement/drop theVICTORY_WAVE_WIDE=1switch or avoid emitting an unsupportedWaveSize(64)tag under it.Minor cleanup
crates/victory-shader/src/resource.rs:2079still matches"v_movrels_b32"even thoughir::restoresno longer insertsv_movrels_b32entries.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.