Skip to content

rdna2spirv: clamp and omod on v_cvt_i16_f16 / v_cvt_u16_f16 leave the result (measured on RDNA2) - #3583

Open
Vonsek wants to merge 4 commits into
ItsNotRexed:mainfrom
Vonsek:claude/cvt16-int-mods
Open

Vonsek wants to merge 4 commits into
ItsNotRexed:mainfrom
Vonsek:claude/cvt16-int-mods

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-CVT16-INT-MODS (claim comment)

What and why

The translator refused v_cvt_u16_f16_e64 / v_cvt_i16_f16_e64 with clamp or an omod (Unsupported: ... output modifier). I found the refusal with a differential hunt in the game's MODE: about 15,000 random f32/f16 VALU programs, run natively on RDNA2 and through the translator plus spirv_mini_interp. Every other difference it found is already on record or claimed: NaN payloads, f32 denormal flush (#2140), the omod -0 → +0 rule (#1281), f16 omod (#1970), and the clamp refusals in #2865, #3495 and eyyun's v_cvt_f16_u16/i16 claim.

On hardware these modifiers do nothing to the integer result. I measured 1,456 programs on gfx1036 through tools/hw_oracle raw kernels: 28 f16 inputs times clamp, mul:2, mul:4, div:2, clamp mul:2, clamp div:2 and source neg/abs/-|x|. Each ran in wave32 and wave64, both in the game's MODE (IEEE off, DX10_CLAMP on, f32 denormals flushed, f16 kept) and with IEEE on. All four runs gave identical words. Every word equals what the translator already produces for the same instruction without the modifier. So for these two opcodes the modifiers are now accepted and ignored. v_cvt_f16_u16/i16 still refuse them; eyyun claimed those.

  • tools/rdna2spirv.py: the refusal is limited to the int → f16 forms.
  • runtime/test/shaders/cs_cvt16_int_mods.asm: 8 cases, with each expected word derived by hand in the header. A float clamp to [0, 1] or an applied omod would change cases 1 to 4 and 7.
  • tests/semantic/test_cvt16_int_mods.py: a plain-Python reference (truncate, saturate, NaN → 0, the destination's high half kept) gives the words, and the translated fixture produces them in the interpreter.
  • docs/design.md: the existing 16-bit conversion row now says what the modifiers do.
  • tests/semantic/test_alu_cvt_16.py: the test that asserted the refusal now checks the unchanged results, and that v_cvt_f16_u16 still refuses clamp.

Tested

  • The 1,456 measured programs were translated with their modifiers and run in the interpreter: 0 mismatches. The 8 fixture cases gave the same words on the oracle in wave32/wave64 and in both IEEE modes.
  • scripts/run_gpu_tests.py --filter cvt16_int: cs_cvt16_int_mods gives 8/8 words and passes spirv-val, on NVIDIA GeForce RTX 5080 (driver 616.92) and AMD Radeon RDNA2 iGPU (Ryzen 9 9950X3D, driver 26.10.1), Windows 11.
  • Red on main: Unsupported: v_cvt_i16_f16 output modifier.
  • Negative control: treating clamp as a float clamp to [0, 1] on v_cvt_u16_f16 (one line) fails on both GPUs (0xdead0064 becomes 0xdead0001) and in the semantic test. Reverted.
  • python -m unittest discover -s tests/semantic, python tests/semantic/regen_fixtures.py --check, python -I tests/test_shader_checks.py (TOTAL +1 for the new compute fixture), compileall: 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.

… result

The translator refused the VOP3 clamp and output multipliers on the
f16-to-16-bit-integer conversions. Measured natively on RDNA2 gfx1036
(1,456 programs, wave32 and wave64, IEEE off and on) they leave the
integer result unchanged, so they are accepted and ignored. The int-to-f16
forms keep refusing them.

Adds the cs_cvt16_int_mods GPU compute test, a semantic test with a
plain-Python reference and the design.md wording.

AI-assisted.
@CaravelaLabs

Copy link
Copy Markdown
Contributor

Automated test: 041fb23c merged onto main f847748c on AMD Radeon 8060S (RADV GFX1151, RDNA 3.5), Mesa 25.2.8, Ubuntu 24.04, runtime rebuilt from this branch in a clean sandbox. Result: pass.

  • scripts/run_gpu_tests.py: 183/200 passed, 15 skipped (plain main: 182/199 passed, 15 skipped).
    • new test cs_cvt16_int_mods: pass (0xdead0001 0xdeadfffe 0xdead0064 0xdead0002 0xdead0064 0xdead8000 0xdead0000 0xdeadffe0)
  • Python tests this PR touches: 2 passed.

Same machine and setup as my earlier manual reports. AI-assisted (Claude Code).

@javdc

javdc commented Nov 22, 2026

Copy link
Copy Markdown

Tested 041fb23 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass

  • python3 -m pytest tests/semantic/test_cvt16_int_mods.py -q -> 2 passed
  • python3 -m pytest tests/test_shader_checks.py -q -> 74 passed, 220 subtests passed
  • python3 -I scripts/run_gpu_tests.py --build <build> --filter cvt16_int_mods -> 1/1 passed (cs_cvt16_int_mods)
  • python3 -I scripts/run_gpu_tests.py --build <build> -> 185/200 passed, 14 skipped, 0 failed (expected D3D12-owned skips)

No runtime C++ changes; GPU suite run from the PR worktree against the existing main runtime build.

AI-assisted (OpenCode).

test_alu_cvt_16 asserted the old refusal; it now checks that clamp and
mul:2 leave the result of v_cvt_u16_f16 / v_cvt_i16_f16 unchanged and that
v_cvt_f16_u16 still refuses clamp.

AI-assisted.
@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Re-tested 0289a73c (head moved since the earlier results) on Windows 11, Python 3.14, llvm-mc 23.1.6, SPIRV-Tools 2026.4 (CPU only; RTX 4070, NVIDIA 621.01 present but not used): pass. test_cvt16_int_mods.py 2 OK and test_alu_cvt_16.py 8 OK; with only tools/rdna2spirv.py restored to main they fail (1 and 2 errors). pytest tests/test_shader_checks.py and tests/test_translate.py -k cvt16: 76 passed. Not run: the GPU test cs_cvt16_int_mods, full semantic suite, other GPUs. Tested with AI assistance (Claude); synthetic shaders only, no game data.

@clutchwtn

Copy link
Copy Markdown

Tested 0289a73c on NVIDIA GeForce RTX 4070 SUPER (Ada, subgroup 32), driver 621.14, Vulkan 1.4, Windows 11; llvm-mc 22.1.2 (WSL), Vulkan SDK 1.4.363 / SPIRV-Tools v2026.4, test programs rebuilt from this branch with MinGW g++ 15.2: pass.

  • run_gpu_tests.py --filter cvt16_int --require-pass: cs_cvt16_int_mods 1/1, words 0xdead0001 0xdeadfffe 0xdead0064 0xdead0002 0xdead0064 0xdead8000 0xdead0000 0xdeadffe0.
  • Full run_gpu_tests.py: 154/200 passed, 46 skipped (wave64 natively, d3d12-run tests), 0 failed; with LEONIDA_W64_EMULATE=1: 185/200, 15 skipped, 0 failed. main f847748c on the same machine: 153/199 and 184/199.
  • Negative control: tools/rdna2spirv.py from main with this branch's fixture: cs_cvt16_int_mods fails (missing .spv (translation failed)).
  • python -m unittest discover -s tests/semantic: 7324 tests OK (1 expected failure); test_cvt16_int_mods.py and test_alu_cvt_16.py OK; regen_fixtures.py --check OK; tests/test_shader_checks.py OK.

tests/semantic/regen_fixtures.py
tests/semantic/test_alu_cvt_16.py
tests/test_shader_checks.py
tools/rdna2spirv.py

main applies the output modifiers on v_cvt_f16_u16/i16; this PR keeps accepting
and ignoring them on v_cvt_u16/i16_f16 (measured). The design.md row follows.

AI-assisted.
@Kev-Ball

Copy link
Copy Markdown

Tested f6377b9a on an NVIDIA GeForce RTX 3080 Ti (32-lane subgroups), driver 620.73.04, CachyOS Linux 7.3.5-2-cachyos. I rebuilt the Vulkan harnesses from this revision and selected the NVIDIA device explicitly.

Ran the PR’s synthetic fixture through scripts/run_gpu_tests.py --build runtime/build/linux --filter <fixture> --require-pass. The shader translated and passed Vulkan SPIR-V validation. GPU readback passed:

  • cs_cvt16_int_mods — 0xdead0001 0xdeadfffe 0xdead0064 0xdead0002 0xdead0064 0xdead8000 0xdead0000 0xdeadffe0.

AI-assisted verification with synthetic inputs.

docs/design.md
scripts/run_gpu_tests.py

AI-assisted.
@junaydirfan

Copy link
Copy Markdown

Tested 0280d671 merged into main 98fa503f on Linux (CachyOS, kernel 7.3.5), llvm-mc 23.1.5, LEONIDA_W64_EMULATE=1, test programs built from main (this PR changes no C++): pass.

GPU driver run_gpu_tests.py main
Intel Raptor Lake-S iGPU (Xe-LP), subgroup 8..32 Mesa ANV 26.3.1 187/218 passed, 31 skipped, 0 failed 186/217
RTX 4080 Laptop GPU (Ada), subgroup 32 NVIDIA 620.73.04 202/218 passed, 16 skipped, 0 failed 201/217

New in this PR:

  • cs_cvt16_int_mods: Intel PASS, 0xdead0001 0xdeadfffe 0xdead0064 0xdead0002 0xdead0064 0xdead8000 0xdead0000 …; RTX 4080 PASS, 0xdead0001 0xdeadfffe 0xdead0064 0xdead0002 0xdead0064 0xdead8000 0xdead0000 …

Every other test has the same result as on main on both GPUs.

@lunarminus

Copy link
Copy Markdown

Tested 0280d671 merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: fail (one semantic test on main conflicts with this change; the GPU side passes)

  • The merge was a fast-forward: the tested tree is exactly 0280d671, which already contains main through 0db7fed5. I rebuilt the runtime from that tree.
  • Failing: tests/semantic/test_valu_cvt_f16_int16_mods.py::test_f16_to_int16_output_modifiers_still_rejected fails for both v_cvt_u16_f16 and v_cvt_i16_f16 (AssertionError: Unsupported not raised). That test came in with 464dce5 (v_cvt_f16_{u16,i16} clamp/omod) and still expects v_cvt_u16_f16 v0, v0 clamp to be refused, which this PR now accepts. The same file passes on d0835dd9 and on 0db7fed5 without the PR (4 tests OK). It probably needs that assertion dropped or turned around, as you did in test_alu_cvt_16.py.
  • python -m unittest discover -s tests/semantic: 6247 tests, failures=5, errors=2, skipped=1, expected failures=1. Two of the failures are the test above. The other 3 failures and 2 errors are in test_loop_ballot_barrier.py (wave64-emulate cases), and they fail the same way on 0db7fed5 without this PR, so they are not caused by it.
  • pytest tests/semantic/test_cvt16_int_mods.py tests/semantic/test_alu_cvt_16.py: 10 passed, 312 subtests. discover -p '*cvt*': 229 tests, the same 2 failures. tests/test_shader_checks.py: 79 OK. regen_fixtures.py --check: OK.
  • scripts/run_gpu_tests.py: 203/218 passed, 15 skipped, 0 failed, both natively and with LEONIDA_W64_EMULATE=1. Per-test comparison with d0835dd9 without the PR (196/210, 14 skipped in each mode): all 210 tests that exist in both runs give the same PASS/SKIP result in both modes. The 8 tests not in that baseline are cs_cvt16_int_mods (this PR, PASS) and 7 that main added after d0835dd9: cs_smem_sconst_off, ps_far_branch, ps_sample_c, ps_sample_c_b, ps_texture_cl, ps_texture_b_cl (PASS) and ps_m2_literal (SKIP, run by d3d12_m2_textured_test).
  • run_gpu_tests.py --filter cvt16_int --require-pass: 1/1 in both modes. cs_cvt16_int_mods gives 0xdead0001 0xdeadfffe 0xdead0064 0xdead0002 0xdead0064 0xdead8000 0xdead0000 0xdeadffe0, which matches the expected words.

AI-assisted (Claude Code).

@jimokulou2-ops

Copy link
Copy Markdown

Tested 0280d67 merged onto main 98fa503 (clean merge) on AMD Radeon RX 9070 XT (RDNA4), AMD 26.11.2 (32.0.32029.2010, LLPC, Vulkan 1.4.359), Windows 11 Pro 26300: pass. A Windows AMD-driver (RDNA4, native wave64) data point next to the runs above.

  • Test programs built from main with llvm-mingw (the PR doesn't touch the runtime C++), llvm-mc 23.1.6 (conda-forge), Vulkan SDK 1.4.363.0, LEONIDA_VK_DEVICE=9070.
  • scripts/run_gpu_tests.py, full suite: 203/218 passed, 15 skipped, 0 failed; 222 shaders translated, 222 pass spirv-val. main 98fa503 on the same machine: 202/217, the same 15 skipped. The only difference is the new test:
    • cs_cvt16_int_mods: PASS 0xdead0001 0xdeadfffe 0xdead0064 0xdead0002 0xdead0064 0xdead8000 0xdead0000 0xdeadffe0
  • tests/semantic/test_alu_cvt_16.py: 8 OK; tests/semantic/test_cvt16_int_mods.py: 2 OK; tests/test_shader_checks.py: 83 passed.
  • tests/semantic/regen_fixtures.py --check: clean.

No game files. AI-assisted (Claude Code).

@junaydirfan

Copy link
Copy Markdown

Correction to my result above: that "pass" covered run_gpu_tests.py only. @lunarminus is right. On the same merge (0280d671 into main 98fa503f), main's tests/semantic/test_valu_cvt_f16_int16_mods.py::test_f16_to_int16_output_modifiers_still_rejected fails for v_cvt_u16_f16 and v_cvt_i16_f16 ("Unsupported not raised"). It passes on main alone.

That test pins clamp/omod on these two ops as Unsupported, which is what this PR implements. So it needs updating or removing as part of this PR; the GPU results are unaffected.

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.

9 participants