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

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

@⁠RVZO6 on GitHub · 2026-11-26 03:59 UTC · original
RVZO6:rvzo/packed16-modifiers-guard → main · +144 −2 · 2 files · 1 commits · open

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).

**@⁠RVZO6** on GitHub · 2026-11-26 03:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/3032) `RVZO6:rvzo/packed16-modifiers-guard` → `main` · +144 −2 · 2 files · 1 commits · open `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).
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`/
`v.sdwa` may be set. Lower::packed16 previously never checked `v.sdwa`,
`v.abs`, or `v_pk_fmac_f16`'s `v.neg`/`v.opsel`, so:
- `v.neg != 0` on v_pk_fmac_f16 negated only the low f16 half (`neg_hi == 0`).
- `v.abs`, `v.sdwa`, and `v.opsel` on v_pk_fmac_f16 were 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
`emit/lower/packed_mod_tests.rs`.

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:27:00 +00:00
Author
Owner

@⁠pawrenity on GitHub · 2026-11-26 05:04 UTC · original

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).

**@⁠pawrenity** on GitHub · 2026-11-26 05:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/3032#issuecomment-7183152686) 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 06:18 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-26 06:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/3032#issuecomment-7184293158) <!-- 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 can be merged automatically.
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/3032/head:github-bot/gh-3032'
git switch 'github-bot/gh-3032'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3032'
git switch 'github-bot/gh-3032'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3032'
git switch 'github-bot/gh-3032'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3032'
git switch 'main'
git merge --squash 'github-bot/gh-3032'
git switch 'main'
git merge --ff-only 'github-bot/gh-3032'
git switch 'main'
git merge 'github-bot/gh-3032'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3032
No description provided.