fix(shader): preserve NaN operands in float min/max lowering #3352

Open
Thomas73737 wants to merge 1 commit from upstream-pr/3352 into main
Thomas73737 commented 2026-11-26 19:49:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Thomas73737 on 2026-11-26T19:49:08Z.


Summary

  • make max_min_flushed explicitly return the other operand when one float min/max operand is NaN, and the first operand when both are NaN
  • add valu_tests coverage for f32/f16 v_min/v_max/v_min3/v_max3 NaN operand handling

Rationale

RDNA2 and DXIL FMax/FMin semantics treat a NaN operand as returning the other operand. The existing lowering depended on DXIL op behavior after custom zero/denormal handling; making NaN propagation explicit avoids driver/backend quirks that could turn NaNs into dark/black pixels in color-sensitive passes such as sun/glow/water highlights.

I could not reproduce or confirm the reported sun/water black artifact in this Linux sandbox: no game files were scanned/downloaded, no Windows/D3D12/WARP/GPU capture is available, and I cannot attribute the report to shader min/max NaN handling without a capture. This is a targeted, low-risk semantic hardening based on shader-lowering inspection.

Validation

  • cargo fmt --package victory-shader -- crates/victory-shader/src/emit/lower.rs crates/victory-shader/src/emit/valu_tests.rs
  • cargo test -p victory-shader --locked --lib emit::valu_tests (compiles/tests run in this Linux environment; the newly added NaN min/max tests are Windows-gated by valu_tests module cfg)
  • not run: Windows/D3D12/WARP/game repro or GPU capture

Risks / follow-ups

  • May not address the reported visual artifact if the root cause is elsewhere (resource state, format conversion, blending, tonemap, or missing GPU feature).
  • Needs Windows/D3D12 validation and, ideally, a PIX/GPU capture or before/after screenshot from the reported scene.

AI-assisted: yes

<!-- greyfinch-sync:Marvisak/VIctory:issue:5516262817 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352). Originally posted by [Thomas73737](https://github.com/Thomas73737) on 2026-11-26T19:49:08Z. --- ## Summary - make `max_min_flushed` explicitly return the other operand when one float min/max operand is NaN, and the first operand when both are NaN - add `valu_tests` coverage for f32/f16 `v_min/v_max/v_min3/v_max3` NaN operand handling ## Rationale RDNA2 and DXIL `FMax`/`FMin` semantics treat a NaN operand as returning the other operand. The existing lowering depended on DXIL op behavior after custom zero/denormal handling; making NaN propagation explicit avoids driver/backend quirks that could turn NaNs into dark/black pixels in color-sensitive passes such as sun/glow/water highlights. I could not reproduce or confirm the reported sun/water black artifact in this Linux sandbox: no game files were scanned/downloaded, no Windows/D3D12/WARP/GPU capture is available, and I cannot attribute the report to shader min/max NaN handling without a capture. This is a targeted, low-risk semantic hardening based on shader-lowering inspection. ## Validation - `cargo fmt --package victory-shader -- crates/victory-shader/src/emit/lower.rs crates/victory-shader/src/emit/valu_tests.rs` - `cargo test -p victory-shader --locked --lib emit::valu_tests` *(compiles/tests run in this Linux environment; the newly added NaN min/max tests are Windows-gated by `valu_tests` module cfg)* - not run: Windows/D3D12/WARP/game repro or GPU capture ## Risks / follow-ups - May not address the reported visual artifact if the root cause is elsewhere (resource state, format conversion, blending, tonemap, or missing GPU feature). - Needs Windows/D3D12 validation and, ideally, a PIX/GPU capture or before/after screenshot from the reported scene. AI-assisted: yes
Jackster commented 2026-11-26 20:04:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T20:04:35Z.


AMD/WARP check at 16c700e: both new tests fail, and the failure is the fixture, not the lowering.

v_max3_f32 [NaN, 1.0, 2.0] returns 2.0 (0x40000000) on the RX 7900 XTX and the same value on WARP; the fixture expects 1.0 (0x3f800000). v_max3_f16 does the same (0x4000 vs 0x3c00).

For a three-operand max the NaN is ignored and the result is the max of the other two operands, so 2.0 is right: the ([nan, a, b], a, a) and ([a, nan, b], a, a) rows only hold for v_max_f32/v_max_f16, where the other operand is unambiguous. The min3 rows are fine (min(1.0, 2.0) = 1.0), and both two-operand forms pass on both backends.

Suggested fix: for v_max3_* expect b (or give the two non-NaN operands the same value). Since the test stops at v_max3_f32, the remaining ops do not run — after the change, this should complete.

Hardware: AMD Radeon RX 7900 XTX (RDNA3, driver 32.0.32029.2010), Windows 11. Synthetic shaders only, no game files. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7202267422 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7202267422). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T20:04:35Z. --- AMD/WARP check at `16c700e`: both new tests fail, and the failure is the fixture, not the lowering. `v_max3_f32 [NaN, 1.0, 2.0]` returns `2.0` (`0x40000000`) on the RX 7900 XTX and the same value on WARP; the fixture expects `1.0` (`0x3f800000`). `v_max3_f16` does the same (`0x4000` vs `0x3c00`). For a three-operand max the NaN is ignored and the result is the max of the **other two** operands, so `2.0` is right: the `([nan, a, b], a, a)` and `([a, nan, b], a, a)` rows only hold for `v_max_f32`/`v_max_f16`, where the other operand is unambiguous. The `min3` rows are fine (`min(1.0, 2.0) = 1.0`), and both two-operand forms pass on both backends. Suggested fix: for `v_max3_*` expect `b` (or give the two non-NaN operands the same value). Since the test stops at `v_max3_f32`, the remaining ops do not run — after the change, this should complete. Hardware: AMD Radeon RX 7900 XTX (RDNA3, driver 32.0.32029.2010), Windows 11. Synthetic shaders only, no game files. AI-assisted.
Thomas73737 commented 2026-11-26 20:09:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Thomas73737 on 2026-11-26T20:09:53Z.


Thanks for the check. Fixed in a9650b2: updated the NaN valu test fixtures so v_max3/v_min3 expect max/min of the remaining operands when a NaN is present (e.g. [NaN,1,2] -> max3 2, min3 1); 2-op cases unchanged. Pushed to the PR.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7202369762 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7202369762). Originally posted by [Thomas73737](https://github.com/Thomas73737) on 2026-11-26T20:09:53Z. --- Thanks for the check. Fixed in `a9650b2`: updated the NaN valu test fixtures so `v_max3/v_min3` expect max/min of the remaining operands when a NaN is present (e.g. `[NaN,1,2]` -> max3 `2`, min3 `1`); 2-op cases unchanged. Pushed to the PR.
Dukestar69 commented 2026-11-26 20:16:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T20:16:08Z.

Review: COMMENTED


Tested on RTX 5090 (Windows / D3D12) against origin/main (63bcca4). Both new tests in valu_tests.rs fail:

emit::valu_tests::max_and_min_treat_a_nan_as_the_other_operand:
  assertion `left == right` failed: hardware: v_max3_f32 [7fc00000, 3f800000, 40000000, 0]
    left: 1073741824 (0x40000000 = 2.0)
   right: 1065353216 (0x3f800000 = 1.0)

emit::valu_tests::f16_max_and_min_treat_a_nan_as_the_other_operand:
  assertion `left == right` failed: hardware: v_max3_f16 [7e00, 3c00, 4000, 0]
    left: 16384 (0x4000 = 2.0)
   right: 15360 (0x3c00 = 1.0)

In both tests, cases defines expected outputs assuming 2-operand min/max (ignoring src2 = 2.0: [nan, 1.0, 2.0] -> 1.0, [nan, nan, 2.0] -> nan), and then reuses those same expected values for 3-operand v_max3_* / v_min3_* — where src2 = 2.0 participates, so v_max3(NaN, 1.0, 2.0) = 2.0 and v_max3(NaN, NaN, 2.0) = 2.0. Splitting the expected values (or separate case tables) for 2-operand vs 3-operand ops will fix both tests.

cargo clippy -p victory-shader --all-targets -- -D warnings and cargo xtask policy (191 files ok) both pass.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6080035338 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#pullrequestreview-6080035338). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T20:16:08Z. **Review:** COMMENTED --- Tested on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). Both new tests in `valu_tests.rs` fail: ``` emit::valu_tests::max_and_min_treat_a_nan_as_the_other_operand: assertion `left == right` failed: hardware: v_max3_f32 [7fc00000, 3f800000, 40000000, 0] left: 1073741824 (0x40000000 = 2.0) right: 1065353216 (0x3f800000 = 1.0) emit::valu_tests::f16_max_and_min_treat_a_nan_as_the_other_operand: assertion `left == right` failed: hardware: v_max3_f16 [7e00, 3c00, 4000, 0] left: 16384 (0x4000 = 2.0) right: 15360 (0x3c00 = 1.0) ``` In both tests, `cases` defines expected outputs assuming 2-operand `min`/`max` (ignoring `src2 = 2.0`: `[nan, 1.0, 2.0] -> 1.0`, `[nan, nan, 2.0] -> nan`), and then reuses those same expected values for 3-operand `v_max3_*` / `v_min3_*` — where `src2 = 2.0` participates, so `v_max3(NaN, 1.0, 2.0) = 2.0` and `v_max3(NaN, NaN, 2.0) = 2.0`. Splitting the expected values (or separate case tables) for 2-operand vs 3-operand ops will fix both tests. `cargo clippy -p victory-shader --all-targets -- -D warnings` and `cargo xtask policy` (191 files ok) both pass. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Thomas73737 commented 2026-11-26 20:18:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Thomas73737 on 2026-11-26T20:18:27Z.


Thanks for testing on RTX 5090. This was the same fixture issue Jackster reported: the 3-op NaN cases reused 2-op expectations. Fixed in a9650b2 (already pushed): v_max3/v_min3 now expect max/min of the remaining operands when a NaN is present ([NaN,1,2] -> max3 2, min3 1; [NaN,NaN,2] -> 2), with 2-op cases unchanged.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7202517768 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7202517768). Originally posted by [Thomas73737](https://github.com/Thomas73737) on 2026-11-26T20:18:27Z. --- Thanks for testing on RTX 5090. This was the same fixture issue Jackster reported: the 3-op NaN cases reused 2-op expectations. Fixed in `a9650b2` (already pushed): `v_max3/v_min3` now expect max/min of the remaining operands when a NaN is present (`[NaN,1,2]` -> max3 `2`, min3 `1`; `[NaN,NaN,2]` -> `2`), with 2-op cases unchanged.
upipibi commented 2026-11-26 20:29:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-26T20:29:27Z.


@Thomas73737 check on a9650b2 fails only on frame::tests::waits_end_on_ticks_and_count_frames (crates/victory-gpu/src/frame.rs:231, left: 0 right: 1), a timing test in a crate this PR does not touch; #1362 hit the same failure and #2877 describes the cause. Re-run check (or push an empty commit). Cargo stopped there, so victory-shader's tests, which cover your change, have not run in CI yet. Fix any failure the re-run shows.

AI-assisted (Claude Code, Claude Sonnet 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7202744204 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7202744204). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-26T20:29:27Z. --- @Thomas73737 `check` on a9650b2 fails only on `frame::tests::waits_end_on_ticks_and_count_frames` (crates/victory-gpu/src/frame.rs:231, `left: 0 right: 1`), a timing test in a crate this PR does not touch; #1362 hit the same failure and #2877 describes the cause. Re-run `check` (or push an empty commit). Cargo stopped there, so victory-shader's tests, which cover your change, have not run in CI yet. Fix any failure the re-run shows. AI-assisted (Claude Code, Claude Sonnet 5.5).
andrewpozdnakov7-jpg commented 2026-11-26 20:35:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T20:35:55Z.


The corrected fixtures at a9650b2 passed three consecutive runs on app-local Agility 1.620.2 / WARP 1.0.22 with the DXIL validator. Both NaN tests and both signed-zero tests passed each time, including the FP16 and FP32 cases. The same fixtures passed three runs in a control that restored the previous max_min_flushed lowering. That confirms the new expectations on WARP. The reported sun/water artifact still needs a capture or adapter result that distinguishes the two lowerings.

I also checked the failed CI job. The failing assertion is the frame clock's zero-timeout poll after the second tick. The test-only change in #2265 already covers this timing assumption. @Thomas73737, the two new shader tests are ready for a retest on the RX 7900 XTX or RTX 5090 using a9650b2.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7202872015 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7202872015). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T20:35:55Z. --- The corrected fixtures at `a9650b2` passed three consecutive runs on app-local Agility 1.620.2 / WARP 1.0.22 with the DXIL validator. Both NaN tests and both signed-zero tests passed each time, including the FP16 and FP32 cases. The same fixtures passed three runs in a control that restored the previous `max_min_flushed` lowering. That confirms the new expectations on WARP. The reported sun/water artifact still needs a capture or adapter result that distinguishes the two lowerings. I also checked the [failed CI job](https://github.com/Marvisak/VIctory/actions/runs/45888817119/job/140146112990). The failing assertion is the frame clock's zero-timeout poll after the second tick. The test-only change in #2265 already covers this timing assumption. @Thomas73737, the two new shader tests are ready for a retest on the RX 7900 XTX or RTX 5090 using `a9650b2`.
fuzeofficlal commented 2026-11-26 20:40:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T20:40:04Z.

Review: CHANGES_REQUESTED


Requesting changes on a9650b2f for a dual-NaN selection bug in max_min_flushed and unrelated whole-file diff churn:

Requested changes

  1. [P2] Two-NaN tie selects b instead of a (crates/victory-shader/src/emit/lower.rs:2223-2226):
    let r = self.s.m.select(c, b_nan, a, r);
    self.s.m.select(c, a_nan, b, r)
    
    When both a and b are NaN, the second select overrides a and returns b (source 1). This contradicts both the PR summary ("and the first operand when both are NaN") and the repository's RDNA2 hardware reference in crates/victory-shader/src/emit/semantics_tests.rs:889-896 ((true, true) | (false, true) => a), and also causes all-NaN v_min3_*/v_max3_*/v_med3_* to return the last operand rather than the first. Swapping the two selects (select(c, a_nan, b, r) first, then select(c, b_nan, a, r)) fixes both the binary and cascaded ternary paths.
  2. [P3] Scope out unrelated whole-file formatting diffs:
    The PR currently includes ~400 lines of unrelated rustfmt reformatting across emit/lower.rs and emit/valu_tests.rs (plus three unmentioned #[cfg(windows)] guards in lower.rs:11691, 11745, 11796). Keeping lower.rs changes scoped strictly to max_min_flushed (and moving/documenting the #[cfg(windows)] test guards separately if intended) avoids unnecessary merge conflicts in a size-capped hot file (522,541 bytes).
  3. [P3] Strengthen NaN payload test coverage (emit/valu_tests.rs:790, 836):
    The new tests pass identical quiet NaNs (f32::NAN / 0x7E00) and check only .is_nan(), so they cannot catch the dual-NaN payload inversion. Using distinct quiet NaN payloads (e.g., 0x7FC0_0001 vs. 0x7FC0_0002, plus [a, b, nan] and three distinct NaNs for min3/max3) will directly guard the rule.

(Local verification on a9650b2f: clippy default & --all-features clean; emit::valu_tests 37 passed, 0 failed on RTX 5090 + WARP.)

<!-- greyfinch-sync:Marvisak/VIctory:review:6080279421 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#pullrequestreview-6080279421). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T20:40:04Z. **Review:** CHANGES_REQUESTED --- Requesting changes on `a9650b2f` for a dual-NaN selection bug in `max_min_flushed` and unrelated whole-file diff churn: ### Requested changes 1. **[P2] Two-NaN tie selects `b` instead of `a` (`crates/victory-shader/src/emit/lower.rs:2223-2226`):** ```rust let r = self.s.m.select(c, b_nan, a, r); self.s.m.select(c, a_nan, b, r) ``` When both `a` and `b` are NaN, the second `select` overrides `a` and returns `b` (source 1). This contradicts both the PR summary (*"and the first operand when both are NaN"*) and the repository's RDNA2 hardware reference in `crates/victory-shader/src/emit/semantics_tests.rs:889-896` (`(true, true) | (false, true) => a`), and also causes all-NaN `v_min3_*`/`v_max3_*`/`v_med3_*` to return the last operand rather than the first. Swapping the two `select`s (`select(c, a_nan, b, r)` first, then `select(c, b_nan, a, r)`) fixes both the binary and cascaded ternary paths. 2. **[P3] Scope out unrelated whole-file formatting diffs:** The PR currently includes ~400 lines of unrelated `rustfmt` reformatting across `emit/lower.rs` and `emit/valu_tests.rs` (plus three unmentioned `#[cfg(windows)]` guards in `lower.rs:11691, 11745, 11796`). Keeping `lower.rs` changes scoped strictly to `max_min_flushed` (and moving/documenting the `#[cfg(windows)]` test guards separately if intended) avoids unnecessary merge conflicts in a size-capped hot file (`522,541` bytes). 3. **[P3] Strengthen NaN payload test coverage (`emit/valu_tests.rs:790, 836`):** The new tests pass identical quiet NaNs (`f32::NAN` / `0x7E00`) and check only `.is_nan()`, so they cannot catch the dual-NaN payload inversion. Using distinct quiet NaN payloads (e.g., `0x7FC0_0001` vs. `0x7FC0_0002`, plus `[a, b, nan]` and three distinct NaNs for `min3`/`max3`) will directly guard the rule. *(Local verification on `a9650b2f`: `clippy` default & `--all-features` clean; `emit::valu_tests` 37 passed, 0 failed on RTX 5090 + WARP.)*
Jackster commented 2026-11-26 21:02:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T21:02:26Z.


Follow-up at a9650b2: the corrected fixtures pass on AMD.

cargo test -p victory-shader --lib treat_a_nan_as_the_other_operand — 2 passed on the RX 7900 XTX (RDNA3, driver 32.0.32029.2010) and WARP, with no backend skipped. That covers the two cases that failed at 16c700e.

Synthetic shaders only, no game files. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203323900 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7203323900). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T21:02:26Z. --- Follow-up at `a9650b2`: the corrected fixtures pass on AMD. `cargo test -p victory-shader --lib treat_a_nan_as_the_other_operand` — 2 passed on the RX 7900 XTX (RDNA3, driver 32.0.32029.2010) and WARP, with no backend skipped. That covers the two cases that failed at `16c700e`. Synthetic shaders only, no game files. AI-assisted.
Thomas73737 commented 2026-11-26 21:50:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Thomas73737 on 2026-11-26T21:50:43Z.


Updated in 0f0a362:

  • Fixed dual-NaN selection in max_min_flushed: when both operands are NaN, the result now keeps the first operand’s NaN (swapped select order), matching RDNA2/semantics_tests::min_max and the cascaded 3-op case.
  • Strengthened NaN valu tests with distinct quiet NaN payloads (0x7FC0_0001/2/3, 0x7E01/2/3) and added an all-NaN min3/max3 case expecting the first NaN, for f32/f16 min/max/min3/max3.

I did not reformat/scope the earlier lower.rs diff in this push to avoid rewriting PR history; I can squash/rebase if preferred. Local: cargo fmt --package victory-shader -- crates/victory-shader/src/emit/lower.rs crates/victory-shader/src/emit/valu_tests.rs; cargo test -p victory-shader --locked --lib (172 passed, 0 failed, 2 ignored; Linux). Windows-gated valu tests not run in this sandbox.

The previous CI failure was unrelated victory-gpu frame::tests::waits_end_on_ticks_and_count_frames; I don’t have admin rights to rerun failed jobs, so CI needs a maintainer rerun or another trigger.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204115604 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7204115604). Originally posted by [Thomas73737](https://github.com/Thomas73737) on 2026-11-26T21:50:43Z. --- Updated in `0f0a362`: - Fixed dual-NaN selection in `max_min_flushed`: when both operands are NaN, the result now keeps the first operand’s NaN (swapped select order), matching RDNA2/`semantics_tests::min_max` and the cascaded 3-op case. - Strengthened NaN valu tests with distinct quiet NaN payloads (`0x7FC0_0001/2/3`, `0x7E01/2/3`) and added an all-NaN `min3/max3` case expecting the first NaN, for f32/f16 min/max/min3/max3. I did not reformat/scope the earlier `lower.rs` diff in this push to avoid rewriting PR history; I can squash/rebase if preferred. Local: `cargo fmt --package victory-shader -- crates/victory-shader/src/emit/lower.rs crates/victory-shader/src/emit/valu_tests.rs`; `cargo test -p victory-shader --locked --lib` (172 passed, 0 failed, 2 ignored; Linux). Windows-gated valu tests not run in this sandbox. The previous CI failure was unrelated `victory-gpu` `frame::tests::waits_end_on_ticks_and_count_frames`; I don’t have admin rights to rerun failed jobs, so CI needs a maintainer rerun or another trigger.
fuzeofficlal commented 2026-11-26 22:08:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:08:17Z.

Review: CHANGES_REQUESTED


Thanks for fixing max_min_flushed at crates/victory-shader/src/emit/lower.rs:2235-2238 so dual-NaN selection keeps the first operand a, and for adding distinct-payload coverage. However, two issues block approval on 0f0a362e:

  1. New f16 test fails on hardware GPU (crates/victory-shader/src/emit/valu_tests.rs:865): Running cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::valu_tests:: emit::lower:: passes 70/70 under VICTORY_WARP=1, but fails 69/70 under VICTORY_WARP=0 on RTX 5090:
    hardware: v_max_f16 [7e01, 7e02, 4000, 0]
      left: 32767
     right: 32257
    
    Because half_fsrc (lower.rs:6921) widens f16 operands via legacyF16ToF32 before max_min_flushed and narrow16, adapters that canonicalize f16 NaN payloads return 0x7FFF (32767) rather than preserving 0x7E01 (32257) (compare v_med3_f16_matches_rdna2_with_nan at valu_tests.rs:950-953, which asserts is_f16_nan(got_h) for the all-NaN f16 case). Please avoid asserting exact non-canonical f16 NaN payload bits on host execution unless the f16 payload is preserved end-to-end without host canonicalization.
  2. Unrelated formatting & guard noise still present: git diff 63bcca43..0f0a362e still contains ~35+ unrelated rustfmt hunks across lower.rs (lines 528–11883) and valu_tests.rs (lines 239–979), plus three unrelated #[cfg(windows)] additions in lower.rs (11700, 11754, 11805). Please revert the unrelated formatting/#[cfg(windows)] hunks so the diff stays scoped strictly to max_min_flushed and the new NaN tests.
<!-- greyfinch-sync:Marvisak/VIctory:review:6080999245 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#pullrequestreview-6080999245). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T22:08:17Z. **Review:** CHANGES_REQUESTED --- Thanks for fixing `max_min_flushed` at `crates/victory-shader/src/emit/lower.rs:2235-2238` so dual-NaN selection keeps the first operand `a`, and for adding distinct-payload coverage. However, two issues block approval on `0f0a362e`: 1. **New f16 test fails on hardware GPU (`crates/victory-shader/src/emit/valu_tests.rs:865`)**: Running `cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::valu_tests:: emit::lower::` passes **70/70** under `VICTORY_WARP=1`, but **fails 69/70** under `VICTORY_WARP=0` on RTX 5090: ```text hardware: v_max_f16 [7e01, 7e02, 4000, 0] left: 32767 right: 32257 ``` Because `half_fsrc` (`lower.rs:6921`) widens f16 operands via `legacyF16ToF32` before `max_min_flushed` and `narrow16`, adapters that canonicalize f16 NaN payloads return `0x7FFF` (`32767`) rather than preserving `0x7E01` (`32257`) (compare `v_med3_f16_matches_rdna2_with_nan` at `valu_tests.rs:950-953`, which asserts `is_f16_nan(got_h)` for the all-NaN f16 case). Please avoid asserting exact non-canonical f16 NaN payload bits on host execution unless the f16 payload is preserved end-to-end without host canonicalization. 2. **Unrelated formatting & guard noise still present**: `git diff 63bcca43..0f0a362e` still contains ~35+ unrelated `rustfmt` hunks across `lower.rs` (lines `528`–`11883`) and `valu_tests.rs` (lines `239`–`979`), plus three unrelated `#[cfg(windows)]` additions in `lower.rs` (`11700`, `11754`, `11805`). Please revert the unrelated formatting/`#[cfg(windows)]` hunks so the diff stays scoped strictly to `max_min_flushed` and the new NaN tests.
fuzeofficlal commented 2026-11-26 22:47:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:47:12Z.

Review: CHANGES_REQUESTED


Thanks for fixing the f16 NaN failure — 8d55a54a now passes all 70 emit::valu_tests:: and emit::lower:: tests on both RTX 5090 (VICTORY_WARP=0) and WARP (VICTORY_WARP=1), as well as rustfmt --edition 2024 --check and cargo clippy.

However, the unrelated diff cleanup requested in the previous review is still missing: relative to 63bcca43, the PR still carries 47 formatting-only hunks (38 in crates/victory-shader/src/emit/lower.rs and 9 in crates/victory-shader/src/emit/valu_tests.rs) plus the 3 unrelated #[cfg(windows)] validator guards at lower.rs:11703, lower.rs:11757, and lower.rs:11808, alongside only ~14 functional lines (lower.rs:2233-2241 and valu_tests.rs:857-866).

Please drop the unrelated rustfmt churn and the three #[cfg(windows)] hunks so the diff is scoped strictly to the max_min_flushed NaN fix and its test update.

<!-- greyfinch-sync:Marvisak/VIctory:review:6081236744 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#pullrequestreview-6081236744). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T22:47:12Z. **Review:** CHANGES_REQUESTED --- Thanks for fixing the f16 NaN failure — `8d55a54a` now passes all 70 `emit::valu_tests::` and `emit::lower::` tests on both RTX 5090 (`VICTORY_WARP=0`) and WARP (`VICTORY_WARP=1`), as well as `rustfmt --edition 2024 --check` and `cargo clippy`. However, the unrelated diff cleanup requested in the previous review is still missing: relative to `63bcca43`, the PR still carries **47 formatting-only hunks** (`38` in `crates/victory-shader/src/emit/lower.rs` and `9` in `crates/victory-shader/src/emit/valu_tests.rs`) plus the **3 unrelated `#[cfg(windows)]` validator guards** at `lower.rs:11703`, `lower.rs:11757`, and `lower.rs:11808`, alongside only ~14 functional lines (`lower.rs:2233-2241` and `valu_tests.rs:857-866`). Please drop the unrelated `rustfmt` churn and the three `#[cfg(windows)]` hunks so the diff is scoped strictly to the `max_min_flushed` NaN fix and its test update.
Thomas73737 commented 2026-11-26 22:59:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Thomas73737 on 2026-11-26T22:59:34Z.


Updated in 8d55a54:

  • Adjusted the f16 NaN min/max/min3/max3 tests to assert NaN-ness (is_f16_nan) rather than exact f16 NaN payload bits. This avoids host f16 widening/narrowing canonicalization (legacyF16ToF32/narrow16) returning a canonical NaN payload on hardware GPUs while still checking the NaN-propagation rule. f32 tests keep exact distinct-payload assertions.

Combined with 0f0a362, this covers the requested dual-NaN first-operand selection and distinct-payload/all-NaN coverage. I have not rewritten history to remove the earlier formatting/#[cfg(windows)] hunks from 16c700e; I can squash/rebase the branch to scope the diff strictly to max_min_flushed and the NaN tests if maintainers prefer. Local: cargo fmt --package victory-shader -- crates/victory-shader/src/emit/lower.rs crates/victory-shader/src/emit/valu_tests.rs; cargo test -p victory-shader --locked --lib (172 passed, 0 failed, 2 ignored; Linux). Windows-gated valu tests not run in this sandbox.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205160161 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7205160161). Originally posted by [Thomas73737](https://github.com/Thomas73737) on 2026-11-26T22:59:34Z. --- Updated in `8d55a54`: - Adjusted the f16 NaN min/max/min3/max3 tests to assert NaN-ness (`is_f16_nan`) rather than exact f16 NaN payload bits. This avoids host f16 widening/narrowing canonicalization (`legacyF16ToF32`/`narrow16`) returning a canonical NaN payload on hardware GPUs while still checking the NaN-propagation rule. f32 tests keep exact distinct-payload assertions. Combined with `0f0a362`, this covers the requested dual-NaN first-operand selection and distinct-payload/all-NaN coverage. I have not rewritten history to remove the earlier formatting/`#[cfg(windows)]` hunks from `16c700e`; I can squash/rebase the branch to scope the diff strictly to `max_min_flushed` and the NaN tests if maintainers prefer. Local: `cargo fmt --package victory-shader -- crates/victory-shader/src/emit/lower.rs crates/victory-shader/src/emit/valu_tests.rs`; `cargo test -p victory-shader --locked --lib` (172 passed, 0 failed, 2 ignored; Linux). Windows-gated valu tests not run in this sandbox.
andrewpozdnakov7-jpg commented 2026-11-27 09:25:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T09:25:14Z.


Thomas73737, both updated NaN tests passed on exact head 8d55a54 under app-local WARP 1.0.22. The synthetic v_max_f32 still emitted two fcmp uno checks. A driver folded that kind of check in the separate v_med3 case reported in #745. Driver report

562a3cd checks the operand magnitudes as integers against the infinity bits. The same shader dumped by DXC now has both unsigned integer comparisons. All 37 VALU tests passed on both revisions, including the new negative-NaN and infinity cases on the follow-up. Strict shader Clippy and asset policy passed.

The commit is ready for review or cherry-pick. A run on an adapter that exhibited the driver fold would verify the hardware side. Please retain the Git author if you take the commit. If folding it into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

AI-assisted with Codex. Synthetic shaders only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7214659397 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7214659397). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T09:25:14Z. --- Thomas73737, both updated NaN tests passed on exact head `8d55a54` under app-local WARP 1.0.22. The synthetic `v_max_f32` still emitted two `fcmp uno` checks. A driver folded that kind of check in the separate `v_med3` case reported in #745. [Driver report](https://github.com/Marvisak/VIctory/issues/745) [562a3cd](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/562a3cdf440c3fa5146d7e45429d26ca76ce10ff) checks the operand magnitudes as integers against the infinity bits. The same shader dumped by DXC now has both unsigned integer comparisons. All 37 VALU tests passed on both revisions, including the new negative-NaN and infinity cases on the follow-up. Strict shader Clippy and asset policy passed. The commit is ready for review or cherry-pick. A run on an adapter that exhibited the driver fold would verify the hardware side. Please retain the Git author if you take the commit. If folding it into another commit, please add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted with Codex. Synthetic shaders only.
Thomas73737 commented 2026-11-27 09:54:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Thomas73737 on 2026-11-27T09:54:54Z.


Updated in e5993b0 (rebased/squashed to scope the diff):

  • Took the NaN classification fix from @andrewpozdnakov7-jpg (integer magnitude check against infinity bits, avoids host float-comparison folding) and kept attribution as Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.
  • Kept dual-NaN first-operand NaN behavior and the strengthened NaN tests (distinct f32 payloads, negative NaN, infinity, all-NaN 3-op; f16 asserts NaN-ness to avoid payload canonicalization).
  • Removed unrelated rustfmt/#[cfg(windows)] churn so the diff is scoped to max_min_flushed and the NaN valu tests.

Local: cargo fmt --package victory-shader -- crates/victory-shader/src/emit/lower.rs crates/victory-shader/src/emit/valu_tests.rs; cargo test -p victory-shader --locked --lib (172 passed, 0 failed, 2 ignored; Linux). Windows-gated valu tests not run in this sandbox.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7215248628 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7215248628). Originally posted by [Thomas73737](https://github.com/Thomas73737) on 2026-11-27T09:54:54Z. --- Updated in `e5993b0` (rebased/squashed to scope the diff): - Took the NaN classification fix from @andrewpozdnakov7-jpg (integer magnitude check against infinity bits, avoids host float-comparison folding) and kept attribution as `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. - Kept dual-NaN first-operand NaN behavior and the strengthened NaN tests (distinct f32 payloads, negative NaN, infinity, all-NaN 3-op; f16 asserts NaN-ness to avoid payload canonicalization). - Removed unrelated `rustfmt`/`#[cfg(windows)]` churn so the diff is scoped to `max_min_flushed` and the NaN valu tests. Local: `cargo fmt --package victory-shader -- crates/victory-shader/src/emit/lower.rs crates/victory-shader/src/emit/valu_tests.rs`; `cargo test -p victory-shader --locked --lib` (172 passed, 0 failed, 2 ignored; Linux). Windows-gated valu tests not run in this sandbox.
andrewpozdnakov7-jpg commented 2026-11-27 12:59:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T12:59:08Z.


I reran both suites on exact head e5993b072f343b806bdc41fd9d3e0ac47a2a429c. All 37 emit::valu_tests:: tests passed on app-local WARP 1.0.22 (Wave32), including the expanded signed NaN and infinity cases. All 33 emit::lower:: tests passed as well. git diff --check passed, and the diff against main is down to emit/lower.rs and emit/valu_tests.rs.

The earlier RTX 5090 result was on 8d55a54. A rerun on current head would confirm the integer NaN classification on that driver and give the reviewer current evidence for the remaining hardware check. Exact-head CI

<!-- greyfinch-sync:Marvisak/VIctory:comment:7218916628 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7218916628). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T12:59:08Z. --- I reran both suites on exact head `e5993b072f343b806bdc41fd9d3e0ac47a2a429c`. All 37 `emit::valu_tests::` tests passed on app-local WARP 1.0.22 (Wave32), including the expanded signed NaN and infinity cases. All 33 `emit::lower::` tests passed as well. `git diff --check` passed, and the diff against `main` is down to `emit/lower.rs` and `emit/valu_tests.rs`. The earlier RTX 5090 result was on `8d55a54`. A rerun on current head would confirm the integer NaN classification on that driver and give the reviewer current evidence for the remaining hardware check. [Exact-head CI](https://github.com/Marvisak/VIctory/actions/runs/45977275004/job/140432049508)
andrewpozdnakov7-jpg commented 2026-11-28 13:02:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T13:02:25Z.


I combined your NaN-selection change at exact e5993b0 with #3733 c909723 in 5839fa6. Both commits are direct parents. The two-stage min/max still calls your explicit NaN-selection helper twice and flushes each of the three incoming values once.

On WARP with Agility 1.620.2, all 438,976 output words matched your head exactly, across both opcodes, four modifier configurations, and NaNs, signed zeros, subnormals and infinities. All 37 VALU tests passed, including your f32/f16 NaN checks. The existing min/max/clamp model also passed. DXIL counts against your head went from 96 to 90 for one min3 or max3 and 712 to 640 for a 12-operation chain. Strict all-feature shader Clippy and the asset policy passed.

@Thomas73737, the combined tree is ready for merge coordination. Please retain Git authorship on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding my changes into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7239645271 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7239645271). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T13:02:25Z. --- I combined your NaN-selection change at exact `e5993b0` with #3733 `c909723` in [`5839fa6`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/5839fa6f92438260a37b25c6e9ea097968b5f7e5). Both commits are direct parents. The two-stage min/max still calls your explicit NaN-selection helper twice and flushes each of the three incoming values once. On WARP with Agility 1.620.2, all 438,976 output words matched your head exactly, across both opcodes, four modifier configurations, and NaNs, signed zeros, subnormals and infinities. All 37 VALU tests passed, including your f32/f16 NaN checks. The existing min/max/clamp model also passed. DXIL counts against your head went from 96 to 90 for one min3 or max3 and 712 to 640 for a 12-operation chain. Strict all-feature shader Clippy and the asset policy passed. @Thomas73737, the combined tree is ready for merge coordination. Please retain Git authorship on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding my changes into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 14:20:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T14:20:47Z.


I combined #3744 at 6f3fa6d with the previous integration of your exact head and #3733 in 5444478. The literal path still runs your explicit NaN selection, including first-operand selection when both operands are NaN. A known nonzero literal lets it skip the two-zero repair. The signed-zero and three-way paths still use that repair.

Against the previous integration, all 47,790 output words matched on Windows WARP with Agility 1.620.2. The test covers both literal positions, signed zeros, subnormals, infinities, signaling and quiet NaNs, and a dynamic control. The ordinary literal max went from 64 to 51 DXIL instructions and the negative-zero min went from 64 to 57. The dynamic control stayed at 66.

All 37 VALU tests passed, including the f32 and f16 NaN tests. The min/max/clamp model, 13 bitcode tests, strict all-feature shader Clippy and the asset policy also passed. @Thomas73737, the fork commit is available for merge coordination. Please retain the Git authors on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding my changes into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7240600037 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7240600037). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T14:20:47Z. --- I combined #3744 at `6f3fa6d` with the [previous integration of your exact head and #3733](https://github.com/Marvisak/VIctory/pull/3352#issuecomment-7239645271) in [`5444478`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/54444789d30fe4f4864f3a04662a57a1345d3182). The literal path still runs your explicit NaN selection, including first-operand selection when both operands are NaN. A known nonzero literal lets it skip the two-zero repair. The signed-zero and three-way paths still use that repair. Against the previous integration, all 47,790 output words matched on Windows WARP with Agility 1.620.2. The test covers both literal positions, signed zeros, subnormals, infinities, signaling and quiet NaNs, and a dynamic control. The ordinary literal max went from 64 to 51 DXIL instructions and the negative-zero min went from 64 to 57. The dynamic control stayed at 66. All 37 VALU tests passed, including the f32 and f16 NaN tests. The min/max/clamp model, 13 bitcode tests, strict all-feature shader Clippy and the asset policy also passed. @Thomas73737, the fork commit is available for merge coordination. Please retain the Git authors on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding my changes into another commit. AI-assisted with OpenAI Codex.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3352:upstream-pr/3352'
git switch 'upstream-pr/3352'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3352'
git switch 'upstream-pr/3352'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3352'
git switch 'upstream-pr/3352'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3352'
git switch 'main'
git merge --squash 'upstream-pr/3352'
git switch 'main'
git merge --ff-only 'upstream-pr/3352'
git switch 'main'
git merge 'upstream-pr/3352'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3352
No description provided.