Repository navigation
rdna2spirv: v_fract_f16 passes a NaN operand through, +0 with clamp (gfx1036) - #7257
nonverifiedperson wants to merge 2 commits into
Conversation
…gfx1036) gfx1036 in the game's MODE (IEEE 0, DX10_CLAMP 1) returns a NaN operand of v_fract_f16 unchanged (payload, signalling bit, sign; neg/abs act on the sign bit only) and +0 with clamp. The translator wrote 0x7e00 and, with clamp, handed the NaN to FClamp (undefined; refused for a constant operand). Select the source half after narrowing (f16_out nan_keep) and replace a NaN operand by +0 before FClamp. Adds tests/semantic/test_fract_f16_nan.py and the rule to docs/design.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review: #7257 — rdna2spirv:
|
…ting/FClamp sentences; test mul:2, |x| clamp and constant NaNs (review) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@tikD1337 thanks, all four addressed in
The 3 |
|
RTX 3080 Ti readback matched the IEEE 0, f16-denormals-kept rule in 393,216/393,216 cases. I ran every 16-bit input through six synthetic wave32 compute forms of
CachyOS, NVIDIA 620.73.04, native Vulkan storage-buffer readback. Synthetic inputs only, AI-assisted. |
|
Tested 3da07f6 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
AI-assisted (OpenCode). |
|
Tested 3da07f6 on Intel Iris Xe Graphics (TGL GT2, Xe-LP), Mesa ANV 26.3.1, Vulkan 1.4.363, Linux 6.12 (Arch container on Debian 13), llvm-mc 23.1.5, SPIRV-Tools v2026.4: pass. Branch and its merge-base Exhaustive sweep, same shape as the RTX 3080 Ti check above: every 16-bit input through six wave32 compute forms of
One difference from the NVIDIA run that supports the change: on The sweep is a throwaway script (one 64-thread group looping over 1,024 × 64 inputs, |
|
Tested 3da07f6 on Intel UHD Graphics 730 (Alder Lake-S GT1, Xe-LP, i5-12400), Intel's Windows driver 101.7092, Vulkan 1.4.323, Windows 11 Pro (build 26300): pass. The Iris Xe result above is Mesa ANV, so this is the other Intel driver. The RTX 5060 Ti in the same PC was excluded with The sweep has the same shape as the two above. Every 16-bit input goes through six wave32 compute forms of
The non-NaN words also match a host model: exact On this driver, Tools: standalone Vulkan tools built with llvm-mingw 20261117 (clang 23.1.6), |
|
Tested 3da07f6 (merged onto main 86a7807) on NVIDIA GeForce RTX 2060 (Turing), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 (10.0.26300), subgroup size 32: pass (no regression) What I ran:
No GPU test changed status against main. This PR adds no GPU fixture of its own, so the run checks that the translator change breaks none of the existing GPU tests; it does not exercise the new rule directly. Unit tests changed by the PR: The one failure on both sides is AI-assisted run (Claude Code); the numbers are from my machine. |
|
Tested 3da07f6 on RX 5700 XT (RDNA1, gfx1010, RADV NAVI10), Mesa 26.3.1, Linux 6.18: pass
LLVM AI-assisted (Claude Code). |
Claimed in #7049 (claim). Depends on: none.
What and why
When
v_fract_f16gets a NaN operand, the translator wrote0x7e00. Withclamp, it passed the NaN toFClamp, which GLSL.std.450 leaves undefined, and it refused the shader when the operand was a constant. On gfx1036, under the game's MODE (IEEE 0, DX10_CLAMP 1), the hardware does this instead:neg/absonly flips or clears the sign bit, andmul:2doesn't change the result.clamp: the result is +0.maintranslatorv_fract_f160x7c01(also_e64,mul:2)0x7c010x7e010x7e000x7c01v_fract_f160xfe11(also_e64,mul:2)0xfe110xfe110x7e000xfe11_e64 -v1,0x7c010xfc010xfe010x7e000xfc01_e64 -v1,0xfe110x7e110x7e110x7e000x7e11_e64 |v1|,0xfe110x7e110x7e110x7e000x7e11_e64 |v1|,0x7c010x7c010x7e010x7e000x7c01_e64 ... clamp, NaN (4 rows)0x00000x00000x0000Infinities (
0xfe00, or 0 withclamp), ordinary values,0x8001(gives0x3bff) andv_fract_f32already matched, and they still do.Change
tools/rdna2spirv.py, f16 unary path, Fract only:f16_in_bits.clamp,f16_outgets a newnan_keep=(is_nan, bits)and selects the source half after narrowing.clamp, a NaN operand becomes +0 beforeFClamp, as an infinity already did.tests/semantic/test_fract_f16_nan.pywithfixtures/ps_fract_f16_nan.asm: a run-time half ins0, covering plain,-x,|x|and-x clampfor two NaNs, +inf and 1.5. The test fails onmain(the interpreter rejectsFClampof a NaN) and passes here.docs/design.md: the NaN rule, how it was measured and the regression test, added to the "Float min/max/med3 with NaN,v_fract" row.Tests
python -m compileall -q make_game.py tools testsandpython -I make_game.py --help: OK.python -I scripts/run_semantic_tests.py tests/semantic: 444 files, 5890 tests, 4 files failed. Those 4 aretest_float_nan_fract(fixed by Preserve signaling NaNs through minmax source modifiers #6685) andtest_image_atomics_guard,test_image_cube_store_glc,test_image_store_d16. All four fail the same way onmainwithout this change (checked by stashing it).tests/semantic/test_fract_f16_nan.py: passes; onmainit errors on both NaN rows.test_fract_f16_infinityandtest_valu_fract_f16still pass.GPU check. Hardware words come from raw
hw_oraclekernels (asm.Kernel(..., raw=True, mode=dict(ieee=0 or 1, dx10_clamp=1, denorm32=0, denorm16_64=3))) on gfx1036. Translator words come fromint_hw_probe.run_translatorwithLEONIDA_VK_DEVICE=radeonandnvidia. 34 rows, 0 differ from the IEEE 0 hardware words on either GPU; 14 differed onmain.Windows 10 22H2, AMD Radeon iGPU (gfx1036, Ryzen 7 9800X3D, driver 32.0.13036.4), NVIDIA RTX 5070 Ti, Vulkan SDK 1.4.363. Synthetic values only, no game files. AI-assisted (Claude Code).
🤖 Generated with Claude Code