Repository navigation
shader: emit WaveSize(32) for small Wave64 groups and elide SGPR spills in SSA - #54
alessiodeia wants to merge 4 commits into
Conversation
…ls in SSA Reduces unnecessary WaveSize(64) declarations that block compute pipelines on Wave32-only GPUs (e.g. NVIDIA, see Marvisak#16) and unblocks SGPR spilling on non-compute stages: - Compute groups with <= 32 total threads: lanes 32..63 are permanently inactive on Wave64 hardware, so declaring WaveSize(32) matches lane indices, ballots, and single-wave LDS lockstep bit for bit while allowing NVIDIA GPUs to create the pipeline. - SGPR spills through VGPR lanes (v_writelane_b32 -> v_readlane_b32 at constant lanes): resolve directly in SSA with dominance checking and elide pure spill writes. Eliminates false console_lanes / WaveSize(64) requirements on compute shaders (even for lanes >= 32) and lets pixel, vertex, and mesh shaders that spill SGPRs lower cleanly. - Single-wave LDS lockstep check: require actual LDS memory instructions (not just a non-zero lds_bytes header field) before forcing WaveSize. - Add synthetic GFX10 -> DXIL -> dxil.dll -> GPU/WARP tests in wave_tests.rs. Co-authored-by: BlueKaiman <360454391+BlueKaiman@users.noreply.github.com>
|
Tested
AI-assisted (DeepSeek V4.1 Flash coding agent). |
| // A group of at most 32 lanes leaves lanes 32..63 inactive on | ||
| // a Wave64 console, so a 32-lane host wave matches bit for bit | ||
| // and lets Wave32-only GPUs (e.g. NVIDIA) accept the pipeline. | ||
| s.wave_size = Some(if threads <= 32 { 32 } else { wave }); |
There was a problem hiding this comment.
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.
| let (Some(Operand::Vector { reg, .. }), [value, at]) = (w.dst, &w.src[..]) else { | ||
| return Err(()); | ||
| }; | ||
| if const_lane(*at).ok_or(())? != lane { |
There was a problem hiding this comment.
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
Addresses review feedback on Marvisak#54: - Introduce WaveRange (min..=max) in victory-shader::emit with WaveRange::choose(console_wave, threads): prefers the console's wave size when the device supports it (keeping AMD GCN/Vega 64..=64 and RDNA 32..=64 at 64), narrows small groups to the smallest supported power-of-two wave >= threads on narrower hosts (e.g. 32 on NVIDIA 32..=32, 16/32 on Intel Arc), and falls back to the console's wave size (64 for Wave64) when no device range is available or nothing fits. - Query D3D12_FEATURE_DATA_D3D12_OPTIONS1 on Host creation in victory-gpu and victory-shader::emit::host, thread it through translate_for / emit_for (keeping translate / emit defaulting to None -> console wave size), and mix wave_range into the on-disk shader cache key. - Add cross-platform WaveRange::choose tests plus PSV0 wave-size checks for None fallback, GCN/Vega (64..=64), and NVIDIA (32..=32). Co-authored-by: BlueKaiman <360454391+BlueKaiman@users.noreply.github.com>
Addresses the second review comment on Marvisak#54: mask constant lane indices in resolve_spills() to the hardware's low bits (lane & 63 in Wave64, lane & 31 in Wave32) so aliased lanes such as 67 and 3 match, and cover lane 67 overwriting lane 3 in wave_tests.rs. Co-authored-by: BlueKaiman <360454391+BlueKaiman@users.noreply.github.com>
|
@raffclar Great catches on both counts — both fixed!
Re-tested with |
|
This is good now. |
|
Tested on RTX 4070 Ti (driver 616.56, Windows 11), merged onto main 35b054e: the four AI-assisted (Claude Code). |
|
Tested on NVIDIA, which has 32-lane waves only. Windows 11, RTX 3080 (driver 616.92), i5-10400F, retail title.
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) |
|
checked: 77eeef0 on Linux x86_64 (Debian, kernel 6.12), Rust 1.98.1 (rust-toolchain.toml), What I ran:
Review notes (none blocking):
Not verified: any Windows or D3D12 run, dxil validation, real NVIDIA/AMD/Intel behavior, the 4 |
|
Independent synthetic test of head Cross-built AI-assisted. |
|
AMD (native 64-lane waves) run, plus a heads-up: merged onto current
Head
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
|
Adds host_waves: None to the Parts initializers added in main by Marvisak#37 and Marvisak#81, and disambiguates the duplicate mod tests introduced in host.rs on main. Co-authored-by: BlueKaiman <360454391+BlueKaiman@users.noreply.github.com>
|
@nullmarsh Thanks for the AMD RDNA4 verification and the catch on Merged Re-verified on Windows 11 + RTX 2070 SUPER (driver |
|
Tested
No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent). |
|
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):
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 Sorry for the noise. |
|
@EduAzevedo Thanks for recounting from full logs, that's really useful.
Good to hear the red flashes did not come back in the combined run. |
|
Confirmed fixed: AI use
|
|
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
All three recovered shaders were native Wave64 programs with at most 32 threads per group. The PR emitted 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. |
|
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 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. |
|
Test report on a machine with a 32-lane and a 64-lane adapter. Tested
So on the 32-lane host the group of at most 32 threads is what changes, as the description says, and nothing differs from Not tested: programs with SGPR spills (none of mine has one); release build; the title (no game files used). AI-assisted. |
|
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4, 32-64 lane waves) and Ryzen 9600X iGPU (RDNA2, gfx1036).
|
…pill elision in SSA Resolved against lane-mask's newer Wave64Mode/TranslateOptions, root views and structured access: host wave ranges ride in TranslateOptions/Parts rather than separate translate_for/emit_for paths, while the PR entry points remain as wrappers. Kept the branch's dynamic loop limit, v_swap/v_xnor, fract threshold and stack-overflow guard.
The console compiler spills lane masks like other SGPRs: v_writelane_b32
to a constant lane, v_readlane_b32 of that lane later. The lane pass took
the read-back value for an opaque mask and the spill write read the mask
as data, which fails for a mask holding lanes not running there ("a lane
mask holding lanes elsewhere read as data").
structure: a v_readlane_b32 of a constant lane that reads back a
v_writelane_b32 of a mask (through writes of other lanes and agreeing
joins), where the mask's value dominates the read, is that mask: each
lane's bit is the one it had when spilled. Wave64 masks need both dwords
read back from the same mask.
lower: the spill resolver from Marvisak#54 now takes masks where the lane pass
took the read for one; the write is then a pure spill and the read's
readers take the lanes' bits.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… key PR Marvisak#54's WaveRange now travels in TranslateOptions; the GPU host records the range it queried and the cache key includes it, so a translation made for one wave range is not reused for another.
Brings in Marvisak#704/Marvisak#193 raw-view stride table and VSH3 cache, Marvisak#329 PSV record counts, and precise copy invalidation. Kept Marvisak#54's host wave range and Marvisak#298's spilled-mask resolution; Parts now carries psv, options and host_waves, and test initializers cover all three.
Short of SGPRs, the console compiler spills a dword into one lane of a VGPR (v_writelane_b32) and reloads it later with v_readlane_b32 at the same constant lane. Lane masks are spilled like this too, and the reload is used as a mask again (s_andn2_b64 vcc, exec, sM; s_and_saveexec; EXEC restores; s_and + s_cselect(exec, 0) + s_cbranch_vccnz). The spill read the mask as a number (failing with "a lane mask holding lanes elsewhere read as data" for an else-mask), and the reload was an opaque cross-lane read the lane-mask analysis no longer knew as that mask. New pass sgpr_spill::forward, run right after the IR is built (in translation and in `victory translate`): every read of a reload whose VGPR lane provably holds one scalar value (through other lanes' writes and agreeing joins, lane bits masked to the wave size, the value available wherever the reload runs) reads that value directly, so structure tracks the reloaded mask as the same mask. sgpr_spill::dead names the reloads and spills nothing reads any more; lowering leaves them out (and out of the console-lane and whole-wave-section scans). Also: - SCC of a scalar mask operation read as data (s_cselect on it) is "some lane is set": the mask's ballot is not zero, where masks may be read as data (compute). Was "a lane mask read as data". - A whole-wave section ends at the EXEC write reading the saved mask from any register, so a forwarded reload of a spilled saved EXEC closes it. Based on the spill resolution in Marvisak#54 by alessiodeia. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Short of SGPRs, the console compiler spills a dword into one lane of a VGPR (v_writelane_b32) and reloads it later with v_readlane_b32 at the same constant lane. Lane masks are spilled like this too, and the reload is used as a mask again (s_andn2_b64 vcc, exec, sM; s_and_saveexec; EXEC restores; s_and + s_cselect(exec, 0) + s_cbranch_vccnz). The spill read the mask as a number (failing with "a lane mask holding lanes elsewhere read as data" for an else-mask), and the reload was an opaque cross-lane read the lane-mask analysis no longer knew as that mask. New pass sgpr_spill::forward, run right after the IR is built (in translation and in `victory translate`): every read of a reload whose VGPR lane provably holds one scalar value (through other lanes' writes and agreeing joins, lane bits masked to the wave size, the value available wherever the reload runs) reads that value directly, so structure tracks the reloaded mask as the same mask. sgpr_spill::dead names the reloads and spills nothing reads any more; lowering leaves them out (and out of the console-lane and whole-wave-section scans). Also: - SCC of a scalar mask operation read as data (s_cselect on it) is "some lane is set": the mask's ballot is not zero, where masks may be read as data (compute). Was "a lane mask read as data". - A whole-wave section ends at the EXEC write reading the saved mask from any register, so a forwarded reload of a spilled saved EXEC closes it. Based on the spill resolution in #54 by alessiodeia. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Short of SGPRs, the console compiler spills a dword into one lane of a VGPR (v_writelane_b32) and reloads it later with v_readlane_b32 at the same constant lane. Lane masks are spilled like this too, and the reload is used as a mask again (s_andn2_b64 vcc, exec, sM; s_and_saveexec; EXEC restores; s_and + s_cselect(exec, 0) + s_cbranch_vccnz). The spill read the mask as a number (failing with "a lane mask holding lanes elsewhere read as data" for an else-mask), and the reload was an opaque cross-lane read the lane-mask analysis no longer knew as that mask. New pass sgpr_spill::forward, run right after the IR is built (in translation and in `victory translate`): every read of a reload whose VGPR lane provably holds one scalar value (through other lanes' writes and agreeing joins, lane bits masked to the wave size, the value available wherever the reload runs) reads that value directly, so structure tracks the reloaded mask as the same mask. sgpr_spill::dead names the reloads and spills nothing reads any more; lowering leaves them out (and out of the console-lane and whole-wave-section scans). Also: - SCC of a scalar mask operation read as data (s_cselect on it) is "some lane is set": the mask's ballot is not zero, where masks may be read as data (compute). Was "a lane mask read as data". - A whole-wave section ends at the EXEC write reading the saved mask from any register, so a forwarded reload of a spilled saved EXEC closes it. Based on the spill resolution in Marvisak#54 by alessiodeia. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Short of SGPRs, the console compiler spills a dword into one lane of a VGPR (v_writelane_b32) and reloads it later with v_readlane_b32 at the same constant lane. Lane masks are spilled like this too, and the reload is used as a mask again (s_andn2_b64 vcc, exec, sM; s_and_saveexec; EXEC restores; s_and + s_cselect(exec, 0) + s_cbranch_vccnz). The spill read the mask as a number (failing with "a lane mask holding lanes elsewhere read as data" for an else-mask), and the reload was an opaque cross-lane read the lane-mask analysis no longer knew as that mask. New pass sgpr_spill::forward, run after unspill (and again after jump threading, whose renaming from registers undoes it): every read of a reload whose VGPR lane provably holds one scalar value (through other lanes' writes and agreeing joins, lane bits masked to the wave size, the value available wherever the reload runs) reads that value directly, so structure tracks the reloaded mask as the same mask. sgpr_spill::dead names the reloads and spills nothing reads any more; lowering leaves them out (and out of the console-lane and whole-wave-section scans). Also: - SCC of a scalar mask operation read as data (s_cselect on it) is "some lane is set": the mask's ballot is not zero, where masks may be read as data (compute). Was "a lane mask read as data". - A whole-wave section ends at the EXEC write reading the saved mask from any register, so a forwarded reload of a spilled saved EXEC closes it. Based on the spill resolution in Marvisak#54 by alessiodeia. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
What
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.