Repository navigation
Shaders: round packed FP16 fused multiply-add once in nearest-even mode - #2884
andrewpozdnakov7-jpg wants to merge 1 commit into
Conversation
|
Reviewed and verified
Looks clean and ready to merge. |
kotekompotek
left a comment
There was a problem hiding this comment.
Right fix for double rounding: a fused fma rounds once, so computing in f32 then narrowing to f16 misrounds exactly the tie cases (exact product-sum needing >f32 mantissa). Keeping the f32 FMad only for directed modes (which need the explicit rounding anyway) is the correct split, and the test was updated to match the new semantics rather than keeping the known-wrong expectation. LGTM.
|
Automated triage for the maintainers. Merge candidate. CI: passing. Generated by Claude Code |
Dukestar69
left a comment
There was a problem hiding this comment.
Verified on RTX 5090 & WARP against origin/main (63bcca4):
cargo test -p victory-shader --lib packed_fused_f16_rounds_each_half_once -- --test-threads=1: passed on RTX 5090 and WARP.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Cleanly ensures packed f16 FMA rounds each half once rather than double-rounding.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal
left a comment
There was a problem hiding this comment.
Routing v_pk_fma_f16 and v_pk_fmac_f16 through fma_f16 in nearest-even mode (matches!(self.mode16, None | Some(0))) eliminates double rounding on midpoint and subnormal ties while preserving op_sel, per-half neg, clamp, and both VOP2/VOP3 FMAC encodings. git merge-tree against main (63bcca43) is clean, and emit/lower.rs is 520,817 bytes (under the 512 KiB limit).
One scope note worth making explicit in the title/summary: directed rounding modes (Some(1..=3)) still go through fmad + narrow16, so RTZ still double-rounds cases like (0x4000, 0x3c00, 0x8001) (2 - 2^-24 rounds to 2.0 in f32 -> 0x4000 instead of 0x3fff), and modes 1 and 2 narrow as nearest-even.
Verified locally on Windows 11 x64 (RTX 5090 + WARP + dxil.dll, 64c62d5e):
cargo run --locked -p xtask -- policy: passed (191 files ok)cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): cleanpacked_fused_f16_rounds_each_half_onceandsixteen_bit_floats_match_the_hardware(-- --test-threads=1, RTX 5090 andVICTORY_WARP=1): 1 passed, 0 failed each on both
|
Thanks, @fuzeofficlal. I clarified the title and summary. The single-rounding path is for round-to-nearest-even, and modes 1–3 continue through the existing f32 FMad and narrowing path. Your toward-zero example remains outside this PR's scope. Review note |
The f32 fallback for
V_PK_FMA_F16andV_PK_FMAC_F16could round the sum to an f16 midpoint before narrowing it. Use the single-rounding helper introduced by #1387 for each nearest-even packed result. Both source-half selectors and the per-half negation and clamp go through the existing packed instruction path.Scope is round-to-nearest-even (RNE), including the default lowering when the rounding mode is unknown. Directed modes 1–3 still use the existing f32 FMad and narrowing path.
The same synthetic fixture on
842b0cband this commit checks 20 input and instruction-form pairs on app-local WARP SM 6.6. Eight pairs disagree with the CPU model on main. For example, both packed operations produce0x3e043e02with0x3e053e01expected. All 20 pairs match with this change, including swapped halves, VOP2/VOP3 accumulators, cancellation and a subnormal tie. The f16 semantics test, 35 VALU tests, DXIL validation, strict shader Clippy and the asset policy passed.#2825 adds a capability-gated native half path. I resolved the adjacent lowering edit locally with its head
3c81083and ran the same WARP tests. The capability probe still selects the fallback on WARP and the packed single-rounding fixture passes in that combined build.RDNA 2 ISA · Coordination claim
Please retain the Git author if cherry-picking or rebasing the commit. If you fold the change into another commit, please add
Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>.