Intel Arc (Xe-LPG): v_med3_f32 with a NaN operand returns the median, not the minimum #971
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#971
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?
@zzm1234560621-prog on GitHub · 2026-11-24 14:36 UTC · original
Intel Arc (Xe-LPG):
v_med3_f32with a NaN operand returns the median, not the minimumEnvironment
vendor 8086), driver32.0.101.6127
mainas of 2026-11-24 ~13:30 UTC (codeload zip; head at the time wasffe310e)What happens
The first four cases (no NaN) pass on this GPU. The first NaN case fails:
v_med3_f32(1.0, 2.0, NaN)gives2.0, where RDNA2 gives1.0.What it is not
VICTORY_WARP=1 cargo test -p victory-shader --lib v_med3_f32_matches_rdna2_with_nanpasses: WARP agrees with RDNA2 onevery case, so the emitted DXIL is right and this is the Intel driver's
handling of it.
v_med3_f16.v_med3_f16_matches_rdna2_with_nanpasses on thesame GPU, so it is the f32 lowering.
Where it points
emit::lower::Lower::med3(lower.rs:1469) computesFor
(1.0, 2.0, NaN):lo = 1,hi = 2,t = min(2, NaN),median = max(1, t),least = min(1, NaN) = 1,nan = true, so the resultshould be
least = 1.The value returned,
2.0, is exactly themedianarm under NaN-skippingmin/max (
min(2, NaN) = 2,max(1, 2) = 2). So on this driver themedianarm is what gets selected: either
cmp(UNO, third, third)is false for a NaNoperand, or the select's arms/materialisation of the
i1disagree with WARP.I cannot tell which from the outside; whichever it is, the two hosts disagree
on the same DXIL.
This is the same class of divergence
valu_tests.rs:312already documents forsigned zero ("DXIL's FMax and FMin compare and select, which can give either
zero") — on this driver it shows on NaN as well.
Why it matters beyond the test
med3is emitted forv_med3_f32, andbinary(35/36)is also whatv_min3_f32/v_max3_f32use. If a host's NaN behaviour differs from theconsole's, a title that feeds NaN into a median (clamped lighting, SSAO,
normal reconstruction) gets a different pixel, not a crash — the kind of
difference that is invisible until it is a visible artefact.
Suggested directions
Xe-LPG-specific.
non-NaN operands with explicit predicate selects (
select(isnan(b), a, b)style) instead of
min, so no host's NaN-skipping rule can change it.cmp(UNO, x, x)is the culprit, a shader-sidex != xviacmp(ONE, x, x)negation would be the cheaper fix, and would need a testof its own.
Note for anyone running the suite on Intel
This was the only failure in
cargo test --workspaceon this machine(120 of 121
victory-shaderlib tests pass, plus every other target). The"hardware" half of
run_caseshad, as far as I can tell, never run on anIntel adapter before, so other host-specific differences may still be hiding
behind the first assertion that fires.
@BastienRodz on GitHub · 2026-11-24 14:48 UTC · original
A candidate fix is on https://github.com/BastienRodz/VIctory/commits/shader/med3-nan-integer-test (
02c6650, one commit onmainffe310e,lower.rs+17/-3).Lower::med3chose the NaN arm withfcmp unonext to theFMin/FMaxtree. That float test is what a driver's optimiser can fold or reassociate with the min/max around it. The branch tests NaN on the integer bits of each operand instead,(bitcast(x) & 0x7fff_ffff) >u 0x7f80_0000, ORed across the three, which no float rule can fold.v_med3_f16goes through the same function, with its operands already widened to f32.On GitHub's
windows-latest(WARP), bothv_med3_f32_matches_rdna2_with_nanandv_med3_f16_matches_rdna2_with_nanpass, andvictory-shaderhas 120 passed: https://github.com/BastienRodz/VIctory/actions/runs/45417688011We have no Intel GPU. Could you run
cargo test -p victory-shader --lib v_med3on the branch on your Arc and say whether both pass? If they do, I'll open the PR with your result.@DrDarkDK on GitHub · 2026-11-24 14:52 UTC · original
#745 already has a candidate for this same failure. I compared
c796377with02c6650: both replace thefcmp unochecks with the same unsigned comparison on each operand’s float bits, and both keep the existing min/median calculation.The #745 patch has a before/after result on Intel Tiger Lake Xe-LP: the f32 case failed on
ffe310e, and both med3 tests passed withc796377. #745An Xe-LPG run would extend that evidence to the adapter reported here. It would make sense to carry one implementation forward and link the results from both Intel generations.
AI-assisted with Codex.
@BastienRodz on GitHub · 2026-11-24 15:11 UTC · original
Thanks @DrDarkDK, I missed #745. Same fix, and #745 already has before/after results on Intel Xe-LP, so let's carry #745's
c796377forward and drop my branch. @zzm1234560621-prog, an Xe-LPG run ofcargo test -p victory-shader --lib v_med3on #745's branch would add your adapter to that evidence.@N7z on GitHub · 2026-11-24 16:03 UTC · original
Also on Intel Xe-LP, not only Arc: Intel UHD Graphics (i7-13620H iGPU), driver 31.0.101.4146,
mainatffe310e.valu_tests::v_med3_f32_matches_rdna2_with_nanfails withv_med3_f32(1.0, 2.0, NaN) = 2 (0x40000000), want 1. On a hybrid laptop this test runs on the iGPU by default (adapter 0), so it can show up for people who think they are testing their NVIDIA GPU. More in #1132.@Marvisak on GitHub · 2026-11-25 06:51 UTC · original
Automated triage for the maintainers.
Thanks for the Xe-LPG result. This is the same defect as #726, which is open and confirmed:
Lower::med3incrates/victory-shader/src/emit/lower.rsstill picks the NaN case withfcmp unocompares, which some drivers (the Intel iGPUs in that thread) fold away. Open PR #2010 changes this lowering, and the integer-bits fix from #745 (c796377) is the candidate the thread above settled on. Your Arc run of that fix would be most useful as a comment on #726. Proposed for closing as a duplicate of #726: it will be closed in 48 hours unless the reporter replies or a maintainer removes the label.Generated by Claude Code
@zzm1234560621-prog on GitHub · 2026-11-26 11:13 UTC · original
Agreed on the duplicate — the triage is right, this is the same defect as #726, and the Arc result is now in that thread instead.
Summary of what went there, in case anyone lands here first: on
mainffe310ethis machine (Intel Arc iGPU, Xe-LPG, driver 32.0.101.6127) failsv_med3_f32_matches_rdna2_with_nanwithv_med3_f32(1.0, 2.0, NaN) = 2, want 1, passes the same test underVICTORY_WARP=1, and passesv_med3_f16. With #1483's lowering (NaN detected on the bits rather than byfcmp uno), all threev_med3tests pass on the iGPU itself. Repro detail is in #726.Closing as a duplicate of #726.
Tested with AI assistance (Claude).