Repository navigation
Conversation
The opcode tables come from Mesa's GFX10 column, which shares opcode numbers between GFX10.1 and GFX10.3 and keeps the older names: VOP2 0x006 and VOP3 0x140 were v_mac_legacy_f32 and v_mad_legacy_f32. On GFX10.3 (RDNA2) those opcodes are v_fmac_legacy_f32 and v_fma_legacy_f32, fused multiply-adds with the D3D9 rule that a zero factor gives a zero product (AMD's RDNA2 ISA; LLVM's gfx1030 tables and assembler tests). They were lowered as a multiply rounded on its own, then an add. Both are now named for RDNA2 and lowered as one FMad (the driver may fuse it, as for v_fma_f32), unless a factor is zero, when the result is the addend.
|
Tested PR #284 at head
Behavior covered: Checks legacy multiply-add lowering follows fused RDNA2/D3D9 behavior, including the signed-zero case. |
|
Ran
The test checks only the zero rule, so I also ran the rounding example from the description (
So NVIDIA's driver contracts the |
|
RDNA2 hardware measurement of both claims, on GFX10.3 silicon: Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (GFX10.3 / RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr, which accepts both mnemonics for gfx1036) runs
Model fit over all 2035 triples, for both opcodes:
So the GFX10.3 names and the fused lowering in this PR match the hardware. A zero factor makes the product +0: AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run. |
|
A follow-up on the GFX10.1-vs-GFX10.3 naming this PR fixes for Two checks on the gfx1036 iGPU from my comment above:
If the console is GFX10.3, as the ray-tracing opcodes suggest, its compiler can't emit these five, so translating them as mads is harmless but wrong as a model. Refusing them, or naming them as not implemented, would match the hardware. I didn't touch the table myself, since this PR is already reworking those two names. AI use: Claude Code (Claude Opus 5.5) ran the probes on the GPU above and drafted this comment; the numbers come from the hardware run. |
|
One more RDNA2 rule for these two opcodes, which the fused lowering here doesn't have yet: Same gfx1036 setup as above. The 2035 triples from my first comment plus 15 with denormal operands or a denormal exact result, run under both f32 denormal modes:
Examples in mode 3 (denormals kept):
What it does end to end: I ran a differential check of the translator against the hardware (the same raw VOP3 words through AI use: Claude Code (Claude Opus 5.5) ran the probes and the differential check on the GPUs above and drafted this comment; the numbers come from those runs. |
|
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4) and the Ryzen 9600X iGPU (RDNA2, gfx1036), each picked as the D3D12 device for
|
mercuryVM
left a comment
There was a problem hiding this comment.
Tested fa5189d on Windows 11, RTX 5070, MSVC: the workspace passes (195 outside victory-shader; victory-shader --lib single-threaded: 71, including v_fma_legacy_f32_follows_the_d3d9_zero_rule on hardware and WARP, and the decode test). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines.
- On GFX10.3, VOP2 6 is
V_FMAC_LEGACY_F32and VOP3 0x140 isV_FMA_LEGACY_F32, as the RDNA2 ISA and LLVM's gfx1030 tables say. The decode test uses LLVM's own encodings, which settles it. fma_legacykeeps the D3D9 rule (either factor exactly ±0, so the product is 0, even against inf or NaN), and0 + addendgives the IEEE sign of the sum. The fused path goes throughfmad, the same "driver may fuse" shortcutv_fma_f32already uses, which the comment notes.v_mad_f32/v_madak/v_madmkno longer share the arm with the legacy op, so they don't pick up the zero rule.
No issues found.
AI-assisted (Claude Code).
… are the fused ones Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Where a fork-only change duplicates upstream's own version of a feature, upstream's is kept and the fork's dropped: - victory-shader is upstream's crate with the fork-only merges replayed onto it oldest first; those that do not apply onto upstream are dropped (37 of 63: among them Marvisak#704/raw views, gather4_l, the lane-mask and Marvisak#308 ports, Marvisak#947, Marvisak#1022, Marvisak#1112, Marvisak#1090, Marvisak#1182). Marvisak#284 (legacy fused madds) and Marvisak#98 (permlane16 in whole-wave sections) are dropped too: the first disagrees with upstream's hardware-checked model, the second refused 46 programs upstream translates. - translate: upstream's --cache replaces Marvisak#254's write-cache and work queue; Marvisak#378, Marvisak#517, Marvisak#673 and the victory.toml console are re-applied. - victory-gpu: upstream's stride table, page table and heap views replace the fork's Marvisak#704/stride-table wiring; fork-only fixes re-applied on top. Package (shaders.rpf, translate --validate --list, counts): vertex/pixel emitted 12559 -> 14295 of 14337, compute 2359 -> 2628 validated, mesh 2730 -> 2811 validated. Tests: the failures left (rect fourth corner, two stride tests, row order, gather4 at a level, memory table, dynamic heap slots) fail on upstream main as well on this host. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Needs rebase. This PR no longer merges cleanly into From the earlier needs-work note, still open: model 0x06/0x140 as fused legacy in Generated by Claude Code |
…fused ones) into the integration Our div_scale/div_fmas/div_fixup arms stay before the renamed multiply-add arm. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
|
Test commit for the triage's point 3 (and rows for point 2):
RTX 3070, driver 616.56, Windows 11:
So the fusion test fails on main and passes on the PR. The denormal rows pass on both here, because the RTX 3070 and WARP flush f32 denormals in this shader themselves. They don't show point 2 on NVIDIA; they would only catch a missing flush on a host that keeps denormals (as in Lyrnc's AMD-host differential run). Point 1 ( AI-assisted (Claude Code, Claude Opus 5.5). |
What's wrong
The opcode tables in
gfx10/opcodes.rsare generated from the GFX10 column of Mesa'saco_opcodes.py. That column shares opcode numbers between GFX10.1 and GFX10.3 (RDNA2), and for two of them it keeps the GFX10.1 name:0x006(and VOP30x106)v_mac_legacy_f32v_fmac_legacy_f320x140v_mad_legacy_f32v_fma_legacy_f32On RDNA2 these are fused multiply-adds: the product isn't rounded before the add. They keep the D3D9 rule that a zero factor gives a zero product, even against infinity or NaN. References:
V_FMAC_LEGACY_F32as VOP2 6 andV_FMA_LEGACY_F32as VOP3 320.V_FMAC_LEGACY_F32 : VOP2_Real_gfx10<0x006>andV_FMA_LEGACY_F32 : VOP3_Real_gfx10<0x140>. Its gfx1030 assembler tests (gfx1030_new.s) encodev_fma_legacy_f32 v0, v1, v2, v3as00 00 40 d5 01 05 0e 04andv_fmac_legacy_f32_e32 v0, v1, v2as01 05 00 0c, andllvm-mc -mcpu=gfx1030has nov_mad_f32there at all.v_mad_legacy_f32is replaced byv_fma_legacy_f32on GFX10.3.The decoder already treats the console as GFX10.3: it handles GFX10.3's ray-tracing instructions (
image_bvh_intersect_ray).lower.rslowered the GFX10.1 forms: a legacy multiply (rounded) followed by a separate add. That gives a result rounded twice, and theselectaround the multiply also stops the driver from contracting the two. For example,v1 = v2 = 0x3F800001andv3 = 0xBF800002give0x28800000(2⁻⁴⁶) fused on RDNA2, and0with the multiply rounded first.What the fix does
opcodes.rsnames the two opcodes as RDNA2 does:v_fmac_legacy_f32andv_fma_legacy_f32.lower.rslowers both with a new helper,fma_legacy(a, b, c):c(as0.0 + c) whenaorbis ±0, otherwise oneFMad(a, b, c). This is the same "the driver may fuse it" shortcut thatv_fma_f32andv_fmac_f32already use, since DXIL has no fused f32 FMA.v_mad_f32/v_madak_f32/v_madmk_f32arm stays as it was, minus the legacy name.How it behaves after the fix
Shaders using these opcodes translate as fused multiply-adds with the D3D9 zero rule, on hosts whose driver fuses
FMad. Their results are then RDNA2's, bit for bit. A host that doesn't fuseFMadrounds twice, as it already does forv_fma_f32. I measured that on GitHub's runner: both its WARP device and its hardware device return0for the example above, with or without this change.Tests
legacy_multiply_adds_are_the_fused_ones(gfx10/mod.rs) decodes LLVM's two gfx1030 encodings above and checks the names.v_fma_legacy_f32_follows_the_d3d9_zero_rule(valu_tests.rs) runsv_fma_legacy_f32(VOP30x140) on the host GPU and on WARP, with three cases:2 × 3 + 1 = 7;0 × ∞ + 1.5 = 1.5;NaN × 0 − 2 = −2.I ran
cargo test --workspaceon GitHub'swindows-latestwith Rust 1.98.1 fromrust-toolchain.toml:victory-shaderhas 71 passed, the other crates have 0 failed.main: the decoder test fails:left: "v_mad_legacy_f32",right: "v_fma_legacy_f32". The zero-rule test passes onmaintoo, since the old lowering also kept that rule.--test-threads=1. With 4 threads, the shader crate's GPU tests sometimes crash on that runner (Tests: victory-shader tests crash (0xC0000005) when several tests use WARP devices in parallel #181, Shaders: share and serialize WARP host operations across threads #244).Not tested: a GPU that fuses
FMad, so the fused rounding itself isn't shown by a test here, and a title shader that uses these opcodes.Related: #200 adds match arms next to the ones this edits in
lower.rs. Whichever merges second needs a trivial rebase.