shader: intersect v_cndmask_b32 active masks with partial_active on 32-lane hosts #2059

Merged
steven-seagull27 merged 1 commit from upstream-pr/2059 into main 2026-11-30 14:12:04 +00:00
steven-seagull27 commented 2026-11-29 08:52:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by steven-seagull27 on 2026-11-29T08:52:21Z.


Related: Marvisak/VIctory#3750 (Cause 3)

What it changes

On 32-lane hosts, counted wave64 compute shaders (USER_DISPATCH_THREADS_X) that cannot early-return at entry (because of a group barrier, two-wave exchange, or loop back to entry) keep threads with x >= count alive under Lower::partial_active.

Previously, ballot and collapsed whole-wave reductions (Shape::Masked, Shape::Active, Shape::Prefix, active_f64_sum) intersected masks in st.active with self.partial_active, but direct mask consumers in crates/victory-shader/src/emit/lower.rs did not:

  • v_cndmask_b32
  • v_add_co_ci_u32 / v_sub_co_ci_u32 / v_subrev_co_ci_u32 (carry-in)
  • v_div_fmas_f32 (VCC)
  • lane_heap_index (Source::Lanes)

When a counted wave64 compute shader saved EXEC with s_or_saveexec_b64, masked inactive lanes to zero with v_cndmask_b32, and ran a cross-lane reduction/DPP prefix sum without collapsing into a single-block whole-wave section, v_cndmask_b32 evaluated entry EXEC as Bool::TRUE in every thread—leaving lanes >= count unzeroed and letting them pollute the cross-lane result.

Changes:

  • Added Lower::launched_mask in crates/victory-shader/src/emit/lower.rs to intersect tracked st.active lane-mask booleans with self.partial_active, and applied it across all eight st.masks.get consumers (fixing the four unguarded sites and unifying the four existing sites).
  • Added a synthetic regression test cndmask_saved_exec_respects_dispatch_x_partial_active in crates/victory-shader/src/emit/wave64_tests.rs: a counted 64-thread compute shader that saves EXEC via s_or_saveexec_b64, zeroes inactive lanes with v_cndmask_b32, runs a 64-lane DPP + v_readlane_b32 prefix sum, and stores (prefix, wave_total) per active lane for counts 5, 37, and 0 (all 64 lanes).

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): NVIDIA RTX 5080 (32-lane native hardware D3D12 compute dispatch) + DXIL validation (dxil.dll); synthetic unit test only (no game assets).
  • Before: Synthetic test cndmask_saved_exec_respects_dispatch_x_partial_active failed on 32-lane hardware at count = 5, lane = 0 with left: (1, 2080) vs right: (1, 15) (lanes 5..63 were not zeroed by v_cndmask_b32, so lane 63 summed 1..=64 = 2080 instead of 1..=5 = 15).
  • After: cndmask_saved_exec_respects_dispatch_x_partial_active passes DXIL validation on both 64-lane and 32-lane forms and passes D3D12 hardware execution on 32-lane waves for counts 5 (total 15), 37 (total 703), and 0 (total 2080). (WARP skipped WaveSize(32)/WaveSize(64) PSO creation on this host.)
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): 64-lane and 32-lane lowering + DXIL validation; 32-lane D3D12 hardware execution.
  • cargo test passed for the crates it touches: yes (cargo test --locked -j 3 -p victory-shader --lib -- wave64_tests --test-threads=1 -> 45 passed, 0 failed; cargo clippy --locked -j 3 -p victory-shader --lib --tests -> 0 new warnings; git diff --check clean).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: Marvisak/VIctory#3750
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5549170024 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2059). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-29T08:52:21Z. --- Related: Marvisak/VIctory#3750 (Cause 3) ## What it changes On 32-lane hosts, counted wave64 compute shaders (`USER_DISPATCH_THREADS_X`) that cannot early-return at entry (because of a group barrier, two-wave exchange, or loop back to entry) keep threads with `x >= count` alive under `Lower::partial_active`. Previously, `ballot` and collapsed whole-wave reductions (`Shape::Masked`, `Shape::Active`, `Shape::Prefix`, `active_f64_sum`) intersected masks in `st.active` with `self.partial_active`, but direct mask consumers in `crates/victory-shader/src/emit/lower.rs` did not: - `v_cndmask_b32` - `v_add_co_ci_u32` / `v_sub_co_ci_u32` / `v_subrev_co_ci_u32` (carry-in) - `v_div_fmas_f32` (VCC) - `lane_heap_index` (`Source::Lanes`) When a counted wave64 compute shader saved `EXEC` with `s_or_saveexec_b64`, masked inactive lanes to zero with `v_cndmask_b32`, and ran a cross-lane reduction/DPP prefix sum without collapsing into a single-block whole-wave section, `v_cndmask_b32` evaluated entry `EXEC` as `Bool::TRUE` in every thread—leaving lanes `>= count` unzeroed and letting them pollute the cross-lane result. Changes: - Added `Lower::launched_mask` in `crates/victory-shader/src/emit/lower.rs` to intersect tracked `st.active` lane-mask booleans with `self.partial_active`, and applied it across all eight `st.masks.get` consumers (fixing the four unguarded sites and unifying the four existing sites). - Added a synthetic regression test `cndmask_saved_exec_respects_dispatch_x_partial_active` in `crates/victory-shader/src/emit/wave64_tests.rs`: a counted 64-thread compute shader that saves `EXEC` via `s_or_saveexec_b64`, zeroes inactive lanes with `v_cndmask_b32`, runs a 64-lane DPP + `v_readlane_b32` prefix sum, and stores `(prefix, wave_total)` per active lane for counts `5`, `37`, and `0` (all 64 lanes). ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): NVIDIA RTX 5080 (32-lane native hardware D3D12 compute dispatch) + DXIL validation (`dxil.dll`); synthetic unit test only (no game assets). - Before: Synthetic test `cndmask_saved_exec_respects_dispatch_x_partial_active` failed on 32-lane hardware at `count = 5, lane = 0` with `left: (1, 2080)` vs `right: (1, 15)` (lanes `5..63` were not zeroed by `v_cndmask_b32`, so lane 63 summed `1..=64 = 2080` instead of `1..=5 = 15`). - After: `cndmask_saved_exec_respects_dispatch_x_partial_active` passes DXIL validation on both 64-lane and 32-lane forms and passes D3D12 hardware execution on 32-lane waves for counts `5` (total `15`), `37` (total `703`), and `0` (total `2080`). (WARP skipped `WaveSize(32)`/`WaveSize(64)` PSO creation on this host.) - For shader changes, the wave sizes tested (32 and/or 64 lanes): 64-lane and 32-lane lowering + DXIL validation; 32-lane D3D12 hardware execution. - `cargo test` passed for the crates it touches: yes (`cargo test --locked -j 3 -p victory-shader --lib -- wave64_tests --test-threads=1` -> 45 passed, 0 failed; `cargo clippy --locked -j 3 -p victory-shader --lib --tests` -> 0 new warnings; `git diff --check` clean). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: Marvisak/VIctory#3750
Dukestar69 commented 2026-11-29 10:30:18 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-29T10:30:18Z.

Review: APPROVED


Tested locally merged onto main (829188e9).

  • Merge: Clean merge across crates/victory-shader/src/emit/lower.rs and wave64_tests.rs.
  • Tests (RTX 5090, Wave32 host): cargo test -p victory-shader --lib emit::wave64_tests:: passed (45 passed; 0 failed, including the new cndmask_saved_exec_respects_dispatch_x_partial_active GPU execution test) with 0 new warnings.

Solid Wave32 v_cndmask_b32 active-mask intersection fix for partial-active dispatches. LGTM.

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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6102479456 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2059#pullrequestreview-6102479456). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-29T10:30:18Z. **Review:** APPROVED --- Tested locally merged onto `main` (`829188e9`). - **Merge**: Clean merge across `crates/victory-shader/src/emit/lower.rs` and `wave64_tests.rs`. - **Tests (RTX 5090, Wave32 host)**: `cargo test -p victory-shader --lib emit::wave64_tests::` passed (`45 passed; 0 failed`, including the new `cndmask_saved_exec_respects_dispatch_x_partial_active` GPU execution test) with 0 new warnings. Solid Wave32 `v_cndmask_b32` active-mask intersection fix for partial-active dispatches. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
dyshay commented 2026-11-29 13:05:16 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-29T13:05:16Z.


Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs, on top of 829188e9 plus a couple of local fixes). Read the full diff first: no network, process spawning, binaries, build/CI/dependency changes or game data. Builds with --profile diag --features diagnostics; clean cherry-pick; the targeted shader tests pass. In-game runs on an RTX 4090 (wave32 host) are queued; results will follow here.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7256279036 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2059#issuecomment-7256279036). Originally posted by [dyshay](https://github.com/dyshay) on 2026-11-29T13:05:16Z. --- Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA), branch `janus-prs`, on top of 829188e9 plus a couple of local fixes). Read the full diff first: no network, process spawning, binaries, build/CI/dependency changes or game data. Builds with `--profile diag --features diagnostics`; clean cherry-pick; the targeted shader tests pass. In-game runs on an RTX 4090 (wave32 host) are queued; results will follow here.
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
trustno1-coder/VIctory-NVIDIA!2059
No description provided.