Repository navigation
test(kyty): check that v_mac_f32 and v_mad_f32 stay unfused - #339
Conversation
Compile v_mac_f32, v_mad_f32, v_fmac_f32 and v_fma_f32 pixel shaders
through the recompiler, with f32_product_no_contraction on and off, and
check the SPIR-V: v_mac_f32 and v_mad_f32 must be an f32 OpFMul feeding
an OpFAdd, both NoContraction, and no GLSL Fma; v_fmac_f32 and
v_fma_f32 must be exactly one GLSL Fma and no separate product and sum.
Every variant must pass spirv-val.
The behaviour follows LLVM's AMDGPU backend: V_MAD_F32 is selected from
ISD::FMAD ("the same result as the separately rounded operations"),
V_FMA_F32 from ISD::FMA ("no intermediate rounding step"), and V_MAC_F32
is the two-address form of v_mad_f32.
Registered as kyty_shim_recompiler_mad_not_fused. First point of simnJS#215.
|
Please make the SPIR-V scan follow the value exported by the shader. It currently counts matching instructions anywhere in the module, so an unused |
|
I closed the companion PR I mistakenly opened against the contributor fork. The focused test improvement remains available as one commit based on this PR's current head |
|
Thanks. The reported export tracing and masked-output controls address the earlier concern in principle. The diff shown here still scans the whole module, so I can’t verify the fix from it. Please incorporate the follow-up into this PR so the updated diff and CI for the resulting head can be reviewed together. |
simnJS
left a comment
There was a problem hiding this comment.
The integration includes the follow-up that traces the exported value and checks the masked-output controls. Both CI suites passed on the tested candidate.
What
First point of #215:
v_mac_f32andv_mad_f32are not fused. The translation already looks right (V_MAC_F32/V_MAD_F32→FPMad32, emitted asOpFMul+OpFAdd, bothNoContraction;V_FMAC_F32/V_FMA_F32→FPFma32, emitted asGLSL.std.450 Fma). This PR adds a test that locks that in, as the issue asks.New case
mad-not-fusedinkyty_shim_recompiler_robustness_tests, registered askyty_shim_recompiler_mad_not_fused. It compiles four pixel shaders throughKytyFuzz::Run(ShaderRecompilerRun.hpp), each withf32_product_no_contractionon and off, and scans the SPIR-V:v_mov_b32 v4, v2+v_mac_f32 v4, v0, v1OpFMulfeeding anOpFAdd, bothNoContraction; noFmav_mad_f32 v4, v0, v1, v2v_mov_b32 v4, v2+v_fmac_f32 v4, v0, v1GLSL.std.450 Fma; no product feeding a sumv_fma_f32 v4, v0, v1, v2Each shader ends with
exp mrt0 v4so the result is live. Thev_mov_b32seeds the accumulator from an input so themacforms don't add a constant 0. Every variant must also passspirv-val.It fails if
V_MAC_F32orV_MAD_F32becomes anFma, if either half losesNoContraction, or ifV_FMAC_F32/V_FMA_F32stop being fused.kyty_shim_f32_product_contraction(#243) already checks theNoContractionmarks of av_mad_f32among other forms. This addsv_mac_f32, the explicit "noFma" check, and the fused controls.Where the behaviour comes from (LLVM AMDGPU backend, at
bd4e29e5bf):V_MAD_F32is selected fromany_fmadandV_FMA_F32fromany_fma: VOP3Instructions.td#L176, #L187ISD::FMAD: "Perform a * b + c, while getting the same result as the separately rounded operations";ISD::FMA: "Perform a * b + c with no intermediate rounding step": ISDOpcodes.h#L522-L526V_MAC_F32is the two-address form that converts tov_mad_f32: VOP2Instructions.td#L910-L911, #L500V_MAD_F320x141,V_FMA_F320x14b (#L2856, #L2866),V_MAC_F320x01f,V_FMAC_F320x02b (VOP2#L2599, VOP2#L2394).These are compiler definitions, not a hardware measurement. A GPU check would belong to #217.
Tested
Windows 11 Pro 25H2, WinLibs GCC 15.2.0 UCRT, LLVM 21.1.8, on
47b61f8c36. No GPU is involved; the test only compiles and inspects SPIR-V.kyty_shim_recompiler_robustness_tests mad-not-fused:mad-not-fused: ok. The unfused shaders come out at 144 SPIR-V words and the fused ones at 145.ctest -R '^kyty_shim_recompiler_': 6/6 passed, includingkyty_shim_recompiler_valid_spirv(every case underKYTY_FUZZ_SPIRV=abort).python3 tools/check_test_registration.py --scripts buildandpython3 tools/check_conventions.py --base origin/AnyKyty: pass.Checklist
AnyKyty; no other open PR implements the same functions.mdfiles or images added to the repository