Shaders: use DXIL IsNaN in med3 so Intel Xe does not fold fcmp uno #110
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!110
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/110/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?
@lordon1a on GitHub · 2026-11-24 00:36 UTC · original
fix/med3-dxil-isnan→main· +75 −6 · 2 files · 3 commits · closed without mergingSummary
Replaces
fcmp unoinLower::med3()(crates/victory-shader/src/emit/lower.rs) with DXIL's explicitdx.op.isSpecialFloat.f32(IsNaN, opcode 8).On Intel Iris Xe D3D12 (
8086:46a6, driver32.0.101.7088), the shader compiler foldsfcmp uno third, thirdtofalseunder default shader fast-math, causingv_med3_f32(1.0, 2.0, NaN)to returnmedian(2.0,0x40000000) instead ofleast(1.0,0x3f800000) as RDNA2 specifies. Discovered while running #37's synthetic GPU VALU tests on Intel Iris Xe.Using
dx.op.isSpecialFloat.f32(8, x)preserves NaN detection across Intel Xe and NVIDIA drivers without conflicting with #37'sfract()hunks.Verification
Tested on Windows 11 (
rustc 1.100.0,x86_64-pc-windows-gnullvm):main@35b054ec0lower.rson Intel Iris Xe8086:46a6, driver32.0.101.7088):cargo test -p victory-shader med3_uses_dxil_isnan_for_nan_operands-> FAILED:v_med3_f32(1.0, 2.0, NaN) got 0x40000000, want 1.cargo test -p victory-shader-> 58 passed, 0 failed (includingmed3_uses_dxil_isnan_for_nan_operands).valu_tests:8086:46a6): 7/7 passed (previously 6/7)10de:24e0, driver616.64): 7/7 passedcargo xtask policy: 150 files ok (synthetic GFX10 shader only; zero game data).cargo clippy -p victory-shader --all-targets: 0 new warnings.AI-assisted.
@lordon1a on GitHub · 2026-11-24 00:43 UTC · original
Updated against latest
main(fc0c4dd, which merged #37'svalu_tests.rsand #56) — dropped the now-redundant test inemit/mod.rsso the diff is just the 1-file fix incrates/victory-shader/src/emit/lower.rs(+13/-3 lines).Re-verified on Windows 11 (
Intel Iris Xe 8086:46a6, driver32.0.101.7088):cargo xtask policy(151 files ok),cargo test -p victory-shader-> 68 passed, 0 failed (includingmain'semit::valu_tests::v_med3_f32_matches_rdna2_with_nan, which fails onmain@fc0c4dd). AI-assisted.@raffclar on GitHub · 2026-11-24 00:58 UTC · original
Your tests only work on Intel hardware.... I don't have an Intel GPU
Do a small test checking that
med3emitsIsNaNinstead offcmp unoto make this more portable@DaviTostes on GitHub · 2026-11-24 01:10 UTC · original
Tested
0322732on Arch Linux x86_64, rustc 1.98.1: pass.cargo test -p victory-shader: 55 passed, 0 failed (2 test binaries).IsNaNpath is unexercised by the suite.victory-gpuE0425.@lordon1a on GitHub · 2026-11-24 02:53 UTC · original
AI-assisted. Thanks for the feedback @raffclar! Added a hardware-independent unit test (\emit::lower::tests::med3_f32_emits_dxil_isnan_instead_of_fcmp_uno) that lowers \_med3_f32\ and inspects the emitted DXIL module directly to verify it emits \dx.op.isSpecialFloat.f32\ (opcode 8, \IsNaN) and does not emit \cmp uno\ (\pred::UNO). Verified \cargo xtask policy\ (151 files ok) and \cargo test -p victory-shader\ (69/69 passed).
@fuzeofficlal on GitHub · 2026-11-24 18:05 UTC · original
Cross-checked
med3NaN lowering alongside#971/#1259across NVIDIA GeForce RTX 5090, AMD Radeon(TM) Graphics, D3D12 WARP, anddxil.dll. Two notes if this PR is rebased onto currentmain:i32NaN test ((as_int(x) & 0x7FFF_FFFF) >u 0x7F80_0000) ++infsubstitution: Testing NaN on integer bits avoids bothfcmp unofolding anddx.op.isSpecialFloatfast-math edge cases without adding#[cfg(test)]fields toLowered, and replacing NaN lanes with+infbeforeself.max_min(false, ...)also preserves RDNA2's-0.0 < +0.0ordering (med3(-0.0, +0.0, NaN) == -0.0) and returns a quiet NaN (0x7FC0_0000) when all three inputs are signaling NaNs (sNaN).f32+f16qNaN/sNaN/±0.0/±infGPU readback tests:fuzeofficlal/VIctory@cc27bcb.@artor410 on GitHub · 2026-11-25 21:53 UTC · original
Tested on RTX 3070 Ti, driver 610.88, Windows 11 26300, rustc 1.98.1. main
13f91ca. This PR is closed and does not merge, so only the headd53fa58was tested.cargo test -p victory-shaderon the head (old base): 69 passed, 0 failed, includingmed3_f32_emits_dxil_isnan_instead_of_fcmp_uno.v_med3_f32_matches_rdna2_with_nanpasses on this card, so the bug does not reproduce here.a5837b8.(Claude Code, Claude Opus 5.5.)
Pull request closed