Skip to content

Shaders: flush subnormals in the f32 cube coordinates - #1709

Closed
Calvix2k wants to merge 1 commit into
Marvisak:mainfrom
Calvix2k:codex/shader-denormals-find4
Closed

Calvix2k wants to merge 1 commit into
Marvisak:mainfrom
Calvix2k:codex/shader-denormals-find4

Conversation

@Calvix2k

@Calvix2k Calvix2k commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests.

f32 min/max/median and cube ops now flush subnormals like RDNA MAD instructions: write_f_with_ftz + flush_f32 (exponent==0 → signed zero via sign mask). +3 macOS tests.

@tumbubu

tumbubu commented Nov 24, 2026

Copy link
Copy Markdown

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

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

@Calvix2k
Calvix2k force-pushed the codex/shader-denormals-find4 branch from 3821b53 to c3182f7 Compare November 24, 2026 22:20
@Calvix2k Calvix2k changed the title Shaders: flush subnormals in f32 min/max/median and cube Shaders: flush subnormals in the f32 cube coordinates Nov 24, 2026
@Calvix2k
Calvix2k force-pushed the codex/shader-denormals-find4 branch from c3182f7 to aaf3243 Compare November 24, 2026 22:21
@Calvix2k

Copy link
Copy Markdown
Contributor Author

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

@alexdeliu

Copy link
Copy Markdown

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.

@Marcos-Barranquero

Copy link
Copy Markdown

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

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 Marvisak#1633.
@Calvix2k
Calvix2k force-pushed the codex/shader-denormals-find4 branch from aaf3243 to d61c307 Compare November 25, 2026 02:25

Copy link
Copy Markdown
Owner

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 Shaders: cube-map face coordinates read denormals as zeros #1766's probe.

CI passes.


Generated by Claude Code

@Calvix2k

Copy link
Copy Markdown
Contributor Author

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 Calvix2k closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants