Shaders: v_med3 tests NaN from the bits, which NVIDIA's compiler keeps (TEST-MED3-NAN) #1689
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1689
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1689/head"
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?
@KevinPratap on GitHub · 2026-11-24 20:46 UTC · original
KevinPratap:shader/med3-nan-nvidia→main· +18 −4 · 1 files · 1 commits · closed without mergingClaimed 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
@KevinPratap on GitHub · 2026-11-24 21:18 UTC · original
Closing as a duplicate of #1483, which already tests NaN from the bits in
med3, and in thev_cmplowering too. It passes the same tests on an RTX 4050 Laptop (results on #1483).Pull request closed