Shaders: lower v_mad_f16 and v_mac_f16 with unfused binary16 product rounding #1597
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1598"
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 Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T19:41:09Z.
Summary
Separates
v_mad_f16/v_mac_f16from fusedv_fma_f16/v_fmac_f16so legacy unfused binary16 multiply-add rounds the intermediate producta * bto binary16 before adding the accumulator (tracking issue #1242,VIC-BT-042).Previously,
Lower::valu16loweredv_fma_f16 | v_fmac_f16 | v_mad_f16 | v_mac_f16identically toself.fmad(a, b, acc). Additionally, DXILlegacyF32ToF16clamps overflowing finite products (|a * b| >= 65520) to±65504(0x7BFF) instead of IEEE-754±inf(0x7C00).Changes
crates/victory-shader/src/emit/lower.rs:f64orINT64DXIL flags) that rounds ties-to-even and produces signed infinity at magnitude>= 65520.v_mad_f16 | v_mac_f16asround_f16(a * b) + accwhile preserving the existing fusedv_fma_f16 | v_fmac_f16path.crates/victory-shader/src/emit/valu_tests.rs: Add GPU-executed regression testv_mad_f16_rounds_the_product_before_addingcomparing unfused MAD against encodedv_fma_f16across 12 cases (product cancellation, overflow threshold65520, normal/subnormal ties, signed zero, and ordinary arithmetic). Note: GFX10.3 encodes only fusedv_fma_f16/v_fmac_f16, so the test uses a#[cfg(test)]-gated mnemonic path to exercise thev_mad_f16lowering directly on GPU hardware and WARP.Verification
cargo test -p victory-shader --lib valu_tests: 14/14 passed on AMD Radeon RX 9060 XT (RDNA4, SM 6.6) and WARP.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 154 files OK.AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:31:46Z.
Automated triage for the maintainers.
The new unfused lowering for
v_mad_f16/v_mac_f16cannot be reached by a title shader: the GFX10 decoder table incrates/victory-shader/src/gfx10/opcodes.rshas nov_mad_f16orv_mac_f16(RDNA2 has only the fusedv_fma_f16/v_fmac_f16, as the PR description itself notes). The test therefore works by renamingv_fma_f16tov_mad_f16through a#[cfg(test)]flag added toLower, so it exercises a path that never runs outside the test, and it adds a test-only field to production code. The names inLower::valu16are leftovers that could simply be removed instead. If a GFX10.3 encoding that decodes to these names exists, please point to it and this can be reconsidered.This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the
triage: proposed closelabel.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-25T02:08:31Z.
Rebased cleanly onto \main\ (\
ccfb029). \cargo test -p victory-shader --locked mad_f16\ (verified on physical AMD RX 9060 XT + WARP + Microsoft \dxil.dll), \cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings, and \cargo xtask policy\ all pass.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:39:21Z.
Review: APPROVED
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_f16/v_mac_f16 unfused binary16 product — overlaps with #1588 and approved #1608 (same f16 mul/add family); whichever lands second must reconcile the rounding path.
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.