Shaders: flush subnormals in the f32 cube coordinates #1709

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

@⁠Calvix2k on GitHub · 2026-11-24 21:03 UTC · original
Calvix2k:codex/shader-denormals-find4 → main · +43 −1 · 2 files · 1 commits · closed without merging

Rebased onto 70564ae and reduced to the cube path only: upstream 77053a0 now flushes denormals for min/max/select and med3 itself, so those parts and the #1554 stack are gone. The cube inputs and result go through the shared ftz helper; v_cube_flushes_subnormals_in_dxil checks the four sequences.

Validation: targeted test passes, clippy -D warnings and cargo xtask policy (174 files) clean. Hardware measurement on the RX 7800 XT remains the same (the hardware flushes; the lowering now emits it explicitly).

**@⁠Calvix2k** on GitHub · 2026-11-24 21:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/1709) `Calvix2k:codex/shader-denormals-find4` → `main` · +43 −1 · 2 files · 1 commits · closed without merging Rebased onto 70564ae and reduced to the cube path only: upstream 77053a0 now flushes denormals for min/max/select and med3 itself, so those parts and the #1554 stack are gone. The cube inputs and result go through the shared `ftz` helper; `v_cube_flushes_subnormals_in_dxil` checks the four sequences. Validation: targeted test passes, clippy `-D warnings` and `cargo xtask policy` (174 files) clean. Hardware measurement on the RX 7800 XT remains the same (the hardware flushes; the lowering now emits it explicitly).
RDNA flushes subnormal inputs and results for v_cubeid/sc/tc/ma_f32.
Upstream now flushes min/max/select and med3 denormals itself, so only
the cube path remains here. Use the shared ftz helper on x, y, z and the
result; add a DXIL check for the four flush sequences.

Addresses FIND-4 from #1633.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:42:20 +00:00
github-bot closed this pull request 2026-11-26 04:42:20 +00:00
Author
Owner

@⁠tumbubu on GitHub · 2026-11-24 22:14 UTC · original

On an RX 7900 XT (RDNA3): #1709 removes six of the seven min/max/med3/cube disagreements #1614's fuzzer finds. With #1483 on top, all seven agree.

RX 7900 XT, driver 32.0.31036.15, Windows 11 26300, dxil.dll 10.0.26100. #1614's fuzzer (fuzz_tests.rs at c3372c1) was copied onto each head, 160 inputs per opcode, comparing the 7900 XT with WARP:

Opcode main ffe310e #1709 3821b53 #1709 + #1483 0daabcc
v_min_f32 5 differ 0 0
v_max_f32 2 0 0
v_min3_f32 2 0 0
v_max3_f32 2 0 0
v_cubesc_f32 19 0 0
v_cubetc_f32 32 0 0
v_med3_f32 10 10 0
all min/max/med3/cube opcodes (34) 7 differ 1 0
  • The 10 v_med3_f32 rows left on #1709 alone are all one case: two flushed denormals of opposite sign, where the 7900 XT returns +0 and WARP returns -0. One example is v_med3_f32(0x00000001, 0x4e800000, 0x807fffff). That is the -0 < +0 ordering #1483 adds to v_med3, and with it the rows agree.
  • #1709 alone: cargo test -p victory-shader --locked -- --test-threads=1 gives 123 passed, 0 failed, 1 ignored. Both DXIL checks ran, since dxc.exe is next to the SDK's dxil.dll.
  • #1709 + #1483 is a local merge: lower.rs merged cleanly, and in valu_tests.rs I kept both sides' new tests. That gives 129 passed, 0 failed.
  • On the whole fuzzer, #1709 alone takes main's 31 disagreements on this card down to 25. What is left is the i64 compares (#1599), the f16 rounding (#422 / 77053a0), the fused v_fma(c)_f32 and v_med3_f32, plus WARP's own inexact v_sin/v_cos/v_log/v_cvt_f32_u32.

Synthetic tests only, no game files. AI-assisted (Claude Code); every run was on this machine.

**@⁠tumbubu** on GitHub · 2026-11-24 22:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1709#issuecomment-7145982254) **On an RX 7900 XT (RDNA3): #1709 removes six of the seven `min`/`max`/`med3`/`cube` disagreements #1614's fuzzer finds. With #1483 on top, all seven agree.** RX 7900 XT, driver 32.0.31036.15, Windows 11 26300, `dxil.dll` 10.0.26100. #1614's fuzzer (`fuzz_tests.rs` at `c3372c1`) was copied onto each head, 160 inputs per opcode, comparing the 7900 XT with WARP: | Opcode | `main` `ffe310e` | #1709 `3821b53` | #1709 + #1483 `0daabcc` | |---|---:|---:|---:| | `v_min_f32` | 5 differ | 0 | 0 | | `v_max_f32` | 2 | 0 | 0 | | `v_min3_f32` | 2 | 0 | 0 | | `v_max3_f32` | 2 | 0 | 0 | | `v_cubesc_f32` | 19 | 0 | 0 | | `v_cubetc_f32` | 32 | 0 | 0 | | `v_med3_f32` | 10 | **10** | 0 | | all `min`/`max`/`med3`/`cube` opcodes (34) | 7 differ | 1 | **0** | - The 10 `v_med3_f32` rows left on #1709 alone are all one case: two flushed denormals of opposite sign, where the 7900 XT returns `+0` and WARP returns `-0`. One example is `v_med3_f32(0x00000001, 0x4e800000, 0x807fffff)`. That is the `-0 < +0` ordering #1483 adds to `v_med3`, and with it the rows agree. - #1709 alone: `cargo test -p victory-shader --locked -- --test-threads=1` gives 123 passed, 0 failed, 1 ignored. Both DXIL checks ran, since `dxc.exe` is next to the SDK's `dxil.dll`. - #1709 + #1483 is a local merge: `lower.rs` merged cleanly, and in `valu_tests.rs` I kept both sides' new tests. That gives 129 passed, 0 failed. - On the whole fuzzer, #1709 alone takes `main`'s 31 disagreements on this card down to 25. What is left is the i64 compares (#1599), the f16 rounding (#422 / `77053a0`), the fused `v_fma(c)_f32` and `v_med3_f32`, plus WARP's own inexact `v_sin`/`v_cos`/`v_log`/`v_cvt_f32_u32`. Synthetic tests only, no game files. AI-assisted (Claude Code); every run was on this machine.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-24 22:21 UTC · original

Reworked on the new base as a standalone cube-only PR (no longer stacked on #1554). See updated body.

**@⁠Calvix2k** on GitHub · 2026-11-24 22:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1709#issuecomment-7146122607) Reworked on the new base as a standalone cube-only PR (no longer stacked on #1554). See updated body.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-25 00:19 UTC · original

Cross-referencing #1766, which makes the same input flush for v_cube*_f32. I compared the two there: the ftz(r) on the result can't change anything, because cube results are ±an input, 2 × an input, or a face id, and write_f already flushes omod products. So the two PRs behave the same; only one should merge. This PR was first. #1766's GPU probe (semantics_tests, checked on an RX 9070 and a gfx1036) can go on top of it if wanted.

**@⁠alexdeliu** on GitHub · 2026-11-25 00:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1709#issuecomment-7148386405) Cross-referencing #1766, which makes the same input flush for `v_cube*_f32`. I compared the two there: the `ftz(r)` on the result can't change anything, because cube results are ±an input, 2 × an input, or a face id, and `write_f` already flushes `omod` products. So the two PRs behave the same; only one should merge. This PR was first. #1766's GPU probe (`semantics_tests`, checked on an RX 9070 and a gfx1036) can go on top of it if wanted.
Author
Owner

@⁠Marcos-Barranquero on GitHub · 2026-11-25 01:12 UTC · original

NVIDIA data point for this and #1766: RTX 4070 Ti SUPER (Ada), driver 32.0.16.1692, Windows 11. The probe is #1766's semantics_tests::cube_faces_match_the_hardware: 14,440 inputs per op, checked against its RDNA2 model.

tree v_cubesc_f32 hardware vs model v_cubetc_f32 hardware vs model hardware vs WARP
main 42363ab + #1766's probe 2,193 2,111 differ on 917 / 1,696
#1766 at 3686431 0 0 agree
this PR at aaf3243 + #1766's probe 0 0 agree

v_cubeid_f32 and v_cubema_f32 are 0 everywhere. This PR's own v_cube_flushes_subnormals_in_dxil passes as well.

On main the RTX keeps a denormal coordinate, as AMD does: v_cubesc_f32(0, NaN, 0x00000001) = 0x80000001, and WARP gives 0x80000000. The mismatch count against the model is the same 2,193 that #1766 reports for the RX 9070. So the flush fixes NVIDIA the same way, and either PR does it. The cross-device fuzzer from #1614 on this card had v_cubesc/tc_f32 among its 9 differences against WARP on main; the other 7 are WARP's own inexactness and the known fused v_fma/v_fmac_f32.

No game data.

AI-assisted (Claude Code).

**@⁠Marcos-Barranquero** on GitHub · 2026-11-25 01:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1709#issuecomment-7149317730) NVIDIA data point for this and #1766: **RTX 4070 Ti SUPER** (Ada), driver 32.0.16.1692, Windows 11. The probe is #1766's `semantics_tests::cube_faces_match_the_hardware`: 14,440 inputs per op, checked against its RDNA2 model. | tree | `v_cubesc_f32` hardware vs model | `v_cubetc_f32` hardware vs model | hardware vs WARP | |---|---|---|---| | `main` 42363ab + #1766's probe | 2,193 | 2,111 | differ on 917 / 1,696 | | #1766 at 3686431 | 0 | 0 | agree | | this PR at aaf3243 + #1766's probe | 0 | 0 | agree | `v_cubeid_f32` and `v_cubema_f32` are 0 everywhere. This PR's own `v_cube_flushes_subnormals_in_dxil` passes as well. On `main` the RTX keeps a denormal coordinate, as AMD does: `v_cubesc_f32(0, NaN, 0x00000001)` = `0x80000001`, and WARP gives `0x80000000`. The mismatch count against the model is the same 2,193 that #1766 reports for the RX 9070. So the flush fixes NVIDIA the same way, and either PR does it. The cross-device fuzzer from #1614 on this card had `v_cubesc/tc_f32` among its 9 differences against WARP on `main`; the other 7 are WARP's own inexactness and the known fused `v_fma/v_fmac_f32`. No game data. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:35 UTC · original

Automated triage for the maintainers.

Needs work. Flushing denormal cube coordinates through ftz in lower.rs (the v_cube*_f32 arm) is backed by hardware results posted on this PR (RX 7900 XT, RTX 4070 Ti SUPER). However, #1766 makes the same input flush and adds a hardware-checked probe, semantics_tests::cube_faces_match_the_hardware, so the maintainer should pick one. If this one goes ahead:

  • dump_cube_dxil in valu_tests.rs copies dump_dxil from emit/mod.rs; please share that helper.
  • The ftz(r) on the result appears to do nothing, since cube results are ± an input, twice an input, or a face id.
  • The test only counts and i32 ... 2139095040 lines, which is weaker than #1766's probe.

CI passes.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/1709#issuecomment-7152053996) <!-- victory-triage v1 head=d61c307c3454d79d24b4ce34f2946125f953193f verdict=needs-work at=2026-11-25T03:40:20Z --> Automated triage for the maintainers. **Needs work.** Flushing denormal cube coordinates through `ftz` in `lower.rs` (the `v_cube*_f32` arm) is backed by hardware results posted on this PR (RX 7900 XT, RTX 4070 Ti SUPER). However, #1766 makes the same input flush and adds a hardware-checked probe, `semantics_tests::cube_faces_match_the_hardware`, so the maintainer should pick one. If this one goes ahead: - `dump_cube_dxil` in `valu_tests.rs` copies `dump_dxil` from `emit/mod.rs`; please share that helper. - The `ftz(r)` on the result appears to do nothing, since cube results are ± an input, twice an input, or a face id. - The test only counts `and i32 ... 2139095040` lines, which is weaker than #1766's probe. CI passes. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 08:37 UTC · original

Closing this in favour of #1766 (@⁠alexdeliu), which the triage also recommends: it makes the same flush and adds a hardware-checked probe (semantics_tests::cube_faces_match_the_hardware) that is stronger than this PR's check for the emitted and 0x7F800000 sequences. @⁠alexdeliu already said whichever lands, the other closes; two green PRs for one behaviour only divides the review.

Nothing is lost: the four emitted sequences this PR checked are the same ones that probe measures on the hardware. If #1766 ends up not landing, the branch here stays rebased and can be reopened.

**@⁠Calvix2k** on GitHub · 2026-11-25 08:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1709#issuecomment-7157263697) Closing this in favour of #1766 (@⁠alexdeliu), which the triage also recommends: it makes the same flush and adds a hardware-checked probe (`semantics_tests::cube_faces_match_the_hardware`) that is stronger than this PR's check for the emitted `and 0x7F800000` sequences. @⁠alexdeliu already said whichever lands, the other closes; two green PRs for one behaviour only divides the review. Nothing is lost: the four emitted sequences this PR checked are the same ones that probe measures on the hardware. If #1766 ends up not landing, the branch here stays rebased and can be reopened.

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