Shaders: the legacy MAD/MAC encodings are one fused multiply-add with flushed sources #1554

Open
github-bot wants to merge 5 commits from github-bot/gh-1554 into main AGit
Owner

@⁠Calvix2k on GitHub · 2026-11-24 19:06 UTC · original
Calvix2k:codex/shader-f32-mad-ftz-043 → main · +110 −17 · 6 files · 5 commits · open

Summary

On RDNA 2 the v_mad_legacy_f32 / v_mac_legacy_f32 encodings are the fused instructions: V_FMA_LEGACY_F32 (VOP3 0x140) and V_FMAC_LEGACY_F32 (VOP2 0x06), per LLVM's AMDGPU GFX10.3 opcode tables. They fuse the product and the add, flush f32 subnormal sources, and keep the legacy rule that a zero factor makes the product +0 rather than turning an infinite or NaN factor into a NaN. The opcodes are now named that way and the lowering's arms follow.

v_mad_f32, v_mac_f32 and v_fmac_f32 are unchanged.

Tests

  • legacy_mad_fuses_its_product_and_flushes_its_sources: (1 + 2^-23)(1 - 2^-23) - 1 is -2^-46 with one rounding and 0 when the product is rounded first; a subnormal source is a zero; a zero factor gives +0 even with an infinite factor.
  • legacy_mad_lowers_to_one_fused_op_with_flushed_sources: one tertiary.f32 and three flushes in the DXIL.
  • fuses_fmad now probes with the same case as the test. KainanP's Xe-LP passes the old probe ((1 - 2^-24)(1 + 2^-23) - 1) but returns 0 for the legacy case, so the old probe was too weak; the legacy test now skips case 0 on a device whose probe says it does not fuse (and on WARP) instead of failing.

Verification

cargo test -p victory-shader --lib skips the GPU cases on this machine (no SM 6.6 device without the Agility opt-in); CI runs them. Clippy -D warnings clean. Thanks to KainanP for the Xe-LP run that exposed the weak probe.

**@⁠Calvix2k** on GitHub · 2026-11-24 19:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554) `Calvix2k:codex/shader-f32-mad-ftz-043` → `main` · +110 −17 · 6 files · 5 commits · open ## Summary On RDNA 2 the `v_mad_legacy_f32` / `v_mac_legacy_f32` encodings are the **fused** instructions: `V_FMA_LEGACY_F32` (VOP3 0x140) and `V_FMAC_LEGACY_F32` (VOP2 0x06), per LLVM's AMDGPU GFX10.3 opcode tables. They fuse the product and the add, flush f32 subnormal sources, and keep the legacy rule that a zero factor makes the product +0 rather than turning an infinite or NaN factor into a NaN. The opcodes are now named that way and the lowering's arms follow. `v_mad_f32`, `v_mac_f32` and `v_fmac_f32` are unchanged. ## Tests - `legacy_mad_fuses_its_product_and_flushes_its_sources`: (1 + 2^-23)(1 - 2^-23) - 1 is -2^-46 with one rounding and 0 when the product is rounded first; a subnormal source is a zero; a zero factor gives +0 even with an infinite factor. - `legacy_mad_lowers_to_one_fused_op_with_flushed_sources`: one `tertiary.f32` and three flushes in the DXIL. - `fuses_fmad` now probes with the same case as the test. KainanP's Xe-LP passes the old probe ((1 - 2^-24)(1 + 2^-23) - 1) but returns 0 for the legacy case, so the old probe was too weak; the legacy test now skips case 0 on a device whose probe says it does not fuse (and on WARP) instead of failing. ## Verification `cargo test -p victory-shader --lib` skips the GPU cases on this machine (no SM 6.6 device without the Agility opt-in); CI runs them. Clippy `-D warnings` clean. Thanks to KainanP for the Xe-LP run that exposed the weak probe.
RDNA2 flushes f32 subnormal operands, products and sums for v_mad_f32,
v_mad_legacy_f32, v_mac_f32 and v_mac_legacy_f32; v_fmac_f32 keeps the
fused behaviour. Use the upstream `ftz` helper for every flush instead
of a private copy, and keep the corrected OMOD regression plus a DXIL check
that the flush sequence is really emitted.
On RDNA 2 (the console's family) the legacy encoding decodes as
`v_fma_legacy_f32`, fused and flushing its f32 denormal sources — not the
separately rounded, product-and-result-flushing form of gfx1010 that the
previous commit modelled (AnyPS5's shader-debt page, `v_mad_legacy_f32`
and `v_mac_legacy_f32` entries).

Lower `v_mad_legacy_f32` and `v_mac_legacy_f32` to one fused multiply-add
of the flushed sources, keeping the legacy zero-factor rule (a +0 product,
so an infinite factor with a zero one does not turn the addend into NaN).
`v_mac_f32`/`v_mad_f32` (no such opcodes on RDNA 2) and `v_fmac_f32` keep
their previous lowering.

Tests: a GPU case for the fused rounding (-2^-46 kept) and the zero rule,
and a DXIL check of one `tertiary.f32` with three source flushes, reusing
the existing `dump_dxil` helper instead of a copy.
`dump_dxil` used one temp name per process, so the interpolation test and
the new legacy-mad test could overwrite each other's container when they
ran in parallel (the interpolation test then read the other module). One
name per call.

WARP rounds the product before the add for the legacy form (the case that
tells fused from separate returns 0 there), so the fusion case asserts on
the hardware only, as other gather/interp tests do.
The pair was written as (1 + 2^-23) * (1 - 2^-24): `0x3F7F_FFFF` is one
unit below 1.0 at that exponent's spacing, not 1 - 2^-23. The fused result
for that pair is +2^-24-ish, not the exact -2^-46 the case asserts; on the
hardware test it failed. `0x3F7F_FFFE` is 1 - 2^-23, whose fused product
minus one is exactly -2^-46 and whose separate product rounds to 1.0.
Review feedback on #1554:

- The VOP2/VOP3 opcodes are named as the GFX10.3 tables name them:
  `v_fmac_legacy_f32` (0x06) and `v_fma_legacy_f32` (0x140), and the
  lowering's arms and comments follow. The citation is LLVM's AMDGPU GFX10.3
  opcode tables, not a project page.
- `valu_tests.rs` ends with a newline.
- The fusing probe now asks the device the same question the lowering does:
  (1 + 2^-23) * (1 - 2^-23) - 1, which is -2^-46 fused and 0 when the product
  is rounded first. KainanP's Xe-LP passes the old probe but returns 0 for
  this case, so the old probe was too weak; the legacy test skips case 0 on a
  device whose probe says it does not fuse (and on WARP), instead of failing.

Title and body updated to say what the branch does: the legacy encodings are
one fused multiply-add with flushed sources; `v_mad_f32`/`v_mac_f32` are
unchanged.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:36:11 +00:00
Author
Owner

@⁠matheusfermiano-source on GitHub · 2026-11-24 19:16 UTC · original

First GPU run of v_mad_f32_flushes_subnormal_sum_before_omod, since it was skipped where the PR was written. It fails, but the cause is the test's inputs, not the lowering.

Result at 115e289. Both GPUs return 0x81000000, want 0:

  • Radeon 660M (RDNA2, RADV Mesa 26.3.1), under Proton with vkd3d-proton 3.1.0 and 3.2.0;
  • RTX 3050 Laptop (NVIDIA 620.73.04), under Proton with vkd3d-proton 3.1.0.

Why. build_valu_cs copies s0..s3 into v1..v4, so the instruction computes src0 * src1 + src2 = 0x00c00000 * 0x00800000 + 0x80800000:

  • That is 1.5·FLT_MIN × FLT_MIN − FLT_MIN, not the 1.5·FLT_MIN − FLT_MIN that the comment describes.
  • The product (about 2e-76) underflows to 0 whether or not subnormals are flushed. The sum is −FLT_MIN, which is normal, so mul:2 gives 0x81000000.

So 0x81000000 is the correct answer for these inputs on any correct implementation, Windows included.

With src1 = 1.0. I changed the case to [0x00c0_0000, 0x3f80_0000, 0x8080_0000, 0]. The sum is then 0.5·FLT_MIN, a subnormal, as the comment intends:

lowering Radeon 660M RTX 3050
this PR 0, pass 0, pass
main (lower.rs from ffe310e, same test) 0, pass 0, pass

These drivers already flush fp32 subnormals on this path. So on my hosts even the fixed test does not tell this PR from main. Showing the fix takes a device that keeps fp32 subnormals there; I don't know which ones do.

Rest of the suite. On the Radeon, nothing else fails beyond emit::tests::stub_pipeline_is_created, which fails on main here too (vkd3d-proton accepts a zeroed DXIL hash; see #1218).

Built on Linux with llvm-mingw for x86_64-pc-windows-gnullvm (Rust 1.98.1); dxil.dll from DXC 1.9.2609 was loaded. Synthetic tests only, no game files. AI-assisted (Claude Code, Opus 5.5); every run was on this machine.

**@⁠matheusfermiano-source** on GitHub · 2026-11-24 19:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7141849049) First GPU run of `v_mad_f32_flushes_subnormal_sum_before_omod`, since it was skipped where the PR was written. It fails, but the cause is the test's inputs, not the lowering. **Result at `115e289`.** Both GPUs return `0x81000000`, want `0`: - Radeon 660M (RDNA2, RADV Mesa 26.3.1), under Proton with vkd3d-proton 3.1.0 and 3.2.0; - RTX 3050 Laptop (NVIDIA 620.73.04), under Proton with vkd3d-proton 3.1.0. **Why.** `build_valu_cs` copies `s0..s3` into `v1..v4`, so the instruction computes `src0 * src1 + src2` = `0x00c00000 * 0x00800000 + 0x80800000`: - That is 1.5·FLT_MIN × FLT_MIN − FLT_MIN, not the 1.5·FLT_MIN − FLT_MIN that the comment describes. - The product (about 2e-76) underflows to 0 whether or not subnormals are flushed. The sum is −FLT_MIN, which is normal, so `mul:2` gives `0x81000000`. So `0x81000000` is the correct answer for these inputs on any correct implementation, Windows included. **With `src1 = 1.0`.** I changed the case to `[0x00c0_0000, 0x3f80_0000, 0x8080_0000, 0]`. The sum is then 0.5·FLT_MIN, a subnormal, as the comment intends: | lowering | Radeon 660M | RTX 3050 | |---|---|---| | this PR | `0`, pass | `0`, pass | | `main` (`lower.rs` from `ffe310e`, same test) | `0`, pass | `0`, pass | These drivers already flush fp32 subnormals on this path. So on my hosts even the fixed test does not tell this PR from `main`. Showing the fix takes a device that keeps fp32 subnormals there; I don't know which ones do. **Rest of the suite.** On the Radeon, nothing else fails beyond `emit::tests::stub_pipeline_is_created`, which fails on `main` here too (vkd3d-proton accepts a zeroed DXIL hash; see #1218). Built on Linux with llvm-mingw for `x86_64-pc-windows-gnullvm` (Rust 1.98.1); `dxil.dll` from DXC 1.9.2609 was loaded. Synthetic tests only, no game files. AI-assisted (Claude Code, Opus 5.5); every run was on this machine.
Author
Owner

@⁠shortselow-byte on GitHub · 2026-11-24 19:32 UTC · original

Following up on the analysis above with the new head: 8c31717 still fails the same way. before_cases keeps src1 = 0x0080_0000 and still expects 0, so on an AMD Radeon RX 6900 XT (RDNA2, native Windows 11, Rust 1.98.1 MSVC, isolated target directory):

assertion `left == right` failed: hardware: MAD flushes subnormal sum before OMOD
  left: 2164260864
 right: 0

With only that one value changed to 0x3f80_0000 (1.0), v_mad_f32_flushes_subnormals_around_omod passes: all four case groups (before_cases, product_cases, input_cases, after_cases) on the AMD device and on WARP. I did not check whether the three new groups also pass on main on these hosts.

**@⁠shortselow-byte** on GitHub · 2026-11-24 19:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7142234723) Following up on the analysis above with the new head: **`8c31717` still fails the same way.** `before_cases` keeps `src1 = 0x0080_0000` and still expects 0, so on an AMD Radeon RX 6900 XT (RDNA2, native Windows 11, Rust 1.98.1 MSVC, isolated target directory): ``` assertion `left == right` failed: hardware: MAD flushes subnormal sum before OMOD left: 2164260864 right: 0 ``` With only that one value changed to `0x3f80_0000` (1.0), `v_mad_f32_flushes_subnormals_around_omod` passes: all four case groups (`before_cases`, `product_cases`, `input_cases`, `after_cases`) on the AMD device and on WARP. I did not check whether the three new groups also pass on `main` on these hosts.
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 19:40 UTC · original

Tested commit 8c31717 on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, gfx1200, SM 6.6) + WARP:

  • cargo test -p victory-shader --lib: 120 passed, 1 FAILED, 1 ignored — emit::valu_tests::v_mad_f32_flushes_subnormals_around_omod fails on the AMD hardware backend:
thread 'emit::valu_tests::v_mad_f32_flushes_subnormals_around_omod' panicked at crates\victory-shader\src\emit\valu_tests.rs:966:9:
assertion `left == right` failed: hardware: MAD flushes subnormal sum before OMOD
  left: 2164260864
 right: 0

Note that 2164260864 == 0x8100_0000 (a non-zero negative normal f32 after OMOD scaling, indicating the subnormal flush before OMOD did not take effect on the AMD D3D12 driver — likely because a float comparison/arithmetic check on denorms gets flushed or folded differently under AMD's shader compiler unless tested bitwise on the exponent bits (bits & 0x7F80_0000) == 0).

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 19:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7142434470) Tested commit `8c31717` on **Windows 11 / AMD Radeon RX 9060 XT (RDNA4, `gfx1200`, SM 6.6)** + **WARP**: - `cargo test -p victory-shader --lib`: **120 passed, 1 FAILED, 1 ignored** — `emit::valu_tests::v_mad_f32_flushes_subnormals_around_omod` fails on the AMD hardware backend: ```text thread 'emit::valu_tests::v_mad_f32_flushes_subnormals_around_omod' panicked at crates\victory-shader\src\emit\valu_tests.rs:966:9: assertion `left == right` failed: hardware: MAD flushes subnormal sum before OMOD left: 2164260864 right: 0 ``` Note that `2164260864 == 0x8100_0000` (a non-zero negative normal f32 after OMOD scaling, indicating the subnormal flush before OMOD did not take effect on the AMD D3D12 driver — likely because a float comparison/arithmetic check on denorms gets flushed or folded differently under AMD's shader compiler unless tested bitwise on the exponent bits `(bits & 0x7F80_0000) == 0`). *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:14 UTC · original · edited 2026-11-24 20:45 UTC

Edited: the failure is a typo in the new test's vector, not a lowering bug

Correction. An earlier version of this comment said that main already has the failing case and passes it. That was wrong. The test is new in this PR. I had compared the PR's two commits with each other instead of with main. The analysis and a verified one-line fix are in the next comment.

What I measured stays valid:

  • Offline: I merged head 8c31717 onto main ffe310e and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. Validated: 21,724 on both, 0 gained, 0 lost, no failure reason changed.
  • Tests: v_mad_f32_flushes_subnormals_around_omod returns 0x81000000 for before_cases, the same on the RTX 4070 SUPER and on WARP. The rest of victory-shader --lib passes.

AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7143234962) · edited 2026-11-24 20:45 UTC ### Edited: the failure is a typo in the new test's vector, not a lowering bug **Correction.** An earlier version of this comment said that `main` already has the failing case and passes it. **That was wrong.** The test is new in this PR. I had compared the PR's two commits with each other instead of with `main`. The analysis and a verified one-line fix are in the next comment. What I measured stays valid: - **Offline:** I merged head 8c31717 onto `main` ffe310e and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. Validated: 21,724 on both, 0 gained, 0 lost, no failure reason changed. - **Tests:** `v_mad_f32_flushes_subnormals_around_omod` returns `0x81000000` for `before_cases`, the same on the RTX 4070 SUPER and on WARP. The rest of `victory-shader --lib` passes. AI-assisted (Claude Code).
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-24 20:25 UTC · original

Thanks for the hardware runs — the first case was wrong, and it is fixed in 418d0b5.

uild_valu_cs copies s0..s3 into 1..v4, so _mad_f32 v0, v1, v2, v3 computes src0 * src1 + src2. With [0x00c0_0000, 0x0080_0000, 0x8080_0000] that is 1.5·FLT_MIN · FLT_MIN − FLT_MIN: the product underflows to zero and the sum is the normal −FLT_MIN, so mul:2 giving ␀x81000000 was correct for those inputs on every implementation.

The case now uses src1 = 1.0:

ust // 1.5 * FLT_MIN * 1.0 - FLT_MIN is a positive subnormal. RDNA flushes // it before mul:2, so it stays +0 instead of becoming FLT_MIN. let before_cases = [[0x00c0_0000, 0x3f80_0000, 0x8080_0000, 0]];

I re-checked the other three groups as well: product_cases, input_cases and fter_cases are arithmetically sound and differ from the unflushed result, so they stay as they are.

Two notes on the remaining comments:

  • As several of you observed, the fixed case still passes on main on drivers that already flush fp32 subnormals on this path, so the test describes the required behaviour but cannot by itself prove the new lowering. A lower-level assertion on the emitted DXIL would be needed for that.
  • On my own Radeon RX 7800 XT the test skips: this install's D3D12 runtime reports SM 6.5 for the hardware device and 6.2 for WARP, below the SM 6.6 the harness requires, so I have no local GPU result to add.

Validation on 418d0b5: cargo test -p victory-shader --locked -- --test-threads=1 --skip emit::valu_tests --skip emit::waterfall_tests (102 passed, 0 failed, 1 ignored), clippy -D warnings, cargo xtask policy, and
ustfmt --check on the test file.

**@⁠Calvix2k** on GitHub · 2026-11-24 20:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7143526605) Thanks for the hardware runs — the first case was wrong, and it is fixed in 418d0b5. uild_valu_cs copies s0..s3 into 1..v4, so _mad_f32 v0, v1, v2, v3 computes src0 * src1 + src2. With [0x00c0_0000, 0x0080_0000, 0x8080_0000] that is 1.5·FLT_MIN · FLT_MIN − FLT_MIN: the product underflows to zero and the sum is the normal −FLT_MIN, so mul:2 giving ␀x81000000 was correct for those inputs on every implementation. The case now uses src1 = 1.0: ` ust // 1.5 * FLT_MIN * 1.0 - FLT_MIN is a positive subnormal. RDNA flushes // it before mul:2, so it stays +0 instead of becoming FLT_MIN. let before_cases = [[0x00c0_0000, 0x3f80_0000, 0x8080_0000, 0]]; ` I re-checked the other three groups as well: product_cases, input_cases and fter_cases are arithmetically sound and differ from the unflushed result, so they stay as they are. Two notes on the remaining comments: - As several of you observed, the fixed case still passes on main on drivers that already flush fp32 subnormals on this path, so the test describes the required behaviour but cannot by itself prove the new lowering. A lower-level assertion on the emitted DXIL would be needed for that. - On my own Radeon RX 7800 XT the test skips: this install's D3D12 runtime reports SM 6.5 for the hardware device and 6.2 for WARP, below the SM 6.6 the harness requires, so I have no local GPU result to add. Validation on 418d0b5: cargo test -p victory-shader --locked -- --test-threads=1 --skip emit::valu_tests --skip emit::waterfall_tests (102 passed, 0 failed, 1 ignored), clippy -D warnings, cargo xtask policy, and ustfmt --check on the test file.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-24 20:26 UTC · original

Follow-up with a hardware run from here, so my previous "no local GPU result" is superseded.

This Windows 10 install's system D3D12 runtime reports only SM 6.5 for the discrete GPU and 6.2 for WARP, which is why the test skipped. Opting the test binary into the Agility SDK runtime (1.616, D3D12Core.dll next to the test exe plus the usual D3D12SDKVersion/D3D12SDKPath exports; local experiment only, not part of the PR) gives the GPU SM 6.6:

  • Radeon RX 7800 XT (RDNA3, driver 32.0.32029.2010), hardware backend: _mad_f32_flushes_subnormals_around_omod passes; all four groups (efore_cases, product_cases, input_cases, fter_cases) are correct.
  • WARP: still skipped, it stays at SM 6.2 here even with the Agility runtime.

I also re-ran the corrected test against lower.rs from main ( fe310e): it passes as well, so this driver already flushes fp32 subnormals on this path and does not distinguish the two. That matches the other reports above — the corrected case pins the required result, but a lowering-level assertion would be needed to prove the new code path on such drivers.

**@⁠Calvix2k** on GitHub · 2026-11-24 20:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7143555550) Follow-up with a hardware run from here, so my previous "no local GPU result" is superseded. This Windows 10 install's system D3D12 runtime reports only SM 6.5 for the discrete GPU and 6.2 for WARP, which is why the test skipped. Opting the test binary into the Agility SDK runtime (1.616, D3D12Core.dll next to the test exe plus the usual D3D12SDKVersion/D3D12SDKPath exports; local experiment only, not part of the PR) gives the GPU SM 6.6: - **Radeon RX 7800 XT (RDNA3, driver 32.0.32029.2010), hardware backend:** _mad_f32_flushes_subnormals_around_omod passes; all four groups (efore_cases, product_cases, input_cases, fter_cases) are correct. - **WARP:** still skipped, it stays at SM 6.2 here even with the Agility runtime. I also re-ran the corrected test against lower.rs from main ( fe310e): it passes as well, so this driver already flushes fp32 subnormals on this path and does not distinguish the two. That matches the other reports above — the corrected case pins the required result, but a lowering-level assertion would be needed to prove the new code path on such drivers.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-24 20:31 UTC · original

Added a lowering-only check in cbb9d2b, since the GPU test cannot distinguish the path on drivers that flush anyway.

_mad_f32_flushes_subnormals_in_dxil lowers _mad_f32 and _fmac_f32, dumps both modules with dxc -dumpbin, and asserts on the emitted instructions:

  • _mad_f32 contains at least five (bits & 0x7F80_0000) == 0 ? bits & 0x8000_0000 : bits sequences — the three inputs, the product and the sum.
  • Every exponent test has a matching sign-mask nd and select i1.
  • _fmac_f32 contains no flush sequence at all.

It needs no GPU, only dxc.exe (same lookup as the rest of the suite, VICTORY_PC_DXC override); it skips when dxc is missing. Against lower.rs from main it fails on the MAD assertion, so it covers the regression.

Validation on cbb9d2b: cargo test -p victory-shader --locked -- --test-threads=1 --skip emit::valu_tests --skip emit::waterfall_tests (103 passed, 0 failed, 1 ignored), clippy -D warnings, cargo xtask policy.

**@⁠Calvix2k** on GitHub · 2026-11-24 20:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7143683755) Added a lowering-only check in cbb9d2b, since the GPU test cannot distinguish the path on drivers that flush anyway. _mad_f32_flushes_subnormals_in_dxil lowers _mad_f32 and _fmac_f32, dumps both modules with dxc -dumpbin, and asserts on the emitted instructions: - _mad_f32 contains at least five (bits & 0x7F80_0000) == 0 ? bits & 0x8000_0000 : bits sequences — the three inputs, the product and the sum. - Every exponent test has a matching sign-mask nd and select i1. - _fmac_f32 contains no flush sequence at all. It needs no GPU, only dxc.exe (same lookup as the rest of the suite, VICTORY_PC_DXC override); it skips when dxc is missing. Against lower.rs from main it fails on the MAD assertion, so it covers the regression. Validation on cbb9d2b: cargo test -p victory-shader --locked -- --test-threads=1 --skip emit::valu_tests --skip emit::waterfall_tests (103 passed, 0 failed, 1 ignored), clippy -D warnings, cargo xtask policy.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:45 UTC · original

The failing case is a test-vector typo, not a lowering bug

Correction to my earlier comment: I wrote that main already has this case. That was wrong. The test is new in this PR. I had read the diff between this PR's two commits, not the diff against main.

What fails. before_cases = [[0x00c0_0000, 0x0080_0000, 0x8080_0000, 0]] in v_mad_f32_flushes_subnormals_around_omod (emit/valu_tests.rs) returns 0x81000000 on both the RTX 4070 SUPER and WARP.

Why. The case loads v1 = 1.5·FLT_MIN, v2 = FLT_MIN and v3 = −FLT_MIN, and v_mad_f32 computes v1·v2 + v3:

  • The product 1.5·FLT_MIN·FLT_MIN ≈ 1.8e-76 underflows to 0.
  • The sum is −FLT_MIN, which is a normal number, so no flush applies.
  • OMOD mul:2 then gives −2·FLT_MIN = 0x81000000.

Both devices return the right answer for these inputs. The test's comment ("1.5 * FLT_MIN - FLT_MIN is a positive subnormal") needs src1 = 1.0, so the second input should be 0x3f80_0000, not 0x0080_0000:

-    let before_cases = [[0x00c0_0000, 0x0080_0000, 0x8080_0000, 0]];
+    let before_cases = [[0x00c0_0000, 0x3f80_0000, 0x8080_0000, 0]];

Checks with that one-line change, merged onto main ffe310e:

  • cargo test --locked -p victory-shader --lib -- v_mad passes on the RTX 4070 SUPER, and with VICTORY_WARP=1. run_cases runs both the hardware and the WARP backend.
  • The other three cases (product, input, after OMOD) passed already.

A side note on coverage. With the corrected vector, the case still passes if I remove the explicit flush before OMOD in the v_mad_f32 lowering (let r = self.flush_f32(r); after the add). Both of these hosts already flush the f32 subnormal sum themselves. So on these devices the case does not prove that this flush is needed. It guards a host that keeps f32 denormals.

AI-assisted (Claude Code). No game data.

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7144015934) ### The failing case is a test-vector typo, not a lowering bug **Correction to my earlier comment:** I wrote that `main` already has this case. That was wrong. The test is new in this PR. I had read the diff between this PR's two commits, not the diff against `main`. **What fails.** `before_cases = [[0x00c0_0000, 0x0080_0000, 0x8080_0000, 0]]` in `v_mad_f32_flushes_subnormals_around_omod` (`emit/valu_tests.rs`) returns `0x81000000` on both the RTX 4070 SUPER and WARP. **Why.** The case loads v1 = 1.5·FLT_MIN, v2 = FLT_MIN and v3 = −FLT_MIN, and `v_mad_f32` computes v1·v2 + v3: - The product 1.5·FLT_MIN·FLT_MIN ≈ 1.8e-76 underflows to 0. - The sum is −FLT_MIN, which is a normal number, so no flush applies. - OMOD mul:2 then gives −2·FLT_MIN = `0x81000000`. Both devices return the right answer for these inputs. The test's comment ("1.5 * FLT_MIN - FLT_MIN is a positive subnormal") needs src1 = 1.0, so the second input should be `0x3f80_0000`, not `0x0080_0000`: ```diff - let before_cases = [[0x00c0_0000, 0x0080_0000, 0x8080_0000, 0]]; + let before_cases = [[0x00c0_0000, 0x3f80_0000, 0x8080_0000, 0]]; ``` **Checks with that one-line change**, merged onto `main` ffe310e: - `cargo test --locked -p victory-shader --lib -- v_mad` passes on the RTX 4070 SUPER, and with `VICTORY_WARP=1`. `run_cases` runs both the hardware and the WARP backend. - The other three cases (product, input, after OMOD) passed already. **A side note on coverage.** With the corrected vector, the case still passes if I remove the explicit flush before OMOD in the `v_mad_f32` lowering (`let r = self.flush_f32(r);` after the add). Both of these hosts already flush the f32 subnormal sum themselves. So on these devices the case does not prove that this flush is needed. It guards a host that keeps f32 denormals. AI-assisted (Claude Code). No game data.
Author
Owner

@⁠tumbubu on GitHub · 2026-11-24 21:51 UTC · original

RX 7900 XT (RDNA3, driver 32.0.31036.15): green.

cbb9d2b, cargo test -p victory-shader --locked -- --test-threads=1: 122 passed, 0 failed, 1 ignored (main: 120).

  • v_mad_f32_flushes_subnormals_around_omod passes on the 7900 XT and on WARP.
  • v_mad_f32_flushes_subnormals_in_dxil ran rather than skipped, because dxc.exe sits next to the SDK's dxil.dll (10.0.26100).

AI-assisted (Claude Code); every run was on this machine.

**@⁠tumbubu** on GitHub · 2026-11-24 21:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7145487613) **RX 7900 XT (RDNA3, driver 32.0.31036.15): green.** `cbb9d2b`, `cargo test -p victory-shader --locked -- --test-threads=1`: **122 passed**, 0 failed, 1 ignored (`main`: 120). - `v_mad_f32_flushes_subnormals_around_omod` passes on the 7900 XT and on WARP. - `v_mad_f32_flushes_subnormals_in_dxil` ran rather than skipped, because `dxc.exe` sits next to the SDK's `dxil.dll` (10.0.26100). AI-assisted (Claude Code); every run was on this machine.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-24 22:20 UTC · original

Reworked on top of 70564ae as one commit (history rewritten):

  • Uses upstream's ftz helper for the operand/product/sum flushes instead of a private flush_f32 copy; v_fmac_f32 stays fused.
  • Keeps the corrected OMOD regression (1.0 as the multiplier) and the DXIL check that the flush sequence is emitted.
  • Note: upstream 77053a0 already flushes min/max/select and med3 denormals; this PR now covers only MAD/MAC.

Validation: v_mad_f32_flushes_subnormals_in_dxil passes, clippy -D warnings and cargo xtask policy (174 files) clean. The hardware regression passed on the RX 7800 XT before the rework and the inputs are unchanged.

**@⁠Calvix2k** on GitHub · 2026-11-24 22:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7146105546) Reworked on top of 70564ae as one commit (history rewritten): - Uses upstream's `ftz` helper for the operand/product/sum flushes instead of a private `flush_f32` copy; `v_fmac_f32` stays fused. - Keeps the corrected OMOD regression (`1.0` as the multiplier) and the DXIL check that the flush sequence is emitted. - Note: upstream `77053a0` already flushes min/max/select and med3 denormals; this PR now covers only MAD/MAC. Validation: `v_mad_f32_flushes_subnormals_in_dxil` passes, clippy `-D warnings` and `cargo xtask policy` (174 files) clean. The hardware regression passed on the RX 7800 XT before the rework and the inputs are unchanged.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-24 22:24 UTC · original

Hardware run of the reworked MAD/MAC flush on a Radeon RX 7800 XT (RDNA3, Windows 10 x64, Agility SDK 1.616 locally for SM 6.6):

  • v_mad_f32_flushes_subnormals_around_omod — passed on the hardware backend (all four groups: subnormal sum before mul:2, product, input, subnormal after div:2). WARP skipped at SM 6.2.
  • v_mad_f32_flushes_subnormals_in_dxil — passed.
  • clippy -D warnings and cargo xtask policy — clean.

The rework uses the shared ftz helper and touches only the MAD/MAC arms; v_fmac_f32 stays fused.

**@⁠Calvix2k** on GitHub · 2026-11-24 22:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7146183570) Hardware run of the reworked MAD/MAC flush on a Radeon RX 7800 XT (RDNA3, Windows 10 x64, Agility SDK 1.616 locally for SM 6.6): - `v_mad_f32_flushes_subnormals_around_omod` — **passed on the hardware backend** (all four groups: subnormal sum before mul:2, product, input, subnormal after div:2). WARP skipped at SM 6.2. - `v_mad_f32_flushes_subnormals_in_dxil` — passed. - clippy `-D warnings` and `cargo xtask policy` — clean. The rework uses the shared `ftz` helper and touches only the MAD/MAC arms; `v_fmac_f32` stays fused.
Author
Owner

@⁠tumbubu on GitHub · 2026-11-24 22:30 UTC · original

dce05bc on an RX 7900 XT (RDNA3): green. On this card, and on WARP, main already gives the flushed MAD results, so only the DXIL check tells the two apart.

RX 7900 XT, driver 32.0.31036.15, dxil.dll/dxc.exe 1.9.2602.17 from SDK 10.0.26100.

Run Result
dce05bc, cargo test -p victory-shader --locked -- --test-threads=1 211 passed, 0 failed, 2 ignored (main 70564ae: 209)
This PR's two tests, lowering left at 70564ae v_mad_f32_flushes_subnormals_around_omod passes on the 7900 XT and WARP. v_mad_f32_flushes_subnormals_in_dxil fails, as it should.
#1614's fuzzer on mad/mac/fma opcodes, 200 inputs, main and dce05bc the same 2 differences on both: the fused v_fma_f32/v_fmac_f32. v_mad_f32, v_mac_f32 and v_mac_legacy_f32 agree with WARP on both.

So on these two devices the hardware test passes without the change. The driver already flushes there, and the explicit flush leaves the results the same. Only ..._in_dxil fails without the change. That is no argument against the PR, since it pins behaviour that DXIL otherwise leaves to the device. But a reviewer with only AMD or WARP will not see the GPU test go red on main.

AI-assisted (Claude Code); synthetic tests only, no game files.

**@⁠tumbubu** on GitHub · 2026-11-24 22:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7146310857) **`dce05bc` on an RX 7900 XT (RDNA3): green. On this card, and on WARP, `main` already gives the flushed MAD results, so only the DXIL check tells the two apart.** RX 7900 XT, driver 32.0.31036.15, `dxil.dll`/`dxc.exe` 1.9.2602.17 from SDK 10.0.26100. | Run | Result | |---|---| | `dce05bc`, `cargo test -p victory-shader --locked -- --test-threads=1` | **211 passed**, 0 failed, 2 ignored (`main` `70564ae`: 209) | | This PR's two tests, lowering left at `70564ae` | `v_mad_f32_flushes_subnormals_around_omod` **passes** on the 7900 XT and WARP. `v_mad_f32_flushes_subnormals_in_dxil` fails, as it should. | | #1614's fuzzer on `mad`/`mac`/`fma` opcodes, 200 inputs, `main` and `dce05bc` | the same 2 differences on both: the fused `v_fma_f32`/`v_fmac_f32`. `v_mad_f32`, `v_mac_f32` and `v_mac_legacy_f32` agree with WARP on both. | So on these two devices the hardware test passes without the change. The driver already flushes there, and the explicit flush leaves the results the same. Only `..._in_dxil` fails without the change. That is no argument against the PR, since it pins behaviour that DXIL otherwise leaves to the device. But a reviewer with only AMD or WARP will not see the GPU test go red on `main`. AI-assisted (Claude Code); synthetic tests only, no game files.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:29 UTC · original · edited 2026-11-25 22:17 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/host.rs, emit/valu_tests.rs and gfx10/opcodes.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: add a fused legacy model in emit/semantics_tests.rs and use it as the hardware model for 0x140/0x06, keeping mad_legacy as ours under shows_where(FMA, ...).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7151970696) · edited 2026-11-25 22:17 UTC <!-- victory-triage v1 head=7570f939d4a573b6007b6d54e283942fb87b7b48 verdict=needs-rebase at=2026-11-25T22:19:40Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/host.rs`, `emit/valu_tests.rs` and `gfx10/opcodes.rs`). It will be reviewed again once it is rebased. From the earlier needs-work note, still open: add a fused legacy model in `emit/semantics_tests.rs` and use it as the hardware model for 0x140/0x06, keeping `mad_legacy` as `ours` under `shows_where(FMA, ...)`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 08:38 UTC · original

On the requested source, I went looking and the nearest documented statement argues against part of this change, so I want to put it here before anyone merges on my account.

The AnyPS5 shader-debt page records hardware measurements of both forms (docs/dev/debt/shader.md, entries for v_mad_legacy_f32/v_mac_legacy_f32 and for f32 denormals):

  • On gfx1010 (RDNA 1), v_mad_legacy_f32/v_mac_legacy_f32 (VOP3 0x140, VOP2 0x06) do flush their f32 denormal sources, their product and their result in every denormal mode.
  • On gfx1031 (RDNA 2, the family the console's compiler targets), the same 0x140 encoding decodes as v_fma_legacy_f32 and is fused, with the source flush only — the separate product/result flush does not apply.
  • v_mac_f32/v_mad_f32 are listed there as "not covered, and not measurable on RDNA2 (no such opcodes)".

This branch flushes sources, product and result and keeps v_mac_f32/v_mad_f32 and the legacy forms unfused (separately rounded), which matches the gfx1010 legacy behaviour but not the RDNA 2 one, and the console is RDNA 2.

So I would not land this as it stands. Two ways forward, both need a decision from the maintainers:

  1. Narrow it to the measured case: legacy forms → fused fmad (like v_fmac_f32) with source flush; leave v_mac_f32/v_mad_f32 alone since they cannot occur on RDNA 2.
  2. Keep the change but cite a measurement of the console's gfx1013/103x behaviour for the unfused forms; I could not find one, and the GPU test here passes on main too, so it is not evidence.

I will do (1) if that is the call. Thanks for pointing out the missing source — it was missing because the claim as written is not supported by the one measurement I could find.

**@⁠Calvix2k** on GitHub · 2026-11-25 08:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7157290228) On the requested source, I went looking and the nearest documented statement argues against part of this change, so I want to put it here before anyone merges on my account. The AnyPS5 shader-debt page records hardware measurements of both forms (`docs/dev/debt/shader.md`, entries for `v_mad_legacy_f32`/`v_mac_legacy_f32` and for f32 denormals): - On **gfx1010** (RDNA 1), `v_mad_legacy_f32`/`v_mac_legacy_f32` (VOP3 0x140, VOP2 0x06) *do* flush their f32 denormal sources, their product and their result in every denormal mode. - On **gfx1031** (RDNA 2, the family the console's compiler targets), the same 0x140 encoding decodes as `v_fma_legacy_f32` and is **fused**, with the *source* flush only — the separate product/result flush does not apply. - `v_mac_f32`/`v_mad_f32` are listed there as "not covered, and not measurable on RDNA2 (no such opcodes)". This branch flushes sources, product and result and keeps `v_mac_f32`/`v_mad_f32` and the legacy forms *unfused* (separately rounded), which matches the gfx1010 legacy behaviour but not the RDNA 2 one, and the console is RDNA 2. So I would not land this as it stands. Two ways forward, both need a decision from the maintainers: 1. Narrow it to the measured case: legacy forms → fused `fmad` (like `v_fmac_f32`) with source flush; leave `v_mac_f32`/`v_mad_f32` alone since they cannot occur on RDNA 2. 2. Keep the change but cite a measurement of the *console's* gfx1013/103x behaviour for the unfused forms; I could not find one, and the GPU test here passes on `main` too, so it is not evidence. I will do (1) if that is the call. Thanks for pointing out the missing source — it was missing because the claim as written is not supported by the one measurement I could find.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 08:50 UTC · original

Reworked as discussed: b634827 replaces the old flush-everything change with the form the measurement supports, and the PR title/body should now be read as the legacy encoding only.

What it does now

  • v_mad_legacy_f32 and v_mac_legacy_f32: flush their sources (inputs and the addend) and lower to one fused multiply-add (tertiary.f32), because on RDNA 2 that encoding decodes as v_fma_legacy_f32 and is fused (AnyPS5's shader-debt page, v_mad_legacy_f32/v_mac_legacy_f32 entries; gfx1031 measured there by pandather).
  • The legacy zero-factor rule is kept with the fusion: a zero factor makes the product a +0, so 0 * inf + c is c (the fused op alone would give NaN).
  • v_mac_f32/v_mad_f32 (no such opcodes on RDNA 2) and v_fmac_f32 are back to main's lowering; the branch no longer touches them, and v_madak/v_madmk are untouched.

Tests

  • GPU (legacy_mad_fuses_its_product_and_flushes_its_sources): (1 + 2^-23)(1 - 2^-23) - 1 must be the exact -2^-46 (a separate product rounds to 0), a subnormal source must read as zero, and 0 * inf + 1 must be 1. Skips here (no SM 6.6 device), runs in CI.
  • DXIL (legacy_mad_lowers_to_one_fused_op_with_flushed_sources): exactly one call float @dx.op.tertiary.f32 and three and i32 … 2139095040 flushes, using the existing emit::tests::dump_dxil (the copy is gone; I made the shared one pub(super)).

Local: both new tests pass (the DXIL one with this machine's SDK dxc.exe), clippy -D warnings clean. The rest of the suite here still shows the known 75 SM-6.6 environment failures (#1991 is not in this branch).

If the console's gfx1013 turns out to keep gfx1010's separate rounding, the old commit a602e36 is still in the history and this one can be dropped — but I would not land the separate form on the RDNA 2 measurement.

**@⁠Calvix2k** on GitHub · 2026-11-25 08:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7157540679) Reworked as discussed: `b634827` replaces the old flush-everything change with the form the measurement supports, and the PR title/body should now be read as the legacy encoding only. **What it does now** - `v_mad_legacy_f32` and `v_mac_legacy_f32`: flush their sources (inputs and the addend) and lower to **one fused** multiply-add (`tertiary.f32`), because on RDNA 2 that encoding decodes as `v_fma_legacy_f32` and is fused (AnyPS5's shader-debt page, `v_mad_legacy_f32`/`v_mac_legacy_f32` entries; gfx1031 measured there by pandather). - The legacy zero-factor rule is kept with the fusion: a zero factor makes the product a +0, so `0 * inf + c` is `c` (the fused op alone would give NaN). - `v_mac_f32`/`v_mad_f32` (no such opcodes on RDNA 2) and `v_fmac_f32` are back to `main`'s lowering; the branch no longer touches them, and `v_madak`/`v_madmk` are untouched. **Tests** - GPU (`legacy_mad_fuses_its_product_and_flushes_its_sources`): `(1 + 2^-23)(1 - 2^-23) - 1` must be the exact `-2^-46` (a separate product rounds to 0), a subnormal source must read as zero, and `0 * inf + 1` must be 1. Skips here (no SM 6.6 device), runs in CI. - DXIL (`legacy_mad_lowers_to_one_fused_op_with_flushed_sources`): exactly one `call float @dx.op.tertiary.f32` and three `and i32 … 2139095040` flushes, using the existing `emit::tests::dump_dxil` (the copy is gone; I made the shared one `pub(super)`). Local: both new tests pass (the DXIL one with this machine's SDK `dxc.exe`), `clippy -D warnings` clean. The rest of the suite here still shows the known 75 SM-6.6 environment failures (#1991 is not in this branch). If the console's gfx1013 turns out to keep gfx1010's separate rounding, the old commit `a602e36` is still in the history and this one can be dropped — but I would not land the separate form on the RDNA 2 measurement.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 10:09 UTC · original

Hardware result on an RX 7800 XT (RDNA3), Windows 10 19045, with SM 6.6 through the Agility runtime staged for the test binaries (#486's opt-in): the fused legacy mad runs as the measurement says.

  • legacy_mad_fuses_its_product_and_flushes_its_sources passes: (1 + 2^-23) * (1 - 2^-23) - 1 is the exact -2^-46 (0xA8800000), a subnormal source reads as zero, and 0 * inf + 1 is 1.
  • The unfused lowering gives 0 for the first case on the same hardware, so the test now separates fused from separate on the card and not only in the DXIL.

One correction to my own test in f5bb6d0: it wrote the pair as (1 + 2^-23) * (1 - 2^-24) — 0x3F7F_FFFF is one ulp below 1.0, not 1 - 2^-23 — and asserted the exact -2^-46; on the hardware run it failed with the value that pair actually gives. 0x3F7F_FFFE is the intended 1 - 2^-23. With that, the GPU case is green here.

**@⁠Calvix2k** on GitHub · 2026-11-25 10:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7159313223) Hardware result on an **RX 7800 XT (RDNA3), Windows 10 19045**, with SM 6.6 through the Agility runtime staged for the test binaries (#486's opt-in): the fused legacy mad runs as the measurement says. - `legacy_mad_fuses_its_product_and_flushes_its_sources` passes: `(1 + 2^-23) * (1 - 2^-23) - 1` is the exact `-2^-46` (`0xA8800000`), a subnormal source reads as zero, and `0 * inf + 1` is 1. - The unfused lowering gives `0` for the first case on the same hardware, so the test now separates fused from separate on the card and not only in the DXIL. One correction to my own test in `f5bb6d0`: it wrote the pair as `(1 + 2^-23) * (1 - 2^-24)` — `0x3F7F_FFFF` is one ulp below 1.0, not `1 - 2^-23` — and asserted the exact `-2^-46`; on the hardware run it failed with the value that pair actually gives. `0x3F7F_FFFE` is the intended `1 - 2^-23`. With that, the GPU case is green here.
Author
Owner

@⁠KainanP on GitHub · 2026-11-25 12:30 UTC · original

On an Intel UHD (Xe-LP 8086:a78b, driver 31.0.101.5445), head f5bb6d02 merged onto main 940d32f gives victory-shader --lib 240 passed, 9 failed. That is one more failure than main's 8: legacy_mad_fuses_its_product_and_flushes_its_sources fails with hardware: case 0, left 0, right 2826960896 (0xA8800000). On the same device hosts_that_do_not_fuse_are_named reports fuses FMad: true. The test passes on an RTX 4060 Laptop. Details: #1829

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

**@⁠KainanP** on GitHub · 2026-11-25 12:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7162472170) On an Intel UHD (Xe-LP `8086:a78b`, driver 31.0.101.5445), head `f5bb6d02` merged onto `main` `940d32f` gives `victory-shader --lib` 240 passed, 9 failed. That is one more failure than `main`'s 8: `legacy_mad_fuses_its_product_and_flushes_its_sources` fails with `hardware: case 0`, left `0`, right `2826960896` (`0xA8800000`). On the same device `hosts_that_do_not_fuse_are_named` reports `fuses FMad: true`. The test passes on an RTX 4060 Laptop. Details: https://git.gtahub.st/github/Marvisak--VIctory/issues/1829 _AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this._
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 16:41 UTC · original

That Xe-LP run is the reason the probe changed, so thank you for it.

The lowering was already one tertiary.f32 per legacy MAD/MAC (the DXIL test asserts one call and three flushes), so the 0 is not the fusion being lowered away: the device reports fuses FMad: true through the old probe ((1 - 2^-24)(1 + 2^-23) - 1 = 2^-24 - 2^-47) and then returns 0 for (1 + 2^-23)(1 - 2^-23) - 1, which is -2^-46 with one rounding and 0 when the product is rounded first. So the old probe was too weak for this case.

fuses_fmad now runs exactly the legacy case, and legacy_mad_fuses_its_product_and_flushes_its_sources skips case 0 on a device whose probe says it does not fuse (as it already did on WARP) instead of failing. The other two cases are device-independent and still run. If you rerun on the Xe-LP, the expected output is the skip line for case 0 and a pass for the rest.

The rest of the triage is in 7570f93: the opcodes are named v_fma_legacy_f32 (0x140) / v_fmac_legacy_f32 (0x06) after LLVM's GFX10.3 tables, the citation is that table instead of a project page, the title/body match what the branch does (legacy fused + flushed, v_mad_f32/v_mac_f32 unchanged), and valu_tests.rs ends with a newline.

**@⁠Calvix2k** on GitHub · 2026-11-25 16:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7168382419) That Xe-LP run is the reason the probe changed, so thank you for it. The lowering was already one `tertiary.f32` per legacy MAD/MAC (the DXIL test asserts one call and three flushes), so the 0 is not the fusion being lowered away: the device reports `fuses FMad: true` through the old probe ((1 - 2^-24)(1 + 2^-23) - 1 = 2^-24 - 2^-47) and then returns 0 for (1 + 2^-23)(1 - 2^-23) - 1, which is -2^-46 with one rounding and 0 when the product is rounded first. So the old probe was too weak for this case. `fuses_fmad` now runs exactly the legacy case, and `legacy_mad_fuses_its_product_and_flushes_its_sources` skips case 0 on a device whose probe says it does not fuse (as it already did on WARP) instead of failing. The other two cases are device-independent and still run. If you rerun on the Xe-LP, the expected output is the skip line for case 0 and a pass for the rest. The rest of the triage is in `7570f93`: the opcodes are named `v_fma_legacy_f32` (0x140) / `v_fmac_legacy_f32` (0x06) after LLVM's GFX10.3 tables, the citation is that table instead of a project page, the title/body match what the branch does (legacy fused + flushed, `v_mad_f32`/`v_mac_f32` unchanged), and `valu_tests.rs` ends with a newline.
github-bot force-pushed github-bot/gh-1554 from 7570f939d4 to aee0d472f8 2026-11-26 13:59:26 +00:00 Compare
Author
Owner

@⁠catminou4 on GitHub · 2026-11-24 19:20 UTC · original · approved these changes

Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96. Execution/valu tests are #[cfg(all(test, windows))] and were not run here.

RDNA MAD/MAC flush binary32 subnormals: flush_f32 keeps only the sign bit when the exponent is zero, applied to inputs, the product, the accumulator and the result for v_mac_f32/v_mac_legacy_f32 (and after OMOD via write_f_with_ftz), while v_fmac_f32 keeps fused semantics. The valu test pins four hardware-observed cases around OMOD (subnormal product/input flushed before mul:2, subnormal after OMOD:div:2 cleared). Windows-only execution; 96 passed on macOS.

**@⁠catminou4** on GitHub · 2026-11-24 19:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/1554#pullrequestreview-6045809911) · **approved these changes** Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), `cargo test -p victory-shader --locked` → 96. Execution/valu tests are `#[cfg(all(test, windows))]` and were not run here. RDNA MAD/MAC flush binary32 subnormals: `flush_f32` keeps only the sign bit when the exponent is zero, applied to inputs, the product, the accumulator and the result for `v_mac_f32`/`v_mac_legacy_f32` (and after OMOD via `write_f_with_ftz`), while `v_fmac_f32` keeps fused semantics. The valu test pins four hardware-observed cases around OMOD (subnormal product/input flushed before mul:2, subnormal after OMOD:div:2 cleared). Windows-only execution; 96 passed on macOS.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1554/head:github-bot/gh-1554'
git switch 'github-bot/gh-1554'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1554'
git switch 'github-bot/gh-1554'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1554'
git switch 'github-bot/gh-1554'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1554'
git switch 'main'
git merge --squash 'github-bot/gh-1554'
git switch 'main'
git merge --ff-only 'github-bot/gh-1554'
git switch 'main'
git merge 'github-bot/gh-1554'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1554
No description provided.