Shaders: a mask read as a number takes lanes 32-63 from its high dword in halves mode #108

Closed
Caasares wants to merge 0 commits from upstream-pr/108 into main
Caasares commented 2026-11-27 18:15:09 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Caasares on 2026-11-27T18:15:09Z.


Bug

A console wave64 compute program that the translator runs as two host waves of 32 ("halves"; used when the host's waves hold at most 32 lanes, as NVIDIA's do) reads a 64-bit lane mask held as a number with the wrong lanes. Lanes 32-63 take bits of the low dword instead of the high one.

Impact

Per-lane results are wrong for lanes 32-63 of such a program, for example a v_cndmask_b32 whose mask is an SGPR pair the program does not track.

Root cause

thread_id numbers the lanes of a halved program through console_thread(). console_lane() and lane_bit() only do the same when exchange is set. Otherwise lane_bit takes waveGetLaneIndex, which is 0-31 in each host wave, so lane < 32 is always true and the high dword is never chosen.

Fix

In halves mode console_lane() gives console_thread() & 63, and lane_bit() uses it, as exchange mode already does.

Testing

  • New test wave64_tests::lanes_past_32_take_the_high_dword_of_a_mask_held_as_a_number. A DPP move makes the program take the console's lanes, so it runs in halves. Then v_cndmask_b32 reads s[2:3] as the mask. The test checks all 64 lanes for three masks, on the hardware device when one takes waves of 32, and skips otherwise.
  • On an NVIDIA GeForce RTX 3070, the test fails on main at lane 32 (mask a0f0123455550f0f) and passes with this change.
  • cargo test -p victory-shader --locked: 289 passed, 0 failed, 4 ignored (already ignored on main).
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings, and the same with --all-features: clean.
  • rustfmt: this change adds no new diffs. lower.rs and wave64_tests.rs already had rustfmt differences on main and the number is unchanged.

Workspace-wide clippy and fmt already fail on main in code this PR does not touch (victory-formats/src/texture.rs:1346, apps/victory).

#52 makes a select on a mask held as a number count toward console_lanes. This PR does not depend on it: its test reaches halves mode with a DPP move. With #52 applied, a wave64 program with such a select does reach halves mode, and this change is what numbers its lanes correctly there. I have not run #52's branch on the card.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5531226083 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/108). Originally posted by [Caasares](https://github.com/Caasares) on 2026-11-27T18:15:09Z. --- ## Bug A console wave64 compute program that the translator runs as two host waves of 32 ("halves"; used when the host's waves hold at most 32 lanes, as NVIDIA's do) reads a 64-bit lane mask held as a number with the wrong lanes. Lanes 32-63 take bits of the low dword instead of the high one. ## Impact Per-lane results are wrong for lanes 32-63 of such a program, for example a `v_cndmask_b32` whose mask is an SGPR pair the program does not track. ## Root cause `thread_id` numbers the lanes of a halved program through `console_thread()`. `console_lane()` and `lane_bit()` only do the same when `exchange` is set. Otherwise `lane_bit` takes `waveGetLaneIndex`, which is 0-31 in each host wave, so `lane < 32` is always true and the high dword is never chosen. ## Fix In halves mode `console_lane()` gives `console_thread() & 63`, and `lane_bit()` uses it, as exchange mode already does. ## Testing - New test `wave64_tests::lanes_past_32_take_the_high_dword_of_a_mask_held_as_a_number`. A DPP move makes the program take the console's lanes, so it runs in halves. Then `v_cndmask_b32` reads `s[2:3]` as the mask. The test checks all 64 lanes for three masks, on the hardware device when one takes waves of 32, and skips otherwise. - On an NVIDIA GeForce RTX 3070, the test fails on `main` at lane 32 (mask `a0f0123455550f0f`) and passes with this change. - `cargo test -p victory-shader --locked`: 289 passed, 0 failed, 4 ignored (already ignored on `main`). - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`, and the same with `--all-features`: clean. - rustfmt: this change adds no new diffs. `lower.rs` and `wave64_tests.rs` already had rustfmt differences on `main` and the number is unchanged. Workspace-wide clippy and fmt already fail on `main` in code this PR does not touch (`victory-formats/src/texture.rs:1346`, `apps/victory`). ## Related #52 makes a select on a mask held as a number count toward `console_lanes`. This PR does not depend on it: its test reaches halves mode with a DPP move. With #52 applied, a wave64 program with such a select does reach halves mode, and this change is what numbers its lanes correctly there. I have not run #52's branch on the card.
cloph-dsp commented 2026-11-28 00:36:17 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by cloph-dsp on 2026-11-28T00:36:17Z.


Independent local verification of PR #108 (lanes past 32 take the high dword of a mask held as a number).

  • Windows, Rust 1.100.0/MSVC (Scoop rust-msvc, no rustup/clippy), cargo test --locked, synthetic inputs only; CPU interpreter (Host::new(false)), no GPU.
  • Head 245cb85145bfd083e3df6769adf68dbdbb670340, merge base 29d8dbf7d9892ceb8bec378a9dbc3c4f2931b745, worktree-local CARGO_TARGET_DIR.
  • Command: cargo test --locked -p victory-shader --lib -- emit::wave64_tests::lanes_past_32_take_the_high_dword_of_a_mask_held_as_a_number --exact --test-threads=1 --quiet → test result: ok. 1 passed; 0 failed; 292 filtered out, exit 0.
  • Negative control: git grep -F lanes_past_32_take_the_high_dword_of_a_mask_held_as_a_number 29d8dbf7 -- crates/victory-shader/src/emit/wave64_tests.rs → exit 1 (test absent on base).
  • git diff --check 29d8dbf7 HEAD clean; diff 2 files, +48/−5.

Only the named test was replayed; full suite not run. GPU/driver N/A (CPU interpreter). AI-assisted (Hy4 flash). No game data, assets, extracted shaders, DRM or decrypt.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7231044404 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/108#issuecomment-7231044404). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T00:36:17Z. --- Independent local verification of PR #108 (lanes past 32 take the high dword of a mask held as a number). - Windows, Rust 1.100.0/MSVC (Scoop rust-msvc, no rustup/clippy), `cargo test --locked`, synthetic inputs only; CPU interpreter (`Host::new(false)`), no GPU. - Head `245cb85145bfd083e3df6769adf68dbdbb670340`, merge base `29d8dbf7d9892ceb8bec378a9dbc3c4f2931b745`, worktree-local `CARGO_TARGET_DIR`. - Command: `cargo test --locked -p victory-shader --lib -- emit::wave64_tests::lanes_past_32_take_the_high_dword_of_a_mask_held_as_a_number --exact --test-threads=1 --quiet` → `test result: ok. 1 passed; 0 failed; 292 filtered out`, exit 0. - Negative control: `git grep -F lanes_past_32_take_the_high_dword_of_a_mask_held_as_a_number 29d8dbf7 -- crates/victory-shader/src/emit/wave64_tests.rs` → exit 1 (test absent on base). - `git diff --check 29d8dbf7 HEAD` clean; diff 2 files, +48/−5. Only the named test was replayed; full suite not run. GPU/driver N/A (CPU interpreter). AI-assisted (Hy4 flash). No game data, assets, extracted shaders, DRM or decrypt.
trustno1-coder commented 2026-11-28 02:49:11 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-28T02:49:11Z.


Merged into main (8fc2254) and shipped in v2026.11.27.10. The commit keeps you as its author, so it counts toward the contributors list. GitHub shows this as closed rather than merged only because the commits were applied on top of the newest main (new commit IDs). Thank you!

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7232614000 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/108#issuecomment-7232614000). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-11-28T02:49:11Z. --- Merged into main (8fc2254) and shipped in [v2026.11.27.10](https://github.com/trustno1-coder/VIctory-NVIDIA/releases/tag/v2026.11.27.10). The commit keeps you as its author, so it counts toward the contributors list. GitHub shows this as closed rather than merged only because the commits were applied on top of the newest main (new commit IDs). Thank you!

Pull request closed

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!108
No description provided.