Skip to content

Translator: apply VOP3 output modifiers on v_fmac_f16 and v_interp_p2/mov_f32 - #956

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
edwin042331-hue:fix/v-fmac-f16-interp-mods
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
edwin042331-hue:fix/v-fmac-f16-interp-mods

Conversation

@edwin042331-hue

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #634 (comment)

What and why

Three VOP3 floating-point handlers in tools/rdna2spirv.py silently dropped VOP3 output modifiers (mul:2, mul:4, div:2, and clamp to [0, 1]):

  1. v_fmac_f16_e64 (line 3363): computed r = self.fma_f16_odd(*vals) and passed r straight to f16_out without self.clamp_mods(r, mods), unlike v_fma_f16 and every other f16 arithmetic op in the translator. Confirmed against LLVM llvm/test/MC/AMDGPU/gfx10_asm_vop2.s (lines 12044–12054: v_fmac_f16_e64 v5, v1, v2 clamp / mul:2 / mul:4 / div:2) and VOP2Instructions.td (VOP_MAC_F16 : VOP_MAC<f16>).
  2. v_interp_p2_f32_e64 and v_interp_mov_f32_e64 (line 4102): passed f straight to dst without self.clamp_mods(f, mods) (sibling to v_interp_p2_f16 clamp). Confirmed against LLVM llvm/test/MC/AMDGPU/gfx10_asm_vop3.s (lines 13210–13261). When mods has no output modifiers, clamp_mods is a zero-instruction no-op, leaving plain v_interp_*_f32 output byte-identical.

Added semantic tests in tests/semantic/test_f16_fma_rounding.py (test_fmac_output_modifiers, including high-half preservation) and tests/semantic/test_interp_f32_mods.py, plus a contract row in docs/design.md.

Tested

CPU-only on Windows 11, Python 3.11.9 (no GPU run, no spirv-val / llvm-mc, no game files):

  • python -m compileall -q make_game.py tools tests — exit 0
  • python -I -W error::ResourceWarning tests/semantic/test_f16_fma_rounding.py -q — 5/5 OK
  • python -I -W error::ResourceWarning tests/semantic/test_interp_f32_mods.py -q — 3/3 OK
  • python -m unittest discover -s tests/semantic -p 'test_interp*.py' -q — 79/79 OK
  • python -m unittest discover -s tests/semantic -p 'test_value_semantics.py' -q — 16/16 OK
  • python -m unittest discover -s tests/semantic -p 'test_f16*.py' -q — 10/10 OK

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

…/mov_f32

Apply clamp_mods (mul:2/mul:4/div:2 then clamp to [0, 1]) in v_fmac_f16_e64 (before f16 narrowing, matching v_fma_f16 and keeping the high half intact) and in v_interp_p2_f32_e64 / v_interp_mov_f32_e64 (zero-instruction no-op when mods has none).

Confirmed against LLVM gfx10_asm_vop2.s (v_fmac_f16_e64 clamp/mul:2/mul:4/div:2) and gfx10_asm_vop3.s (v_interp_p2_f32_e64, v_interp_mov_f32_e64). Verified on CPU with tests/semantic/test_f16_fma_rounding.py, tests/semantic/test_interp_f32_mods.py, tests/semantic/test_interp_f16.py and tests/semantic/test_value_semantics.py.
@evilclanker9000

Copy link
Copy Markdown
Contributor

The f32 interpolation part of 643f9d0596614c777d11706c6eb7d908e137b563 passes an independent rendered-pixel check on Windows RTX 5080 (616.92) and AMD Radeon Graphics (26.10.1). The v_fmac_f16 change overlaps #718, which already has GPU and raw RDNA2 results; the two interpolants below are separate coverage.

I assembled the synthetic VS/PS with LLVM for gfx1013 and ran spirv-val and vk_harness. The VS varies U and V across a 64×64 triangle and sets a flat attribute to (1.5 + vertex index, −0.75). The PS uses two v_interp_p2_f32_e64 instructions with clamp mul:2 / clamp mul:4 and two v_interp_mov_f32_e64 P0 reads with clamp div:2 / mul:4. At pixel centers the CPU reference is (min(2u,1), min(4v,1), 0.75, −3). The blue result distinguishes division before clamp (0.75) from clamp before division (0.5).

Draw Pixels differing from the reference per GPU Channels that differed
PR head 0/4096 none
Same assembly, translator from parent 067d3e8 4096/4096 RGBA
Head, remove only the P2 modifiers 4096/4096 RG
Head, remove only the MOV modifiers 4096/4096 BA

Each control also matched its own predicted raw RGBA32F values across the whole frame. These measurements cover translated Vulkan execution. AI-assisted, synthetic inputs only.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 643f9d0 on Windows 11 (Python 3.12, llvm-mc 23.1.6 with AMDGPU, spirv-tools): pass

  • pytest tests/test_translate.py tests/semantic/test_f16_fma_rounding.py tests/semantic/test_interp_f32_mods.py: 280 passed, 244 subtests
  • Negative control: with tools/rdna2spirv.py from main, 3 fail.

@IAmNotSiob IAmNotSiob left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm. scaling by a power of two and clamping to [0,1] both commute with the later f16 rounding of the round-to-odd value (barring overflow and denormals), so the order works. tests pass with main ^^ AI-assisted review (Claude Code).

@poststructural

Copy link
Copy Markdown

GPU check of 643f9d0 on Linux: NVIDIA GeForce RTX 2080 (Turing, subgroup 32), driver 610.57.04, llvm-mc 21.1.8, GCC build of runtime/. AI-assisted.

  • scripts/run_gpu_tests.py: 74/101 passed, 27 skipped (skips = wave64, no 64-wide subgroup); LEONIDA_W64_EMULATE=1: 101/101 passed.
  • python -m unittest discover -s tests/semantic: Ran 1024 tests, OK.

main (067d3e8) on the same machine: 74/101 native, 101/101 emulated.

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.

6 participants