Shaders: v_med3 with a NaN operand gives the median on NVIDIA (fcmp uno folded); fix on a branch #745
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#745
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?
@raphael-riesner on GitHub · 2026-11-24 09:26 UTC · original
v_med3_f32_matches_rdna2_with_nanfails on currentmain(8e79c80) on an NVIDIA GeForce RTX 3050 Ti Laptop GPU (driver 32.0.16.2114, Windows 11):Cause:
med3incrates/victory-shader/src/emit/lower.rschooses the NaN case (least operand) withfcmp uno. NVIDIA's driver assumes no NaNs in that compare and folds it to false, so a NaN operand gives the plain median.fractnext to it already works around the same driver behaviour.Fix: test the operands for NaN on their bits (
|x| > +infas integers), which the driver cannot fold away. 17 lines inlower.rs, one commit:Tested on the same GPU:
cargo test -p victory-shader --lib v_med3: fails before (above), both med3 tests pass aftercargo test -p victory-shader: 89 passed, 1 ignoredcargo clippy -p victory-shader --all-targets: cleanNot tested on AMD.
I tried to open a pull request, but creating one was refused for my account (pull requests seem limited to collaborators right now), so the fix is offered here instead. Happy to open the PR if that opens up again.
🤖 Generated with Claude Code
@slint6614-dev on GitHub · 2026-11-24 09:36 UTC · original
Read the branch (
shader/med3-nan-bits, 1 commit ahead of main, 0 behind). I reviewed the code but did not run it.is_nan_bitsis right:(bits & 0x7FFFFFFF) > 0x7F800000as an unsigned compare is true exactly for NaNs (both quiet and signalling, either sign), and false for ±inf.v_med3_f16. That call site (lower.rs~4384) passes operands fromhalf_fsrc, which widens withlegacyF16ToF32, somed3always sees f32 values. A NaN half stays a NaN after the widening, so the f32 bit test holds there too, and no separate 16-bit constant is needed.fcmp unoform already gives the RDNA2 result: on main,v_med3_f32_matches_rdna2_with_nanandv_med3_f16_matches_rdna2_with_nanpass on an RX 9070 (RDNA4) and a Ryzen 9600X iGPU (RDNA2) as the hardware device. So for AMD this change only replaces an equivalent compare.@26dwh7yy8g-rgb on GitHub · 2026-11-24 11:55 UTC · original
Ran the branch on Ada: RTX 4060 (desktop), driver 616.92, Windows 11 Pro 26200, Ryzen 5 5600X (no iGPU, so the hardware adapter is the RTX), Rust 1.98.1 (
x86_64-pc-windows-msvc), Windows SDK 10.0.26100.Compared
mainatffe310ewithffe310e+c796377(cherry-picks cleanly):cargo test --workspace --locked --no-fail-fast: 342 passed, 0 failed, 6 ignored on both. The 4diff_testsskip here (no console compiler), so they are not covered.cargo test --locked -p victory-shader --lib v_med3 -- --test-threads=1 --nocapture, 10 runs on each: both tests pass every time on the hardware adapter and WARP, no adapter skipped.--workspace --all-targets --locked -- -D warningsis clean, also with--all-features.The failure does not reproduce on this card, so this does not confirm the fix; it only shows no regression here.
No game data used. AI-assisted (Claude Code).
@ayanbarosan on GitHub · 2026-11-24 12:41 UTC · original
Tested this fix on Intel UHD Graphics (Tiger Lake Xe-LP, driver 31.0.101.5333), Windows 11 build 26300, where the failure does reproduce. The test host used the Intel iGPU here (DXGI adapter 0 on an Optimus laptop), so the
fcmp unofold is not NVIDIA-only.mainatffe310e:v_med3_f32_matches_rdna2_with_nanfails with the same result:hardware: v_med3_f32(1.0, 2.0, NaN) = 2 (0x40000000), want 1mainatffe310ewithc796377cherry-picked (applies cleanly): both med3 tests pass, on the Intel UHD and on WARPcargo test -p victory-shader --libwith the fix: 120 passed, 0 failed, 1 ignoredNo game data used. AI-assisted (Claude Code).
@Sunkiller-qc on GitHub · 2026-11-24 12:54 UTC · original
This is the same failure as #726 (
v_med3_f32(1.0, 2.0, NaN)returns 2 on NVIDIA). The data on #726 has it passing on desktop cards (2080, 4070 Ti, 5060 Ti, 5070 Ti, GTX 1060) and failing on the RTX 5060 Laptop it was reported on. Together with your 3050 Ti Laptop and the Intel UHD result above, it doesn't look like it hits every NVIDIA card. It would help to link this branch on #726 so the people there can try it, then close one of the two issues.@0xKaji on GitHub · 2026-11-24 14:14 UTC · original
Tested
main(ffe310e) on desktop NVIDIA GeForce RTX 3060 8GB (Ampere, Linux via Wine + DXVK + vkd3d-proton, proprietary driver620.73.04, CachyOS kernel7.3.5-2-cachyos,wine-11.22,DXVK v3.1.1-97-ga78a467cadb22be-pcos+ NVAPI).Both
v_med3_f32_matches_rdna2_with_nanandv_med3_f16_matches_rdna2_with_nan(along with all13/13emit::valu_tests) pass under both vkd3d-proton versions tested:vkd3d-proton 3.1.0(0bb64c56c8f0dcc):cargo xwin build --tests -p victory-shader --target x86_64-pc-windows-msvc->wine victory_shader.exe -- --test-threads=1->valu_tests13 passed, 0 failed (full crate run:119 passed, 1 failed, 1 ignored— the only failure isemit::tests::stub_pipeline_is_created, where vkd3d-proton accepts an all-zero DXIL MD5 digest).vkd3d-proton 3.2.0(GE-Proton11-14,cae8353ed7959c4+):valu_tests13 passed, 0 failed (pluswaterfall_tests5 passed).This matches the
#726/#745pattern (desktop NVIDIA passing while laptop NVIDIA / Intel UHD fail on Windows native DXIL drivers), and confirmsvkd3d-proton'sdxil-spirv-> NVIDIA Vulkan path preserves the NaN comparison semantics on Ampere.(No game data used.)
@DeerSilver on GitHub · 2026-11-24 18:52 UTC · original
Before/after for
c796377on two more adapters, in one laptop: Intel UHD Graphics (Raptor Lake Xe-LP,8086:a788), driver 32.0.101.7088, and NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell,10de:2d59), driver 621.24. Windows 11 26300, Rust 1.98.1. No game files: the test suite only.c796377cherry-picks cleanly ontomainffe310e. To pick the adapter, I added a local, uncommitted switch toemit::host::Host::newthat creates the device on a given DXGI adapter and prints its name. Every run below printed the adapter it ran on.cargo test --locked -p victory-shader --lib v_med3 -- --test-threads=1, 5 runs of each:mainffe310ev_med3_f32fails 5 of 5:hardware: v_med3_f32(1.0, 2.0, NaN) = 2 (0x40000000), want 1.v_med3_f16passesmain+c796377The whole
victory-shaderlib suite on the Intel UHD: 119 passed, 1 failed onmain, where the failure isv_med3_f32, and 120 passed, 0 failed withc796377, with no SM 6.6 skips. So on this Xe-LP no other shader test fails behind the med3 one, which #971 asked about.Together with the Tiger Lake Xe-LP run above (31.0.101.5333) and #110's Iris Xe (32.0.101.7088, failing), the
fcmp unofold is on current Intel drivers too, and the bit test fixes it there. On NVIDIA Blackwell with a current driver,mainalready passes and the fix keeps it passing.AI-assisted (Claude Code).
@MamaLeVrai on GitHub · 2026-11-24 19:45 UTC · original
@raphael-riesner your fix for this issue is now in a pull request, #1610, with seven other fixes from contributors' forks: the branch is merged as it is, with your commit(s) and your name unchanged, onto
mainffe310e. Clippy (both runs) andcargo test --workspacepass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1610. AI-assisted (Claude Code); no game data.@Marvisak on GitHub · 2026-11-25 03:49 UTC · original
Automated triage for the maintainers.
This is the same failure as #726, which is open and confirmed and is where the cause is tracked. On
main,Lower::med3incrates/victory-shader/src/emit/lower.rsstill picks the NaN case withpred::UNOcompares. The comments here show the failing devices are Intel UHD/Xe iGPUs and some laptop NVIDIA GPUs. They also show thatc796377fixes it.Your commit was carried in bundle #1610, which was closed without merging, so the fix is not on
main. Open PRs carrying a fix: #2010 (NaN-safev_med3_f32) and #1483 (bit test plus adapter choice, needs a rebase). Pull requests are open to everyone. Ifc796377is preferred over those, please open it as its own PR.Proposed close as a duplicate of #726. This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the label.
Generated by Claude Code