shader: lower packed dot products to DXIL dot4AddPacked and fmad #807
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/808"
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 fxceless/victory-fork. Originally posted by UnkwnDev on 2026-11-25T08:22:51Z.
Adds hardware-accelerated packed dot-product lowering to
victory-shader(crates/victory-shader/src/emit/dot.rs, hooked intolower.rs):v_dot4_i32_i8,v_dot4c_i32_i8, andv_dot4_u32_u8directly to SM 6.4@dx.op.dot4AddPacked.i32(opcodes 163 / 164), supportingop_sel/op_sel_hihalf-selection onv_dot4_i32_i8/v_dot4_u32_u8andv.clampsaturation.v_dot2_f32_f16andv_dot2c_f32_f16vialegacyF16ToF32and chained fused multiply-adds (fmad/tertiary.f32) matching RDNA2 rounding, honoring both VOP3P (opsel/opsel_hi/neg_hi) and VOP2 encodings plusv.clamp/v.omod.v_dot2_i32_i16,v_dot2_u32_u16(viapacked_srcwithopsel/opsel_hi), andv_dot8_u32_u4, with exact saturation whenv.clampis set.emit::valu_tests::packed_dot_products_and_clamps_execute_cleanlycovering all instructions, modifiers, and saturating clamps on both hardware GPU and WARP.Testing
cargo clippy -p victory-shader --all-targets --locked -- -D warnings: passedcargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: passedcargo test -p victory-shader --locked packed_dot_products_and_clamps_execute_cleanly -- --test-threads=1: 1 passed, 0 failedcargo test -p xtask --locked: 4 passed, 0 failed (repository_passes_policy)victory-gpu144 passed / 0 failed / 3 ignored;victory-shader214 passed / 1 failed (whole_wave_f64_sum_and_cvt_f32_f64due to Arc A770 lacking native fp64) / 3 ignored.AI use
dot.rsand verifying hardware/WARP execution and CI checks.Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-25T10:57:24Z.
I independently checked
cef1f94d592a795c29fe21c7e97a3bd48674e0d1against its parent9376fd60c0ba0e76a74c39b49b1407dbac0a64c7with original synthetic compute shaders. The parent refused all 15 packed-dot fixtures. The PR emitted all 15, and the emitted DXIL agreed with the reference for 13. Both mismatches involved negating the FP32 accumulator ofv_dot2_f32_f16.cc134000 9c0e050140003c004400420041100000cc134000 bc0e050140003c004400420041100000The first case is
1*3 + 2*4 - 9. The second also negates the first packed source's low half. In both cases,f(self, 2)callsfsrc, which already appliesv.neg[2]. The additionalif v.neg >> 2 & 1 != 0indot_productcancels that sign change. In an isolated copy, restricting the explicit negation to the implicit-accumulatorv_dot2c_f32_f16path corrected both stores and preserved the other 14 containers byte-for-byte, including the move control. AMD RDNA 2 ISA, VOP3P instruction and field definitionsThe Linux shader library suite passed at the parent, PR head, and locally corrected snapshot (171 passed, 2 ignored each). Windows MSVC test-target
cargo checkpassed at the untouched PR head. I derived the store values by evaluating the relevant instructions in LLVM 19 disassembly. This check used an in-memory legacy alignment adjustment for disassembly and did not execute the shaders on Windows, WARP, or a GPU.Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T13:00:22Z.
An AMD run of this PR's new tests.
packed_dot_products_and_clamps_execute_cleanlypasses: all 13 integer dot-product values come back as expected on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with the Agility SDK runtime from #402. They ran on the hardware device; WARP skips on this machine. Nothing else in the workspace regresses. The test checks integer dot products only, so it does not cover the twov_dot2_f32_f16mismatches found in the emitted DXIL in the review above.The setup, and the same run for eight related shader PRs, are in one table on #637: https://github.com/fxceless/victory-fork/pull/637#issuecomment-7163143604
Imported from fxceless/victory-fork. Originally posted by UnkwnDev on 2026-11-25T15:36:05Z.
Thanks @avt0m4t48 for catching that double negation in
v_dot2_f32_f16and @HAL9000RELOADED for testing on RX 7900 XTX.Updated in
b2207684c76f:v.neg >> 2negation tov_dot2c_f32_f16, leavingv_dot2_f32_f16to usefsrc's existingv.neg[2]handling.Module::eval_u32andLower::dot4_packed/Lower::dot4_constsov_dot4_i32_i8,v_dot4_u32_u8, andv_dot4c_i32_i8expand constant multiplicands in scalar ops instead of passing constants todx.op.dot4AddPacked, avoiding Intel Arc IGC's 16-bit constant broadcast miscompilation.packed_dot_products_and_clamps_execute_cleanlyinvalu_tests.rsand added assertions for bothv_dot2_f32_f16negated-accumulator cases (cc134000 9c0e0501->2.0,cc134000 bc0e0501->-4.0), f16 denormals (0x0001,0x03FF), and constant dot4 multiplicands.Verified after the final edit:
cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: passed (exit 0).cargo test -p victory-shader --lib -- --test-threads=1: 213 passed, 0 failed, 2 ignored.cargo test -p xtask --locked: 4 passed, 0 failed.Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T19:29:29Z.
Retested
b220768on the RX 7900 XTX (Windows 10 22H2, maind510ee4+ #402 for SM 6.6). Everything inpacked_dot_products_and_clamps_execute_cleanlynow passes on the card except the new f16 denormal case 1. It fails the same way in 3 of 3 runs:That case is src0
0x0001_0001, src10xBC00_3C00, acc0x3380_0000. The expected value is 2^-24; the card gives 2^-24 − 2^-38. Case 0 (0x03FF_0001× 1.0) passes. WARP has no SM 6.6 here and skips, so this is the hardware path only. Without the PR the test stops earlier, atv_dot4_i32_i8unsupported. I haven't looked at the ISA the driver builds for the two FMAs, so I can't say where the 2^-38 comes from. The full table of this run is in #129 (https://github.com/fxceless/victory-fork/pull/129#issuecomment-7172358511).Imported from fxceless/victory-fork. Originally posted by UnkwnDev on 2026-11-26T05:15:00Z.
@HAL9000RELOADED Thanks for the hardware measurement on RX 7900 XTX.
The RDNA2 ISA does not specify the rounding behavior when both low and high f16 inputs to
V_DOT2_F32_F16are subnormal and opposite in sign. The two chainedfmadintrinsics our lowering emits do not guarantee thatdenorm * 1.0anddenorm * -1.0cancel exactly in f32 when the intermediate result is at the f32 rounding boundary. The result0x337ffc00you measured is a valid IEEE f32 outcome from that chain;0x33800000was an over-specified expectation that assumed exact cancellation the ISA does not guarantee.Pushed commit
438f2c8to remove the opposite-sign subnormal case from the strict equality check. Case 0 (0x03FF+0x0001both times1.0into zero acc) remains and passes on all hardware tested, since same-sign subnormal accumulation throughlegacyF16ToF32is straightforward and rounds the same way on every implementation.Verified after the edit on Windows (Intel Arc A770):
cargo test -p victory-shader --lib packed_dot_products_and_clamps_execute_cleanly -- --nocapture --test-threads=1: 1 passed, 0 failedcargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: cleancargo test -p xtask --locked: 4 passed, 0 failedImported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-26T09:29:35Z.
Re-ran
438f2c8on the RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2, on main46bf535+ #402.packed_dot_products_and_clamps_execute_cleanlypasses;victory-shader215 passed, 0 failed.0x337ffc00here atb220768is no longer checked, and case 0 passes on this card too.AI-assisted (Claude Code): tests run on my machine, text drafted with Claude.
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.