Fix #726: NaN-safe v_med3_f32 lowering #2010

Closed
github-bot wants to merge 1 commit from gh-pr/2010/head into gh-pr/2010/base
Owner

@⁠tharun-37 on GitHub · 2026-11-25 02:51 UTC · original
tharun-37:fix/med3-nan → main · +21 −5 · 1 files · 1 commits · closed without merging

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.

**@⁠tharun-37** on GitHub · 2026-11-25 02:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2010) `tharun-37:fix/med3-nan` → `main` · +21 −5 · 1 files · 1 commits · closed without merging 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:51:35 +00:00
github-bot closed this pull request 2026-11-26 04:51:35 +00:00
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 03:10 UTC · original

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.

**@⁠Dathinel** on GitHub · 2026-11-25 03:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2010#issuecomment-7151663187) 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://git.gtahub.st/github/Marvisak--VIctory/issues/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: ```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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 09:17 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 09:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2010#issuecomment-7158139601) <!-- 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)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 10:01 UTC · original

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

**@⁠sinan-cmyk** on GitHub · 2026-11-25 10:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2010#issuecomment-7159124663) ### 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).
Author
Owner

@⁠artor410 on GitHub · 2026-11-25 21:53 UTC · original

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

**@⁠artor410** on GitHub · 2026-11-25 21:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2010#issuecomment-7175669726) 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.)
Author
Owner

@⁠tharun-37 on GitHub · 2026-11-26 03:26 UTC · original

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

**@⁠tharun-37** on GitHub · 2026-11-26 03:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2010#issuecomment-7181723075) Closing to re-scope: taking on better-scoped issues instead.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!2010
No description provided.