shader: VOP3 0x140 and VOP2 0x006 are RDNA2's fused legacy multiply-adds (#321) #323
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/323"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T11:31:19Z.
What this changes
Refs #321
VOP3 0x140 and VOP2 0x006 were named and lowered as GFX10.1's
v_mad_legacy_f32andv_mac_legacy_f32(legacy product, rounded, then the add). On GFX10.3 (RDNA2) the same encodings arev_fma_legacy_f32andv_fmac_legacy_f32, one rounding:llvm-mc -mcpu=gfx1030assemblesv_fma_legacy_f32to the bytes gfx1010 givesv_mad_legacy_f32and refuses the latter; gfx1010 and gfx1013 do the opposite.gfx10/opcodes.rs: the two names.emit/lower.rs:legacy_fmamakes both factors 0 where either is 0 (DX9's rule: a zero factor gives +0 against infinity and NaN too), thenfmad, asv_fma_f32already uses.v_mad_f32and the plainv_mac_f32are unchanged.semantics_tests.rs(Windows):fma_legacyis the console's result for both opcodes, with the unfused one still allowed, as forv_fma_f32andv_fmac_f32.How it was tested
legacy_fma_tests::the_legacy_multiply_adds_round_once_and_keep_dx9_zeros(victory-gpu, Metal, Metal Shader Converter 4.0 beta 3): (1 + 2^-12)^2 - 1 is 0x3a000400 fromv_fma_f32,v_fma_legacy_f32andv_fmac_legacy_f32(on main the legacy two give 0x3a000000, the product rounded first), andv_fma_legacy_f32of 0 and infinity plus 1.0 is 1.0. The test fails on main.cargo test -p victory-shader(330 passed),cargo clippy --no-deps -p victory-shader --all-targets -- -D warningsfor the host and forx86_64-pc-windows-msvc(the semantics tests only build on Windows: type-checked, not run),cargo xtask policy.Checklist
VICTORY_*variable and documented (none added)Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T12:00:38Z.
Thank you. The point that RDNA2 gives these two encodings the fused names, with the
llvm-mcoutput, is clear and the value test is a good one.I ran every shader by output on
0fe4ab0a(33,625 containers, against mainc1b95875): nothing gained, nothing lost, nothing changed. So no shader in my dump of the game uses VOP3 0x140 or VOP2 0x006, and this has no effect on the game today. If your dump has shaders that use them, please say how many.Before I merge: I have approved your workflow, so please check it is green. The doc line for
legacy_mul(0 × anything = 0, as in D3D9) is now abovelegacy_fma; please move it back. And does the console flush a denormal input to zero for these two? Your semantics probe uses a flush, the lowering does not. Say which you know and which you guess.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T12:06:22Z.
Workflow is green (
0fe4ab0). Moved thelegacy_muldoc line back (132294b). I have no dump of the game, so I cannot count shaders that use these opcodes. On denormals, known: the semantics model reads a denormal factor ofv_mul_legacy_f32as 0, measured on RDNA2 by the Leonida project as its comment says. Guessed: I gavefma_legacythe same rule in the model; nothing I have measuresv_fma_legacy_f32with a denormal. The lowering does not flush, and did not before: measured on Metal now,v_mul_legacy_f32andv_fma_legacy_f32of the smallest denormal and infinity both give infinity (the model says 0 for the multiply), and 0x400000 times 2.0 gives 0x800000, so the host keeps denormals.legacy_fmatherefore does whatlegacy_mulalready does; reading a denormal factor as 0 in both would change the title's most used instruction, so I would make it a separate pull request if you want it.