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

Closed
github-bot wants to merge 4 commits from gh-pr/54/head into gh-pr/54/base
Owner

@⁠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 merging

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.

**@⁠alessiodeia** on GitHub · 2026-11-23 23:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/54) `alessiodeia:fix/wave32-and-sgpr-spills` → `main` · +993 −22 · 8 files · 4 commits · closed without merging ## 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.
Reduces unnecessary WaveSize(64) declarations that block compute pipelines on Wave32-only GPUs (e.g. NVIDIA, see #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 <[email protected]>
Addresses review feedback on #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 <[email protected]>
Addresses the second review comment on #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 <[email protected]>
Adds host_waves: None to the Parts initializers added in main by #37 and #81, and disambiguates the duplicate mod tests introduced in host.rs on main.

Co-authored-by: BlueKaiman <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:48:28 +00:00
github-bot closed this pull request 2026-11-26 03:48:28 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:05 UTC · original

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 #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).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7117694110) 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 #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).
Author
Owner

@⁠alessiodeia on GitHub · 2026-11-24 00:19 UTC · original

@⁠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).

**@⁠alessiodeia** on GitHub · 2026-11-24 00:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7117939424) @⁠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`).
Author
Owner

@⁠raffclar on GitHub · 2026-11-24 00:21 UTC · original

This is good now.

**@⁠raffclar** on GitHub · 2026-11-24 00:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7117988637) This is good now.
Author
Owner

@⁠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 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).

**@⁠IDXTRI** on GitHub · 2026-11-24 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7118111498) 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).
Author
Owner

@⁠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.

  • Base: main at 97c78d1, plus #45 and #89 (both needed on this machine), plus #46, plus this PR.
  • Run: diagnostics build. Played through the first-boot menus with a pad into the world, about 20 s in the world.
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)

**@⁠HenriqueSBueno** on GitHub · 2026-11-24 00:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7118116362) · 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. - **Base:** `main` at 97c78d1, plus #45 and #89 (both needed on this machine), plus #46, plus this PR. - **Run:** diagnostics build. Played through the first-boot menus with a pad into the world, about 20 s in the world. | | 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)
Author
Owner

@⁠tanishq-dubey on GitHub · 2026-11-24 00:46 UTC · original

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.

**@⁠tanishq-dubey** on GitHub · 2026-11-24 00:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7118425545) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 00:42 UTC · original · edited 2026-11-24 00:47 UTC

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

  • The lowering-only checks above (wave size and "does it lower") need no device. Splitting those out of the Windows-only file would let them run in Linux test runs too, with only the dispatch parts gated.
  • cargo fmt --check -p victory-shader reports two hunks in lines this PR adds: the long boolean in emit/host.rs (wave_range) and the walk(...) call in lower.rs (resolve_spills).
  • The D3D12_FEATURE_D3D12_OPTIONS1 query is written twice (victory-gpu/src/host.rs and emit/host.rs); one could call the other.
  • uses_lds only counts Fields::Ds. I found no handling of the MUBUF/MTBUF lds bit in lower.rs, so I do not think this changes behavior today, but a one-line comment may help.
  • The lane masking (& 63 in Wave64, & 31 in Wave32) looks consistent with the lane-select width described for v_readlane/v_writelane; I did not check it against hardware.
  • Conflicts with other open PRs (trial git merge-tree of the two PR heads, checked against the 18 other open PRs at the time): textual conflicts with #48 in emit/mod.rs (both change emit(): #48 wraps it in a retry, this PR adds emit_for), with #69 and #116 in lower.rs, and with #94 in victory-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).
  • Edit note: an earlier version of this comment said the merge with #48 was clean and did not list #116; that came from a truncated check and is corrected here.

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.

**@⁠tedin7** on GitHub · 2026-11-24 00:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7118353628) · edited 2026-11-24 00:47 UTC 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 #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): - The lowering-only checks above (wave size and "does it lower") need no device. Splitting those out of the Windows-only file would let them run in Linux test runs too, with only the dispatch parts gated. - `cargo fmt --check -p victory-shader` reports two hunks in lines this PR adds: the long boolean in `emit/host.rs` (`wave_range`) and the `walk(...)` call in `lower.rs` (`resolve_spills`). - The `D3D12_FEATURE_D3D12_OPTIONS1` query is written twice (`victory-gpu/src/host.rs` and `emit/host.rs`); one could call the other. - `uses_lds` only counts `Fields::Ds`. I found no handling of the MUBUF/MTBUF `lds` bit in `lower.rs`, so I do not think this changes behavior today, but a one-line comment may help. - The lane masking (`& 63` in Wave64, `& 31` in Wave32) looks consistent with the lane-select width described for v_readlane/v_writelane; I did not check it against hardware. - Conflicts with other open PRs (trial `git merge-tree` of the two PR heads, checked against the 18 other open PRs at the time): textual conflicts with #48 in `emit/mod.rs` (both change `emit()`: #48 wraps it in a retry, this PR adds `emit_for`), with #69 and #116 in `lower.rs`, and with #94 in `victory-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). - Edit note: an earlier version of this comment said the merge with #48 was clean and did not list #116; that came from a truncated check and is corrected here. 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.
Author
Owner

@⁠ghost on GitHub · 2026-11-24 00:51 UTC · original

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

  • error[E0063]: missing field 'host_waves' in initializer of 'Parts<'_>' at crates/victory-shader/src/emit/lower.rs:6878 and crates/victory-shader/src/emit/valu_tests.rs:129. Both initializers came in after your base: the lower.rs one with #81 (s_addc/s_subb carry test), and valu_tests.rs with #37. The merge itself is clean, so GitHub won't flag it.

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.
**@⁠ghost** on GitHub · 2026-11-24 00:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7118499935) AMD (native 64-lane waves) run, plus a heads-up: **merged onto current `main` `9aef3d9`, this no longer compiles.** - `error[E0063]: missing field 'host_waves' in initializer of 'Parts<'_>'` at `crates/victory-shader/src/emit/lower.rs:6878` and `crates/victory-shader/src/emit/valu_tests.rs:129`. Both initializers came in after your base: the `lower.rs` one with #81 (`s_addc`/`s_subb` carry test), and `valu_tests.rs` with #37. The merge itself is clean, so GitHub won't flag it. 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.
Author
Owner

@⁠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 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.

**@⁠alessiodeia** on GitHub · 2026-11-24 00:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7118643979) @⁠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.
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:59 UTC · original

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

**@⁠DaviTostes** on GitHub · 2026-11-24 00:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7118648565) 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).
Author
Owner

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

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.

**@⁠EduAzevedo** on GitHub · 2026-11-24 01:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7118722119) 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.
Author
Owner

@⁠alessiodeia on GitHub · 2026-11-24 01:08 UTC · original

@⁠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.

**@⁠alessiodeia** on GitHub · 2026-11-24 01:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7118800194) @⁠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.
Author
Owner

@⁠ghost on GitHub · 2026-11-24 01:15 UTC · original

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.
**@⁠ghost** on GitHub · 2026-11-24 01:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7118914671) 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.
Author
Owner

@⁠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::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.

**@⁠jeremygold02** on GitHub · 2026-11-24 01:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7118923073) 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.
Author
Owner

@⁠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.

**@⁠Raxstreams** on GitHub · 2026-11-24 01:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7119625112) 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.
Author
Owner

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

  • 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 #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.

**@⁠r4tedx** on GitHub · 2026-11-24 02:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7120456435) 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 #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.
Author
Owner

@⁠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 --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 #404).
**@⁠slint6614-dev** on GitHub · 2026-11-24 08:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#issuecomment-7125666293) 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 #404).
Author
Owner

@⁠raffclar on GitHub · 2026-11-24 00:03 UTC · original · edited 2026-11-24 00:06 UTC
On crates/victory-shader/src/emit/lower.rs line 647 (outdated):

@@ -374,10 +632,19 @@ impl<'a> Lower<'a> {
                         .any(|a| matches!(a, Atom::Opaque(_) | Atom::Constant(_)))
                 })
             };
+            let uses_lds = insts().any(|i| {
+                matches!(i.fields, Fields::Ds { .. })
+                    && !i.name().starts_with("ds_swizzle")
+                    && !i.name().contains("permute")
+            });
             let wave = if x.native.wave64 { 64 } else { 32 };
-            let one_wave = cs.threads.iter().product::<u32>() <= wave;
-            if console_lanes || one_wave && s.lds_dwords > 0 {
-                s.wave_size = Some(wave);
+            let threads = cs.threads.iter().product::<u32>();
+            let one_wave = threads <= wave;
+            if console_lanes || one_wave && s.lds_dwords > 0 && uses_lds {
+                // 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 });

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:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#discussion_r4673703861) · edited 2026-11-24 00:06 UTC On `crates/victory-shader/src/emit/lower.rs` line 647 (outdated): ```diff @@ -374,10 +632,19 @@ impl<'a> Lower<'a> { .any(|a| matches!(a, Atom::Opaque(_) | Atom::Constant(_))) }) }; + let uses_lds = insts().any(|i| { + matches!(i.fields, Fields::Ds { .. }) + && !i.name().starts_with("ds_swizzle") + && !i.name().contains("permute") + }); let wave = if x.native.wave64 { 64 } else { 32 }; - let one_wave = cs.threads.iter().product::<u32>() <= wave; - if console_lanes || one_wave && s.lds_dwords > 0 { - s.wave_size = Some(wave); + let threads = cs.threads.iter().product::<u32>(); + let one_wave = threads <= wave; + if console_lanes || one_wave && s.lds_dwords > 0 && uses_lds { + // 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 }); ``` 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.
Author
Owner

@⁠raffclar on GitHub · 2026-11-24 00:09 UTC · original
On crates/victory-shader/src/emit/lower.rs line 428 (outdated):

@@ -318,6 +332,241 @@ fn unsupported(offset: usize, what: Why) -> Stop {
     Stop::Fail(ShaderError::Unsupported { offset, what })
 }
 
+fn const_lane(op: Operand) -> Option<u32> {
+    match op {
+        Operand::Const(c) => crate::resource::inline(c),
+        Operand::Literal(x) => Some(x),
+        _ => None,
+    }
+}
+
+/// Resolves SGPR spills through VGPR lanes (`v_writelane_b32` ->
+/// `v_readlane_b32` at a constant lane) directly in SSA, and identifies the
+/// `v_writelane_b32` sites whose VGPR output never escapes to any other use.
+fn resolve_spills(p: &Program, st: &Structured) -> (HashMap<Site, Spill>, HashSet<Site>) {
+    let mut def_site: HashMap<Value, Site> = HashMap::new();
+    let mut def_block: HashMap<Value, usize> = HashMap::new();
+    let mut phi_at: HashMap<Value, (usize, usize)> = HashMap::new();
+    for &(_, v) in &p.inputs {
+        def_block.insert(v, 0);
+    }
+    for (b, block) in p.blocks.iter().enumerate() {
+        for (i, phi) in block.phis.iter().enumerate() {
+            phi_at.insert(phi.value, (b, i));
+            def_block.insert(phi.value, b);
+        }
+        for (i, inst) in block.insts.iter().enumerate() {
+            for &(_, w) in &inst.writes {
+                def_site.insert(w, (b, i));
+                def_block.insert(w, b);
+            }
+        }
+    }
+
+    let order = crate::ir::reverse_postorder(&p.blocks);
+    let mut rpo = vec![usize::MAX; p.blocks.len()];
+    for (n, &b) in order.iter().enumerate() {
+        rpo[b] = n;
+    }
+    let idom = crate::ir::idoms(&p.blocks, &order, &rpo);
+    let dominates = |a: usize, mut b: usize| -> bool {
+        if rpo[a] == usize::MAX || rpo[b] == usize::MAX {
+            return false;
+        }
+        while b != a {
+            let d = idom[b];
+            if d == b || d == usize::MAX {
+                return false;
+            }
+            b = d;
+        }
+        true
+    };
+
+    fn walk(
+        p: &Program,
+        st: &Structured,
+        def_site: &HashMap<Value, Site>,
+        phi_at: &HashMap<Value, (usize, usize)>,
+        v: Value,
+        lane: u32,
+        seen: &mut Vec<Value>,
+    ) -> Result<Option<Spill>, ()> {
+        if let Some(&(b, i)) = phi_at.get(&v) {
+            if seen.contains(&v) {
+                return Ok(None);
+            }
+            seen.push(v);
+            let mut found = None;
+            for &arg in &p.blocks[b].phis[i].args {
+                if let Some(m) = walk(p, st, def_site, phi_at, arg, lane, seen)? {
+                    if found.is_some_and(|f| f != m) {
+                        return Err(());
+                    }
+                    found = Some(m);
+                }
+            }
+            return Ok(found);
+        }
+        let &(b, i) = def_site.get(&v).ok_or(())?;
+        let inst = &p.blocks[b].insts[i];
+        let Fields::Valu(w) = &inst.fields else {
+            return Err(());
+        };
+        if inst.name() != "v_writelane_b32"
+            || w.abs != 0
+            || w.neg != 0
+            || w.opsel != 0
+            || w.sdwa.is_some()
+            || w.dpp.is_some()
+        {
+            return Err(());
+        }
+        let (Some(Operand::Vector { reg, .. }), [value, at]) = (w.dst, &w.src[..]) else {
+            return Err(());
+        };
+        if const_lane(*at).ok_or(())? != lane {

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

**@⁠raffclar** on GitHub · 2026-11-24 00:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/54#discussion_r4673755248) On `crates/victory-shader/src/emit/lower.rs` line 428 (outdated): ```diff @@ -318,6 +332,241 @@ fn unsupported(offset: usize, what: Why) -> Stop { Stop::Fail(ShaderError::Unsupported { offset, what }) } +fn const_lane(op: Operand) -> Option<u32> { + match op { + Operand::Const(c) => crate::resource::inline(c), + Operand::Literal(x) => Some(x), + _ => None, + } +} + +/// Resolves SGPR spills through VGPR lanes (`v_writelane_b32` -> +/// `v_readlane_b32` at a constant lane) directly in SSA, and identifies the +/// `v_writelane_b32` sites whose VGPR output never escapes to any other use. +fn resolve_spills(p: &Program, st: &Structured) -> (HashMap<Site, Spill>, HashSet<Site>) { + let mut def_site: HashMap<Value, Site> = HashMap::new(); + let mut def_block: HashMap<Value, usize> = HashMap::new(); + let mut phi_at: HashMap<Value, (usize, usize)> = HashMap::new(); + for &(_, v) in &p.inputs { + def_block.insert(v, 0); + } + for (b, block) in p.blocks.iter().enumerate() { + for (i, phi) in block.phis.iter().enumerate() { + phi_at.insert(phi.value, (b, i)); + def_block.insert(phi.value, b); + } + for (i, inst) in block.insts.iter().enumerate() { + for &(_, w) in &inst.writes { + def_site.insert(w, (b, i)); + def_block.insert(w, b); + } + } + } + + let order = crate::ir::reverse_postorder(&p.blocks); + let mut rpo = vec![usize::MAX; p.blocks.len()]; + for (n, &b) in order.iter().enumerate() { + rpo[b] = n; + } + let idom = crate::ir::idoms(&p.blocks, &order, &rpo); + let dominates = |a: usize, mut b: usize| -> bool { + if rpo[a] == usize::MAX || rpo[b] == usize::MAX { + return false; + } + while b != a { + let d = idom[b]; + if d == b || d == usize::MAX { + return false; + } + b = d; + } + true + }; + + fn walk( + p: &Program, + st: &Structured, + def_site: &HashMap<Value, Site>, + phi_at: &HashMap<Value, (usize, usize)>, + v: Value, + lane: u32, + seen: &mut Vec<Value>, + ) -> Result<Option<Spill>, ()> { + if let Some(&(b, i)) = phi_at.get(&v) { + if seen.contains(&v) { + return Ok(None); + } + seen.push(v); + let mut found = None; + for &arg in &p.blocks[b].phis[i].args { + if let Some(m) = walk(p, st, def_site, phi_at, arg, lane, seen)? { + if found.is_some_and(|f| f != m) { + return Err(()); + } + found = Some(m); + } + } + return Ok(found); + } + let &(b, i) = def_site.get(&v).ok_or(())?; + let inst = &p.blocks[b].insts[i]; + let Fields::Valu(w) = &inst.fields else { + return Err(()); + }; + if inst.name() != "v_writelane_b32" + || w.abs != 0 + || w.neg != 0 + || w.opsel != 0 + || w.sdwa.is_some() + || w.dpp.is_some() + { + return Err(()); + } + let (Some(Operand::Vector { reg, .. }), [value, at]) = (w.dst, &w.src[..]) else { + return Err(()); + }; + if const_lane(*at).ok_or(())? != lane { ``` 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!54
No description provided.