Skip to content

test(kyty): check that v_mac_f32 and v_mad_f32 stay unfused - #339

Merged
simnJS merged 1 commit into
simnJS:AnyKytyfrom
discordbarca:kyty-mad-not-fused
Nov 27, 2026
Merged

simnJS merged 1 commit into
simnJS:AnyKytyfrom
discordbarca:kyty-mad-not-fused

Conversation

@discordbarca

Copy link
Copy Markdown
Contributor

What

First point of #215: v_mac_f32 and v_mad_f32 are not fused. The translation already looks right (V_MAC_F32 / V_MAD_F32 → FPMad32, emitted as OpFMul + OpFAdd, both NoContraction; V_FMAC_F32 / V_FMA_F32 → FPFma32, emitted as GLSL.std.450 Fma). This PR adds a test that locks that in, as the issue asks.

New case mad-not-fused in kyty_shim_recompiler_robustness_tests, registered as kyty_shim_recompiler_mad_not_fused. It compiles four pixel shaders through KytyFuzz::Run (ShaderRecompilerRun.hpp), each with f32_product_no_contraction on and off, and scans the SPIR-V:

shader expected SPIR-V
v_mov_b32 v4, v2 + v_mac_f32 v4, v0, v1 one f32 OpFMul feeding an OpFAdd, both NoContraction; no Fma
v_mad_f32 v4, v0, v1, v2 same
v_mov_b32 v4, v2 + v_fmac_f32 v4, v0, v1 exactly one GLSL.std.450 Fma; no product feeding a sum
v_fma_f32 v4, v0, v1, v2 same

Each shader ends with exp mrt0 v4 so the result is live. The v_mov_b32 seeds the accumulator from an input so the mac forms don't add a constant 0. Every variant must also pass spirv-val.

It fails if V_MAC_F32 or V_MAD_F32 becomes an Fma, if either half loses NoContraction, or if V_FMAC_F32 / V_FMA_F32 stop being fused.

kyty_shim_f32_product_contraction (#243) already checks the NoContraction marks of a v_mad_f32 among other forms. This adds v_mac_f32, the explicit "no Fma" check, and the fused controls.

Where the behaviour comes from (LLVM AMDGPU backend, at bd4e29e5bf):

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, including kyty_shim_recompiler_valid_spirv (every case under KYTY_FUZZ_SPIRV=abort).
  • python3 tools/check_test_registration.py --scripts build and python3 tools/check_conventions.py --base origin/AnyKyty: pass.

Checklist

  • Based on current AnyKyty; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and licence notices
  • Unimplemented paths throw; silent stubs are listed in their library's technical debt file (n/a: test only)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (n/a)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none (first point of shaders: check the Kyty recompiler against known RDNA2 behaviours: arithmetic and formats #215)
  • Unblocks: none
  • GPUs tested: n/a (recompiler-only test, no GPU)
  • AI-assisted: yes

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.
@discordbarca
discordbarca temporarily deployed to repository-maintenance November 26, 2026 20:05 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown

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 Fma could satisfy a fused control even if the exported value no longer comes from it. Check that the exported value comes from the Fma in the fused cases and from the NoContraction multiply/add pair in the unfused cases.

mjnhbg3 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

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 91d9f3448a. It traces the value exported by the pixel shader, distinguishing the unfused multiply/add from the fused Fma, and adds masked-output controls. Exact-head AnyKyty CI and offline CI passed. Please review or cherry-pick if it fits this PR.

@github-actions

Copy link
Copy Markdown

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 simnJS left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@simnJS
simnJS merged commit 91d9f34 into simnJS:AnyKyty Nov 27, 2026
16 checks passed

This branch was previously deployed

1 inactive deployment
repository-maintenance — 91d9f344 Deployed Nov 26, 2026 by discordbarca via review #10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants