shader: lower remaining packed dot products and clamped integer forms #2200
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2202"
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 UnkwnDev on 2026-11-25T07:44:43Z.
Split out from #740 per triage feedback against current
main(940d32f).mainalready lowersv_dot4_i32_i8(withopsel/opsel_hi) and unclampedv_dot4c_i32_i8to DXILdot4AddPacked.i32. This PR adds the remaining dot-product lowering and saturation forms:v_dot4_u32_u8: lowers through the sameopsel/opsel_hihalf-selection helper todot4AddPacked.i32(DXIL opcode 164,Dot4AddU8Packed), with overflow-safeselect(sum < acc, u32::MAX, sum)whenv.clampis set.v.clampsaturation onv_dot4_i32_i8andv_dot4c_i32_i8: emitsdot4AddPacked.i32(0, a, b)(bounded within[-65024, +65536]) and saturatesdot + accin 64-bit arithmetic before truncating toi32.v_dot2_f32_f16andv_dot2c_f32_f16: converts operands vialegacyF16ToF32(handling both VOP3Popsel/opsel_hi+neg_hiand VOP2[15:0]/[31:16]slicing) and chainsfmad(tertiary.f32) matching RDNA2 rounding, usingwrite_fforv.clamp/v.omod.v_dot2_i32_i16andv_dot2_u32_u16: extracts halves viapacked_srcwith 64-bit clamping whenv.clampis set.v_dot8_u32_u4: unpacks and accumulates 8 nibble products with wrapping saturation whenv.clampis set.emit::valu_tests::packed_dot_products_and_clamps_execute_cleanlyincrates/victory-shader/src/emit/valu_tests.rs.Testing
cargo test -p victory-shader --locked packed_dot_products_and_clamps_execute_cleanly -- --test-threads=1: 1 passed, 0 failed.cargo test -p victory-shader --locked -- --test-threads=1: 244 passed, 4 failed, 3 ignored. All 4 failures are pre-existing baseline failures on this adapter (stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware,valu_tests::fspx_programs_run_with_the_hardwares_dot_productswhich also fails identically onmain940d32f, andvalu_tests::image_atomics_of_64_bits).cargo clippy -p victory-shader --all-targets --lockedand--all-features: clean on all modified code (1 pre-existingneedless_range_loopwarning atlower.rs:1009).cargo test -p xtask --locked: 6 passed, 0 failed (repository_passes_policy).AI use
mainand verifying hardware/WARP execution tests.Closes part of #740.
Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-25T07:57:58Z.
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head
cecd8e77intomain940d32fin a throwaway tree (no conflict).cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with--all-features: clean.cargo test --workspace --locked: 702 passed, 0 failed, 10 ignored, two runs (mainalone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.AI-assisted (Claude Code); no game data.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:10:11Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed / 2 ignored. Remaining packed dot products and clamped integers lowered — packed-op lowering completeness.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T09:23:40Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, withdxil.dllvalidator):cargo test -p victory-shader --lib packed_dot_products_and_clamps_execute_cleanly— passed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean lowering of remaining packed dot products and clamped integer forms, verified end-to-end on hardware and WARP. Looks good.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T10:57:28Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
cecd8e77ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:28:39Z.
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main(conflicts incrates/victory-shader/src/emit/bitcode.rsandemit/valu_tests.rs). It will be reviewed again once it is rebased.From the earlier needs-work note, still open: a source or a distinguishing test for fused rounding in
v_dot2_f32_f16, splitting the Intel Arc workaround into its own PR with a repro, and a green CI.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by UnkwnDev on 2026-11-25T15:35:52Z.
Updated in
cf43fda230c8to address the review points and add edge-case assertions:RDNA2 ISA semantics and comments:
V_DOT2_F32_F16/V_DOT2C_F32_F16: per the AMD RDNA2 Instruction Set Architecture manual (VOP3P / VOP2 dot-product definitions), each packed f16 input pair (including denormals) is converted to f32 without precision loss, then accumulated with two chained f32 fused multiply-adds (fma(a0, b0, c)followed byfma(a1, b1, inner)). In DXIL,legacyF16ToF32decodes f16 including subnormals (whereas SM 6.4f16arithmetic may flush),fmadsupplies the fused rounding, andwrite_fappliesv.clamp(saturate to[0.0, 1.0]) andv.omod.neg/neg_hihandling: VOP2 encoding (0x02) has noneg/absmodifiers; VOP3v_dot2c_f32_f16carries operand-widev.negapplied to both halves ofsrc0orsrc1(if !is_vop3p); VOP3Pv_dot2_f32_f16splits low/high halves acrossv.neg/v.neg_hi. Also fixed a double-negation bug onv_dot2_f32_f16wherefsrcalready appliedv.neg[2]before an unconditional extra negation indot_productcancelled it out; explicitv.neg >> 2negation is now restricted tov_dot2c_f32_f16.clamp=1saturates signed results to[i32::MIN, i32::MAX]via 64-bit bounds clamping (sat_64/sat_i32_add) and unsigned results tou32::MAX(sat_u32_add, since max unsigned 4x8 / 8x4 dot products stay below 260,101 and overflow iffsum < acc).Constant dot4 expansion for Intel Arc IGC:
Module::eval_u32andLower::dot4_packed/Lower::dot4_constsov_dot4_i32_i8,v_dot4_u32_u8, andv_dot4c_i32_i8expand constant multiplicands in scalar arithmetic instead of emittingdx.op.dot4AddPackedwith a constant operand, avoiding Intel Arc IGC's 16-bit constant broadcast miscompilation.Expanded
packed_dot_products_and_clamps_execute_cleanlyassertions:i32::MIN/i32::MAXsaturation onv_dot2_i32_i16,u32::MAXsaturation onv_dot2_u32_u16andv_dot8_u32_u4, negated accumulator and low-half operands onv_dot2_f32_f16(2.0and-4.0), f16 denormals (0x0001,0x03FF), and constant dot4 multiplicands acrossv_dot4_i32_i8,v_dot4_u32_u8, andv_dot4c_i32_i8.Verified after the final edit:
cargo test -p victory-shader --locked packed_dot_products_and_clamps_execute_cleanly -- --nocapture --test-threads=1: passed (Arc A770 hardware + WARP).cargo test -p victory-shader --locked fspx_programs_run_with_the_hardwares_dot_products -- --nocapture --test-threads=1: passed (Arc A770 hardware + WARP).cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (exit 0).cargo test -p xtask --locked: 6 passed, 0 failed.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.