Fix #726: NaN-safe v_med3_f32 lowering #2008

Closed
tharun-37 wants to merge 1 commit from upstream-pr/2010 into main
tharun-37 commented 2026-11-25 02:51:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tharun-37 on 2026-11-25T02:51:55Z.


Split from #2000 (shader-only, covered by macOS test queue). NaN-safe min/max so a NaN operand yields the smaller of the two numbers. v_med3_f32_matches_rdna2_with_nan passes.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6596090702 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2010). Originally posted by [tharun-37](https://github.com/tharun-37) on 2026-11-25T02:51:55Z. --- Split from #2000 (shader-only, covered by macOS test queue). NaN-safe min/max so a NaN operand yields the smaller of the two numbers. v_med3_f32_matches_rdna2_with_nan passes.
catminou4 commented 2026-11-25 04:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:34:28Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

144 passed / 0 failed. NaN-safe v_med3_f32 lowering — fixes issue #726. Note: #2000 claimed #726 too (as part of #721/#722/#726); #2009+#2010 split it. Also relates to #1259 (v_med3 -0/+0 ordering) — check the three compose.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051470014 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2010#pullrequestreview-6051470014). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T03:34:28Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 144 passed / 0 failed. NaN-safe v_med3_f32 lowering — fixes issue #726. **Note**: #2000 claimed #726 too (as part of #721/#722/#726); #2009+#2010 split it. Also relates to #1259 (v_med3 -0/+0 ordering) — check the three compose.
Dathinel commented 2026-11-25 04:06:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-25T03:10:33Z.


The existing v_med3_f32_matches_rdna2_with_nan test runs on Windows. On an RTX 3050 Laptop (driver 610.62) and WARP it passes on both 940d32f and this PR's 36451bd, including the original (1, 2, NaN) case. A macOS test run omits this module.

I also compared all 216 ordered triples drawn from −1, −0, +0, +2 and two quiet NaNs with different signs and payloads. Both revisions matched the same reference for every triple on each backend. I compared signed zeros by bit pattern and accepted any NaN for the all-NaN case.

The remaining check that can distinguish the fix is a before/after run on the Intel UHD setup that reproduces #726. The patch still emits unordered floating-point comparisons for its NaN checks. On that setup, please record the actual adapter and the result of this exact test on each revision:

cargo test --locked -p victory-shader --lib emit::valu_tests::v_med3_f32_matches_rdna2_with_nan -- --exact --nocapture

Synthetic inputs only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151663187 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2010#issuecomment-7151663187). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-25T03:10:33Z. --- The existing `v_med3_f32_matches_rdna2_with_nan` test runs on Windows. On an RTX 3050 Laptop (driver 610.62) and WARP it passes on both `940d32f` and this PR's `36451bd`, including the original `(1, 2, NaN)` case. A macOS test run omits this module. I also compared all 216 ordered triples drawn from −1, −0, +0, +2 and two quiet NaNs with different signs and payloads. Both revisions matched the same reference for every triple on each backend. I compared signed zeros by bit pattern and accepted any NaN for the all-NaN case. The remaining check that can distinguish the fix is a before/after run on the [Intel UHD setup that reproduces #726](https://github.com/Marvisak/VIctory/issues/726#issuecomment-7140559071). The patch still emits unordered floating-point comparisons for its NaN checks. On that setup, please record the actual adapter and the result of this exact test on each revision: ```text cargo test --locked -p victory-shader --lib emit::valu_tests::v_med3_f32_matches_rdna2_with_nan -- --exact --nocapture ``` Synthetic inputs only. AI-assisted.
Marvisak commented 2026-11-25 10:07:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:17:49Z.


Automated triage for the maintainers.

Needs work.

  • In emit/lower.rs med3, each min/max now goes through new nan_safe_min/nan_safe_max, which add fcmp uno self-compares and selects around max_min_flushed. On a host whose minnum/maxnum already ignore NaN (as DXIL requires), these selects change nothing. The PR gives no evidence that they change anything on the setup where #726 reproduces. The run posted here (RTX 3050 Laptop and WARP) has the existing test passing both before and after the change, so it does not show a fix.
  • The new checks are float self-compares, the same kind #1689 reports NVIDIA's compiler folding away in this function. If the Intel driver does the same, the change has no effect there. To move this forward, post a before/after run of v_med3_f32_matches_rdna2_with_nan on the Intel UHD setup from #726 (adapter and driver named), and consider bit-pattern NaN tests as in #1689.
  • Small: the helpers are inserted between med3's doc comment and fn med3, so that comment now documents nan_safe_min. Move them below med3.
  • Overlap: #2000 contains the same change, bundled with unrelated copy-back changes. #1689 changes the NaN test of the same function in a different way.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158139601 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2010#issuecomment-7158139601). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T09:17:49Z. --- <!-- victory-triage v1 head=36451bdadd00b7ff594db09e341fbfe34aec5631 verdict=needs-work at=2026-11-25T09:17:41Z --> Automated triage for the maintainers. **Needs work.** - In `emit/lower.rs` `med3`, each min/max now goes through new `nan_safe_min`/`nan_safe_max`, which add `fcmp uno` self-compares and selects around `max_min_flushed`. On a host whose `minnum`/`maxnum` already ignore NaN (as DXIL requires), these selects change nothing. The PR gives no evidence that they change anything on the setup where #726 reproduces. The run posted here (RTX 3050 Laptop and WARP) has the existing test passing both before and after the change, so it does not show a fix. - The new checks are float self-compares, the same kind #1689 reports NVIDIA's compiler folding away in this function. If the Intel driver does the same, the change has no effect there. To move this forward, post a before/after run of `v_med3_f32_matches_rdna2_with_nan` on the Intel UHD setup from #726 (adapter and driver named), and consider bit-pattern NaN tests as in #1689. - Small: the helpers are inserted between `med3`'s doc comment and `fn med3`, so that comment now documents `nan_safe_min`. Move them below `med3`. - Overlap: #2000 contains the same change, bundled with unrelated copy-back changes. #1689 changes the NaN test of the same function in a different way. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 10:07:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T10:01:43Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head 36451bda onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159124663 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2010#issuecomment-7159124663). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T10:01:43Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 36451bda onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
artor410 commented 2026-11-25 22:04:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by artor410 on 2026-11-25T21:53:27Z.


Tested on RTX 3070 Ti, driver 610.88, Windows 11 26300, rustc 1.98.1. main 13f91ca. Merged into main cleanly (e69a7e2).

  • cargo test -p victory-shader -- --skip heap_direct_texture_reads_mark_their_heap_index: that test crashes the process on this card on main (0xc0000005), so it is skipped. Main: 266 passed, 3 failed (a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, gathers_at_a_level_match_the_hardware).
  • With this PR: 266 passed, same 3 failed. No new test.
  • v_med3_f32_matches_rdna2_with_nan already passes on main on this card, so #726 does not reproduce here, and this PR is neither confirmed nor refuted on this hardware.
  • Note: the NaN detection here is still fcmp uno, and the PR adds more of it. #110 reports that this compare is folded away by a driver under fast-math. If that is the cause, this PR would not fix it. The VItoriaBr and DexNom forks test NaN on the integer bits instead (abs(bits) > 0x7F800000).

(Claude Code, Claude Opus 5.5.)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175669726 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2010#issuecomment-7175669726). Originally posted by [artor410](https://github.com/artor410) on 2026-11-25T21:53:27Z. --- Tested on RTX 3070 Ti, driver 610.88, Windows 11 26300, rustc 1.98.1. main 13f91ca. Merged into main cleanly (e69a7e2). - `cargo test -p victory-shader -- --skip heap_direct_texture_reads_mark_their_heap_index`: that test crashes the process on this card on main (0xc0000005), so it is skipped. Main: 266 passed, 3 failed (`a_heap_buffer_read_by_element_takes_the_views_stride`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `gathers_at_a_level_match_the_hardware`). - With this PR: 266 passed, same 3 failed. No new test. - `v_med3_f32_matches_rdna2_with_nan` already passes on main on this card, so #726 does not reproduce here, and this PR is neither confirmed nor refuted on this hardware. - Note: the NaN detection here is still `fcmp uno`, and the PR adds more of it. #110 reports that this compare is folded away by a driver under fast-math. If that is the cause, this PR would not fix it. The VItoriaBr and DexNom forks test NaN on the integer bits instead (`abs(bits) > 0x7F800000`). (Claude Code, Claude Opus 5.5.)
upstream-sync closed this pull request 2026-11-26 04:05:03 +00:00
tharun-37 commented 2026-11-26 04:06:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tharun-37 on 2026-11-26T03:26:34Z.


Closing to re-scope: taking on better-scoped issues instead.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181723075 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2010#issuecomment-7181723075). Originally posted by [tharun-37](https://github.com/tharun-37) on 2026-11-26T03:26:34Z. --- Closing to re-scope: taking on better-scoped issues instead.

Pull request closed

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!2008
No description provided.