fix(shader): decode scalar NULL operand as Bool::FALSE in lane mask analysis #3369

Open
reeledMarek wants to merge 1 commit from upstream-pr/3369 into main
reeledMarek commented 2026-11-26 20:40:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T20:40:30Z.


Summary

  • Lanes::operand guarded scalar operands with if code != NULL, letting scalar NULL (code 125, which always reads as 0) fall through to _ => return None.
  • Scalar lane-mask instructions reading null (such as s_and_saveexec_b32 s0, null or s_mov_b32 exec_lo, null) therefore failed in Lanes::sop, turning EXEC and saved masks into Atom::Opaque instead of Bool::FALSE.
  • Decodes Operand::Scalar { code: NULL, .. } as (Bool::FALSE, false) in Lanes::operand, matching wave.rs and resource.rs.
  • Adds regression test null_scalar_operand_is_zero_mask.

Verification

  • Executed null_scalar_operand_is_zero_mask directly against victory-shader on Linux
  • cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings
  • cargo test -p xtask --locked
<!-- greyfinch-sync:Marvisak/VIctory:issue:5516862011 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3369). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T20:40:30Z. --- ### Summary - `Lanes::operand` guarded scalar operands with `if code != NULL`, letting scalar `NULL` (code 125, which always reads as 0) fall through to `_ => return None`. - Scalar lane-mask instructions reading `null` (such as `s_and_saveexec_b32 s0, null` or `s_mov_b32 exec_lo, null`) therefore failed in `Lanes::sop`, turning `EXEC` and saved masks into `Atom::Opaque` instead of `Bool::FALSE`. - Decodes `Operand::Scalar { code: NULL, .. }` as `(Bool::FALSE, false)` in `Lanes::operand`, matching `wave.rs` and `resource.rs`. - Adds regression test `null_scalar_operand_is_zero_mask`. ### Verification - Executed `null_scalar_operand_is_zero_mask` directly against `victory-shader` on Linux - `cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` - `cargo test -p xtask --locked`
Dukestar69 commented 2026-11-26 20:48:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T20:48:55Z.

Review: APPROVED


LGTM — verified on Windows against origin/main (63bcca4).

  • Decoding Operand::Scalar { code: NULL, .. } as (Bool::FALSE, false) in Lanes::operand accurately reflects that NULL reads as 0 and keeps EXEC tracking precise instead of turning it opaque.
  • cargo test -p victory-shader --lib structure:: -- --test-threads=1: 14 passed, 0 failed (1 ignored; including null_scalar_operand_is_zero_mask).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6080343191 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3369#pullrequestreview-6080343191). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T20:48:55Z. **Review:** APPROVED --- LGTM — verified on Windows against `origin/main` (`63bcca4`). - Decoding `Operand::Scalar { code: NULL, .. }` as `(Bool::FALSE, false)` in `Lanes::operand` accurately reflects that `NULL` reads as 0 and keeps `EXEC` tracking precise instead of turning it opaque. - `cargo test -p victory-shader --lib structure:: -- --test-threads=1`: 14 passed, 0 failed (1 ignored; including `null_scalar_operand_is_zero_mask`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 20:54:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T20:54:54Z.

Review: APPROVED


LGTM — decoding Operand::Scalar { code: NULL, .. } as (Bool::FALSE, false) in Lanes::operand matches RDNA2 (NULL always reads 0) across both wave32 and wave64, aligning structure.rs with wave.rs and resource.rs.

Verified

  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --all-features): clean.
  • rustfmt --edition 2024: clean on all PR-touched hunks in crates/victory-shader/src/structure.rs.
  • cargo test --locked -p victory-shader --lib -- --test-threads=1 structure:: resource:: ir::: 58 passed, 0 failed, 1 ignored (including null_scalar_operand_is_zero_mask).

Non-blocking downstream notes

  • In structure.rs:1107-1114, "wqm" builds a | Atom::Quad(lo). With null now decoding to Bool::FALSE, s_wqm_b32 exec_lo, null produces Quad, which emit/lower.rs:2592 unconditionally lowers to true (same pre-existing behavior as inline 0; folding a == Bool::FALSE in "wqm" to (Bool::FALSE, Some(Bool::FALSE)) would avoid this).
  • s_cmp_eq/lg with null (structure.rs:1208) inherits the existing per-lane mask comparison behavior used for inline 0; float inline constants (240..=248) remain unresolved in Lanes::operand, and the new test covers wave32 only.
<!-- greyfinch-sync:Marvisak/VIctory:review:6080387263 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3369#pullrequestreview-6080387263). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T20:54:54Z. **Review:** APPROVED --- LGTM — decoding `Operand::Scalar { code: NULL, .. }` as `(Bool::FALSE, false)` in `Lanes::operand` matches RDNA2 (`NULL` always reads 0) across both wave32 and wave64, aligning `structure.rs` with `wave.rs` and `resource.rs`. ### Verified - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--all-features`): clean. - `rustfmt --edition 2024`: clean on all PR-touched hunks in `crates/victory-shader/src/structure.rs`. - `cargo test --locked -p victory-shader --lib -- --test-threads=1 structure:: resource:: ir::`: **58 passed, 0 failed, 1 ignored** (including `null_scalar_operand_is_zero_mask`). ### Non-blocking downstream notes - In `structure.rs:1107-1114`, `"wqm"` builds `a | Atom::Quad(lo)`. With `null` now decoding to `Bool::FALSE`, `s_wqm_b32 exec_lo, null` produces `Quad`, which `emit/lower.rs:2592` unconditionally lowers to `true` (same pre-existing behavior as inline `0`; folding `a == Bool::FALSE` in `"wqm"` to `(Bool::FALSE, Some(Bool::FALSE))` would avoid this). - `s_cmp_eq/lg` with `null` (`structure.rs:1208`) inherits the existing per-lane mask comparison behavior used for inline `0`; float inline constants (`240..=248`) remain unresolved in `Lanes::operand`, and the new test covers wave32 only.
Jackster commented 2026-11-26 22:29:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:29:05Z.


Windows 11, 63bcca4 + this PR:

  • structure::tests::null_scalar_operand_is_zero_mask by name: 1 passed.
  • cargo test -p victory-shader --lib structure::: green.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

The program is s_and_saveexec_b32 s0, null followed by a restore from s0; the new arm decodes the NULL scalar as Bool::FALSE rather than falling through to the mask lookup, so the guard comes out Some(Bool::FALSE) instead of opaque. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204719002 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3369#issuecomment-7204719002). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T22:29:05Z. --- Windows 11, `63bcca4` + this PR: - `structure::tests::null_scalar_operand_is_zero_mask` by name: 1 passed. - `cargo test -p victory-shader --lib structure::`: green. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. The program is `s_and_saveexec_b32 s0, null` followed by a restore from `s0`; the new arm decodes the NULL scalar as `Bool::FALSE` rather than falling through to the mask lookup, so the guard comes out `Some(Bool::FALSE)` instead of opaque. Synthetic only. AI-assisted.
cloph-dsp commented 2026-11-27 01:23:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T01:23:17Z.


Independent local verification of PR #3369 (head 9ff1d512c446acf1c861708c4d0285a4519dc3e2), Windows / Rust 1.100.0 / MSVC, worktree-local CARGO_TARGET_DIR, CARGO_BUILD_JOBS=2, synthetic source only, no game data.

Command:
cargo test --locked -p victory-shader --lib -- structure::tests::null_scalar_operand_is_zero_mask --exact --test-threads=1 --quiet

Result: running 1 test, test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 305 filtered out.

git diff --check 63bcca43c6a00a758510398fa43096ce7e4f7df0 HEAD (the real merge base) exits 0. The new test name is absent from origin/main (git grep found 0 hits), confirming the test is added by this PR. Against current origin/main an unrelated trailing blank line in crates/victory-formats/src/xma/tables.rs pollutes diff --check, so the merge base was used.

Only the named test was run; the full crate suite was not exercised. GPU/driver: N/A (CPU-only lane-mask analysis). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM were used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7207246273 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3369#issuecomment-7207246273). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-27T01:23:17Z. --- Independent local verification of PR #3369 (head `9ff1d512c446acf1c861708c4d0285a4519dc3e2`), Windows / Rust 1.100.0 / MSVC, worktree-local `CARGO_TARGET_DIR`, `CARGO_BUILD_JOBS=2`, synthetic source only, no game data. Command: `cargo test --locked -p victory-shader --lib -- structure::tests::null_scalar_operand_is_zero_mask --exact --test-threads=1 --quiet` Result: `running 1 test`, `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 305 filtered out`. `git diff --check 63bcca43c6a00a758510398fa43096ce7e4f7df0 HEAD` (the real merge base) exits 0. The new test name is absent from `origin/main` (`git grep` found 0 hits), confirming the test is added by this PR. Against current `origin/main` an unrelated trailing blank line in `crates/victory-formats/src/xma/tables.rs` pollutes `diff --check`, so the merge base was used. Only the named test was run; the full crate suite was not exercised. GPU/driver: N/A (CPU-only lane-mask analysis). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM were used.
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/3369:upstream-pr/3369'
git switch 'upstream-pr/3369'

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