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

Open
github-bot wants to merge 1 commit from github-bot/gh-108 into main AGit
Owner

@⁠Caasares on GitHub · 2026-11-27 18:15 UTC · original
Caasares:fix/shader-halves-lane-bit → main · +48 −5 · 2 files · 1 commits · open

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.

**@⁠Caasares** on GitHub · 2026-11-27 18:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/108) `Caasares:fix/shader-halves-lane-bit` → `main` · +48 −5 · 2 files · 1 commits · open ## 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.
A console wave64 compute program that runs as two host waves of 32
("halves") numbers its lanes through console_thread (thread_id does).
console_lane and lane_bit still read the host lane index unless
exchange is set. A 64-bit mask read as a number, such as a select on
an SGPR pair, then gave lanes 32-63 the bits of the low dword: their
host lane is 0-31, so the test `lane < 32` always picked the low dword.

Use the console lane in both places when halves is set, as exchange
already does.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 18:17:18 +00:00
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-28 00:36 UTC · original

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.

**@⁠cloph-dsp** on GitHub · 2026-11-28 00:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/108#issuecomment-7231044404) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/108/head:github-bot/gh-108'
git switch 'github-bot/gh-108'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-108'
git switch 'github-bot/gh-108'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-108'
git switch 'github-bot/gh-108'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-108'
git switch 'main'
git merge --squash 'github-bot/gh-108'
git switch 'main'
git merge --ff-only 'github-bot/gh-108'
git switch 'main'
git merge 'github-bot/gh-108'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.