shader: emit WaveSize(32) for small Wave64 groups and elide SGPR spills in SSA #54
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!54
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/54/head"
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?
@alessiodeia on GitHub · 2026-11-23 23:54 UTC · original
alessiodeia:fix/wave32-and-sgpr-spills→main· +993 −22 · 8 files · 4 commits · closed without mergingWhat
Reduces unnecessary
WaveSize(64)requirements that causeCreateComputePipelineStaterefusals on Wave32-only GPUs such as NVIDIA (see #16), and unblocks SGPR spilling on non-compute stages:<= 32threads): on a Wave64 console, lanes32..63are permanently inactive whenthreads <= 32, so declaringWaveSize(32)matches lane indices, ballots, and single-wave LDS lockstep bit for bit while letting Wave32-only GPUs accept the pipeline.v_writelane_b32→v_readlane_b32at constant lanes): resolves spilled non-mask SGPRs directly in SSA (with dominance checking) and elides pure spill writes whose VGPR never escapes. Eliminates falseconsole_lanes/WaveSize(64)requirements on compute shaders (even when spilled to lanes>= 32) and allows pixel, vertex, and mesh shaders that spill SGPRs to lower cleanly instead of failing as cross-lane ops.WaveSizewhen the shader actually contains LDS memory instructions (Fields::Dsother thands_swizzle/permute), not merely a non-zerolds_bytesheader field.crates/victory-shader/src/emit/wave_tests.rs): covers Wave64 32-thread cross-lane compute, Wave64 64-thread compute with SGPR spills across lanes3and40, Wave64 unused-LDS header, and a rasterized pixel shader with SGPR spills.Tested
Windows 11 x64 (26300), Rust
1.98.1(--locked), NVIDIA GeForce RTX 2070 SUPER (driver617.42) + WARP +dxil.dll1.9.2609:E_INVALIDARGon RTX 2070 SUPER for the 3 Wave64 compute cases;"a cross-lane operation outside compute"for the pixel shader).cargo test -p victory-shader --locked --offline: 61 passed, 0 failed (dxil.dllvalidation + RTX 2070 SUPER + WARP).cargo test --workspace --locked --offline(skipping sandboxed socket testonly_loopback_is_reachable): all passed.cargo clippy -p victory-shader --all-targets --locked --offline -- -D warnings: 0 warnings.cargo --offline xtask policy:asset policy: 149 files ok.AI-assisted; no game assets were used.
@DaviTostes on GitHub · 2026-11-24 00:05 UTC · original
Tested
249e114stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass (no regression only).cargo test --workspace: 155 passed, 0 failed, 3 ignored; the merge with #39 is clean and nothing else in the workspace changes.emit/wave_tests.rsthis PR adds is gated#[cfg(all(test, windows))]inemit/mod.rs, so it does not compile or run on Linux — the new WaveSize(32)/spill-elision cases need a Windows runner (cargo test -p victory-shaderthere). What ran here is the rest of the suite.AI-assisted (DeepSeek V4.1 Flash coding agent).
@alessiodeia on GitHub · 2026-11-24 00:19 UTC · original
@raffclar Great catches on both counts — both fixed!
Device-queried wave size (
4083d25): replaced the hard-coded Wave32 withWaveRange { min, max }queried fromD3D12_FEATURE_DATA_D3D12_OPTIONS1:WaveRange::choose(console_wave, threads)keepsconsole_wavewhen supported (preserving AMD GCN/Vega64..=64and RDNA32..=64at64), otherwise picks the smallest supported power-of-two wave>= threads(e.g.32on NVIDIA32..=32,16/32on Intel Arc), and falls back toconsole_wave(64for Wave64) when no device range is available (None) or nothing smaller fits.translate_for/emit_for(translate/emitdefault toNone→ console wave size), wired intovictory-gpu(Host::wave_range, mixed into the on-disk shader cache key) andvictory translate.WaveRange::chooseunit tests +PSV0wave-size checks forNone→(64, 64), GCN/Vega64..=64→(64, 64), and NVIDIA32..=32→(32, 32).Hardware lane masking in
resolve_spills(77eeef0):const_lanenow masks constant lane indices tolane & 63(Wave64) /lane & 31(Wave32) before comparing, so aliased lanes like67and3match. Added a GPU + WARP regression test inwave_tests.rswhere writing lane67overwrites an earlier spill to lane3.Re-tested with
cargo test --workspace --locked --offline(victory-shader62/62 on RTX 2070 SUPER + WARP +dxil.dll),cargo clippy --all-targets -- -D warnings(0 warnings), andcargo xtask policy(149 files ok).@raffclar on GitHub · 2026-11-24 00:21 UTC · original
This is good now.
@IDXTRI on GitHub · 2026-11-24 00:28 UTC · original
Tested on RTX 4070 Ti (driver 616.56, Windows 11), merged onto main
35b054e: the fourwave_testspass on the hardware adapter (WARP skips wave size 32). Over the whole shader pack, refused compute pipelines go from 321 to 306, and 51 more vertex/pixel and 1 more mesh pipeline are created; nothing newly refused. Details in #71.AI-assisted (Claude Code).
@HenriqueSBueno on GitHub · 2026-11-24 00:29 UTC · original · edited 2026-11-24 00:44 UTC
Tested on NVIDIA, which has 32-lane waves only. Windows 11, RTX 3080 (driver 616.92), i5-10400F, retail title.
mainat97c78d1, plus #45 and #89 (both needed on this machine), plus #46, plus this PR.host pipeline refused(all compute,E_INVALIDARG)So this PR recovers about a third of the compute pipelines NVIDIA refuses. The other 51 are still refused, presumably the ones with more than 32 threads that need 64-lane waves. The world picture is still black here. Both runs then hit a GPU timeout, described on #46.
AI-assisted (Claude Code)
@tanishq-dubey on GitHub · 2026-11-24 00:46 UTC · original
Independent synthetic test of head
77eeef0f492ea98c3839a283fa0ff54366fdb412on Linux x86_64: RTX 5090, NVIDIA driver 620.70.06, Wine 11.22, vkd3d-proton 3.2.0 (build2576c0b4adfae4a), and DXVK 3.1.1.Cross-built
victory-shadertests forx86_64-pc-windows-msvc, then ran the Windows test binary under Wine withwave_tests --nocapture --test-threads=1: 4 passed, 0 failed. DXIL validator and WARP coverage were not independently confirmed. This is synthetic coverage only; I did not run this PR branch against the game.AI-assisted.
@tedin7 on GitHub · 2026-11-24 00:42 UTC · original · edited 2026-11-24 00:47 UTC
checked:
77eeef0on Linux x86_64 (Debian, kernel 6.12), Rust 1.98.1 (rust-toolchain.toml),cargo -j4. No GPU, no Windows, no game files. Other testers have already covered Windows hardware here; this adds an independent Linux build and a way to see the before/after of the lowering without a GPU.What I ran:
cargo test -j4 -p victory-shaderon the PR head alone: 52 passed, 0 failed. This includeswave_range_matches_device_capabilities.wave_tests.rsis#[cfg(all(test, windows))], so its 4 tests do not compile or run on Linux.cargo clippy -j4 -p victory-shader --tests: nothing new from this PR (one existing dead_code warning,constant_color).victory-gpuon Linux (E0425host_resource, same as current main). So I built a throwaway stack of #39 (c0b749d) + this PR: it merges cleanly,cargo check -p victory-gpu --testsand-p victory --testspass, andcargo test -j4 --workspace --no-fail-fastshows 0 failures (victory-shader 52, victory-gpu 23, victory-hle 46, victory-formats 17 with 3 ignored, etc.). Clippy on victory-shader, victory-gpu and victory shows no warnings in the files this PR changes.wave_tests.rsinto a throwaway test (not part of the PR) that only runslower::lowerand reads the PSV wave size, skipping the validator and dispatch. I ran it on this PR and on current main (237f2e8, wherehost_wavesdoes not exist). Wave size is the PSV min/max; (0, MAX) means no WaveSize attribute:v_mov, and a spill VGPR that is also stored as data. So the SSA resolution does not seem to over-reach in these cases.Review notes (none blocking):
cargo fmt --check -p victory-shaderreports two hunks in lines this PR adds: the long boolean inemit/host.rs(wave_range) and thewalk(...)call inlower.rs(resolve_spills).D3D12_FEATURE_D3D12_OPTIONS1query is written twice (victory-gpu/src/host.rsandemit/host.rs); one could call the other.uses_ldsonly countsFields::Ds. I found no handling of the MUBUF/MTBUFldsbit inlower.rs, so I do not think this changes behavior today, but a one-line comment may help.& 63in Wave64,& 31in Wave32) looks consistent with the lane-select width described for v_readlane/v_writelane; I did not check it against hardware.git merge-treeof the two PR heads, checked against the 18 other open PRs at the time): textual conflicts with #48 inemit/mod.rs(both changeemit(): #48 wraps it in a retry, this PR addsemit_for), with #69 and #116 inlower.rs, and with #94 invictory-gpu/src/host.rs. Clean with current main and with the others I tried (#67, #70, #73, #78, #79, #81, #87, #91, #92, #101, #105, #110, #126, #127).Not verified: any Windows or D3D12 run, dxil validation, real NVIDIA/AMD/Intel behavior, the 4
wave_testsas written, ballot or LDS semantics on a Wave32 host.@ghost on GitHub · 2026-11-24 00:51 UTC · original
AMD (native 64-lane waves) run, plus a heads-up: merged onto current
main9aef3d9, this no longer compiles.error[E0063]: missing field 'host_waves' in initializer of 'Parts<'_>'atcrates/victory-shader/src/emit/lower.rs:6878andcrates/victory-shader/src/emit/valu_tests.rs:129. Both initializers came in after your base: thelower.rsone with #81 (s_addc/s_subbcarry test), andvalu_tests.rswith #37. The merge itself is clean, so GitHub won't flag it.Head
77eeef0as is (based222b87), AMD Radeon RX 9060 XT (RDNA4, wave 32–64), driver 32.0.32029.2010, Ryzen 7 5800X3D, Windows 11 Pro 26200, Rust 1.98.1, debug:cargo test --workspace: 229 passed, 0 failed, 3 ignored.cargo test -p victory-shader wave: 8 passed, includingwave_range_matches_device_capabilitiesand all fourwave_testson the hardware adapter (wave64_small_group_runs_on_wave32_host,wave64_64thread_sgpr_spills_run_on_wave32_host,wave64_unused_lds_header_does_not_force_wave64,pixel_shader_sgpr_spill_lowers_and_draws). WARP skipped the wave-32 case as on NVIDIA (WaveRange { min: 4, max: 4 }).So the wave-range choice holds on a GPU that offers both 32 and 64, which every run above was missing. No retail title here.
AI use
@alessiodeia on GitHub · 2026-11-24 00:59 UTC · original
@nullmarsh Thanks for the AMD RDNA4 verification and the catch on
main!Merged
origin/main(9aef3d9) into this branch inf30734fand addedhost_waves: Noneto both newPartsinitializers (from #37 and #81), plus disambiguated the duplicatemod testscurrently onmainincrates/victory-gpu/src/host.rs.Re-verified on Windows 11 + RTX 2070 SUPER (driver
617.42):cargo test --workspacepasses all 268 tests (including all 74victory-shadertests and all 43victory-gputests) andcargo xtask policyreports 152 files ok.@DaviTostes on GitHub · 2026-11-24 00:59 UTC · original
Tested
77eeef0both ways: pass on Linux, and the Windows-only wave tests pass under Wine.cargo test -p victory-shader— 52 passed, 0 failed; the wave tests are#[cfg(all(test, windows))], so they are skipped there.cargo xwin ... --target x86_64-pc-windows-msvc) run under Wine 11.22 + DXVK 2.7.1 on an AMD RX 9060 XT (RADV 26.3.1): 61 passed, 1 failed. The failure isemit::tests::stub_pipeline_is_created(the container-digest check needsdxil.dll, absent here), not this PR.emit::wave_tests::pixel_shader_sgpr_spill_lowers_and_drawsemit::wave_tests::wave64_64thread_sgpr_spills_run_on_wave32_hostemit::wave_tests::wave64_small_group_runs_on_wave32_hostemit::wave_tests::wave64_unused_lds_header_does_not_force_wave64No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
@EduAzevedo on GitHub · 2026-11-24 01:04 UTC · original
Correction to my test above: the 47 → 9 refused compute pipelines is wrong. Both numbers were counted from a terminal's scrollback, which had dropped the start of each run, so they are not comparable.
Counted again from full log files (each run from an empty cache, same route to the first mission's intro, RTX 2070 SUPER, driver 610.88, Windows 11, native D3D12):
E_INVALIDARG), distinct77eeef0)107 of the 110 are the same pipelines in both runs, so on this card this PR changes few of the refusals; the device reports
wave_range=Some(WaveRange { min: 32, max: 32 }). The rest of my earlier comment stands: no regression in menus, and the world still ends in0x887A0004. The red flashes I reported did not appear in this combined run.Sorry for the noise.
@alessiodeia on GitHub · 2026-11-24 01:08 UTC · original
@EduAzevedo Thanks for recounting from full logs, that's really useful.
113 -> 110matches the scope of this PR and the other retail runs (321 -> 306from @IDXTRI,77 -> 51from @HenriqueSBueno): it only narrows Wave64 compute groups of<= 32threads toWaveSize(32)and removes false Wave64 requirements caused by SGPR spills. Most of the remaining refusals are groups of 64+ threads that really depend on 64-lane semantics (ballots, lane indices, LDS lockstep), and those still need a Wave64 emulation path on Wave32-only hosts. That's a separate follow-up and outside this PR.Good to hear the red flashes did not come back in the combined run.
@ghost on GitHub · 2026-11-24 01:15 UTC · original
Confirmed fixed:
f30734fmerged onto currentmaind2a4bae(clean merge) builds, andcargo test --workspacepasses, 269 passed, 0 failed, 4 ignored.cargo test -p victory-shader wave: 8 passed on the RX 9060 XT (RDNA4), including the fourwave_testson the hardware adapter.AI use
@jeremygold02 on GitHub · 2026-11-24 01:15 UTC · original
On a physical RTX 5070 (driver 621.01), #54 recovered 3 of 74 distinct compute pipelines previously refused during our saved loading run. I matched the original inputs locally and repeated pipeline creation through VIctory’s runtime
HostPipeline::newwith its title root-signature construction.9aef3d9f30734fAll three recovered shaders were native Wave64 programs with at most 32 threads per group. The PR emitted
WaveSize(32)for exactly those three. The other 71 still emittedWaveSize(64)and remained refused. A trace-confirmed successful shader with matching root parameters, samplers, resource use and compute group metadata to one of the failures created successfully on both revisions.The device LUID matched the physical adapter. The base needed the same test-module rename as the PR to compile the probe. This comparison ended at PSO creation, before any dispatch. We have no in-game frame or stability result for this change.
@Raxstreams on GitHub · 2026-11-24 01:58 UTC · original
Follow-up from testing #54 together with #180 on an RTX 3080 Ti (617.14). Some Wave32 material-resolve shaders use the spill pattern here to save EXEC itself. In one example the compiler saves the mask in VGPR lane 5, restores it into an SGPR, then joins it with a predicate from the other branch. The existing spill resolver deliberately excludes mask values, so the join can still report
a lane-mask join of an untracked mask.In a local follow-up I reused the constant-lane and dominance checks to keep the original per-lane predicate available at the join. That change cleared 33 of 41 such shaders. The other eight also needed to extract the current lane's bit when an incoming SGPR held an ordinary numeric word. Together the changes got all 41 through DXIL validation and D3D12 compute pipeline creation. These are incremental results with local changes on top of the PR.
I also dispatched a synthetic Wave32 shader with different masks on the two branches. It returned the expected value for every lane on both the direct and restored paths on the RTX. No title launch was involved.
@r4tedx on GitHub · 2026-11-24 02:45 UTC · original
Test report on a machine with a 32-lane and a 64-lane adapter.
Tested
f30734f, translating withemit_for(..., host.wave_range())(32..32 and 32..64).cargo test -p victory-shader: 74 passed, 0 failed.split_tests.rs), each lane checked against the console's result, five runs each with identical results:s_bcnt1of a 64-bit mask, group of 32 threadsWaveSize(32); no pipeline onmain)mainv_readlane 40; DPP +ds_swizzle; DPProw_mask; DPP +v_readfirstlane, 64 threadsmainSo on the 32-lane host the group of at most 32 threads is what changes, as the description says, and nothing differs from
mainon the Radeon for these programs.Not tested: programs with SGPR spills (none of mine has one); release build; the title (no game files used).
AI-assisted.
@slint6614-dev on GitHub · 2026-11-24 08:03 UTC · original
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4, 32-64 lane waves) and Ryzen 9600X iGPU (RDNA2, gfx1036).
cargo test -p victory-shader --releasewith each GPU as the hardware device: 74 passed, 0 failed on both (the WARP part of one wave test skips: "wave range 4-4 cannot hold 32 lanes").victory translate --validate --pipelineson the RX 9070 against main1f858b0(emitted / validated / pipelines):v_permlanex16_b32refusal (see #404).@raffclar on GitHub · 2026-11-24 00:03 UTC · original · edited 2026-11-24 00:06 UTC
On
crates/victory-shader/src/emit/lower.rsline 647 (outdated):Choose the wave size from what the device reports it supports, falling back to 64 if nothing can be found. Don't hard-code this.
If you don't do this, older AMD GPUs (GNC and Vega use only 64-lane waves) will fail but your fix works for Nvidia at least.
@raffclar on GitHub · 2026-11-24 00:09 UTC · original
On
crates/victory-shader/src/emit/lower.rsline 428 (outdated):The hardware only uses the low bits of the lane number, so lane 67 is really lane 3..
Just mask both lane numbers before comparing should sort this
Pull request closed