shader(fold): sign-extend negative inline constants in upper mask9 half #2983

Open
RanoGames wants to merge 1 commit from upstream-pr/2983 into main
RanoGames commented 2026-11-29 19:12:58 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by RanoGames on 2026-11-29T19:12:58Z.


What it changes

Fixes mask9 in crates/victory-shader/src/fold.rs when folding 64-lane VALU instructions (such as v_cndmask_b32 and *_co_ci_u32 carry-in) into lower/upper 32-lane halves:

  • Inline positive integers 129..=192 and 32-bit literals 255 already mapped to 128 (0) in upper(half) (Half::B / Half::BSwap).
  • Inline negative integers 193..=208 (-1..=-16) sign-extend to -1 (0xFFFF_FFFF, code 193) in bits 32..63 (matching halves()), but mask9 previously returned Ok(code) unchanged for 194..=208, clearing bits in lanes 32..35 on the upper half.
  • Added 193..=208 if upper(half) => Ok(193) and unit test fold::tests::mask9_sign_extends_negative_inline_constants_in_upper_half.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): N/A (unit + folded_tests in victory-shader)
  • Before: mask9(194..=208, Half::B | Half::BSwap, ...) returned 194..=208 (-2..=-16) instead of 193 (-1, all 32 upper lanes set).
  • After: mask9(193..=208, Half::B | Half::BSwap, ...) returns 193.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): Wave64 folded to 2x Wave32 (emit::folded_tests + fold::tests)
  • cargo test passed for the crates it touches: yes (cargo test --locked -p victory-shader --lib -- fold::tests emit::folded_tests: 18 passed, 0 failed; cargo xtask policy --staged passed)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5554138388 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2983). Originally posted by [RanoGames](https://github.com/RanoGames) on 2026-11-29T19:12:58Z. --- ## What it changes Fixes `mask9` in `crates/victory-shader/src/fold.rs` when folding 64-lane VALU instructions (such as `v_cndmask_b32` and `*_co_ci_u32` carry-in) into lower/upper 32-lane halves: - Inline positive integers `129..=192` and 32-bit literals `255` already mapped to `128` (`0`) in `upper(half)` (`Half::B` / `Half::BSwap`). - Inline negative integers `193..=208` (`-1..=-16`) sign-extend to `-1` (`0xFFFF_FFFF`, code `193`) in bits `32..63` (matching `halves()`), but `mask9` previously returned `Ok(code)` unchanged for `194..=208`, clearing bits in lanes `32..35` on the upper half. - Added `193..=208 if upper(half) => Ok(193)` and unit test `fold::tests::mask9_sign_extends_negative_inline_constants_in_upper_half`. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): N/A (unit + `folded_tests` in `victory-shader`) - Before: `mask9(194..=208, Half::B | Half::BSwap, ...)` returned `194..=208` (`-2..=-16`) instead of `193` (`-1`, all 32 upper lanes set). - After: `mask9(193..=208, Half::B | Half::BSwap, ...)` returns `193`. - For shader changes, the wave sizes tested (32 and/or 64 lanes): Wave64 folded to 2x Wave32 (`emit::folded_tests` + `fold::tests`) - `cargo test` passed for the crates it touches: yes (`cargo test --locked -p victory-shader --lib -- fold::tests emit::folded_tests`: 18 passed, 0 failed; `cargo xtask policy --staged` passed) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches.
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/2983:upstream-pr/2983'
git switch 'upstream-pr/2983'

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/2983'
git switch 'upstream-pr/2983'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2983'
git switch 'upstream-pr/2983'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2983'
git switch 'main'
git merge --squash 'upstream-pr/2983'
git switch 'main'
git merge --ff-only 'upstream-pr/2983'
git switch 'main'
git merge 'upstream-pr/2983'
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
trustno1-coder/VIctory-NVIDIA!2983
No description provided.