fix(shader): track wave width and parked-lane restores in wave barriers #3348

Open
legayclightning22 wants to merge 1 commit from upstream-pr/3348 into main
legayclightning22 commented 2026-11-26 19:30:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-26T19:30:53Z.


Summary

Tracks wave width and parked-lane restores across shader wave barriers and unspill handling (5794ccc), updating shader cache keys and barrier gating/relaxation logic.

Changes

  • Update wave-mode settings, shader cache keys, and gated/relaxed barrier handling to track wave width and parked-lane restores across 7 files (+463/-23)[cite: 26].
  • Add 6 unit tests covering wave barrier width tracking and parked-lane unspill behavior[cite: 26].

Verification

  • cargo test -p victory-shader --lib (297 passed, 6 new tests passing; 11 known baseline hardware failures, 3 ignored)[cite: 26]
  • cargo test -p victory-gpu --lib cache tests[cite: 26]
  • cargo clippy --locked --all-targets -- -D warnings[cite: 26]
  • cargo xtask policy[cite: 26]
<!-- greyfinch-sync:Marvisak/VIctory:issue:5516035056 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3348). Originally posted by [legayclightning22](https://github.com/legayclightning22) on 2026-11-26T19:30:53Z. --- ## Summary Tracks wave width and parked-lane restores across shader wave barriers and unspill handling (`5794ccc`), updating shader cache keys and barrier gating/relaxation logic. ## Changes - Update wave-mode settings, shader cache keys, and gated/relaxed barrier handling to track wave width and parked-lane restores across 7 files (`+463/-23`)[cite: 26]. - Add 6 unit tests covering wave barrier width tracking and parked-lane unspill behavior[cite: 26]. ## Verification - `cargo test -p victory-shader --lib` (297 passed, 6 new tests passing; 11 known baseline hardware failures, 3 ignored)[cite: 26] - `cargo test -p victory-gpu --lib` cache tests[cite: 26] - `cargo clippy --locked --all-targets -- -D warnings`[cite: 26] - `cargo xtask policy`[cite: 26]
Dukestar69 commented 2026-11-26 19:49:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T19:49:41Z.

Review: APPROVED


LGTM — verified on RTX 5090 (Windows / D3D12) against origin/main (63bcca4).

  • Tracking host wave width in shader cache keys, gating wave64 programs on 32-lane hosts, handling divergent single-wave barriers without group sync, and preserving parked-lane restores in IR all pass cleanly on RTX 5090.
  • cargo test -p victory-shader --lib ir:: -- --test-threads=1: 12 passed, 0 failed.
  • cargo test -p victory-shader --lib structure:: -- --test-threads=1: 13 passed, 0 failed (1 ignored).
  • cargo test -p victory-shader --lib emit::tests:: -- --test-threads=1: 20 passed, 0 failed (barrier_modes_keep_the_shared_and_uav_fences, divergent_barriers_drop_group_sync_in_one_wave, wave64_on_32_lane_host_is_gated).
  • cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1: 5 passed, 0 failed (wave_settings_have_distinct_cache_keys).
  • cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6079764121 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3348#pullrequestreview-6079764121). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T19:49:41Z. **Review:** APPROVED --- LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Tracking host wave width in shader cache keys, gating wave64 programs on 32-lane hosts, handling divergent single-wave barriers without group sync, and preserving parked-lane restores in IR all pass cleanly on RTX 5090. - `cargo test -p victory-shader --lib ir:: -- --test-threads=1`: 12 passed, 0 failed. - `cargo test -p victory-shader --lib structure:: -- --test-threads=1`: 13 passed, 0 failed (1 ignored). - `cargo test -p victory-shader --lib emit::tests:: -- --test-threads=1`: 20 passed, 0 failed (`barrier_modes_keep_the_shared_and_uav_fences`, `divergent_barriers_drop_group_sync_in_one_wave`, `wave64_on_32_lane_host_is_gated`). - `cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1`: 5 passed, 0 failed (`wave_settings_have_distinct_cache_keys`). - `cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
cloph-dsp commented 2026-11-26 19:55:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T19:55:33Z.


Independent local verification of PR #3348 (fix(shader): track wave width and parked-lane restores in wave barriers), head 5794ccca63.

  • Windows, Rust 1.100.0/MSVC, cargo test --locked, CARGO_BUILD_JOBS=2, per-worktree CARGO_TARGET_DIR (D:\Victory-Contrib\target-3348).
  • cargo test --locked -p victory-shader --lib -- --exact ir::tests::parked_lane_restores_look_past_other_registers -> 1 passed, 0 failed, 310 filtered, exit 0.
  • git diff --check origin/main HEAD -> clean.
  • Negative control: the test name is absent from the merge base 63bcca43..., so it is genuinely added by this PR.
  • CPU-side IR test only; the barrier/hardware and shader-cache tests in this 7-file PR were not exercised here.

AI-assisted (Hy4 flash). GPU/driver: N/A for this CPU test. No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7202106989 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3348#issuecomment-7202106989). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T19:55:33Z. --- Independent local verification of PR #3348 (`fix(shader): track wave width and parked-lane restores in wave barriers`), head 5794ccca63ddc1efe46e122366280f7d35699b13. - Windows, Rust 1.100.0/MSVC, `cargo test --locked`, `CARGO_BUILD_JOBS=2`, per-worktree `CARGO_TARGET_DIR` (`D:\Victory-Contrib\target-3348`). - `cargo test --locked -p victory-shader --lib -- --exact ir::tests::parked_lane_restores_look_past_other_registers` -> 1 passed, 0 failed, 310 filtered, exit 0. - `git diff --check origin/main HEAD` -> clean. - Negative control: the test name is absent from the merge base 63bcca43..., so it is genuinely added by this PR. - CPU-side IR test only; the barrier/hardware and shader-cache tests in this 7-file PR were not exercised here. AI-assisted (Hy4 flash). GPU/driver: N/A for this CPU test. No game data used.
fuzeofficlal commented 2026-11-26 20:38:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T20:38:19Z.

Review: CHANGES_REQUESTED


Tested locally merged onto origin/main (63bcca43) at PR head 5794ccca across three adapters on Windows 11 x64 (NVIDIA GeForce RTX 5090, AMD Radeon Graphics gfx1036, Microsoft WARP; VICTORY_D3D12_DEBUG=1).

Baseline build checks pass (cargo xtask policy: 191 files ok, emit/lower.rs is 522,803 B < 524,288 B; clippy default & --all-features clean; shader_cache key hashing covers host_lanes/wide64/group_sync), but there are three blocking correctness bugs reproduced locally:

1. Unconditional rejection of all wave64 programs on 32-lane hosts (emit/lower.rs:250, 290, shader_cache.rs:74)

On NVIDIA adapters (WaveLaneCountMax == 32, VICTORY_WAVE_WIDE unset), wave64_unsupported = x.native.wave64 && wave.host_lanes < 64 && !wave.wide64 rejects every wave64 shader before lowering — including completely unrestricted wave64 programs with no wave ops and no LDS (which already lower to unrestricted DXIL and run natively in Wave32 on main).

Reproduced locally with a minimal unrestricted wave64 compute shader (rsrc2 = 0, s_endpgm) under WaveMode::with(32, false, GroupSync::Auto):
Err(Unsupported { offset: 0, what: "a wave64 program on a 32-lane host (VICTORY_WAVE_WIDE=1)" }).

Any 32-lane host gating should only apply to programs that actually require 64-lane wave semantics, not every native.wave64 shader.

2. Unsound single_wave barrier relaxation from WaveLaneCountMax (host.rs:19-34, emit/lower.rs:257-272)

host.rs derives max_wave_lanes from WaveLaneCountMax (clamping values < 32 up to 32), and lower.rs drops SYNC_THREAD_GROUP (bit 1) from divergent s_barriers whenever group_lanes <= wave.host_lanes.

Measured D3D12_FEATURE_DATA_D3D12_OPTIONS1 across three real adapters on this machine:

  • NVIDIA GeForce RTX 5090: WaveLaneCountMin = 32, WaveLaneCountMax = 32 (host_lanes = 32)
  • AMD Radeon Graphics: WaveLaneCountMin = 32, WaveLaneCountMax = 64 (host_lanes = 64)
  • Microsoft WARP: WaveLaneCountMin = 4, WaveLaneCountMax = 4 (clamped up to host_lanes = 32)

On AMD RDNA2/3 (host_lanes = 64), a [64, 1, 1] wave32 (or unrestricted) compute shader executes as two 32-lane waves, yet 64 <= 64 marks single_wave = true and strips SYNC_THREAD_GROUP (reproduced locally: barrier_modes = [8] instead of [9]). Likewise on WARP (Min = Max = 4), [32, 1, 1] is eight 4-lane waves, yet 32 <= 32 strips group sync. Dropping SYNC_THREAD_GROUP is only sound when group_lanes <= WaveLaneCountMin (or when DXIL explicitly declares a fixed WaveSize >= group_lanes).

3. Soundness bugs in ir.rs::restores (crates/victory-shader/src/ir.rs:599-643)

  1. Missing invalidation on v_writelane_b32 (L599-L607): When v_writelane_b32 writes a non-SGPR value (e.g. an inline constant/literal) or uses a dynamic lane operand, parked_scalar/operand_number returns None and the early continue at L606 skips invalidating parked. Reproduced locally with v_writelane_b32 v1, s0, 0 followed by v_writelane_b32 v1, 0, 0 and v_readlane_b32 s5, v1, 0: p.restored still maps s5 to the overwritten s0 (Some(Value(4))).
  2. Incorrect vector semantics for v_movrels_b32 / v_movreld_b32 / v_swaprel_b32 (L620-L638): These are per-lane VGPR vector moves, not scalar broadcasts of one parked lane (and v_movreld_b32 indexes the destination v[dst + m0], not v.src[0], nor does the loop at L639-L643 invalidate v[dst + m0]). Reproduced locally with v_writelane_b32 v7, s0, 3 (only lane 3 parked) + s_mov_b32 m0, 3 + v_movrels_b32 v0, v4: p.restored falsely maps the entire vector result v0 to scalar s0 (Some(Value(255))), which then propagates into resource.rs and structure.rs (l.restored).

Synthetic tests only.

<!-- greyfinch-sync:Marvisak/VIctory:review:6080265883 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3348#pullrequestreview-6080265883). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T20:38:19Z. **Review:** CHANGES_REQUESTED --- Tested locally merged onto `origin/main` (`63bcca43`) at PR head `5794ccca` across three adapters on Windows 11 x64 (NVIDIA GeForce RTX 5090, AMD Radeon Graphics `gfx1036`, Microsoft WARP; `VICTORY_D3D12_DEBUG=1`). Baseline build checks pass (`cargo xtask policy`: 191 files ok, `emit/lower.rs` is 522,803 B < 524,288 B; clippy default & `--all-features` clean; `shader_cache` key hashing covers `host_lanes`/`wide64`/`group_sync`), **but there are three blocking correctness bugs reproduced locally**: ### 1. Unconditional rejection of all `wave64` programs on 32-lane hosts (`emit/lower.rs:250, 290`, `shader_cache.rs:74`) On NVIDIA adapters (`WaveLaneCountMax == 32`, `VICTORY_WAVE_WIDE` unset), `wave64_unsupported = x.native.wave64 && wave.host_lanes < 64 && !wave.wide64` rejects **every** `wave64` shader before lowering — including completely unrestricted `wave64` programs with no wave ops and no LDS (which already lower to unrestricted DXIL and run natively in Wave32 on `main`). Reproduced locally with a minimal unrestricted `wave64` compute shader (`rsrc2 = 0`, `s_endpgm`) under `WaveMode::with(32, false, GroupSync::Auto)`: `Err(Unsupported { offset: 0, what: "a wave64 program on a 32-lane host (VICTORY_WAVE_WIDE=1)" })`. Any 32-lane host gating should only apply to programs that actually require 64-lane wave semantics, not every `native.wave64` shader. ### 2. Unsound `single_wave` barrier relaxation from `WaveLaneCountMax` (`host.rs:19-34`, `emit/lower.rs:257-272`) `host.rs` derives `max_wave_lanes` from `WaveLaneCountMax` (clamping values `< 32` up to `32`), and `lower.rs` drops `SYNC_THREAD_GROUP` (bit 1) from divergent `s_barrier`s whenever `group_lanes <= wave.host_lanes`. Measured `D3D12_FEATURE_DATA_D3D12_OPTIONS1` across three real adapters on this machine: - NVIDIA GeForce RTX 5090: `WaveLaneCountMin = 32, WaveLaneCountMax = 32` (`host_lanes = 32`) - AMD Radeon Graphics: `WaveLaneCountMin = 32, WaveLaneCountMax = 64` (`host_lanes = 64`) - Microsoft WARP: `WaveLaneCountMin = 4, WaveLaneCountMax = 4` (clamped up to `host_lanes = 32`) On AMD RDNA2/3 (`host_lanes = 64`), a `[64, 1, 1]` `wave32` (or unrestricted) compute shader executes as **two 32-lane waves**, yet `64 <= 64` marks `single_wave = true` and strips `SYNC_THREAD_GROUP` (reproduced locally: `barrier_modes = [8]` instead of `[9]`). Likewise on WARP (`Min = Max = 4`), `[32, 1, 1]` is eight 4-lane waves, yet `32 <= 32` strips group sync. Dropping `SYNC_THREAD_GROUP` is only sound when `group_lanes <= WaveLaneCountMin` (or when DXIL explicitly declares a fixed `WaveSize >= group_lanes`). ### 3. Soundness bugs in `ir.rs::restores` (`crates/victory-shader/src/ir.rs:599-643`) 1. **Missing invalidation on `v_writelane_b32` (`L599-L607`):** When `v_writelane_b32` writes a non-SGPR value (e.g. an inline constant/literal) or uses a dynamic lane operand, `parked_scalar`/`operand_number` returns `None` and the early `continue` at `L606` skips invalidating `parked`. Reproduced locally with `v_writelane_b32 v1, s0, 0` followed by `v_writelane_b32 v1, 0, 0` and `v_readlane_b32 s5, v1, 0`: `p.restored` still maps `s5` to the overwritten `s0` (`Some(Value(4))`). 2. **Incorrect vector semantics for `v_movrels_b32` / `v_movreld_b32` / `v_swaprel_b32` (`L620-L638`):** These are per-lane VGPR vector moves, not scalar broadcasts of one parked lane (and `v_movreld_b32` indexes the *destination* `v[dst + m0]`, not `v.src[0]`, nor does the loop at `L639-L643` invalidate `v[dst + m0]`). Reproduced locally with `v_writelane_b32 v7, s0, 3` (only lane 3 parked) + `s_mov_b32 m0, 3` + `v_movrels_b32 v0, v4`: `p.restored` falsely maps the entire vector result `v0` to scalar `s0` (`Some(Value(255))`), which then propagates into `resource.rs` and `structure.rs` (`l.restored`). Synthetic tests only.
legayclightning22 commented 2026-11-26 22:30:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-26T22:30:29Z.


Pushed d4bfcbd fixing all three blocking issues:

  1. Scoped 32-lane host wave64 gating so unrestricted wave64 shaders without 64-lane wave semantics lower normally on 32-lane hosts, with a unit test under WaveMode::with(32, false, GroupSync::Auto).
  2. Switched single_wave barrier relaxation to check group_lanes <= WaveLaneCountMin (without clamping values < 32 up to 32) so AMD (Min=32, Max=64) and WARP (Min=Max=4) preserve SYNC_THREAD_GROUP, with regression tests for both.
  3. Fixed ir.rs::restores to invalidate parked entries on non-SGPR/dynamic-lane v_writelane_b32 writes and removed the unsound scalar-broadcast mapping on v_movrels_b32/v_movreld_b32/v_swaprel_b32 with proper VGPR invalidation and regression tests.

Re-verified victory-shader tests, shader_cache::, clippy --all-features -- -D warnings, and cargo xtask policy.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204740031 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3348#issuecomment-7204740031). Originally posted by [legayclightning22](https://github.com/legayclightning22) on 2026-11-26T22:30:29Z. --- Pushed `d4bfcbd` fixing all three blocking issues: 1. Scoped 32-lane host wave64 gating so unrestricted `wave64` shaders without 64-lane wave semantics lower normally on 32-lane hosts, with a unit test under `WaveMode::with(32, false, GroupSync::Auto)`. 2. Switched `single_wave` barrier relaxation to check `group_lanes <= WaveLaneCountMin` (without clamping values `< 32` up to `32`) so AMD (`Min=32, Max=64`) and WARP (`Min=Max=4`) preserve `SYNC_THREAD_GROUP`, with regression tests for both. 3. Fixed `ir.rs::restores` to invalidate `parked` entries on non-SGPR/dynamic-lane `v_writelane_b32` writes and removed the unsound scalar-broadcast mapping on `v_movrels_b32`/`v_movreld_b32`/`v_swaprel_b32` with proper VGPR invalidation and regression tests. Re-verified `victory-shader` tests, `shader_cache::`, `clippy --all-features -- -D warnings`, and `cargo xtask policy`.
fuzeofficlal commented 2026-11-26 23:02:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:02:41Z.

Review: CHANGES_REQUESTED


Thanks for updating ir::restores (crates/victory-shader/src/ir.rs:317-364) and narrowing the wave64 rejection to programs that actually set s.wave_size == Some(64) (emit/lower.rs:650-653). Verified on three live D3D12 adapters (RTX 5090, AMD gfx1036 iGPU, and WARP with VICTORY_D3D12_DEBUG=1): both previous ir::restores soundness bugs are resolved and unrestricted wave64 compute shaders now compile and create PSOs cleanly on all three adapters with 0 Debug Layer errors.

However, two blocking issues remain on the updated head (d4bfcbd6):

1. declared_wave_size(c) trusts the console container's PSV0 as the host's wave size, stripping SYNC_THREAD_GROUP from multi-wave threadgroups (emit/mod.rs:454-459, 536 + emit/lower.rs:585-598)

emit_with_wave (crates/victory-shader/src/emit/mod.rs:536) extracts PSV0 bytes 20..28 from the console input container c and passes it as wave.fixed_wave_size. Lower::new (crates/victory-shader/src/emit/lower.rs:585-598) then computes single_wave before s.wave_size (lower.rs:647) using:

let single_wave = group_lanes.is_some_and(|n| {
    n > 0 && (n <= wave.min_lanes || wave.fixed_wave_size.is_some_and(|size| size >= n))
});

Because this inspects the console container's PSV0 rather than the emitted host DXIL's s.wave_size (and never checks size <= wave.host_lanes), a compute shader whose emitted host DXIL declares no WaveSize (PSV0 = 0..=4294967295) still has SYNC_THREAD_GROUP (bit 0) stripped whenever the console container had min == max:

  • RTX 5090 (min=32, max=32), console wave64 CS (threads=[64, 1, 1], console PSV0=64, divergent s_barrier with s_and_saveexec_b64, s.wave_size = None): lowers to barrier_modes = [8] (bit 0 stripped) and emitted host PSV0 = (0..=4294967295), even though 64 threads execute as 2 waves of 32 lanes on RTX 5090.
  • WARP (min=4, max=4), console wave32 CS (threads=[32, 1, 1], console PSV0=32, divergent s_barrier, s.wave_size = None): lowers to barrier_modes = [8] with emitted host PSV0 = (0..=4294967295), even though WARP runs 8 waves of 4 lanes.
  • AMD gfx1036 (min=32, max=64), console wave64 CS (threads=[64, 1, 1], console PSV0=64, divergent s_barrier, s.wave_size = None): lowers to barrier_modes = [8] with emitted host PSV0 = (0..=4294967295), where the driver is free to dispatch 2× Wave32 waves.

Suggested fix: Do not derive single_wave from the console input container's PSV0. Compute single_wave after s.wave_size (lower.rs:647) and only relax divergent barriers when the host is genuinely guaranteed to run one wave: n <= wave.min_lanes || s.wave_size.is_some_and(|w| w >= n && w <= wave.host_lanes).

2. VICTORY_WAVE_WIDE=1 still emits DXIL WaveSize(64) (rejected by 32-lane/4-lane adapters) and host.rs:24-32 misclamps WARP's WaveLaneCountMax = 4 to 32

  • When a wave64 shader sets s.wave_size = Some(64) on a host with host_lanes < 64, lower.rs:1349 directs the user to VICTORY_WAVE_WIDE=1. However, setting wide64 = true only clears wave64_unsupported (lower.rs:650-653) while lower.rs:647 still sets s.wave_size = Some(64) (writing WaveSize(64) and PSV0 min=64, max=64) without any wave64 emulation.
  • Live CreateComputePipelineState verification with VICTORY_D3D12_DEBUG=1 on the lowered wide64 = true DXIL (v_readlane_b32 + s_endpgm, wave64 = true):
    • NVIDIA GeForce RTX 5090 (WaveLaneCountMin=32, WaveLaneCountMax=32): Err(E_INVALIDARG / 0x80070057) — ID3D12Device::CreateComputeShader: Shader wants wave lane count of 64 but maximum wave lane count for device is 32.
    • Microsoft Basic Render Driver (WARP) (WaveLaneCountMin=4, WaveLaneCountMax=4): Err(E_INVALIDARG / 0x80070057) — ID3D12Device::CreateComputeShader: Shader wants wave lane count of 64 but maximum wave lane count for device is 4.
    • AMD Radeon(TM) Graphics (gfx1036) (WaveLaneCountMin=32, WaveLaneCountMax=64): Ok (0 Debug Layer messages).
  • Also in crates/victory-gpu/src/host.rs:24-32, when WaveLaneCountMax < 32 (observed on WARP: WaveLaneCountMin=4, WaveLaneCountMax=4), max_wave_lanes is clamped up to 32 (Host reported min_wave_lanes=4, max_wave_lanes=32). Please preserve the actual reported WaveLaneCountMax (e.g., wave_options.WaveLaneCountMax when lanes.is_ok() && wave_options.WaveLaneCountMax > 0) and either implement/drop the VICTORY_WAVE_WIDE=1 switch or avoid emitting an unsupported WaveSize(64) tag under it.

Minor cleanup

  • crates/victory-shader/src/resource.rs:2079 still matches "v_movrels_b32" even though ir::restores no longer inserts v_movrels_b32 entries.
<!-- greyfinch-sync:Marvisak/VIctory:review:6081324324 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3348#pullrequestreview-6081324324). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T23:02:41Z. **Review:** CHANGES_REQUESTED --- Thanks for updating `ir::restores` (`crates/victory-shader/src/ir.rs:317-364`) and narrowing the `wave64` rejection to programs that actually set `s.wave_size == Some(64)` (`emit/lower.rs:650-653`). Verified on three live D3D12 adapters (RTX 5090, AMD `gfx1036` iGPU, and WARP with `VICTORY_D3D12_DEBUG=1`): both previous `ir::restores` soundness bugs are resolved and unrestricted `wave64` compute shaders now compile and create PSOs cleanly on all three adapters with 0 Debug Layer errors. However, two blocking issues remain on the updated head (`d4bfcbd6`): ### 1. `declared_wave_size(c)` trusts the console container's `PSV0` as the host's wave size, stripping `SYNC_THREAD_GROUP` from multi-wave threadgroups (`emit/mod.rs:454-459, 536` + `emit/lower.rs:585-598`) `emit_with_wave` (`crates/victory-shader/src/emit/mod.rs:536`) extracts `PSV0` bytes `20..28` from the **console** input container `c` and passes it as `wave.fixed_wave_size`. `Lower::new` (`crates/victory-shader/src/emit/lower.rs:585-598`) then computes `single_wave` **before** `s.wave_size` (`lower.rs:647`) using: ```rust let single_wave = group_lanes.is_some_and(|n| { n > 0 && (n <= wave.min_lanes || wave.fixed_wave_size.is_some_and(|size| size >= n)) }); ``` Because this inspects the console container's `PSV0` rather than the **emitted host DXIL's** `s.wave_size` (and never checks `size <= wave.host_lanes`), a compute shader whose emitted host DXIL declares **no** `WaveSize` (`PSV0 = 0..=4294967295`) still has `SYNC_THREAD_GROUP` (bit 0) stripped whenever the console container had `min == max`: - **RTX 5090 (`min=32, max=32`)**, console `wave64` CS (`threads=[64, 1, 1]`, console `PSV0=64`, divergent `s_barrier` with `s_and_saveexec_b64`, `s.wave_size = None`): lowers to `barrier_modes = [8]` (bit 0 stripped) and emitted host `PSV0 = (0..=4294967295)`, even though 64 threads execute as **2 waves of 32 lanes** on RTX 5090. - **WARP (`min=4, max=4`)**, console `wave32` CS (`threads=[32, 1, 1]`, console `PSV0=32`, divergent `s_barrier`, `s.wave_size = None`): lowers to `barrier_modes = [8]` with emitted host `PSV0 = (0..=4294967295)`, even though WARP runs **8 waves of 4 lanes**. - **AMD `gfx1036` (`min=32, max=64`)**, console `wave64` CS (`threads=[64, 1, 1]`, console `PSV0=64`, divergent `s_barrier`, `s.wave_size = None`): lowers to `barrier_modes = [8]` with emitted host `PSV0 = (0..=4294967295)`, where the driver is free to dispatch 2× Wave32 waves. **Suggested fix:** Do not derive `single_wave` from the console input container's `PSV0`. Compute `single_wave` **after** `s.wave_size` (`lower.rs:647`) and only relax divergent barriers when the host is genuinely guaranteed to run one wave: `n <= wave.min_lanes || s.wave_size.is_some_and(|w| w >= n && w <= wave.host_lanes)`. ### 2. `VICTORY_WAVE_WIDE=1` still emits DXIL `WaveSize(64)` (rejected by 32-lane/4-lane adapters) and `host.rs:24-32` misclamps WARP's `WaveLaneCountMax = 4` to `32` - When a `wave64` shader sets `s.wave_size = Some(64)` on a host with `host_lanes < 64`, `lower.rs:1349` directs the user to `VICTORY_WAVE_WIDE=1`. However, setting `wide64 = true` only clears `wave64_unsupported` (`lower.rs:650-653`) while `lower.rs:647` still sets `s.wave_size = Some(64)` (writing `WaveSize(64)` and `PSV0 min=64, max=64`) without any wave64 emulation. - Live `CreateComputePipelineState` verification with `VICTORY_D3D12_DEBUG=1` on the lowered `wide64 = true` DXIL (`v_readlane_b32` + `s_endpgm`, `wave64 = true`): - **NVIDIA GeForce RTX 5090** (`WaveLaneCountMin=32, WaveLaneCountMax=32`): `Err(E_INVALIDARG / 0x80070057)` — `ID3D12Device::CreateComputeShader: Shader wants wave lane count of 64 but maximum wave lane count for device is 32.` - **Microsoft Basic Render Driver (WARP)** (`WaveLaneCountMin=4, WaveLaneCountMax=4`): `Err(E_INVALIDARG / 0x80070057)` — `ID3D12Device::CreateComputeShader: Shader wants wave lane count of 64 but maximum wave lane count for device is 4.` - **AMD Radeon(TM) Graphics (`gfx1036`)** (`WaveLaneCountMin=32, WaveLaneCountMax=64`): `Ok` (0 Debug Layer messages). - Also in `crates/victory-gpu/src/host.rs:24-32`, when `WaveLaneCountMax < 32` (observed on WARP: `WaveLaneCountMin=4, WaveLaneCountMax=4`), `max_wave_lanes` is clamped **up** to `32` (`Host` reported `min_wave_lanes=4, max_wave_lanes=32`). Please preserve the actual reported `WaveLaneCountMax` (e.g., `wave_options.WaveLaneCountMax` when `lanes.is_ok() && wave_options.WaveLaneCountMax > 0`) and either implement/drop the `VICTORY_WAVE_WIDE=1` switch or avoid emitting an unsupported `WaveSize(64)` tag under it. ### Minor cleanup - `crates/victory-shader/src/resource.rs:2079` still matches `"v_movrels_b32"` even though `ir::restores` no longer inserts `v_movrels_b32` entries.
legayclightning22 commented 2026-11-27 01:17:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-27T01:17:27Z.


Pushed <NEW_SHA> fixing both blocking issues and the minor cleanup:

  1. Moved single_wave derivation after s.wave_size is finalized in emit/lower.rs (instead of inspecting the console input container's PSV0), relaxing divergent s_barrier SYNC_THREAD_GROUP only when n <= wave.min_lanes || s.wave_size.is_some_and(|w| w >= n && w <= wave.host_lanes).
  2. Preserved WaveLaneCountMax < 32 in crates/victory-gpu/src/host.rs (so WARP reports 4 instead of clamping to 32) and prevented VICTORY_WAVE_WIDE=1 from emitting unsupported WaveSize(64) metadata on < 64-lane hosts.
  3. Removed the dead "v_movrels_b32" match arm in crates/victory-shader/src/resource.rs.

Added regression tests for all three and re-verified victory-shader, victory-gpu, clippy --all-features -- -D warnings, and cargo xtask policy.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7207169644 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3348#issuecomment-7207169644). Originally posted by [legayclightning22](https://github.com/legayclightning22) on 2026-11-27T01:17:27Z. --- Pushed `<NEW_SHA>` fixing both blocking issues and the minor cleanup: 1. Moved `single_wave` derivation after `s.wave_size` is finalized in `emit/lower.rs` (instead of inspecting the console input container's `PSV0`), relaxing divergent `s_barrier` `SYNC_THREAD_GROUP` only when `n <= wave.min_lanes || s.wave_size.is_some_and(|w| w >= n && w <= wave.host_lanes)`. 2. Preserved `WaveLaneCountMax < 32` in `crates/victory-gpu/src/host.rs` (so WARP reports `4` instead of clamping to `32`) and prevented `VICTORY_WAVE_WIDE=1` from emitting unsupported `WaveSize(64)` metadata on `< 64`-lane hosts. 3. Removed the dead `"v_movrels_b32"` match arm in `crates/victory-shader/src/resource.rs`. Added regression tests for all three and re-verified `victory-shader`, `victory-gpu`, `clippy --all-features -- -D warnings`, and `cargo xtask policy`.
fuzeofficlal commented 2026-11-27 01:21:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:21:21Z.

Review: APPROVED


All issues from the previous review are resolved cleanly on 8013170d8030c10f9631cc9eea3a6c1e2a1da370:

  • single_wave (crates/victory-shader/src/emit/lower.rs:640-644) only relaxes divergent barriers when the group fits within min_lanes or an explicitly emitted s.wave_size that the host supports (w >= n && w <= wave.host_lanes), without trusting console PSV0 metadata alone.
  • wave64_unsupported (lower.rs:660-661, 679-684) refuses WaveSize(64) on narrower hosts instead of emitting invalid DXIL, and WaveMode::new gates wide64 on host_lanes >= 64.
  • wave_lane_count_max (crates/victory-gpu/src/host.rs:9-11) preserves reported values below 32 (such as WARP's 4), and shader_cache::key hashes all four WaveMode fields (host_lanes, min_lanes, wide64, group_sync).
  • ir::restores invalidates parked lanes on all VGPR writes (including M0-relative ranges expanded into inst.writes).

Verified:

  • cargo xtask policy passes cleanly (emit/lower.rs = 522,999 bytes < 512 KiB).
  • cargo clippy --lib and --tests (default and --features diagnostics, -D warnings) pass across victory-shader and victory-gpu.
  • Verified live across three D3D12 adapters with VICTORY_WAVE_WIDE=1:
    • RTX 5090 (min=32, max=32): wide64: false
    • AMD integrated RDNA2 GPU (min=32, max=64): wide64: true
    • WARP (min=4, max=4): max_wave_lanes=4, min_wave_lanes=4, wide64: false
  • Unit tests pass: victory-shader emit::tests (23/23) and ir::tests (14/14); victory-gpu shader_cache::tests (5/5) and reported_wave_lane_count_max_is_not_rounded_up (1/1).
<!-- greyfinch-sync:Marvisak/VIctory:review:6082242826 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3348#pullrequestreview-6082242826). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T01:21:21Z. **Review:** APPROVED --- All issues from the previous review are resolved cleanly on `8013170d8030c10f9631cc9eea3a6c1e2a1da370`: - `single_wave` (`crates/victory-shader/src/emit/lower.rs:640-644`) only relaxes divergent barriers when the group fits within `min_lanes` or an explicitly emitted `s.wave_size` that the host supports (`w >= n && w <= wave.host_lanes`), without trusting console `PSV0` metadata alone. - `wave64_unsupported` (`lower.rs:660-661, 679-684`) refuses `WaveSize(64)` on narrower hosts instead of emitting invalid DXIL, and `WaveMode::new` gates `wide64` on `host_lanes >= 64`. - `wave_lane_count_max` (`crates/victory-gpu/src/host.rs:9-11`) preserves reported values below 32 (such as WARP's `4`), and `shader_cache::key` hashes all four `WaveMode` fields (`host_lanes`, `min_lanes`, `wide64`, `group_sync`). - `ir::restores` invalidates parked lanes on all VGPR writes (including M0-relative ranges expanded into `inst.writes`). Verified: - `cargo xtask policy` passes cleanly (`emit/lower.rs` = 522,999 bytes < 512 KiB). - `cargo clippy --lib` and `--tests` (default and `--features diagnostics`, `-D warnings`) pass across `victory-shader` and `victory-gpu`. - Verified live across three D3D12 adapters with `VICTORY_WAVE_WIDE=1`: - RTX 5090 (`min=32, max=32`): `wide64: false` - AMD integrated RDNA2 GPU (`min=32, max=64`): `wide64: true` - WARP (`min=4, max=4`): `max_wave_lanes=4, min_wave_lanes=4, wide64: false` - Unit tests pass: `victory-shader` `emit::tests` (23/23) and `ir::tests` (14/14); `victory-gpu` `shader_cache::tests` (5/5) and `reported_wave_lane_count_max_is_not_rounded_up` (1/1).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3348:upstream-pr/3348'
git switch 'upstream-pr/3348'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3348'
git switch 'upstream-pr/3348'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3348'
git switch 'upstream-pr/3348'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3348'
git switch 'main'
git merge --squash 'upstream-pr/3348'
git switch 'main'
git merge --ff-only 'upstream-pr/3348'
git switch 'main'
git merge 'upstream-pr/3348'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3348
No description provided.