Shaders: v_mad_f32 and v_mac_f32 multiply apart from their add #1920
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!1920
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1920"
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?
@kais7654 on GitHub · 2026-11-25 01:00 UTC · original
kais7654:shader/mac-mad-fma→main· +19 −2 · 1 files · 1 commits · openSame root cause as #1903 (FMad over an opaque zero), this time on the plain
v_mad_f32/v_mac_f32paths: the lowering emits the product rounded beforethe add, which is what the ISA says, but the driver folds the
fmulinto thefollowing
faddas an FMA although nothing carries a fast-math flag. Onerounding where two were due shifts the tail of the product:
v_mad_f32: 2 of 2560 inputs mismatch on hardware, 0 on WARP, 0 in themodel (
[3f7fffff, 3f800001, bf800000]straddles 1.0, where double vssingle rounding is visible);
v_mac_f32: 102 of 14440.The legacy variants already pass, because
legacy_mulends in aselectthat cuts the
fmul → faddedge. This replaces the plain product with anFMad over a zero signed by the operands' own signs (
sign(a) ^ sign(b)),which rounds exactly like a plain IEEE multiply — signed zeros included,
denormal outputs the same way as the fused
v_fma_f32path alreadyverified — and hides the multiply behind a call the fusion pass sees no
other side of. +19/−2 in
emit/lower.rs, no test changes.With it,
arithmetic_matches_the_hardwarepasses on both backends word forword (the rest of the suite's failures on this branch are the ones covered
by #1903, #1896 and #1857).
Local: RTX 5070 Laptop GPU (driver 616.87) and WARP, 240 tests pass.
AI-assisted (Mistral Vibe).
@Headache3318 on GitHub · 2026-11-25 02:08 UTC · original
Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head
7054097applied cleanly onto currentmainccfb029.cargo test -p victory-shader --locked: 144 passed, 0 failed, 2 ignored. All tests pass.cargo clippy -p victory-shader --all-targets -- -D warnings: 4 pre-existing errors in test code (fail identically on mainccfb029). The PR introduces no new clippy warnings.Not tested: Windows MSVC build, the title itself. AI-assisted.
@Marvisak on GitHub · 2026-11-25 08:19 UTC · original
Automated triage for the maintainers.
Merge candidate.
In
crates/victory-shader/src/emit/lower.rs, the plainv_mad_f32/v_mac_f32product becomesmul_apart: anFMad(DXIL op 46, the samefmadthatv_fmac_f32uses) over a zero whose sign issign(a) ^ sign(b). That givesround(a*b)whether or not the host fusesFMad, because adding a zero of the product's own sign is exact, and it keeps-0products. The followingfaddcan then no longer be contracted with a barefmul. The legacy variant (legacy_mul) is unchanged. The evidence is the hardware-reference testarithmetic_matches_the_hardware: per the PR it now matches on an NVIDIA card where it mismatched before, and WARP was already clean.Cost: three integer ops per
v_mad_f32/v_mac_f32. Related to #1903 (the same technique on other opcodes), but it doesn't depend on it.CI:
checkpasses.Generated by Claude Code
@sinan-cmyk on GitHub · 2026-11-25 11:28 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head
70540976ontomain940d32f(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).
@catminou4 on GitHub · 2026-11-25 02:49 UTC · original · approved these changes
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. v_mad_f32/v_mac_f32 multiply kept apart from the add (no FMA contraction) — precision fix matching #1903's ray-test treatment; suite green.
@fuzeofficlal on GitHub · 2026-11-26 18:53 UTC · original · approved these changes
Verified
70540976ce32e6a8d3b1aa97773c9724a2574265cleanly merged ontomain(63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDKdxil.dll):Lower::mul_apart(crates/victory-shader/src/emit/lower.rs:2221-2230) applies consistently tov_mac_f32andv_mad_f32/v_madak_f32/v_madmk_f32(lower.rs:6290-6309), preserving the-0.0product sign viaFMad(a, b, copysign(0.0, a * b))and preventing host contraction with the followingfadd, while leavingv_fma*_f32/v_fmac_f32and*_legacy_f32paths untouched.emit/lower.rssize: 521,365 B (under 524,288 B);cargo test -p xtask --locked policy::tests::repository_passes_policy:1 passed(asset policy: 191 files ok).cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features): clean.emit::semantics_tests::arithmetic_matches_the_hardware(7.04sRTX 5090 /0.58sWARP),emit::valu_tests::v_mul_legacy_f32_treats_denormals_as_zero,emit::tests::constant_color_validates, andemit::lower::tests::(33 passed, 0 failed) all pass on both RTX 5090 and WARP.Ready to merge.
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.