Repository navigation
rdna2spirv: widen f16 denormal operands without UnpackHalf2x16 (NVIDIA reads them as 0) - #3220
Conversation
Gen.f16_in widened every f16 VALU operand with GLSL.std.450 UnpackHalf2x16. NVIDIA's reads an f16 denormal as 0 (RTX 5060 Ti, 610.88), so ps_sdwa_f16_const's word y, the denormal 0x0040 times 1024.0, came back 0x0000 instead of 0x1c00 natively and under --wave64-emulate. RDNA2's f16 MODE keeps denormals. A half with a zero exponent field is now widened exactly as sign * mantissa * 2^-24 with integer ops; other halves keep the UnpackHalf2x16 result. A semantic test runs ps_sdwa_f16_const with a flushing UnpackHalf2x16 and fails on the old translation. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A local probe on the RTX 5060 Ti (610.88) found that UnpackHalf2x16 loses an f16 denormal only when an SDWA BYTE_1 select produced it, from an inline constant or a VGPR alike; the same denormal as a literal or already in a VGPR widens right on main. The code is unchanged; the docstring, the test comment and the design.md row now say that instead of "NVIDIA reads denormals as 0". AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent check, AI-assisted. Tested
Caveat: the same fixture also passes at base No game files used; counts only. |
|
Tested Independent Linux Vulkan check of All four generated modules passed SPIR-V validation for Vulkan 1.2. Disassembly confirmed that none declared AI-assisted verification. |
|
Tested 3b99b37 on NVIDIA GeForce RTX 3060 Ti (Ampere), driver 610.88, Vulkan 1.4.341, Windows 11 (26200): pass, and the bug reproduces on main. Test programs built from this commit (MSVC from VS 2026 + Ninja); llvm-mc 23.1.6 (conda-forge llvm-tools); SPIRV-Tools from Vulkan SDK 1.4.357.0. Same harness, only tools/rdna2spirv.py swapped:
So the flushed f16 denormal on the SDWA path is not Blackwell-only: Ampere reads it as 0 as well on this driver. No game files. AI-assisted (Claude Code). |
|
Tested
Note: this driver passes |
|
Apple M2 no-regression check. Tested head 3b99b37 on Apple M2 (Mac14,3), macOS 26.4 (25E246), MoltenVK 1.4.2 (direct), subgroup 4..32, llvm-mc 23.1.6, Python 3.13.18.
Build note: full build fails on AppleClang 17 at vk_pipeline_check.cpp:567 (BUILD-822, fixed by open PR #2927); GPU binaries built, so the suite above is valid. Head fetched read-only; no rebase/edit/push. Synthetic shaders and counts only; no game files. AI-assisted. |
|
Tested
AI-assisted (Claude Code). Synthetic test shaders only, no game files. |
|
Tested
So on 621.01 (an RTX 5080), Also:
|
Testers on ItsNotRexed#3220 saw ps_sdwa_f16_const fail on main with NVIDIA 610.88, 595.99 and 580.173, and pass with 621.01 and 621.24. The row now says so; the translation is unchanged. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested 9d71037 on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:
AI-assisted (Claude Code). |
|
Follow-up on the same RTX 3060 Ti (580.173.02, Linux), now at
|
|
Independent Windows GPU check, run with Codex assistance. I tested
All 194 shader modules translated and passed With the regression test’s simulated denormal flushing, the base produced |
|
A note next to @FIocker's run: the base fails |
|
Rebase check for the A/B that @bobcatchris asked about in the coordination issue: The conflict is in one row of With that applied on
Test by test, the only result that changes on either GPU is Not checked: MoltenVK (no Mac here), the complete The diff against
|
# Conflicts: # docs/design.md
|
Independent Windows Vulkan check on an NVIDIA GeForce RTX 5060 Ti (NVIDIA 621.14, Vulkan 1.4.357, subgroup 32..32). The reported I translated the repository's synthetic fixture on A separate focused run on |
…pk_fmac_f16 9d71037 (ItsNotRexed#3220) widened f16 operands exactly in Gen.f16_in because NVIDIA read an SDWA-selected denormal as 0. v_cvt_f32_f16, v_pk_fma_f16 and v_pk_fmac_f16 still widen with UnpackHalf2x16 directly, and no GPU fixture fed them a denormal. cs_w32_f16_denorm_widen does: denormals from a VGPR, a literal and an SDWA WORD_1 select, as multiplicands, addends and the fmac accumulator, plus a normal control word. Expected words follow from RDNA2 keeping f16 denormals. Registered in check.py and run_gpu_tests.py (wave32 dump), in regen_fixtures.py, and run on the CPU by test_f16_denorm_widen_fixture.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FXR27ZYP9qtZtN8SG7QPWW
…pk_fmac_f16 9d71037 (ItsNotRexed#3220) widened f16 operands exactly in Gen.f16_in because NVIDIA read an SDWA-selected denormal as 0. v_cvt_f32_f16, v_pk_fma_f16 and v_pk_fmac_f16 still widen with UnpackHalf2x16 directly, and no GPU fixture fed them a denormal. cs_w32_f16_denorm_widen does: denormals from a VGPR, a literal and an SDWA WORD_1 select, as multiplicands, addends and the fmac accumulator, plus a normal control word. Expected words follow from RDNA2 keeping f16 denormals. Registered in check.py and run_gpu_tests.py (wave32 dump), in regen_fixtures.py, and run on the CPU by test_f16_denorm_widen_fixture.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FXR27ZYP9qtZtN8SG7QPWW
Claimed in the coordination issue: #3047 (comment) (from my finding #2891 (comment)). No item ID yet.
What and why
Gen.f16_inwidened every f16 VALU operand to f32 with GLSL.std.450UnpackHalf2x16. On an RTX 5060 Ti (610.88) that gives 0 for an f16 denormal that an SDWABYTE_1select produced. So onmain1628210,ps_sdwa_f16_constfails, natively and under--wave64-emulate:It depends on the NVIDIA driver. From the test reports on this PR,
mainfails this way with 610.88 (RTX 5060 Ti, RTX 3060 Ti, Windows), 595.99.02 (RTX 5090, Linux) and 580.173.02 (RTX 3060 Ti, Linux), and passes with 621.01 (RTX 5080) and 621.24 (RTX 5070, RTX 3080 Laptop). This branch passes on all of them, and on Apple M2 (MoltenVK) and the AMD drivers reported.Word y is
v_mul_f16_sdwa v3, 2.0, v1 src0_sel:BYTE_1 .... BYTE_1 of 2.0 is the f16 denormal0x0040(2^-18), and times 1024.0 that's0x1c00. RDNA2's f16 MODE keeps denormals, andGen.f16_bitsalready produces them on the way out. Only the way in lost them.It isn't every denormal. A local probe (not part of this PR) of
0x0040 × 1024.0on the same RTX, each word withmain's translator and this branch's:mainv_mul_f16_sdwa, inline constant 2.0,src0_sel:BYTE_10x00000x1c00v_mul_f16_sdwa,0x4000in a VGPR,src0_sel:BYTE_10x00000x1c00v_mul_f16_e32, literal0x400x1c000x1c00v_mul_f16_e32,0x40in a VGPR0x1c000x1c00v_add_f16,v_fma_mixlo_f16,v_pk_mul/add/fma_f16andv_cvt_f32_f16with a denormal in a VGPR also gave the right words onmain. Why the SDWA-selected value is different I don't know: both reachUnpackHalf2x16with0x0040in the low 16 bits. The fix doesn't depend on that: it doesn't useUnpackHalf2x16for exponent-0 halves at all.tools/rdna2spirv.pyGen.f16_in: when the half's exponent field is 0, the operand issign × mantissa × 2^-24(OpConvertUToFof the 10-bit mantissa, exact in f32). Other halves keep theUnpackHalf2x16result, so normal, inf and NaN halves are unchanged.tests/semantic/test_value_semantics.py:test_f16_denormal_operand_does_not_rely_on_unpack_halfrunsps_sdwa_f16_constthrough the interpreter with anUnpackHalf2x16that flushes denormals, as NVIDIA's does. It needs the same four words as the existing test.docs/design.md: the "f16 rounding" row adds the widening side, with how it was confirmed.Not changed: the other
UnpackHalf2x16uses (packed-f16 reads, interpolants, d16 image results). They may read denormals the same way, but no test here shows it, so I left them alone.Tested
AI-assisted (Claude Code). AMD Ryzen 5 7600X, Windows 11 Home 26300. GPUs: NVIDIA GeForce RTX 5060 Ti, driver 610.88 (subgroup 32..32); AMD Radeon(TM) Graphics iGPU (RDNA2 gfx1036, subgroup 32..64), driver 24.10.24 (Vulkan driver 2.0.302). MSVC 14.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 (
scripts\build_llvm_mc.ps1), Python 3.12.10. Test programs built withscripts\build_runtime.ps1. Implicit layers off. No game files.python -I scripts/run_gpu_tests.py, whole suite:main1628210ps_sdwa_f16_const)ps_sdwa_f16_const4096/4096 exactLEONIDA_W64_EMULATE=1ps_sdwa_f16_const)ps_sdwa_f16_const4096/4096 exactLEONIDA_W64_EMULATE=1The iGPU skips
ps_sdwa_f16_constand most pixel tests (128-byte push constants), so the change only has an NVIDIA GPU result here. A desktop RDNA2 run would help.python -m unittest discover -s tests/semantic: 4143 tests OK (main: 4142). The new test fails onmain's translator with'0xaaaa0000' != '0xaaaa1c00'(component y) and passes with the change.python -I tests/semantic/regen_fixtures.py --check: exit 0.python -I tests/test_shader_checks.py,python -I tests/test_docs_design_rows.py: OK.python -m compileall -q make_game.py tools tests: clean.tests/test_translate.py(needs pytest, not installed here).Checklist
docs/design.md, with how it was confirmed.🤖 Generated with Claude Code