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

Open
Calvix2k wants to merge 5 commits from upstream-pr/1554 into main
Calvix2k commented 2026-11-24 19:06:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T19:06:29Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5478556620 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T19:06:29Z. --- ## 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.
catminou4 commented 2026-11-24 19:20:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:20:51Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6045809911 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#pullrequestreview-6045809911). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T19:20:51Z. **Review:** APPROVED --- 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.
matheusfermiano-source commented 2026-11-24 20:03:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by matheusfermiano-source on 2026-11-24T19:16:09Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7141849049 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7141849049). Originally posted by [matheusfermiano-source](https://github.com/matheusfermiano-source) on 2026-11-24T19:16:09Z. --- 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.
shortselow-byte commented 2026-11-24 20:03:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-24T19:32:03Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142234723 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7142234723). Originally posted by [shortselow-byte](https://github.com/shortselow-byte) on 2026-11-24T19:32:03Z. --- 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.
geiyiliyabumo commented 2026-11-24 20:03:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T19:40:40Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142434470 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7142434470). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T19:40:40Z. --- 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.*
Calvix2k commented 2026-11-24 21:03:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T20:25:27Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143526605 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7143526605). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T20:25:27Z. --- 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 commented 2026-11-24 21:03:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T20:26:40Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143555550 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7143555550). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T20:26:40Z. --- 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 commented 2026-11-24 21:03:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T20:31:43Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143683755 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7143683755). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T20:31:43Z. --- 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.
sinan-cmyk commented 2026-11-24 21:03:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:14:20Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143234962 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7143234962). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:14:20Z. --- ### 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 commented 2026-11-24 21:03:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:45:29Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144015934 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7144015934). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:45:29Z. --- ### 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.
tumbubu commented 2026-11-24 22:02:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tumbubu on 2026-11-24T21:51:48Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145487613 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7145487613). Originally posted by [tumbubu](https://github.com/tumbubu) on 2026-11-24T21:51:48Z. --- **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.
Calvix2k commented 2026-11-24 23:05:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T22:20:18Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146105546 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7146105546). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T22:20:18Z. --- 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 commented 2026-11-24 23:05:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T22:24:06Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146183570 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7146183570). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T22:24:06Z. --- 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.
tumbubu commented 2026-11-24 23:05:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tumbubu on 2026-11-24T22:30:24Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146310857 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7146310857). Originally posted by [tumbubu](https://github.com/tumbubu) on 2026-11-24T22:30:24Z. --- **`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.
Marvisak commented 2026-11-25 04:06:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:29:57Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151970696 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7151970696). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:29:57Z. --- <!-- 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)_
Calvix2k commented 2026-11-25 09:06:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T08:38:33Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7157290228 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7157290228). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T08:38:33Z. --- 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 commented 2026-11-25 09:06:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T08:50:37Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7157540679 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7157540679). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T08:50:37Z. --- 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 commented 2026-11-25 11:05:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T10:09:54Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159313223 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7159313223). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T10:09:54Z. --- 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.
KainanP commented 2026-11-25 13:02:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-25T12:30:41Z.


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://github.com/Marvisak/VIctory/issues/1829#issuecomment-7162467900

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7162472170 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7162472170). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-25T12:30:41Z. --- 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://github.com/Marvisak/VIctory/issues/1829#issuecomment-7162467900 _AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this._
upstream-sync changed title from [PR #1554] Shaders: flush subnormals in f32 MAD and MAC to [PR #1554] Shaders: the legacy MAD/MAC encodings are one fused multiply-add with flushed sources 2026-11-25 17:02:45 +00:00
Calvix2k commented 2026-11-25 17:05:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T16:41:29Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7168382419 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7168382419). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T16:41:29Z. --- 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.
ColorMeBoom commented 2026-11-27 02:01:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T02:01:58Z.


RDNA1 run (AMD RX 5700 XT, Navi 10, driver 32.0.21045.29003, Windows 11 26200; from the batch in #3410). Head aee0d47 merged onto main 63bcca4. Three findings:

1. Two of the new tests don't run at this head. Since f339de8, v_mad_f32_flushes_subnormals_around_omod and legacy_mad_fuses_its_product_and_flushes_its_sources have no #[test]. The first also stops after defining its inputs: the four run_cases calls from 8a3d629 are gone. That is CI's check failure (8 unused/never-used errors under clippy -D warnings). For the runs below, I restored both attributes and the four calls from 8a3d629 unchanged.

2. On the RX 5700 XT, arithmetic_matches_the_hardware fails for the legacy FMA/FMAC with the new lowering, on the hardware adapter only. It passes on main.

v_mov_b32 v5, v3; v_fmac_legacy_f32 v5, v1, v2: 14440 inputs, model mismatches ["hardware 420", "warp 0"]
  hardware: in [00000000, 00000000, 80000000, 0badf00d] want [00000000] got [80000000]
v_fma_legacy_f32 v5, v1, v2, v3: 14440 inputs, model mismatches ["hardware 420", "warp 0"]

A zero factor with a -0 addend should give +0 + -0 = +0, but the card returns -0. legacy_fmad builds that branch as fadd(0.0, c) with a constant +0.0. The AMD driver appears to fold this to c, a fold that ignores signed zeros, and WARP doesn't fold it. Zeroing the factors with select and keeping the single tertiary.f32 leaves the driver no constant add to fold:

     fn legacy_fmad(&mut self, a: V, b: V, c: V) -> V {
         let cur = self.cur;
-        let fused = self.fmad(a, b, c);
         let zero = self.s.m.f32(0);
         let az = self.s.m.cmp(cur, pred::OEQ, a, zero);
         let bz = self.s.m.cmp(cur, pred::OEQ, b, zero);
         let z = self.s.m.bin(cur, Bin::Or, az, bz);
-        // +0 + c, so the sign of a zero addend follows the addition.
-        let addend = self.s.m.bin(cur, Bin::Add, zero, c);
-        self.s.m.select(cur, z, addend, fused)
+        // A zero factor zeroes both, so the product is +0 * +0 and the add
+        // happens at run time: no constant `0.0 + c` for a driver to fold.
+        let a = self.s.m.select(cur, z, zero, a);
+        let b = self.s.m.select(cur, z, zero, b);
+        self.fmad(a, b, c)
     }

With this change and the restored tests, the full victory-shader --lib suite passes on the RX 5700 XT and WARP: 305 passed, 0 failed, 3 ignored. Clippy -D warnings is clean. Both restored tests pass with either lowering. I haven't run the change on another vendor.

3. RDNA1 does not fuse FMad here. With the restored tests, fuses_fmad() reports false on the RX 5700 XT, so legacy_mad_fuses_its_product_and_flushes_its_sources skips case 0 on hardware, as it does on WARP and the Xe-LP. The other two cases pass. So on this card the legacy forms aren't fused, even with one tertiary.f32.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7207774213 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7207774213). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T02:01:58Z. --- **RDNA1 run** (AMD RX 5700 XT, Navi 10, driver 32.0.21045.29003, Windows 11 26200; from the batch in #3410). Head `aee0d47` merged onto main `63bcca4`. Three findings: **1. Two of the new tests don't run at this head.** Since `f339de8`, `v_mad_f32_flushes_subnormals_around_omod` and `legacy_mad_fuses_its_product_and_flushes_its_sources` have no `#[test]`. The first also stops after defining its inputs: the four `run_cases` calls from `8a3d629` are gone. That is CI's `check` failure (8 unused/never-used errors under clippy `-D warnings`). For the runs below, I restored both attributes and the four calls from `8a3d629` unchanged. **2. On the RX 5700 XT, `arithmetic_matches_the_hardware` fails for the legacy FMA/FMAC with the new lowering, on the hardware adapter only.** It passes on main. ``` v_mov_b32 v5, v3; v_fmac_legacy_f32 v5, v1, v2: 14440 inputs, model mismatches ["hardware 420", "warp 0"] hardware: in [00000000, 00000000, 80000000, 0badf00d] want [00000000] got [80000000] v_fma_legacy_f32 v5, v1, v2, v3: 14440 inputs, model mismatches ["hardware 420", "warp 0"] ``` A zero factor with a `-0` addend should give `+0 + -0 = +0`, but the card returns `-0`. `legacy_fmad` builds that branch as `fadd(0.0, c)` with a constant `+0.0`. The AMD driver appears to fold this to `c`, a fold that ignores signed zeros, and WARP doesn't fold it. Zeroing the factors with `select` and keeping the single `tertiary.f32` leaves the driver no constant add to fold: ```diff fn legacy_fmad(&mut self, a: V, b: V, c: V) -> V { let cur = self.cur; - let fused = self.fmad(a, b, c); let zero = self.s.m.f32(0); let az = self.s.m.cmp(cur, pred::OEQ, a, zero); let bz = self.s.m.cmp(cur, pred::OEQ, b, zero); let z = self.s.m.bin(cur, Bin::Or, az, bz); - // +0 + c, so the sign of a zero addend follows the addition. - let addend = self.s.m.bin(cur, Bin::Add, zero, c); - self.s.m.select(cur, z, addend, fused) + // A zero factor zeroes both, so the product is +0 * +0 and the add + // happens at run time: no constant `0.0 + c` for a driver to fold. + let a = self.s.m.select(cur, z, zero, a); + let b = self.s.m.select(cur, z, zero, b); + self.fmad(a, b, c) } ``` With this change and the restored tests, the full `victory-shader --lib` suite passes on the RX 5700 XT and WARP: 305 passed, 0 failed, 3 ignored. Clippy `-D warnings` is clean. Both restored tests pass with either lowering. I haven't run the change on another vendor. **3. RDNA1 does not fuse `FMad` here.** With the restored tests, `fuses_fmad()` reports false on the RX 5700 XT, so `legacy_mad_fuses_its_product_and_flushes_its_sources` skips case 0 on hardware, as it does on WARP and the Xe-LP. The other two cases pass. So on this card the legacy forms aren't fused, even with one `tertiary.f32`. AI use: Claude Code (Claude Opus 5.5).
andrewpozdnakov7-jpg commented 2026-11-27 08:34:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T08:34:47Z.


Thanks @ColorMeBoom for the RX 5700 XT run and the factor-select fix. 1f86690 applies it directly to aee0d47 and credits your contribution.

I restored the legacy GPU test for both FMA and FMAC, including positive and negative zero factors with a negative-zero addend. I removed the incomplete non-legacy OMOD fixture left by the earlier scope change. The DXIL test now also checks that zero products go through the multiply-add. It found one standalone fadd on aee0d47 and zero with the fix, while both versions emit one tertiary.f32.

On app-local WARP 1.0.22 the two legacy tests passed, and the arithmetic matrix had zero mismatches across 14,440 inputs per legacy instruction. The focused fusion-only case skipped on this runtime by design. The full shader suite had 299 passes, 3 ignored and the same five pre-existing failures as the local reference. Strict shader Clippy and asset policy passed.

@Calvix2k the commit is ready to cherry-pick. Please retain the Git author and ColorMeBoom's co-author trailer. If folding it in, please also add:

Co-authored-by: andrewpozdnakov7-jpg [email protected]

If you have another RX 5700 XT slot, a rerun of arithmetic_matches_the_hardware on this exact commit would confirm the final version on that driver. AI-assisted with Codex. Synthetic shaders only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7213688693 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7213688693). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T08:34:47Z. --- Thanks @ColorMeBoom for the RX 5700 XT run and the factor-select fix. [1f86690](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/1f86690e908036096f8ae29c6591134b7370551c) applies it directly to `aee0d47` and credits your contribution. I restored the legacy GPU test for both FMA and FMAC, including positive and negative zero factors with a negative-zero addend. I removed the incomplete non-legacy OMOD fixture left by the earlier scope change. The DXIL test now also checks that zero products go through the multiply-add. It found one standalone `fadd` on `aee0d47` and zero with the fix, while both versions emit one `tertiary.f32`. On app-local WARP 1.0.22 the two legacy tests passed, and the arithmetic matrix had zero mismatches across 14,440 inputs per legacy instruction. The focused fusion-only case skipped on this runtime by design. The full shader suite had 299 passes, 3 ignored and the same five pre-existing failures as the local reference. Strict shader Clippy and asset policy passed. @Calvix2k the commit is ready to cherry-pick. Please retain the Git author and ColorMeBoom's co-author trailer. If folding it in, please also add: Co-authored-by: andrewpozdnakov7-jpg <[email protected]> If you have another RX 5700 XT slot, a rerun of `arithmetic_matches_the_hardware` on this exact commit would confirm the final version on that driver. AI-assisted with Codex. Synthetic shaders only.
ColorMeBoom commented 2026-11-27 10:34:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T10:34:46Z.


@andrewpozdnakov7-jpg Reran on the RX 5700 XT (Navi 10, driver 32.0.21045.29003, Windows 11 26200): your 1f86690 merged onto main 63bcca4, against the hardware adapter and WARP.

  • arithmetic_matches_the_hardware passes. The two legacy rows that showed the signed-zero fold before are clean:
    v_mov_b32 v5, v3; v_fmac_legacy_f32 v5, v1, v2: 14440 inputs, model mismatches ["hardware 0", "warp 0"], hardware/warp differ on 0
    v_fma_legacy_f32 v5, v1, v2, v3: 14440 inputs, model mismatches ["hardware 0", "warp 0"], hardware/warp differ on 0
    
    On aee0d47 they were hardware 420. Every other row in the matrix is 0/0 too, including the clamp and OMOD variants.
  • legacy_mad_fuses_its_product_and_flushes_its_sources and legacy_mad_lowers_to_one_fused_op_with_flushed_sources pass. The fusing case still skips on this card ("the device rounds the product before the add"), as before.
  • Full victory-shader --lib: 304 passed, 0 failed, 3 ignored. cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7216054968 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7216054968). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T10:34:46Z. --- @andrewpozdnakov7-jpg Reran on the RX 5700 XT (Navi 10, driver 32.0.21045.29003, Windows 11 26200): your `1f86690` merged onto `main` `63bcca4`, against the hardware adapter and WARP. - `arithmetic_matches_the_hardware` passes. The two legacy rows that showed the signed-zero fold before are clean: ``` v_mov_b32 v5, v3; v_fmac_legacy_f32 v5, v1, v2: 14440 inputs, model mismatches ["hardware 0", "warp 0"], hardware/warp differ on 0 v_fma_legacy_f32 v5, v1, v2, v3: 14440 inputs, model mismatches ["hardware 0", "warp 0"], hardware/warp differ on 0 ``` On `aee0d47` they were `hardware 420`. Every other row in the matrix is 0/0 too, including the clamp and OMOD variants. - `legacy_mad_fuses_its_product_and_flushes_its_sources` and `legacy_mad_lowers_to_one_fused_op_with_flushed_sources` pass. The fusing case still skips on this card ("the device rounds the product before the add"), as before. - Full `victory-shader --lib`: 304 passed, 0 failed, 3 ignored. `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean. AI use: Claude Code (Claude Opus 5.5).
andrewpozdnakov7-jpg commented 2026-11-27 14:34:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T14:34:50Z.


I checked #1554 together with #3221 on 63bcca4. Combined branch 1a96aa6 retains both PR histories, Moon0755's 19-cell test and the signed-zero fix from the RX 5700 XT follow-up.

The added WARP test reads back two results for each of seven rows of v_fma_legacy_f32: div:2 and div:2 clamp. On the #1554 branch with 1f86690, three rows returned 00000000 instead of 80000000 before clamp. One of those rows uses the legacy -0 × inf + (-FLT_MIN) rule. The combined branch matches all 14 words: the underflow retains its sign before clamp, and clamp gives positive zero for those rows.

On app-local WARP 1.0.22 with DXIL validation, the full shader suite went from 300 passed, 5 failed, 3 ignored to 303 passed, 4 failed, 3 ignored. The four remaining failures were the same gather, two permute and edge-flagged-triangle tests. The arithmetic matrix, strict shader Clippy and asset policy passed. The new seven-row test was run on WARP here; the physical RX 5700 XT result above covers the earlier 1f86690 branch.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7220963027 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7220963027). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T14:34:50Z. --- I checked #1554 together with #3221 on `63bcca4`. [Combined branch `1a96aa6`](https://github.com/andrewpozdnakov7-jpg/VIctory/tree/review/legacy-fma-and-fp32-div2) retains both PR histories, Moon0755's 19-cell test and the signed-zero fix from the RX 5700 XT follow-up. The added WARP test reads back two results for each of seven rows of `v_fma_legacy_f32`: `div:2` and `div:2 clamp`. On the #1554 branch with `1f86690`, three rows returned `00000000` instead of `80000000` before clamp. One of those rows uses the legacy `-0 × inf + (-FLT_MIN)` rule. The combined branch matches all 14 words: the underflow retains its sign before clamp, and clamp gives positive zero for those rows. On app-local WARP 1.0.22 with DXIL validation, the full shader suite went from 300 passed, 5 failed, 3 ignored to 303 passed, 4 failed, 3 ignored. The four remaining failures were the same gather, two permute and edge-flagged-triangle tests. The arithmetic matrix, strict shader Clippy and asset policy passed. The new seven-row test was run on WARP here; the physical RX 5700 XT result above covers the earlier `1f86690` branch.
ColorMeBoom commented 2026-11-27 23:06:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T23:06:29Z.


@andrewpozdnakov7-jpg Ran your combined branch 1a96aa6 on the RX 5700 XT (Navi 10, driver 32.0.21045.29003, Windows 11 26200), against the hardware adapter and WARP, to cover the new seven-row test on hardware:

  • legacy_fma_div2_preserves_underflow_sign_before_clamp passes, and all 14 words match on the card:
    v_fma_legacy_f32 v5, v1, v2, v3 div:2; v_fma_legacy_f32 v6, v1, v2, v3 div:2 clamp: 7 inputs, model mismatches ["hardware 0", "warp 0"], hardware/warp differ on 0
    
  • Full victory-shader --lib --features host: 307 passed, 0 failed, 3 ignored.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7229876905 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1554#issuecomment-7229876905). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T23:06:29Z. --- @andrewpozdnakov7-jpg Ran your combined branch `1a96aa6` on the RX 5700 XT (Navi 10, driver 32.0.21045.29003, Windows 11 26200), against the hardware adapter and WARP, to cover the new seven-row test on hardware: - `legacy_fma_div2_preserves_underflow_sign_before_clamp` passes, and all 14 words match on the card: ``` v_fma_legacy_f32 v5, v1, v2, v3 div:2; v_fma_legacy_f32 v6, v1, v2, v3 div:2 clamp: 7 inputs, model mismatches ["hardware 0", "warp 0"], hardware/warp differ on 0 ``` - Full `victory-shader --lib --features host`: 307 passed, 0 failed, 3 ignored. AI use: Claude Code (Claude Opus 5.5).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1554:upstream-pr/1554'
git switch 'upstream-pr/1554'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/1554'
git switch 'upstream-pr/1554'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1554'
git switch 'upstream-pr/1554'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1554'
git switch 'main'
git merge --squash 'upstream-pr/1554'
git switch 'main'
git merge --ff-only 'upstream-pr/1554'
git switch 'main'
git merge 'upstream-pr/1554'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1553
No description provided.