Repository navigation
rdna2spirv: preserve f16 denormals, NaN payloads, and bit-exact clamp in conversions (SHADER-CVT-F16-DENORM-AND-MODS) - #2419
Conversation
… in conversions (SHADER-CVT-F16-DENORM-AND-MODS) Route v_cvt_f32_f16 through f16_in_bits so SDWA/DPP half selection, subnormals, neg/abs, and IEEE=0 NaN sign/payload bits are preserved without raw UnpackHalf2x16 flush risk, and clamp v_cvt_f16_f32 and v_div_fixup_f16 directly on rounded f16 bits via shared clamp_f16_bits. Verified on RTX 3060 (driver 617.14, native + --wave64-emulate: fixed first word 0x7FFFFFFF -> 0xFFC4A000 on cs_w32_cvt_f16_mods), 13/13 new semantic tests, 501-module semantic suite (6,385 passed, 0 failed), and 100/100 real corpus shaders passing spirv-val. AI-assisted: Codex gpt-6.2-sol + Antigravity gemini-4-neon.
|
On a Windows 11 RTX 4090 (NVIDIA 616.64), I get 0 wrong output words out of 786,432 at
For the rebase with #2362, I tested its general neg/abs forwarding on top of this PR. Store the shuffled value and its two modifier flags in |
|
Thanks @ecox982745 for the exhaustive RTX 4090 verification across all 65,536 binary16 encodings and 327,680 narrowing inputs ( Noted on |
tiguan26
left a comment
There was a problem hiding this comment.
Approving. Checked on df294dd merged onto current main (d1dff79).
Translator semantic suite: 501 files, only main's known test_fspx_dot4_op_sel_disasm and test_int32_to_f64 failures. tests/test_translate.py: 721 passed, the one failure is main's ps_sdwa_f16_const.asm. GPU fixtures on llvmpipe under Wine: ps_outmods_f16, ps_fmac_f16_mods, ps_interp_mov_mods, ps_interp_f32_mods, the six med3 fixtures, cs_cvt_f32_sat, cs_cvt_pk_u8 and ps_cvt_off all pass. Against main's translator test_cvt_f16_denorm_mods fails 6 times.
Read the diff. clamp_f16_bits is right as an unsigned compare: everything above 0x7C00 (negatives, -0, positive NaNs) goes to +0, +inf caps to 0x3C00, positive subnormals survive, and it keeps clamp off the driver's float path, where an UnpackHalf2x16 could flush them. The DPP change is a real fix: before it, neg on a v_cvt_f32_f16_dpp source went through modify() on the 32-bit word, flipping bit 31 instead of the half's sign. On llvmpipe the fixture shows exactly that: against main, word 0 is 0x7FC4A000, with the PR it is 0xFFC4A000.
One suggestion: cs_w32_cvt_f16_mods is in WAVE32_LANE_DUMPS, so it skips on any device that can't give exactly 32 lanes (llvmpipe here: "can't run this shader at 32 lanes on request"). Its only cross-lane read is the quad_perm inside one quad, so it doesn't need 32. With that one line removed locally it runs at llvmpipe's 8 lanes and all eight words match CVT_F16_MODS_WORDS. Keeping it in WAVE32_DUMPS (wave32 translation) but out of the forced-size list would let it run on more devices. Not a blocker.
timbot103
left a comment
There was a problem hiding this comment.
Verified head df294dd8a (vs parent d1dff7949) on Windows 11 with dual-GPU hardware readback (RTX 5080 616.64 + AMD Radeon gfx1036 32.0.21030.2001, Vulkan SDK 1.4.363.0 Core + SyncVal).
Static & semantic checks:
- Bitwise f16 NaN payload/sign reconstruction, subnormal widening (
mantissa * 2^-24), rounded-half clamp mapping, and DPP modifier forwarding viaargs[first]all check out. tests/semantic/test_cvt_f16_denorm_mods.py— 13/13 OK.tests/semantic/test_frexp_ldexp_f16_mods.py— 7/7 OK.
Dual-GPU hardware checks (Vulkan SDK 1.4.363.0 Core + SyncVal):
- Checked-in fixtures (
cs_w32_cvt_f16_mods,cs_w32_new_ops,ps_sdwa_f16_const): PASS (exit 0 under Core + SyncVal) on both RTX 5080 and AMD Radeon (cs_w32_cvt_f16_modsexact 8/8 words,ps_sdwa_f16_const4096/4096 pixels). - Directed compute shader covering DPP
row_shr:1across row boundaries (lanes 0 & 16) underbound_ctrl:0andbound_ctrl:1withnegon subnormal0x0001(0xb3800000interior, sentinel0xdeadbeef/0x80000000on boundaries) plusop_selhigh-destinationv_ldexp_f16andv_frexp_mant_f16clamp preserving low halves (128 readback words):- Parent
d1dff7949: 62/128 mismatches on RTX 5080 and 62/128 mismatches on AMD Radeon (0 VUIDs). - Head
df294dd8a: 0/128 mismatches on RTX 5080 and 0/128 mismatches on AMD Radeon (0 VUIDs).
- Parent
Minor note (non-blocking): Agree with the earlier review note that cs_w32_cvt_f16_mods only uses a within-quad swap and writes from lane 0, so keeping its wave32 translation registration while removing it from the forced 32-lane list in scripts/run_gpu_tests.py avoids unnecessary skips on 8-lane devices.
No game data used. AI-assisted review (Codex static audit + Gemini dual-GPU verification).
|
#2419 | head The semantic tests caught half-precision conversion/modifier regressions. The compute shader also returned an incorrect word on both physical devices before the merge. Captured 12 distinct complete SPIR-V module(s) emitted while rerunning test_cvt_f16_denorm_mods.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand. cs_w32_cvt_f16_mods assembled and validated on both trees. Its output failed the PR checker on both GPUs on main and matched on both after merging. Windows Vulkan adapters: AMD Radeon(TM) Graphics (26.11.2) and NVIDIA GeForce RTX 5070 Ti (610.74). Additional commands
Base |
|
The PR fixture adapted to a native 64-lane workgroup (same encoded instructions) went from 1/8 wrong to 0/8. A 64-lane arithmetic fixture went from 82/896 wrong to 0/896: 18 NaN lanes lost the negated sign on widening, and all 64 lanes were wrong for negation after DPP selection. The subnormal-clamp controls matched on both builds on this driver; they are not part of the hardware Red count. The merge also preserved all 384 checked untouched half-words. The targeted semantic suite went from 6 failures in 13 tests to 13/13 passed. The modules passed AI-assisted. |
|
Merged, thank you @Andretuta! This translator PR (rdna2spirv: preserve f16 denormals, NaN payloads, and bit-exact clamp in conversions (SHADER-CVT-F16-DENORM-AND-MODS)) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers. |
Claimed in the coordination issue as: SHADER-CVT-F16-DENORM-AND-MODS (#1608 (comment))
Related: #2362 (independent — merges cleanly standalone on
main; overlaps 4 lines intools/rdna2spirv.pydpp_insnsrc0neg/absforwarding, keepingargs[first]on rebase so destination-lessv_cmpxstays intact)What and why
v_cvt_f32_f16throughGen.f16_in_bitsinstead of rawUnpackHalf2x16, preserving f16 subnormals, applyingneg/absto the half selected by SDWA or DPP (avoiding 32-bitmodifyon a 16-bit half), and preservingIEEE=0NaN sign and payload bits out of driver float arithmetic.Gen.clamp_f16_bits(3-instruction exact DX10 clamp on rounded f16 words: negative halves including-0and NaNs map to+0, positive values cap at1.0, positive subnormals are preserved bit-exactly) and reuse it inv_cvt_f16_f32,v_div_fixup_f16,v_frexp_mant_f16, andv_ldexp_f16.UnpackHalf2x16sites intools/rdna2spirv.py.tests/semantic/test_cvt_f16_denorm_mods.pyand Vulkan GPU fixtureruntime/test/shaders/cs_w32_cvt_f16_mods.asm(wired intoruntime/test/shaders/check.pyandscripts/run_gpu_tests.py), plus contract update indocs/design.md.Tested
python -I tests/semantic/test_cvt_f16_denorm_mods.py: 13/13 OK (6 fail on unpatchedmaind1dff7949; validated with bothspirv-asandspirv_asm.py+spirv-val --target-env vulkan1.2).scripts/run_gpu_tests.py, native andLEONIDA_W64_EMULATE=1):cs_w32_cvt_f16_modsbefore (d1dff7949):7FFFFFFF 33800000 36800000 AAAA0001 AAAA03FF AAAA0000 AAAA0000 AAAA0001; after:FFC4A000 33800000 36800000 AAAA0001 AAAA03FF AAAA0000 AAAA0000 AAAA0001(word 0 fixesv_cvt_f32_f16DPPnegon NaN; exact 8/8 words in both modes);cs_w32_new_ops(8/8 exact) andps_sdwa_f16_const(4,096/4,096 pixels exact) pass in both modes.v_cvt_f32_f16andv_cvt_f16_f32translate and passspirv-val(100/100 before and after).python -I tests/test_run_gpu_tests.py(71/71 OK), doc/line-ending tests (25/25 OK),python -I scripts/check_no_game_data.py(exit 0).GPUs tested: NVIDIA GeForce RTX 3060 12 GB, NVIDIA driver 617.14, Windows 10
AI-assisted: yes (Codex gpt-6.2-sol + Antigravity gemini-4-neon)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.