Repository navigation
Shaders: v_med3 tests NaN from the bits, which NVIDIA's compiler keeps (TEST-MED3-NAN) - #1689
Closed
KevinPratap wants to merge 1 commit into
Closed
KevinPratap wants to merge 1 commit into
KevinPratap wants to merge 1 commit into
Conversation
With a NaN operand the hardware gives the minimum of the three. The lowering chose that with float self-compares (fcmp uno); on an RTX 4050 Laptop the driver folded them away and gave the median: v_med3_f32(1.0, 2.0, NaN) = 2 where RDNA2 gives 1, failing v_med3_f32_matches_rdna2_with_nan on main. NaN is now tested as an integer compare of the magnitude bits (> 0x7F800000), for both the f32 and f16 forms (the f16 one is widened to f32 first). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 24, 2026
Contributor
Author
This was referenced Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in #1633 as
TEST-MED3-NAN.Problem
v_med3_f32_matches_rdna2_with_nanfails onmainon NVIDIA (RTX 4050 Laptop):When an operand is NaN, the hardware returns the minimum of the three. The lowering picks that case with float self-compares (
fcmp uno). NVIDIA's shader compiler folds those away, so the median comes back instead. A comment onfractin the same file describes the same kind of folding on NVIDIA.Fix
NaN is tested from the bits instead:
(bits & 0x7FFFFFFF) > 0x7F800000, an integer compare that the driver keeps.med3serves bothv_med3_f32andv_med3_f16, and the f16 operands are widened to f32 before it runs, so the one test covers both.Verified
v_med3_f32_matches_rdna2_with_nanandv_med3_f16_matches_rdna2_with_nanpass on the GPU and on WARP. Before the change, the f32 one failed.cargo test -p victory-shaderpasses: 120 passed, 0 failed.cargo clippy -p victory-shader --all-targets -- -D warningsis clean.cargo fmt --checkreports no changes in the edited lines. The remaining diffs inlower.rsare already onmain.Only
crates/victory-shader/src/emit/lower.rschanges.AI-assisted.
🤖 Generated with Claude Code