Intel Arc (Xe-LPG): v_med3_f32 with a NaN operand returns the median, not the minimum #971

Closed
opened 2026-11-26 04:15:19 +00:00 by github-bot · 6 comments
Owner

@⁠zzm1234560621-prog on GitHub · 2026-11-24 14:36 UTC · original

Intel Arc (Xe-LPG): v_med3_f32 with a NaN operand returns the median, not the minimum

Environment

  • Windows 11 Pro for Workstations (26200), Core Ultra 9 185H, 32 GB
  • GPU: Intel(R) Arc(TM) Graphics (integrated, vendor 8086), driver
    32.0.101.6127
  • Rust 1.98.1 (the pinned toolchain), MSVC 14.51
  • main as of 2026-11-24 ~13:30 UTC (codeload zip; head at the time was
    ffe310e)

What happens

cargo test -p victory-shader --lib v_med3_f32_matches_rdna2_with_nan
thread 'emit::valu_tests::v_med3_f32_matches_rdna2_with_nan' panicked at
crates/victory-shader/src/emit/valu_tests.rs:296:27:
assertion `left == right` failed:
hardware: v_med3_f32(1.0, 2.0, NaN) = 2 (0x40000000), want 1

The first four cases (no NaN) pass on this GPU. The first NaN case fails:
v_med3_f32(1.0, 2.0, NaN) gives 2.0, where RDNA2 gives 1.0.

What it is not

  • Not the test's WARP half. VICTORY_WARP=1 cargo test -p victory-shader --lib v_med3_f32_matches_rdna2_with_nan passes: WARP agrees with RDNA2 on
    every case, so the emitted DXIL is right and this is the Intel driver's
    handling of it.
  • Not v_med3_f16. v_med3_f16_matches_rdna2_with_nan passes on the
    same GPU, so it is the f32 lowering.

Where it points

emit::lower::Lower::med3 (lower.rs:1469) computes

let lo = self.binary(36, a, b);      // min(a, b)
let hi = self.binary(35, a, b);      // max(a, b)
let t = self.binary(36, hi, third);  // min(max(a,b), c)
let median = self.binary(35, lo, t);// max(min(a,b), min(max(a,b), c))
let least = self.binary(36, lo, third);
let nan = or(cmp(UNO, a, b), cmp(UNO, third, third));
select(c, nan, least, median)

For (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 result
should be least = 1.

The value returned, 2.0, is exactly the median arm under NaN-skipping
min/max (min(2, NaN) = 2, max(1, 2) = 2). So on this driver the median
arm is what gets selected: either cmp(UNO, third, third) is false for a NaN
operand, or the select's arms/materialisation of the i1 disagree 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:312 already documents for
signed 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

med3 is emitted for v_med3_f32, and binary(35/36) is also what
v_min3_f32 / v_max3_f32 use. If a host's NaN behaviour differs from the
console'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

  1. Confirm on another Intel GPU (Arc A-series or Xe2) whether it is
    Xe-LPG-specific.
  2. Make the NaN arm not depend on the host's min: compute the smallest of the
    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.
  3. If cmp(UNO, x, x) is the culprit, a shader-side x != x via
    cmp(ONE, x, x) negation would be the cheaper fix, and would need a test
    of its own.

Note for anyone running the suite on Intel

This was the only failure in cargo test --workspace on this machine
(120 of 121 victory-shader lib tests pass, plus every other target). The
"hardware" half of run_cases had, as far as I can tell, never run on an
Intel adapter before, so other host-specific differences may still be hiding
behind the first assertion that fires.

**@⁠zzm1234560621-prog** on GitHub · 2026-11-24 14:36 UTC · [original](https://github.com/Marvisak/VIctory/issues/971) # Intel Arc (Xe-LPG): `v_med3_f32` with a NaN operand returns the median, not the minimum ## Environment - Windows 11 Pro for Workstations (26200), Core Ultra 9 185H, 32 GB - GPU: Intel(R) Arc(TM) Graphics (integrated, `vendor 8086`), driver **32.0.101.6127** - Rust 1.98.1 (the pinned toolchain), MSVC 14.51 - `main` as of 2026-11-24 ~13:30 UTC (codeload zip; head at the time was `ffe310e`) ## What happens ``` cargo test -p victory-shader --lib v_med3_f32_matches_rdna2_with_nan ``` ``` thread 'emit::valu_tests::v_med3_f32_matches_rdna2_with_nan' panicked at crates/victory-shader/src/emit/valu_tests.rs:296:27: assertion `left == right` failed: hardware: v_med3_f32(1.0, 2.0, NaN) = 2 (0x40000000), want 1 ``` The first four cases (no NaN) pass on this GPU. The first NaN case fails: `v_med3_f32(1.0, 2.0, NaN)` gives `2.0`, where RDNA2 gives `1.0`. ## What it is not - **Not the test's WARP half.** `VICTORY_WARP=1 cargo test -p victory-shader --lib v_med3_f32_matches_rdna2_with_nan` passes: WARP agrees with RDNA2 on every case, so the emitted DXIL is right and this is the Intel driver's handling of it. - **Not `v_med3_f16`.** `v_med3_f16_matches_rdna2_with_nan` passes on the same GPU, so it is the f32 lowering. ## Where it points `emit::lower::Lower::med3` (`lower.rs:1469`) computes ```rust let lo = self.binary(36, a, b); // min(a, b) let hi = self.binary(35, a, b); // max(a, b) let t = self.binary(36, hi, third); // min(max(a,b), c) let median = self.binary(35, lo, t);// max(min(a,b), min(max(a,b), c)) let least = self.binary(36, lo, third); let nan = or(cmp(UNO, a, b), cmp(UNO, third, third)); select(c, nan, least, median) ``` For `(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 result should be `least = 1`. The value returned, `2.0`, is exactly the **`median`** arm under NaN-skipping min/max (`min(2, NaN) = 2`, `max(1, 2) = 2`). So on this driver the `median` arm is what gets selected: either `cmp(UNO, third, third)` is false for a NaN operand, or the select's arms/materialisation of the `i1` disagree 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:312` already documents for signed 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 `med3` is emitted for `v_med3_f32`, and `binary(35/36)` is also what `v_min3_f32` / `v_max3_f32` use. If a host's NaN behaviour differs from the console'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 1. Confirm on another Intel GPU (Arc A-series or Xe2) whether it is Xe-LPG-specific. 2. Make the NaN arm not depend on the host's min: compute the smallest of the 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. 3. If `cmp(UNO, x, x)` is the culprit, a shader-side `x != x` via `cmp(ONE, x, x)` negation would be the cheaper fix, and would need a test of its own. ## Note for anyone running the suite on Intel This was the **only** failure in `cargo test --workspace` on this machine (120 of 121 `victory-shader` lib tests pass, plus every other target). The "hardware" half of `run_cases` had, as far as I can tell, never run on an Intel adapter before, so other host-specific differences may still be hiding behind the first assertion that fires.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:15:19 +00:00
Author
Owner

@⁠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 on main ffe310e, lower.rs +17/-3).

Lower::med3 chose the NaN arm with fcmp uno next to the FMin/FMax tree. 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_f16 goes through the same function, with its operands already widened to f32.

On GitHub's windows-latest (WARP), both v_med3_f32_matches_rdna2_with_nan and v_med3_f16_matches_rdna2_with_nan pass, and victory-shader has 120 passed: https://github.com/BastienRodz/VIctory/actions/runs/45417688011

We have no Intel GPU. Could you run cargo test -p victory-shader --lib v_med3 on the branch on your Arc and say whether both pass? If they do, I'll open the PR with your result.

**@⁠BastienRodz** on GitHub · 2026-11-24 14:48 UTC · [original](https://github.com/Marvisak/VIctory/issues/971#issuecomment-7134970128) A candidate fix is on https://github.com/BastienRodz/VIctory/commits/shader/med3-nan-integer-test (`02c6650`, one commit on `main` `ffe310e`, `lower.rs` +17/-3). `Lower::med3` chose the NaN arm with `fcmp uno` next to the `FMin`/`FMax` tree. 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_f16` goes through the same function, with its operands already widened to f32. On GitHub's `windows-latest` (WARP), both `v_med3_f32_matches_rdna2_with_nan` and `v_med3_f16_matches_rdna2_with_nan` pass, and `victory-shader` has 120 passed: https://github.com/BastienRodz/VIctory/actions/runs/45417688011 We have no Intel GPU. Could you run `cargo test -p victory-shader --lib v_med3` on the branch on your Arc and say whether both pass? If they do, I'll open the PR with your result.
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-24 14:52 UTC · original

#745 already has a candidate for this same failure. I compared c796377 with 02c6650: both replace the fcmp uno checks 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 with c796377. #745

An 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.

**@⁠DrDarkDK** on GitHub · 2026-11-24 14:52 UTC · [original](https://github.com/Marvisak/VIctory/issues/971#issuecomment-7135095599) #745 already has a candidate for this same failure. I compared `c796377` with `02c6650`: both replace the `fcmp uno` checks 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 with `c796377`. https://git.gtahub.st/github/Marvisak--VIctory/issues/745 An 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.
Author
Owner

@⁠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 c796377 forward and drop my branch. @⁠zzm1234560621-prog, an Xe-LPG run of cargo test -p victory-shader --lib v_med3 on #745's branch would add your adapter to that evidence.

**@⁠BastienRodz** on GitHub · 2026-11-24 15:11 UTC · [original](https://github.com/Marvisak/VIctory/issues/971#issuecomment-7135601189) Thanks @⁠DrDarkDK, I missed #745. Same fix, and #745 already has before/after results on Intel Xe-LP, so let's carry #745's `c796377` forward and drop my branch. @⁠zzm1234560621-prog, an Xe-LPG run of `cargo test -p victory-shader --lib v_med3` on #745's branch would add your adapter to that evidence.
Author
Owner

@⁠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, main at ffe310e. valu_tests::v_med3_f32_matches_rdna2_with_nan fails with v_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.

**@⁠N7z** on GitHub · 2026-11-24 16:03 UTC · [original](https://github.com/Marvisak/VIctory/issues/971#issuecomment-7137062817) Also on Intel Xe-LP, not only Arc: Intel UHD Graphics (i7-13620H iGPU), driver 31.0.101.4146, `main` at `ffe310e`. `valu_tests::v_med3_f32_matches_rdna2_with_nan` fails with `v_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.
Author
Owner

@⁠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::med3 in crates/victory-shader/src/emit/lower.rs still picks the NaN case with fcmp uno compares, 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

**@⁠Marvisak** on GitHub · 2026-11-25 06:51 UTC · [original](https://github.com/Marvisak/VIctory/issues/971#issuecomment-7155238153) <!-- victory-issue-triage v1 verdict=proposed-close seen=2026-11-24T16:03:58Z at=2026-11-25T06:51:52Z --> Automated triage for the maintainers. Thanks for the Xe-LPG result. This is the same defect as #726, which is open and confirmed: `Lower::med3` in `crates/victory-shader/src/emit/lower.rs` still picks the NaN case with `fcmp uno` compares, 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](https://claude.ai/code)_
Author
Owner

@⁠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 main ffe310e this machine (Intel Arc iGPU, Xe-LPG, driver 32.0.101.6127) fails v_med3_f32_matches_rdna2_with_nan with v_med3_f32(1.0, 2.0, NaN) = 2, want 1, passes the same test under VICTORY_WARP=1, and passes v_med3_f16. With #1483's lowering (NaN detected on the bits rather than by fcmp uno), all three v_med3 tests pass on the iGPU itself. Repro detail is in #726.

Closing as a duplicate of #726.

Tested with AI assistance (Claude).

**@⁠zzm1234560621-prog** on GitHub · 2026-11-26 11:13 UTC · [original](https://github.com/Marvisak/VIctory/issues/971#issuecomment-7190451025) 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 `main` `ffe310e` this machine (Intel Arc iGPU, Xe-LPG, driver 32.0.101.6127) fails `v_med3_f32_matches_rdna2_with_nan` with `v_med3_f32(1.0, 2.0, NaN) = 2, want 1`, passes the same test under `VICTORY_WARP=1`, and passes `v_med3_f16`. With #1483's lowering (NaN detected on the bits rather than by `fcmp uno`), all three `v_med3` tests pass on the iGPU itself. Repro detail is in [#726](https://git.gtahub.st/github/Marvisak--VIctory/issues/726). Closing as a duplicate of #726. _Tested with AI assistance (Claude)._
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#971
No description provided.