Shaders: lower v_mad_f16 and v_mac_f16 with unfused binary16 product rounding #1598
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!1598
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@geiyiliyabumo on GitHub · 2026-11-24 19:41 UTC · original
geiyiliyabumo:fix/shader-mad-f16-unfused→main· +159 −6 · 2 files · 1 commits · openSummary
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.
@Marvisak on GitHub · 2026-11-25 01:31 UTC · original · edited 2026-11-25 02:27 UTC
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
@geiyiliyabumo on GitHub · 2026-11-25 02:08 UTC · original
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.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.