Skip to content

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

Open
RVZO6 wants to merge 1 commit into
Marvisak:mainfrom
RVZO6:rvzo/packed16-modifiers-guard
Open

RVZO6 wants to merge 1 commit into
Marvisak:mainfrom
RVZO6:rvzo/packed16-modifiers-guard

Conversation

@RVZO6

@RVZO6 RVZO6 commented Nov 26, 2026

Copy link
Copy Markdown

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

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 Marvisak#2229 (DPP `self.src0` in `fmac_half`). Tests live in
`emit/lower/packed_mod_tests.rs`.

Assisted-by: T3 Code (Antigravity, gemini-4-neon)

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

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 (Shader tests: heap_direct_texture_reads_mark_their_heap_index kills the test process on a real GPU (RTX 5070, main 67e8ae1) #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

AI-assisted (Claude Code).

Copy link
Copy Markdown
Owner

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

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants