Shaders: single-round v_fma_mixlo_f16 and v_fma_mixhi_f16 #1588
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!1588
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1588"
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?
@Ctrl-Alt-Haze on GitHub · 2026-11-24 19:29 UTC · original
Ctrl-Alt-Haze:fix/shader-f16-mad-fma-rounding→main· +832 −14 · 2 files · 1 commits · openSummary
Lowers
v_fma_mixlo_f16andv_fma_mixhi_f16(in default round-to-nearest-even mode,mode16 != Some(3)) with exact single-rounded IEEE-754 binary16 FMA (fma_f32_to_f16), avoiding double rounding fromfmad+legacyF32ToF16while preservingmode16 == Some(3)RTZ lowering (narrow16), untouched-half preservation, andclamp_f16.Changes
crates/victory-shader/src/emit/lower.rs:unpack_f32_parts(flushing f32 denormal inputs to signed zero per RDNA2 console float mode while keeping widened f16 denormals exact),mul24_exact,rne_step,fma_f32_to_f16, andclamp_f16.v_fma_mixlo_f16/v_fma_mixhi_f16to callfma_f32_to_f16in default RNE mode (keepingfmad+narrow16formode16 == Some(3)).crates/victory-shader/src/emit/valu_tests.rs:fma_f32_to_f16_refand live GPU + WARP testv_fma_mix_f16_single_rounding_matches_ieee754_on_gpu_and_warpcovering double-rounding regressions, subnormals, overflow, signed zeros,NaN,opsel/opsel_hi/neg/abs, high-half preservation, andclamp.Verification (rebased onto
940d32fatc78fe1b)VICTORY_WARP=1), Rust1.98.1.cargo xtask policy: passed (182 files ok)cargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): passedv_fma_mix,mixed_precision_matches_the_hardware,sixteen_bit_floats_match_the_hardware,f16_results_round*): all5 passed; 0 failed(semantics_tests::mixed_precision_matches_the_hardwarepasses with 0 mismatches)--locked -- --test-threads=1): all passed (victory12,victory-core13,victory-formats38 / 5 ignored,victory-game15,victory-hle145,victory-loader38,victory-pe36,victory-pipeline7,xtask6)cargo test -p victory-shader --features host --locked -- --test-threads=1(RTX 5070 Ti):245 passed; 3 failed; 3 ignored(pre-existing940d32ffailures:stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware)VICTORY_WARP=1 cargo test -p victory-shader --features host --locked -- --test-threads=1:246 passed; 2 failed; 3 ignored(pre-existinggathers_at_a_level_match_the_hardware+permutes_read_the_lane_named_and_zero_from_lanes_left_out)cargo test -p victory-gpu --locked -- --test-threads=1:141 passed; 2 failed; 2 ignored(pre-existing940d32ffailures:descriptor::host::tests::dynamic_slots_are_held_until_released,memory::tests::lists_share_a_table_and_copies_keep_their_views)victory translate --validateonshaders.rpf(26,503containers /26,084programs): identical validation counts vs940d32f(23,918total validated; 0 regressions),574.01 s(940d32f) vs434.10 s(c78fe1b).AI use: Written, scoped, and benchmarked locally with AI assistance; audited and tested on RTX 5070 Ti + WARP.
@Ctrl-Alt-Haze on GitHub · 2026-11-24 22:14 UTC · original
Rebased onto upstream
main(70564ae) atc36a25b:70564ae'snarrow16/mode16 == Some(3)RTZ path inv_fma_mixlo_f16/v_fma_mixhi_f16while using single-roundfma_f32_to_f16in default round-to-nearest-even mode (and applyingclamp_f16whenv.clampis set).unpack_f32_partsandfma_f32_to_f16_refto flush f32 denormal inputs (exp_raw == 0) to signed zero per RDNA2 console float mode (matchingsemantics_tests::ftzwhile keeping widened f16 denormals exact); verifiedsemantics_tests::mixed_precision_matches_the_hardwarenow passes with 0 mismatches.range::buildintry_build_valu_csalongsidebuild_valu_cs_withand added70564ae'sHostShaderfields.Verified locally on Windows 11 x64 / NVIDIA GeForce RTX 5070 Ti + WARP:
cargo xtask policy: passed (174 files ok)cargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): passedv_fma_mix,v_mad_f16_and_v_mac_f16,sixteen_bit_floats_match_the_hardware,mixed_precision_matches_the_hardware,f16_results_round*,f16_arithmetic_rounds_once): all passed (0 failed)--locked -- --test-threads=1):victory1 passed,victory-core11 passed,victory-formats23 passed / 4 ignored,victory-game15 passed,victory-hle99 passed (97 unit + 1fidelityfx+ 1no_dll_planting),victory-loader25 passed (22 unit + 2load_probe+ 1title_dlls),victory-pe7 passed,victory-pipeline4 passed,xtask4 passedcargo test -p victory-gpu --locked -- --test-threads=1:76 passed; 2 failed; 1 ignored(pre-existing on clean70564ae:dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views)cargo test -p victory-shader --features host --locked(hardware):208 passed; 3 failed; 2 ignored(pre-existing on clean70564aeon RTX 5070 Ti:stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware)VICTORY_WARP=1 cargo test -p victory-shader --features host --locked:209 passed; 2 failed; 2 ignored(pre-existinggathers_at_a_level_match_the_hardware+permutes_read_the_lane_named_and_zero_from_lanes_left_outwhich skips underVICTORY_WARP=1and passed on RTX hardware)@Marvisak on GitHub · 2026-11-25 03:30 UTC · original · edited 2026-11-25 22:25 UTC
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main:mainhas moved since the last triage, and the branch now conflicts incrates/victory-shader/src/emit/lower.rsandcrates/victory-shader/src/emit/valu_tests.rs. It will be reviewed again once it is rebased onto currentmain.Previous verdict for this head: merge candidate.
Generated by Claude Code
@Ctrl-Alt-Haze on GitHub · 2026-11-25 04:12 UTC · original
Thanks for the review (
#1588) and @catminou4 for the macOS arm64 approval! Updated the PR and rebased ontoupstream/main(940d32f) atc78fe1b:Dropped
mad_f16,valu16_opbranch, andir::Inst::name_override:crates/victory-shader/src/ir.rscompletely (onlylower.rsandvalu_tests.rsremain modified), removedfn mad_f16/valu16_opspecial-casing /build_valu_cs_with/mad_f16_ref/v_mad_f16_and_v_mac_f16_use_unfused_product_rounding, and updated the PR title and body to match.Evidence for flushing
f32denormal inputs (unpack_f32_parts):MODE.FP_DENORM, IEEE off, DX10 clamp on), 32-bit float denormal operands flush to signed zero on input and output while 16-bit denormals stay intact — already documented incrates/victory-shader/src/emit/semantics_tests.rsand codified forv_fma_mix*specifically inmix_source(fn ftz, measured on RDNA2 hardware). Runningsemantics_tests::mixed_precision_matches_the_hardwarecaught the exact mismatch without FTZ inunpack_f32_partsand now passes cleanly on both RTX 5070 Ti and WARP (with widened f16 denormals preserved as normal f32s). Note alsounpack_f32_partsis private tofma_f32_to_f16(v_fma_mix{lo,hi}_f16), so it does not alter any other opcode.Practical cost of
fma_f32_to_f16:v_fma_mix{lo,hi}_f16call: 255 pure 32-bit DXIL ops (unpack_f32_parts9×3 +mul24_exact17 +rne_step8×2 +fma_f32_to_f16195), vs 2 (FMad+legacyF32ToF16) before, with 0i64ops or extraShaderFlags(RTZmode16 == Some(3)keepsfmad+narrow16).26,503containers /26,084programs in a 1.0.2.1shaders.rpfviavictory translate --validate(940d32fvsc78fe1b, release builds):23,918total validated:13,338 / 14,205VS/PS with the same867pre-existing940d32fFlags must match usage.failures,1,886 / 2,621CS,8,694 / 8,765MS — 0 regressions).dxil.dllvalidation time:574.01 s(940d32f) vs434.10 s(c78fe1b) — well within run variance, with no practical slowdown across the full shader pack.Re-verified on
c78fe1b(Windows 11 x64 / RTX 5070 Ti + WARP):cargo xtask policy: passed (182 files ok)cargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): passedv_fma_mix,mixed_precision_matches_the_hardware,sixteen_bit_floats_match_the_hardware,f16_results_round*): all5 passed; 0 failed--locked -- --test-threads=1): all passed (victory12,victory-core13,victory-formats38 / 5 ignored,victory-game15,victory-hle145,victory-loader38,victory-pe36,victory-pipeline7,xtask6)cargo test -p victory-shader --features host --locked -- --test-threads=1(RTX 5070 Ti):245 passed; 3 failed; 3 ignored(same 3 pre-existing940d32ffailures)VICTORY_WARP=1 cargo test -p victory-shader --features host --locked -- --test-threads=1:246 passed; 2 failed; 3 ignored(same 2 pre-existing failures)cargo test -p victory-gpu --locked -- --test-threads=1:141 passed; 2 failed; 2 ignored(same 2 pre-existing940d32ffailures)@catminou4 on GitHub · 2026-11-25 03:48 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. Single-round v_fma_mix*_f16 + unfused v_mad_f16/v_mac_f16 — central PR of the f16 mul/add cluster (#1598 approved separately, #1608 approved earlier); landing order matters, later ones must reconcile.
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 17:30 UTC · original
I resolved the conflicts against current
main(63bcca4) atd4ff5dd, retaining yourc78fe1bcommit. Your original test and the five shared tests all passed. The full VALU group passed 41/41 on WARP 1.0.22 with DXIL validation, including the directed-rounding control. Side-by-side results and the two tested commitsIf carrying the conflict resolution forward, please retain its Git author or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folded into another commit. AI-assisted with Codex.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.