mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:55:52 +01:00
[PR #642] [MERGED] rdna2spirv: VOP3 clamp of a NaN gives +0 under DX10_CLAMP (SHADER-CLAMP-NAN) #682
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#682
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/642
Author: @aadheel
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism
Base:
main← Head:fix/vop3-clamp-nan-zero📝 Commits (1)
a9bed90rdna2spirv: VOP3 clamp of a NaN gives +0 (DX10_CLAMP)📊 Changes
11 files changed (+173 additions, -23 deletions)
View changed files
📝
docs/design.md(+2 -2)📝
docs/shader_validation.md(+2 -1)📝
tests/semantic/f16_unary_cases.py(+3 -3)📝
tests/semantic/test_alu_f32_min_max.py(+5 -4)📝
tests/semantic/test_alu_min3_max3.py(+7 -8)📝
tests/semantic/test_alu_vop3_mods_hw.py(+2 -1)📝
tests/semantic/test_valu_f32_min3_max3_mad.py(+2 -2)➕
tests/semantic/test_vop3_clamp_nan.py(+137 -0)📝
tests/test_f64_conversion.py(+3 -0)📝
tests/test_rcp_iflag_mods.py(+3 -0)📝
tools/rdna2spirv.py(+7 -2)📄 Description
Claimed in the coordination issue as: SHADER-CLAMP-NAN
What and why
Gen.clamp_modsapplied the VOP3clampbit as a bareOpExtInst %float %glsl FClamp v %f0 %f1. GLSL.std.450 leavesFClampundefined when an operand is NaN, so any NaN reaching the clamp (a NaN operand,inf - inf,-inf * 0, an all-NaN min/max) gave SPIR-V whose result is up to the driver. The CPU interpreter refuses it (UnsupportedConstruct), andtests/spirv_interp.pypasses the NaN through.The game's MODE has DX10_CLAMP=1. Under it the hardware turns a NaN result into +0. This is already measured on gfx1036 in
docs/shader_validation.md: thev_rcp_iflag_f32run (a NaN result is +0 except with DX10_CLAMP off, 169 programs) and SHADER-186 (v_fmac_f16,v_fma_mixlo_f16,v_fma_mix_f32).docs/design.mdlisted it as "Not modelled".test_alu_vop3_mods_hw.pyleaves out those hardware rows because the translation was undefined, anddesign.mdcounts most of its 6,430 undefined cases as this one.The fix selects +0 for a NaN before
FClamp(OpIsNan+OpSelect), the same pattern the translator already uses for thev_div_fixup_f32,v_cvt_pk_u8_f32andv_cvt_pknorm_*clamps. Every f32/f16 op that appliesclampthroughclamp_mods/clamp_f16gets it: the F1/F2 ALU tables, fma/fmac/mad and the legacy ops, min/max/min3/max3/med3, conversions, mix ops, interp, f16 arithmetic and transcendentals. Non-NaN values are unchanged:FClampsees the same operand as before, and omod still applies before the clamp.Not in this PR:
clamp_mods_f64and the packedv_pk_*clamp still emit a bareFClamp. #475 is rewritingclamp_mods_f64, and the f64 row indesign.mdplus that docstring still say "as for f32 ... left to the driver". Whichever of the two lands second should drop "as for f32". I left those lines alone to avoid a conflict with #475.v_dot2_f32_f16also routes its clamp throughclamp_mods. #410 measured that clamp as a hardware no-op and removes it. The two PRs merge cleanly and their tests pass together.tools/mode_diff.py,div_fixup_diff.pyandf16misc_diff.pystill mark clamp of a NaN as "not judged". Follow-up: they can now judge it as +0.Tested
tests/semantic/test_vop3_clamp_nan.py, 12 tests. Covered: quiet, negative and signalling NaN operands and invalid operations underclamp, for f32 ops, legacy mul/mad, f16 ops writing the low half and the high half (the full word is checked, so the other half must be kept), all-NaNv_med3_f16,v_cvt_f32_f16/v_cvt_f16_f32with and without omod, andv_fma_mix_f32/v_fma_mixlo_f16/v_fma_mixhi_f16. Each case expects +0. Controls without a NaN check that the clamp is unchanged. The test fails 33 subtests onmainand passes with the change.FClampwas refused (test_alu_f32_min_max,test_alu_min3_max3, including the min3/max3 reference model), and the f16 unary harness (f16_unary_cases.py), which now checks clamp of a NaN result instead of skipping it.v_sqrt_f16/v_rsq_f16of a negative now exercise it.tests/test_rcp_iflag_mods.pyandtests/test_f64_conversion.pymatch the SPIR-V text and now expect theOpIsNan/OpSelectbeforeFClamp.python -I scripts/run_semantic_tests.py tests/semantic: 466 files, 6,120 tests, all pass excepttest_int32_to_f64. That one also fails on unmodifiedmainon this machine, because Ubuntu 24.04'sspirv-opt2025.1~rc1 segfaults on it.tests/test_translate.py: 666 passed, 1 failed (ps_sdwa_f16_const.asm), the same failure as onmainhere (Ubuntu's LLVM 18llvm-mc). The other translator unit tests (test_f16misc_diff,test_div_fixup_diff,test_mode_diff,test_rdna2spirv_cli,test_text_write_line_endingsand the rest of the 122tests/test_*.pyfiles that use the translator) pass.spirv-val(Vulkan 1.2).scripts/check_no_game_data.pyon every changed file: clean.git merge-treeagainst the heads of the 82 open PRs that touch these files adds no conflicted file. #475, #410, #270 and #309 also pass their own tests and this one when merged with it.GPUs tested: n/a. CPU interpreter and
spirv-valonly; no GPU fixture was run (nollvm-mcwith the AMDGPU target on this machine).AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.