Skip to content

Translator: v_interp_p2_f16 takes its VOP3 clamp - #746

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
fearkov:fix/interp-p2-f16-clamp
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
fearkov:fix/interp-p2-f16-clamp

Conversation

@fearkov

@fearkov fearkov commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in #374 as: #374 (comment)

What and why

v_interp_p2_f16 takes the VOP3 clamp bit: llvm-mc encodes it (and no omod on this op), and Mesa ACO declares
the op dst(F16) in aco_opcodes.py, which takes output modifiers. The translator narrowed the attribute without
it, so a saturated 16-bit interpolant came out unclamped. Now clamp_mods runs before the narrowing, as for the
other f16 results (#718 does the same for v_cvt_f16_f32 and v_fmac_f16; the two don't touch the same lines).

Commits:

  1. the v_interp_p2_f16 handler in tools/rdna2spirv.py
  2. tests/semantic/test_interp_f16.py: the interpreter feeds attr0 = (1.5, -0.25) and reads it with and without
    clamp. Only the low half of each result is checked, since this test isn't about what the instruction leaves in
    the high half.
  3. a "v_interp_p2_f16 clamp" row in docs/design.md

No GPU test: vs_ids gives attributes in [0, 1) only, where the clamp changes nothing.

Tested

NVIDIA GeForce RTX 2060 SUPER, Linux, driver 620.70.06, llvm-mc 23.1.5, on top of 762893f.

Check this branch
runtime/test/shaders/build.py 87 translated, 87 pass spirv-val
runtime/test/shaders/check.py 56 of 84 pass, 28 skipped
scripts/run_gpu_tests.py 64/91 passed, 27 skipped
python -m unittest discover -s tests/semantic OK
python -m pytest tests --ignore=tests/semantic 1988 passed, 38 skipped, 1 xfailed

The skips are the wave64 tests (32-wide subgroups here) and, in check.py, the mesh fixtures build.py doesn't build.
On main's translator test_interp_f16.py fails with 0x3e00, 0xb400 where the clamp gives 0x3c00, 0x0000.

The runs above are from my own machine.

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.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 23e0f544ad9cc694a32b5c242c844412ceae552e on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

I ran the translated fragment shader from test_interp_f16.py in vk_harness. A synthetic full-screen triangle supplied the same attr0.xy at each vertex. The shader reads x and y first with clamp, then without it. I compared the low 16 bits of all four raw output channels at every pixel.

Vertex attribute (x, y) Clamped x, y (hex) Unclamped x, y (hex) Exact pixels
1.5, −0.25 3c00, 0000 3e00, b400 4096/4096
0.75, 0.25 3a00, 3400 3a00, 3400 4096/4096

All generated vertex and fragment modules passed spirv-val for Vulkan 1.2. The first draw distinguishes clipping at both ends; the second verifies that in-range values survive. This checks the low-half result on the PR head with constant vertex attributes.

AI-assisted verification.

@dougmb

dougmb commented Nov 22, 2026

Copy link
Copy Markdown

Tested 23e0f54 (merged with main 67204bf, no conflicts) on NVIDIA GeForce RTX 3060, driver 620.73.04, Linux (llvm-mc 23.1.5): pass. scripts/run_gpu_tests.py gives 64/91 passed, 27 skipped, 0 failed, the same as main. tests/semantic (including test_interp_f16.py) is OK. AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit e69c573 into ItsNotRexed:main Nov 22, 2026
8 of 9 checks passed
@abilliontokens

Copy link
Copy Markdown
Contributor

Tested 23e0f54 on RTX 5060 Ti (NVIDIA 621.24, Windows 11 26200), llvm-mc 21.1.8, SPIRV-Tools v2026.4, main baseline 067d3e8: native 64 passed/0 failed/27 skipped; LEONIDA_W64_EMULATE=1 91/0/0. Same expected skip profile as this PR's base on a 32-wide-subgroup GPU, every non-skipped test passes in both forms, no new failures vs baseline. No game files. AI-assisted (omp orchestrator).

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.

5 participants