Skip to content

shader: emit WaveSize(32) for small Wave64 groups and elide SGPR spills in SSA - #54

Closed
alessiodeia wants to merge 4 commits into
Marvisak:mainfrom
alessiodeia:fix/wave32-and-sgpr-spills
Closed

alessiodeia wants to merge 4 commits into
Marvisak:mainfrom
alessiodeia:fix/wave32-and-sgpr-spills

Conversation

@alessiodeia

Copy link
Copy Markdown
Contributor

What

Reduces unnecessary WaveSize(64) requirements that cause CreateComputePipelineState refusals on Wave32-only GPUs such as NVIDIA (see #16), and unblocks SGPR spilling on non-compute stages:

  • Small Wave64 compute groups (<= 32 threads): on a Wave64 console, lanes 32..63 are permanently inactive when threads <= 32, so declaring WaveSize(32) matches lane indices, ballots, and single-wave LDS lockstep bit for bit while letting Wave32-only GPUs accept the pipeline.
  • SSA resolution of SGPR spills (v_writelane_b32 → v_readlane_b32 at constant lanes): resolves spilled non-mask SGPRs directly in SSA (with dominance checking) and elides pure spill writes whose VGPR never escapes. Eliminates false console_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.
  • Single-wave LDS lockstep check: only require lockstep WaveSize when the shader actually contains LDS memory instructions (Fields::Ds other than ds_swizzle/permute), not merely a non-zero lds_bytes header field.
  • Synthetic GPU/WARP tests (crates/victory-shader/src/emit/wave_tests.rs): covers Wave64 32-thread cross-lane compute, Wave64 64-thread compute with SGPR spills across lanes 3 and 40, 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 (driver 617.42) + WARP + dxil.dll 1.9.2609:

  • Reproduced all 4 failures before the fix (E_INVALIDARG on 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.dll validation + RTX 2070 SUPER + WARP).
  • cargo test --workspace --locked --offline (skipping sandboxed socket test only_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.

…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>
@DaviTostes

Copy link
Copy Markdown

Tested 249e114 stacked 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 Build: make workspace tests run on Linux #39 is clean and nothing else in the workspace changes.
  • Scope note: the 446-line emit/wave_tests.rs this PR adds is gated #[cfg(all(test, windows))] in emit/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-shader there). What ran here is the rest of the suite.
  • No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

Comment thread crates/victory-shader/src/emit/lower.rs Outdated
// 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 });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/victory-shader/src/emit/lower.rs Outdated
let (Some(Operand::Vector { reg, .. }), [value, at]) = (w.dst, &w.src[..]) else {
return Err(());
};
if const_lane(*at).ok_or(())? != lane {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

alessiodeia and others added 2 commits November 24, 2026 01:14
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>
@alessiodeia

Copy link
Copy Markdown
Contributor Author

@raffclar Great catches on both counts — both fixed!

  1. Device-queried wave size (4083d25): replaced the hard-coded Wave32 with WaveRange { min, max } queried from D3D12_FEATURE_DATA_D3D12_OPTIONS1:

    • WaveRange::choose(console_wave, threads) keeps console_wave when supported (preserving AMD GCN/Vega 64..=64 and RDNA 32..=64 at 64), otherwise picks the smallest supported power-of-two wave >= threads (e.g. 32 on NVIDIA 32..=32, 16/32 on Intel Arc), and falls back to console_wave (64 for Wave64) when no device range is available (None) or nothing smaller fits.
    • Threaded through translate_for / emit_for (translate / emit default to None → console wave size), wired into victory-gpu (Host::wave_range, mixed into the on-disk shader cache key) and victory translate.
    • Added cross-platform WaveRange::choose unit tests + PSV0 wave-size checks for None → (64, 64), GCN/Vega 64..=64 → (64, 64), and NVIDIA 32..=32 → (32, 32).
  2. Hardware lane masking in resolve_spills (77eeef0): const_lane now masks constant lane indices to lane & 63 (Wave64) / lane & 31 (Wave32) before comparing, so aliased lanes like 67 and 3 match. Added a GPU + WARP regression test in wave_tests.rs where writing lane 67 overwrites an earlier spill to lane 3.

Re-tested with cargo test --workspace --locked --offline (victory-shader 62/62 on RTX 2070 SUPER + WARP + dxil.dll), cargo clippy --all-targets -- -D warnings (0 warnings), and cargo xtask policy (149 files ok).

@raffclar

Copy link
Copy Markdown
Contributor

This is good now.

@IDXTRI

IDXTRI commented Nov 24, 2026

Copy link
Copy Markdown

Tested on RTX 4070 Ti (driver 616.56, Windows 11), merged onto main 35b054e: the four wave_tests pass 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

HenriqueSBueno commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Tested on NVIDIA, which has 32-lane waves only. Windows 11, RTX 3080 (driver 616.92), i5-10400F, retail title.

without this PR with this PR
host pipeline refused (all compute, E_INVALIDARG) 77 51
draws per frame in the world ~600 1,590–2,634

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)

@tedin7

tedin7 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

checked: 77eeef0 on 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-shader on the PR head alone: 52 passed, 0 failed. This includes wave_range_matches_device_capabilities. wave_tests.rs is #[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).
  • The PR head alone does not build victory-gpu on Linux (E0425 host_resource, same as current main). So I built a throwaway stack of Build: make workspace tests run on Linux #39 (c0b749d) + this PR: it merges cleanly, cargo check -p victory-gpu --tests and -p victory --tests pass, and cargo test -j4 --workspace --no-fail-fast shows 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.
  • Before/after without a GPU: I copied the PR's own instruction encoders from wave_tests.rs into a throwaway test (not part of the PR) that only runs lower::lower and reads the PSV wave size, skipping the validator and dispatch. I ran it on this PR and on current main (237f2e8, where host_waves does not exist). Wave size is the PSV min/max; (0, MAX) means no WaveSize attribute:
program main this PR
Wave64, 8x4 threads, v_mbcnt + readlane, no host range (64,64) (64,64)
same, host range 64..64 n/a (64,64)
same, host range 32..32 n/a (32,32)
same but 8x8 = 64 threads, host range 32..32 n/a (64,64), kept
Wave64 8x8, spill s0 to lane 3 and s1 to lane 40, read back (64,64) (0,MAX)
writelane at lane 67 then readlane lane 3 (64,64) (0,MAX)
8x8, LDS header set, no ds_ instructions (64,64) (0,MAX)
spill of a literal constant at lane 9 (64,64) (0,MAX)
Wave32 console, writelane lane 35 then readlane lane 3 (32,32) (0,MAX)
pixel shader with spills at lanes 2 and 35 refused: "a cross-lane operation outside compute is not supported" lowers
  • Cases that must not be resolved stay conservative on this PR, all (64,64): reading lane 4 after writing only lane 3, reading a lane of a VGPR that was first filled by 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):

Not verified: any Windows or D3D12 run, dxil validation, real NVIDIA/AMD/Intel behavior, the 4 wave_tests as written, ballot or LDS semantics on a Wave32 host.

@tanishq-dubey

Copy link
Copy Markdown

Independent synthetic test of head 77eeef0f492ea98c3839a283fa0ff54366fdb412 on Linux x86_64: RTX 5090, NVIDIA driver 620.70.06, Wine 11.22, vkd3d-proton 3.2.0 (build 2576c0b4adfae4a), and DXVK 3.1.1.

Cross-built victory-shader tests for x86_64-pc-windows-msvc, then ran the Windows test binary under Wine with wave_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.

@ghost

ghost commented Nov 24, 2026

Copy link
Copy Markdown

AMD (native 64-lane waves) run, plus a heads-up: merged onto current main 9aef3d9, this no longer compiles.

Head 77eeef0 as is (base d222b87), 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, including wave_range_matches_device_capabilities and all four wave_tests on 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

  • Claude Code (Claude Opus 5.5) ran the commands and wrote this report from the logs; I checked it before posting.

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>
@alessiodeia

Copy link
Copy Markdown
Contributor Author

@nullmarsh Thanks for the AMD RDNA4 verification and the catch on main!

Merged origin/main (9aef3d9) into this branch in f30734f and added host_waves: None to both new Parts initializers (from #37 and #81), plus disambiguated the duplicate mod tests currently on main in crates/victory-gpu/src/host.rs.

Re-verified on Windows 11 + RTX 2070 SUPER (driver 617.42): cargo test --workspace passes all 268 tests (including all 74 victory-shader tests and all 43 victory-gpu tests) and cargo xtask policy reports 152 files ok.

@DaviTostes

Copy link
Copy Markdown

Tested 77eeef0 both ways: pass on Linux, and the Windows-only wave tests pass under Wine.

  • Linux (Arch x86_64, rustc 1.98.1): cargo test -p victory-shader — 52 passed, 0 failed; the wave tests are #[cfg(all(test, windows))], so they are skipped there.
  • Windows build of this head (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 is emit::tests::stub_pipeline_is_created (the container-digest check needs dxil.dll, absent here), not this PR.
  • The four Windows-only tests this PR exercises all pass under Wine, through a real DXVK draw:
    • emit::wave_tests::pixel_shader_sgpr_spill_lowers_and_draws
    • emit::wave_tests::wave64_64thread_sgpr_spills_run_on_wave32_host
    • emit::wave_tests::wave64_small_group_runs_on_wave32_host
    • emit::wave_tests::wave64_unused_lds_header_does_not_force_wave64
  • That is the first time these have run on a non-Windows machine as far as I can tell, and they do the wave32 fallback on RADV.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

@EduAzevedo

Copy link
Copy Markdown

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):

Build Compute pipelines refused by the host (E_INVALIDARG), distinct
#55 + the RTV patch from #55's thread 113
the same + this PR (77eeef0) 110

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 in 0x887A0004. The red flashes I reported did not appear in this combined run.

Sorry for the noise.

@alessiodeia

Copy link
Copy Markdown
Contributor Author

@EduAzevedo Thanks for recounting from full logs, that's really useful.

113 -> 110 matches the scope of this PR and the other retail runs (321 -> 306 from @IDXTRI, 77 -> 51 from @HenriqueSBueno): it only narrows Wave64 compute groups of <= 32 threads to WaveSize(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

ghost commented Nov 24, 2026

Copy link
Copy Markdown

Confirmed fixed: f30734f merged onto current main d2a4bae (clean merge) builds, and cargo test --workspace passes, 269 passed, 0 failed, 4 ignored. cargo test -p victory-shader wave: 8 passed on the RX 9060 XT (RDNA4), including the four wave_tests on the hardware adapter.

AI use

  • Claude Code (Claude Opus 5.5) ran the commands and wrote this report from the logs; I checked it before posting.

@jeremygold02

Copy link
Copy Markdown
Contributor

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::new with its title root-signature construction.

Same 74 inputs Base 9aef3d9 PR f30734f
Translated 74 74
Host compute pipeline created 0 3
Creation still refused 74 71

All 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 emitted WaveSize(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

Copy link
Copy Markdown

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

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Test report on a machine with a 32-lane and a 64-lane adapter.

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 f30734f, translating with emit_for(..., host.wave_range()) (32..32 and 32..64). cargo test -p victory-shader: 74 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), each lane checked against the console's result, five runs each with identical results:
Program RTX 5070 Radeon iGPU
s_bcnt1 of a 64-bit mask, group of 32 threads exact (WaveSize(32); no pipeline on main) exact
the same, groups of 48 and 64 threads no pipeline, as on main exact
v_readlane 40; DPP + ds_swizzle; DPP row_mask; DPP + v_readfirstlane, 64 threads no pipeline, as on main exact

So on the 32-lane host the group of at most 32 threads is what changes, as the description says, and nothing differs from main on 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

Copy link
Copy Markdown

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 --release with 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").
  • Full retail shader pack (26,503 containers), victory translate --validate --pipelines on the RX 9070 against main 1f858b0 (emitted / validated / pipelines):
    • main: VS/PS 12272 / 12172 / 12272, MS 8191 / 8129 / 8191
    • this PR: VS/PS 12323 / 12223 / 12323, MS 8192 / 8130 / 8192, CS unchanged.
    • Refusals: "a lane mask read as data" 206 → 154, "a cross-lane operation outside compute" 46 → 0, "a cross-lane operation in a mesh shader" 1 → 0; but "an opaque lane mask" 29 → 49, "a lane-mask join of an untracked mask" 39 → 44, and 1 new v_permlanex16_b32 refusal (see shader: lower v_permlanex16_b32 #404).

@Marvisak Marvisak closed this Nov 24, 2026
Kam471 pushed a commit to Kam471/VIctory that referenced this pull request Nov 24, 2026
…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.
Kam471 pushed a commit to Kam471/VIctory that referenced this pull request Nov 24, 2026
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>
Kam471 pushed a commit to Kam471/VIctory that referenced this pull request Nov 24, 2026
… 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.
Kam471 pushed a commit to Kam471/VIctory that referenced this pull request Nov 24, 2026
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.
@alessiodeia
alessiodeia deleted the fix/wave32-and-sgpr-spills branch November 24, 2026 09:53
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
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
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
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
itsonlysimbo pushed a commit to itsonlysimbo/VIctory that referenced this pull request Nov 24, 2026
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
alex3112 pushed a commit to alex3112/VIctory that referenced this pull request Nov 25, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.