fix(victory-shader): exclude partial_active tail lanes in cross-lane ops #485

Merged
mauroalvare merged 1 commit from upstream-pr/485 into main 2026-11-27 19:38:44 +00:00
mauroalvare commented 2026-11-27 07:34:39 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T07:34:39Z.


What failed

In third_party/victory/crates/victory-shader/src/emit/lower.rs, spilled 64-thread wave64 compute shaders dispatched with a partial final group (USER_DISPATCH_THREADS_X, such as the ray-tracing BVH structure builder kernels) run on 32-lane hosts (NVIDIA) with self.partial_active = Some(runs) so unlaunched tail lanes stay alive in the host wave to reach group barriers.

While memory operations (memory_guard), lane-mask ballots (launched), scc_some, wave_wide, and whole-wave reductions already masked out unlaunched tail lanes via partial_active, three cross-lane paths did not:

  1. v_permlane16_b32 and v_permlanex16_b32 (fi:0): balloted guard.unwrap_or(true) without partial_active, so active launched lanes reading an unlaunched tail lane received stale VGPR data instead of keeping vdst (bound_ctrl:0) or reading 0 (bound_ctrl:1).
  2. ds_bpermute_b32: zeroed source values using guard alone (skipping partial_active), so launched lanes reading an unlaunched tail lane received stale VGPR data instead of 0.
  3. v_readfirstlane_b32 (first_live_lane): balloted guard without partial_active, so a guarded first-lane read matching only unlaunched tail lanes returned an unlaunched lane's value instead of falling back to lane 0 as when EXEC == 0.

On base b62053f, the synthetic 64-thread partial-dispatch compute test fails on an RTX 5070 Ti (host_wave = 32, count = 10, lane 0) on all four checks:

assertion `left == right` failed: count 10, lane 0
  left: [115, 116, 115, 120]
 right: [43690, 0, 0, 100]

How to reproduce

From third_party/victory:

cargo test --locked -p victory-shader partial_dispatch_cross_lane_ops_exclude_unlaunched_lanes -- --test-threads=1 --nocapture

The synthetic spilled wave64 compute shader runs on a 32-lane host (TEST_HOST_WAVE = 32) with USER_DISPATCH_THREADS_X set to 10, 45, and 0 (full 64-lane group), validating the emitted DXIL with dxil.dll and checking v_permlane16_b32 (bound_ctrl:0), v_permlanex16_b32 (bound_ctrl:1), ds_bpermute_b32, and guarded v_readfirstlane_b32 across all 64 lanes.

What changed

  • third_party/victory/crates/victory-shader/src/emit/lower.rs:
    • Add Lower::active_guard(&mut self, guard: Option<V>) -> Option<V> combining a lane guard with self.partial_active, and delegate memory_guard to it.
    • Use self.active_guard(guard) in first_live_lane (v_readfirstlane_b32), ds_bpermute_b32, and v_permlane16_b32 / v_permlanex16_b32 (fi:0).
  • third_party/victory/crates/victory-shader/src/emit/wave64_tests.rs:
    • Add synthetic hardware regression test partial_dispatch_cross_lane_ops_exclude_unlaunched_lanes.

Verification

Tested on Windows x64, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver 621.40), WARP, and dxil.dll (10.0.26100.0), base SHA b62053f:

  • Base b62053f: partial_dispatch_cross_lane_ops_exclude_unlaunched_lanes failed (count 10, lane 0: [115, 116, 115, 120] vs expected [43690, 0, 0, 100]).
  • With fix:
    • cargo test --locked -p victory-shader partial_dispatch_cross_lane_ops_exclude_unlaunched_lanes -- --test-threads=1 --nocapture: 1 passed; 0 failed (RTX 5070 Ti + dxil.dll).
    • cargo test --locked -p victory-shader -- --test-threads=1: 318 passed; 0 failed; 4 ignored (benchmarks / explicit sweeps).
    • cargo xtask policy: asset policy: 289 files ok.

All measurements are from synthetic unit tests only (no game files or game runs).

AI assistance

Assisted by AI (Antigravity) for root-cause analysis, synthetic shader construction, implementation, and local hardware verification.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5522956437 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/485). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-27T07:34:39Z. --- ## What failed In `third_party/victory/crates/victory-shader/src/emit/lower.rs`, spilled 64-thread wave64 compute shaders dispatched with a partial final group (`USER_DISPATCH_THREADS_X`, such as the ray-tracing BVH structure builder kernels) run on 32-lane hosts (NVIDIA) with `self.partial_active = Some(runs)` so unlaunched tail lanes stay alive in the host wave to reach group barriers. While memory operations (`memory_guard`), lane-mask ballots (`launched`), `scc_some`, `wave_wide`, and whole-wave reductions already masked out unlaunched tail lanes via `partial_active`, three cross-lane paths did not: 1. `v_permlane16_b32` and `v_permlanex16_b32` (`fi:0`): balloted `guard.unwrap_or(true)` without `partial_active`, so active launched lanes reading an unlaunched tail lane received stale VGPR data instead of keeping `vdst` (`bound_ctrl:0`) or reading `0` (`bound_ctrl:1`). 2. `ds_bpermute_b32`: zeroed source values using `guard` alone (skipping `partial_active`), so launched lanes reading an unlaunched tail lane received stale VGPR data instead of `0`. 3. `v_readfirstlane_b32` (`first_live_lane`): balloted `guard` without `partial_active`, so a guarded first-lane read matching only unlaunched tail lanes returned an unlaunched lane's value instead of falling back to lane 0 as when `EXEC == 0`. On base `b62053f`, the synthetic 64-thread partial-dispatch compute test fails on an RTX 5070 Ti (`host_wave = 32`, `count = 10`, lane 0) on all four checks: ``` assertion `left == right` failed: count 10, lane 0 left: [115, 116, 115, 120] right: [43690, 0, 0, 100] ``` ## How to reproduce From `third_party/victory`: ```powershell cargo test --locked -p victory-shader partial_dispatch_cross_lane_ops_exclude_unlaunched_lanes -- --test-threads=1 --nocapture ``` The synthetic spilled wave64 compute shader runs on a 32-lane host (`TEST_HOST_WAVE = 32`) with `USER_DISPATCH_THREADS_X` set to `10`, `45`, and `0` (full 64-lane group), validating the emitted DXIL with `dxil.dll` and checking `v_permlane16_b32` (`bound_ctrl:0`), `v_permlanex16_b32` (`bound_ctrl:1`), `ds_bpermute_b32`, and guarded `v_readfirstlane_b32` across all 64 lanes. ## What changed - `third_party/victory/crates/victory-shader/src/emit/lower.rs`: - Add `Lower::active_guard(&mut self, guard: Option<V>) -> Option<V>` combining a lane guard with `self.partial_active`, and delegate `memory_guard` to it. - Use `self.active_guard(guard)` in `first_live_lane` (`v_readfirstlane_b32`), `ds_bpermute_b32`, and `v_permlane16_b32` / `v_permlanex16_b32` (`fi:0`). - `third_party/victory/crates/victory-shader/src/emit/wave64_tests.rs`: - Add synthetic hardware regression test `partial_dispatch_cross_lane_ops_exclude_unlaunched_lanes`. ## Verification Tested on Windows x64, Ryzen 7 9700X, **NVIDIA GeForce RTX 5070 Ti (driver `621.40`)**, WARP, and `dxil.dll` (`10.0.26100.0`), base SHA `b62053f`: - **Base `b62053f`**: `partial_dispatch_cross_lane_ops_exclude_unlaunched_lanes` **failed** (`count 10, lane 0: [115, 116, 115, 120]` vs expected `[43690, 0, 0, 100]`). - **With fix**: - `cargo test --locked -p victory-shader partial_dispatch_cross_lane_ops_exclude_unlaunched_lanes -- --test-threads=1 --nocapture`: **1 passed; 0 failed** (RTX 5070 Ti + `dxil.dll`). - `cargo test --locked -p victory-shader -- --test-threads=1`: **318 passed; 0 failed; 4 ignored** (benchmarks / explicit sweeps). - `cargo xtask policy`: **asset policy: 289 files ok**. All measurements are from synthetic unit tests only (no game files or game runs). ## AI assistance Assisted by AI (Antigravity) for root-cause analysis, synthetic shader construction, implementation, and local hardware verification.
LooperSalty commented 2026-11-27 16:59:20 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T16:59:20Z.


Two things before merge:

  1. Shader cache key. This changes the DXIL emitted for split wave64 groups, but TRANSLATOR_VERSION (victory-shader/src/lib.rs:29) stays at 2, and cached DXIL is keyed on it (shader_cache.rs). Existing caches would keep serving the unmasked shaders. Please bump it (note that #456, also open, moves it to 3; take the next free value when you rebase).
  2. Coverage of the other cross-lane reads. Tail lanes are now excluded in v_readfirstlane, the prefix/ballot path and the shuffle ballot, but quad_pick / quad_read (DPP quad reads), the permlane read_lane(x, src) paths and v_readlane_b32 in lower.rs can still read a lane past the launched tail. On RDNA 2 those lanes are EXEC-off and must not contribute. Please mask them with active_guard too, or explain why a tail lane can never be their source, and extend partial_dispatch_cross_lane_ops_exclude_unlaunched_lanes to one of them.
<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7223898457 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/485#issuecomment-7223898457). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T16:59:20Z. --- Two things before merge: 1. **Shader cache key.** This changes the DXIL emitted for split wave64 groups, but `TRANSLATOR_VERSION` (`victory-shader/src/lib.rs:29`) stays at 2, and cached DXIL is keyed on it (`shader_cache.rs`). Existing caches would keep serving the unmasked shaders. Please bump it (note that #456, also open, moves it to 3; take the next free value when you rebase). 2. **Coverage of the other cross-lane reads.** Tail lanes are now excluded in `v_readfirstlane`, the prefix/ballot path and the shuffle ballot, but `quad_pick` / `quad_read` (DPP quad reads), the permlane `read_lane(x, src)` paths and `v_readlane_b32` in `lower.rs` can still read a lane past the launched tail. On RDNA 2 those lanes are EXEC-off and must not contribute. Please mask them with `active_guard` too, or explain why a tail lane can never be their source, and extend `partial_dispatch_cross_lane_ops_exclude_unlaunched_lanes` to one of them.
mauroalvare commented 2026-11-27 17:27:01 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T17:27:01Z.


Rebased onto \origin/main\ (\445308) and updated in ${sha485}:

  1. **\TRANSLATOR_VERSION**: bumped \2 -> 4\ in \ hird_party/victory/crates/victory-shader/src/lib.rs\ (leaving \3\ free for #456).
  2. **Remaining cross-lane reads masked with \partial_active**:
    • \dpp()\ (DPP16 & DPP8, \FI=0): balloted \partial_active\ via a shared \lane_active\ helper on the
      ead_lane\ path (clamping \safe_src\ first), so reading an unlaunched tail lane yields \
<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7224418475 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/485#issuecomment-7224418475). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-27T17:27:01Z. --- Rebased onto \origin/main\ (\445308\) and updated in \${sha485}\: 1. **\TRANSLATOR_VERSION\**: bumped \2 -> 4\ in \ hird_party/victory/crates/victory-shader/src/lib.rs\ (leaving \3\ free for #456). 2. **Remaining cross-lane reads masked with \partial_active\**: - **\dpp()\ (DPP16 & DPP8, \FI=0\)**: balloted \partial_active\ via a shared \lane_active\ helper on the \ ead_lane\ path (clamping \safe_src\ first), so reading an unlaunched tail lane yields \
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
LooperSalty/AnyXboxX!485
No description provided.