Shaders/Lower: reject unmodeled non-VOP3P modifiers in Lower::packed16 #3030

Open
RVZO6 wants to merge 1 commit from upstream-pr/3032 into main
RVZO6 commented 2026-11-26 03:59:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T03:59:50Z.


v_pk_fmac_f16 is decoded as VOP2 (0x03C, supporting DPP16/SDWA) and VOP3 (0x13C, not VOP3P), where v.neg_hi is always 0 and v.abs, v.opsel, or v.sdwa may be set.

Lower::packed16 (crates/victory-shader/src/emit/lower.rs:7311-7334) previously checked only v.omod != 0 || !float && (v.clamp || v.neg != 0 || v.neg_hi != 0):

  • Setting v.neg != 0 on VOP3/DPP v_pk_fmac_f16 silently negated only the low f16 half (let neg = if high { v.neg_hi } else { v.neg } with neg_hi == 0).
  • Setting v.abs != 0, v.opsel != 0, or v.sdwa.is_some() was silently ignored.

Fail closed on v.sdwa.is_some() || v.abs != 0 || (op == "fmac_f16" && (v.neg != 0 || v.opsel != 0)) while keeping plain v_pk_fmac_f16 (and DPP without abs/neg) and all VOP3P modifiers (v_pk_fma_f16 etc.) intact. Disjoint from #2229 (DPP self.src0 in fmac_half). Tests live in crates/victory-shader/src/emit/lower/packed_mod_tests.rs (keeping lower.rs at 520,741 B, well under the 512 KiB limit).

Verification

  • Negative control (before fix): packed16_rejects_unmodeled_fmac_and_sdwa_modifiers_while_keeping_valid_ops failed (VOP3 v_pk_fmac_f16 with neg must be rejected).
  • After fix: rejects VOP3 v_pk_fmac_f16 with neg, abs, or opsel, and VOP2 SDWA v_pk_fmac_f16, while plain VOP2/VOP3 v_pk_fmac_f16 and VOP3P v_pk_fma_f16 (with neg + neg_hi + dxil.dll validation) continue passing.
  • Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, default + --tests + --features diagnostics clippy, xtask policy, full workspace tests): RVZO6/VIctory CI run #45748741503 (green, combined Wave 10 check on 63bcca4).
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6619197457 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3032). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-26T03:59:50Z. --- `v_pk_fmac_f16` is decoded as VOP2 (`0x03C`, supporting DPP16/SDWA) and VOP3 (`0x13C`, not VOP3P), where `v.neg_hi` is always `0` and `v.abs`, `v.opsel`, or `v.sdwa` may be set. `Lower::packed16` (`crates/victory-shader/src/emit/lower.rs:7311-7334`) previously checked only `v.omod != 0 || !float && (v.clamp || v.neg != 0 || v.neg_hi != 0)`: - Setting `v.neg != 0` on VOP3/DPP `v_pk_fmac_f16` silently negated **only the low f16 half** (`let neg = if high { v.neg_hi } else { v.neg }` with `neg_hi == 0`). - Setting `v.abs != 0`, `v.opsel != 0`, or `v.sdwa.is_some()` was silently ignored. Fail closed on `v.sdwa.is_some() || v.abs != 0 || (op == "fmac_f16" && (v.neg != 0 || v.opsel != 0))` while keeping plain `v_pk_fmac_f16` (and DPP without `abs`/`neg`) and all VOP3P modifiers (`v_pk_fma_f16` etc.) intact. Disjoint from #2229 (DPP `self.src0` in `fmac_half`). Tests live in `crates/victory-shader/src/emit/lower/packed_mod_tests.rs` (keeping `lower.rs` at `520,741 B`, well under the 512 KiB limit). ### Verification - **Negative control (before fix):** `packed16_rejects_unmodeled_fmac_and_sdwa_modifiers_while_keeping_valid_ops` failed (`VOP3 v_pk_fmac_f16 with neg must be rejected`). - **After fix:** rejects VOP3 `v_pk_fmac_f16` with `neg`, `abs`, or `opsel`, and VOP2 SDWA `v_pk_fmac_f16`, while plain VOP2/VOP3 `v_pk_fmac_f16` and VOP3P `v_pk_fma_f16` (with `neg` + `neg_hi` + `dxil.dll` validation) continue passing. - Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, default + `--tests` + `--features diagnostics` clippy, `xtask policy`, full workspace tests): [RVZO6/VIctory CI run #45748741503](https://github.com/RVZO6/VIctory/actions/runs/45748741503) (green, combined Wave 10 check on `63bcca4`). - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon).
fuzeofficlal commented 2026-11-26 05:03:57 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


The new guards on v.omod, v.sdwa, v.abs, and VOP3 v_pk_fmac_f16 neg/opsel cleanly preserve VOP3P opsel/opsel_hi/neg/neg_hi (crates/victory-shader/src/emit/lower.rs also stays under the 512 KiB cap at 520,741 bytes), but one unmodeled v_pk_fmac_f16 encoding path is still silently miscompiled:

  1. Unmodeled DPP on v_pk_fmac_f16 (crates/victory-shader/src/emit/lower.rs:5818-5828, lower.rs:7275-7295, lower.rs:7313-7319):
    v_pk_fmac_f16 is a VOP2 opcode (0x3C) and supports DPP16/DPP8 (v.dpp.is_some()). Lower::valu computes the shuffled lane value into self.src0 = Some(x), then dispatches to packed16 -> fmac_half. However, fmac_half calls self.operand(inst, &op) (lower.rs:7285), which never reads self.src0, and the new guard checks v.sdwa.is_some() without checking v.dpp.is_some(). As a result, a modifier-free v_pk_fmac_f16_dpp (e.g., quad_perm:[1,0,3,2]) still lowers without error while silently reading the local lane's src0 instead of the shuffled lane. Either reject v.dpp.is_some() here or consume self.src0 for k == 0 in fmac_half (note #2229 also targets DPP handling for v_pk_fmac_f16).
  2. Test assertions (crates/victory-shader/src/emit/lower/packed_mod_tests.rs:96-134):
    • The negative cases only assert .is_err(), which would also pass on an earlier decode/lowering failure; checking the returned ShaderError message ensures the new modifier guard is what rejected them.
    • The positive VOP3P control tests neg/neg_hi with opsel = opsel_hi = 0; adding a case with non-zero opsel/opsel_hi would also cover VOP3P half selection.
<!-- greyfinch-sync:Marvisak/VIctory:review:6068446528 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3032#pullrequestreview-6068446528). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T04:11:56Z. **Review:** CHANGES_REQUESTED --- The new guards on `v.omod`, `v.sdwa`, `v.abs`, and VOP3 `v_pk_fmac_f16` `neg`/`opsel` cleanly preserve VOP3P `opsel`/`opsel_hi`/`neg`/`neg_hi` (`crates/victory-shader/src/emit/lower.rs` also stays under the 512 KiB cap at 520,741 bytes), but one unmodeled `v_pk_fmac_f16` encoding path is still silently miscompiled: 1. **Unmodeled DPP on `v_pk_fmac_f16`** (`crates/victory-shader/src/emit/lower.rs:5818-5828`, `lower.rs:7275-7295`, `lower.rs:7313-7319`): `v_pk_fmac_f16` is a VOP2 opcode (`0x3C`) and supports DPP16/DPP8 (`v.dpp.is_some()`). `Lower::valu` computes the shuffled lane value into `self.src0 = Some(x)`, then dispatches to `packed16` -> `fmac_half`. However, `fmac_half` calls `self.operand(inst, &op)` (`lower.rs:7285`), which never reads `self.src0`, and the new guard checks `v.sdwa.is_some()` without checking `v.dpp.is_some()`. As a result, a modifier-free `v_pk_fmac_f16_dpp` (e.g., `quad_perm:[1,0,3,2]`) still lowers without error while silently reading the local lane's `src0` instead of the shuffled lane. Either reject `v.dpp.is_some()` here or consume `self.src0` for `k == 0` in `fmac_half` (note `#2229` also targets DPP handling for `v_pk_fmac_f16`). 2. **Test assertions (`crates/victory-shader/src/emit/lower/packed_mod_tests.rs:96-134`)**: - The negative cases only assert `.is_err()`, which would also pass on an earlier decode/lowering failure; checking the returned `ShaderError` message ensures the new modifier guard is what rejected them. - The positive VOP3P control tests `neg`/`neg_hi` with `opsel = opsel_hi = 0`; adding a case with non-zero `opsel`/`opsel_hi` would also cover VOP3P half selection.
kotekompotek commented 2026-11-26 05:03:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T04:40:51Z.

Review: APPROVED


LGTM — fails closed on sdwa/abs/fmac-neg-opsel instead of silently mis-lowering (neg on v_pk_fmac_f16 would only negate the low half); accepted plain and VOP3P forms still pass.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068636752 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3032#pullrequestreview-6068636752). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T04:40:51Z. **Review:** APPROVED --- LGTM — fails closed on sdwa/abs/fmac-neg-opsel instead of silently mis-lowering (neg on v_pk_fmac_f16 would only negate the low half); accepted plain and VOP3P forms still pass.
pawrenity commented 2026-11-26 05:04:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pawrenity on 2026-11-26T05:04:13Z.


VERIFY-3032: verified f618abc on NVIDIA GeForce RTX 4070, Windows 11 (MSVC toolchain, dxil.dll validator loaded).

Tests

  • The new test packed_mod_tests::packed16_rejects_unmodeled_fmac_and_sdwa_modifiers_while_keeping_valid_ops passes. The other packed tests pass too, including valu_tests::packed_fmac_accumulates_each_half.

  • Full cargo test --locked -p victory-shader: 299 passed and 3 failed. All 3 failures are known on main on this card: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros and synthetic_tests::gathers_at_a_level_match_the_hardware. I skipped memory_tests::heap_direct_texture_reads_mark_their_heap_index (#2571). The resource_tracking integration tests pass.

  • Mutation check: I reverted only the packed16 condition to origin/main and kept the test. The test then fails with "VOP3 v_pk_fmac_f16 with neg must be rejected".

  • The new test only asserts is_err(), so I added a temporary probe that runs each case on its own:

    Case With the fix Condition reverted
    VOP3 neg rejected ("modifiers on a packed 16-bit operation") lowered
    VOP3 abs rejected (same error) lowered
    VOP3 opsel rejected (same error) lowered
    VOP2 SDWA rejected (same error) lowered
    Plain VOP2 and VOP3 v_pk_fmac_f16, VOP3 with clamp, VOP3P v_pk_fma_f16 with neg and neg_hi lowered, passes dxil.dll validation not checked

    So each negative assertion fails for the intended reason, not for some unrelated lowering error.

  • cargo clippy --locked -p victory-shader --all-targets [--features diagnostics] -- -D warnings: clean. cargo xtask policy: ok.

  • Trial merge onto current origin/main (63bcca4): clean. The PR is based on it.

Review (from reading the code only)

  • The decoder backs the PR's premise. gfx10/fields.rs writes abs and opsel only for VOP3 (VOP3P writes neg_hi/opsel/opsel_hi instead), and it maps DPP and SDWA neg/abs into v.neg/v.abs. Before the fix, packed16 applied v.neg to the low half only (neg_hi is 0 outside VOP3P) and ignored abs, opsel and sdwa. VOP3P never sets abs or sdwa, so the new abs/sdwa terms only affect the non-VOP3P v_pk_fmac_f16 forms. Refusing these unmodeled modifiers, instead of guessing their per-half meaning, is the safe choice. No defects found.
  • Nit: the new packed_mod_tests.rs is not rustfmt-clean (2 hunks: comment alignment at :17 and a long expect line at :99). Main already has many rustfmt diffs elsewhere in the crate.
  • Nit: if Validator::load fails, the test silently skips DXIL validation (if let Ok).

Overlap

  • #1142 (saturating clamp on packed integer ops) edits the same packed16 modifier condition. git merge-tree shows a textual conflict in lower.rs with this PR, so whichever lands second needs a rebase.
  • #2229 (fmac_half DPP src0) and #2884 (round packed FMA once) both merge cleanly with this PR.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183152686 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3032#issuecomment-7183152686). Originally posted by [pawrenity](https://github.com/pawrenity) on 2026-11-26T05:04:13Z. --- VERIFY-3032: verified `f618abc` on NVIDIA GeForce RTX 4070, Windows 11 (MSVC toolchain, dxil.dll validator loaded). **Tests** - The new test `packed_mod_tests::packed16_rejects_unmodeled_fmac_and_sdwa_modifiers_while_keeping_valid_ops` passes. The other `packed` tests pass too, including `valu_tests::packed_fmac_accumulates_each_half`. - Full `cargo test --locked -p victory-shader`: 299 passed and 3 failed. All 3 failures are known on main on this card: `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` and `synthetic_tests::gathers_at_a_level_match_the_hardware`. I skipped `memory_tests::heap_direct_texture_reads_mark_their_heap_index` (#2571). The `resource_tracking` integration tests pass. - Mutation check: I reverted only the `packed16` condition to origin/main and kept the test. The test then fails with "VOP3 v_pk_fmac_f16 with neg must be rejected". - The new test only asserts `is_err()`, so I added a temporary probe that runs each case on its own: | Case | With the fix | Condition reverted | |---|---|---| | VOP3 `neg` | rejected ("modifiers on a packed 16-bit operation") | lowered | | VOP3 `abs` | rejected (same error) | lowered | | VOP3 `opsel` | rejected (same error) | lowered | | VOP2 SDWA | rejected (same error) | lowered | | Plain VOP2 and VOP3 `v_pk_fmac_f16`, VOP3 with `clamp`, VOP3P `v_pk_fma_f16` with `neg` and `neg_hi` | lowered, passes dxil.dll validation | not checked | So each negative assertion fails for the intended reason, not for some unrelated lowering error. - `cargo clippy --locked -p victory-shader --all-targets [--features diagnostics] -- -D warnings`: clean. `cargo xtask policy`: ok. - Trial merge onto current origin/main (`63bcca4`): clean. The PR is based on it. **Review (from reading the code only)** - The decoder backs the PR's premise. `gfx10/fields.rs` writes `abs` and `opsel` only for VOP3 (VOP3P writes `neg_hi`/`opsel`/`opsel_hi` instead), and it maps DPP and SDWA `neg`/`abs` into `v.neg`/`v.abs`. Before the fix, `packed16` applied `v.neg` to the low half only (`neg_hi` is 0 outside VOP3P) and ignored `abs`, `opsel` and `sdwa`. VOP3P never sets `abs` or `sdwa`, so the new `abs`/`sdwa` terms only affect the non-VOP3P `v_pk_fmac_f16` forms. Refusing these unmodeled modifiers, instead of guessing their per-half meaning, is the safe choice. No defects found. - Nit: the new `packed_mod_tests.rs` is not rustfmt-clean (2 hunks: comment alignment at :17 and a long `expect` line at :99). Main already has many rustfmt diffs elsewhere in the crate. - Nit: if `Validator::load` fails, the test silently skips DXIL validation (`if let Ok`). **Overlap** - #1142 (saturating clamp on packed integer ops) edits the same `packed16` modifier condition. `git merge-tree` shows a textual conflict in `lower.rs` with this PR, so whichever lands second needs a rebase. - #2229 (`fmac_half` DPP src0) and #2884 (round packed FMA once) both merge cleanly with this PR. AI-assisted (Claude Code).
Dukestar69 commented 2026-11-26 07:01:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:49:25Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64:

  • Diff review: Rejecting unmodeled sdwa, abs, and fmac_f16 neg/opsel modifiers in Lower::packed16 (with tests cleanly placed in emit/lower/packed_mod_tests.rs to stay under the lower.rs size limit) prevents silent mislowering of non-VOP3P modifiers.
  • cargo test -p victory-shader packed_mod_tests: all tests passed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6069681509 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3032#pullrequestreview-6069681509). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T06:49:25Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - Diff review: Rejecting unmodeled `sdwa`, `abs`, and `fmac_f16` `neg`/`opsel` modifiers in `Lower::packed16` (with tests cleanly placed in `emit/lower/packed_mod_tests.rs` to stay under the `lower.rs` size limit) prevents silent mislowering of non-VOP3P modifiers. - `cargo test -p victory-shader packed_mod_tests`: all tests passed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Marvisak commented 2026-11-26 07:01:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:18:03Z.


Automated triage for the maintainers.

Lower::packed16 (crates/victory-shader/src/emit/lower.rs) now refuses modifiers it does not model, instead of silently mis-lowering them. These are SDWA, abs, and neg/opsel on the VOP2/VOP3 encodings of v_pk_fmac_f16. Before this change, neg there negated only the low half, because neg_hi is 0 outside VOP3P, and abs, opsel and SDWA were ignored. I checked against the decoder (gfx10/fields.rs): abs is set only for VOP3/DPP/SDWA, never for VOP3P, and fmac_f16 is never VOP3P. So the existing VOP3P modifier handling (v_pk_fma_f16 with neg/neg_hi/opsel) is unaffected. The PR does not claim any new semantics; it fails closed, which is the crate's usual way of handling an unmodelled case.

Things to know before merging: a title shader that does use one of these forms will now fail to translate instead of being approximated. #1142 edits the same condition and will conflict textually. The new test module is not rustfmt-clean.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184293158 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3032#issuecomment-7184293158). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:18:03Z. --- <!-- victory-triage v1 head=f618abcd5e8a8b84344627efdfce2acc094c127b verdict=merge-candidate at=2026-11-26T06:23:00Z --> Automated triage for the maintainers. `Lower::packed16` (`crates/victory-shader/src/emit/lower.rs`) now refuses modifiers it does not model, instead of silently mis-lowering them. These are SDWA, `abs`, and `neg`/`opsel` on the VOP2/VOP3 encodings of `v_pk_fmac_f16`. Before this change, `neg` there negated only the low half, because `neg_hi` is 0 outside VOP3P, and `abs`, `opsel` and SDWA were ignored. I checked against the decoder (`gfx10/fields.rs`): `abs` is set only for VOP3/DPP/SDWA, never for VOP3P, and `fmac_f16` is never VOP3P. So the existing VOP3P modifier handling (`v_pk_fma_f16` with `neg`/`neg_hi`/`opsel`) is unaffected. The PR does not claim any new semantics; it fails closed, which is the crate's usual way of handling an unmodelled case. Things to know before merging: a title shader that does use one of these forms will now fail to translate instead of being approximated. #1142 edits the same condition and will conflict textually. The new test module is not rustfmt-clean. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
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/3032:upstream-pr/3032'
git switch 'upstream-pr/3032'

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