Shaders: round packed FP16 fused multiply-add once in nearest-even mode #2884
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2884
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2884"
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?
@andrewpozdnakov7-jpg on GitHub · 2026-11-25 23:02 UTC · original
andrewpozdnakov7-jpg:codex2/packed-fma-nearest-even→main· +74 −37 · 2 files · 1 commits · openThe 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 <[email protected]>.@fuzeofficlal on GitHub · 2026-11-25 23:10 UTC · original
Reviewed and verified
64c62d5eon Windows 11 (RTX 5090 + WARP +dxil.dll) againstmain(842b0cb):v_pk_fma_f16/v_pk_fmac_f16throughfma_f16(TwoSum single rounding) under RNE (None | Some(0)) while keeping the directed-roundingfmad + narrow16path forSome(1..=3)eliminates double-rounding while preservingop_sel, per-halfneg, andclamp(and complements#2825's native-16-bit path on software/WARP hosts).semantics_tests35/35 passed (includingpacked_fused_f16_rounds_each_half_onceacross all 20 cases with 0 discrepancies on RTX 5090, WARP, and the reference model),emit::lower::tests33/33 passed,cargo clippy --locked -p victory-shader --all-targets -- -D warnings0 warnings,cargo xtask policy(191 files ok;emit/lower.rs=520,817bytes).Looks clean and ready to merge.
@Marvisak on GitHub · 2026-11-26 04:28 UTC · original
Automated triage for the maintainers.
Merge candidate.
v_pk_fma_f16andv_pk_fmac_f16in nearest-even mode now go through the single-roundingfma_f16helper the scalarv_fma_f16already uses (packed16inemit/lower.rs); directed modes keep the f32 FMad. This matches the RDNA2 ISA's definition of these as fused.packed_fused_f16_rounds_each_half_oncechecks against an exact f64 fused result, with midpoints, a subnormal tie, op_sel/neg per half, clamp, and both encodings ofv_pk_fmac_f16.CI: passing.
Generated by Claude Code
@kotekompotek on GitHub · 2026-11-25 23:34 UTC · original · reviewed
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.
@Dukestar69 on GitHub · 2026-11-26 09:29 UTC · original · approved these changes
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 on GitHub · 2026-11-26 10:32 UTC · original · reviewed
Routing
v_pk_fma_f16andv_pk_fmac_f16throughfma_f16in nearest-even mode (matches!(self.mode16, None | Some(0))) eliminates double rounding on midpoint and subnormal ties while preservingop_sel, per-halfneg,clamp, and both VOP2/VOP3 FMAC encodings.git merge-treeagainstmain(63bcca43) is clean, andemit/lower.rsis520,817bytes (under the 512 KiB limit).One scope note worth making explicit in the title/summary: directed rounding modes (
Some(1..=3)) still go throughfmad + narrow16, so RTZ still double-rounds cases like(0x4000, 0x3c00, 0x8001)(2 - 2^-24rounds to2.0in f32 ->0x4000instead of0x3fff), 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 bothShaders: round packed half-precision fused multiply-add onceto Shaders: round packed FP16 fused multiply-add once in nearest-even mode@andrewpozdnakov7-jpg on GitHub · 2026-11-26 11:40 UTC · original
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
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.