Shaders/Lower: reject unmodeled non-VOP3P modifiers in Lower::packed16 #3030
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3032"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T03:59:50Z.
v_pk_fmac_f16is decoded as VOP2 (0x03C, supporting DPP16/SDWA) and VOP3 (0x13C, not VOP3P), wherev.neg_hiis always0andv.abs,v.opsel, orv.sdwamay be set.Lower::packed16(crates/victory-shader/src/emit/lower.rs:7311-7334) previously checked onlyv.omod != 0 || !float && (v.clamp || v.neg != 0 || v.neg_hi != 0):v.neg != 0on VOP3/DPPv_pk_fmac_f16silently negated only the low f16 half (let neg = if high { v.neg_hi } else { v.neg }withneg_hi == 0).v.abs != 0,v.opsel != 0, orv.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 plainv_pk_fmac_f16(and DPP withoutabs/neg) and all VOP3P modifiers (v_pk_fma_f16etc.) intact. Disjoint from #2229 (DPPself.src0infmac_half). Tests live incrates/victory-shader/src/emit/lower/packed_mod_tests.rs(keepinglower.rsat520,741 B, well under the 512 KiB limit).Verification
packed16_rejects_unmodeled_fmac_and_sdwa_modifiers_while_keeping_valid_opsfailed (VOP3 v_pk_fmac_f16 with neg must be rejected).v_pk_fmac_f16withneg,abs, oropsel, and VOP2 SDWAv_pk_fmac_f16, while plain VOP2/VOP3v_pk_fmac_f16and VOP3Pv_pk_fma_f16(withneg+neg_hi+dxil.dllvalidation) continue passing.--tests+--features diagnosticsclippy,xtask policy, full workspace tests): RVZO6/VIctory CI run #45748741503 (green, combined Wave 10 check on63bcca4).AI-assisted: T3 Code (Antigravity, gemini-4-neon).
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 VOP3v_pk_fmac_f16neg/opselcleanly preserve VOP3Popsel/opsel_hi/neg/neg_hi(crates/victory-shader/src/emit/lower.rsalso stays under the 512 KiB cap at 520,741 bytes), but one unmodeledv_pk_fmac_f16encoding path is still silently miscompiled:v_pk_fmac_f16(crates/victory-shader/src/emit/lower.rs:5818-5828,lower.rs:7275-7295,lower.rs:7313-7319):v_pk_fmac_f16is a VOP2 opcode (0x3C) and supports DPP16/DPP8 (v.dpp.is_some()).Lower::valucomputes the shuffled lane value intoself.src0 = Some(x), then dispatches topacked16->fmac_half. However,fmac_halfcallsself.operand(inst, &op)(lower.rs:7285), which never readsself.src0, and the new guard checksv.sdwa.is_some()without checkingv.dpp.is_some(). As a result, a modifier-freev_pk_fmac_f16_dpp(e.g.,quad_perm:[1,0,3,2]) still lowers without error while silently reading the local lane'ssrc0instead of the shuffled lane. Either rejectv.dpp.is_some()here or consumeself.src0fork == 0infmac_half(note#2229also targets DPP handling forv_pk_fmac_f16).crates/victory-shader/src/emit/lower/packed_mod_tests.rs:96-134):.is_err(), which would also pass on an earlier decode/lowering failure; checking the returnedShaderErrormessage ensures the new modifier guard is what rejected them.neg/neg_hiwithopsel = opsel_hi = 0; adding a case with non-zeroopsel/opsel_hiwould also cover VOP3P half selection.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.
Imported from Marvisak/VIctory. Originally posted by pawrenity on 2026-11-26T05:04:13Z.
VERIFY-3032: verified
f618abcon 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_opspasses. The otherpackedtests pass too, includingvalu_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_zerosandsynthetic_tests::gathers_at_a_level_match_the_hardware. I skippedmemory_tests::heap_direct_texture_reads_mark_their_heap_index(#2571). Theresource_trackingintegration tests pass.Mutation check: I reverted only the
packed16condition 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:negabsopselv_pk_fmac_f16, VOP3 withclamp, VOP3Pv_pk_fma_f16withnegandneg_hiSo 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)
gfx10/fields.rswritesabsandopselonly for VOP3 (VOP3P writesneg_hi/opsel/opsel_hiinstead), and it maps DPP and SDWAneg/absintov.neg/v.abs. Before the fix,packed16appliedv.negto the low half only (neg_hiis 0 outside VOP3P) and ignoredabs,opselandsdwa. VOP3P never setsabsorsdwa, so the newabs/sdwaterms only affect the non-VOP3Pv_pk_fmac_f16forms. Refusing these unmodeled modifiers, instead of guessing their per-half meaning, is the safe choice. No defects found.packed_mod_tests.rsis not rustfmt-clean (2 hunks: comment alignment at :17 and a longexpectline at :99). Main already has many rustfmt diffs elsewhere in the crate.Validator::loadfails, the test silently skips DXIL validation (if let Ok).Overlap
packed16modifier condition.git merge-treeshows a textual conflict inlower.rswith this PR, so whichever lands second needs a rebase.fmac_halfDPP src0) and #2884 (round packed FMA once) both merge cleanly with this PR.AI-assisted (Claude Code).
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:sdwa,abs, andfmac_f16neg/opselmodifiers inLower::packed16(with tests cleanly placed inemit/lower/packed_mod_tests.rsto stay under thelower.rssize 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).
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, andneg/opselon the VOP2/VOP3 encodings ofv_pk_fmac_f16. Before this change,negthere negated only the low half, becauseneg_hiis 0 outside VOP3P, andabs,opseland SDWA were ignored. I checked against the decoder (gfx10/fields.rs):absis set only for VOP3/DPP/SDWA, never for VOP3P, andfmac_f16is never VOP3P. So the existing VOP3P modifier handling (v_pk_fma_f16withneg/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:
checkpassing.Generated by Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.