Shaders: cube-map face coordinates read denormals as zeros #1766

Manually merged
github merged 2 commits from gh-pr/1766/head into gh-pr/1766/base 2026-11-26 04:43:57 +00:00
Owner

@⁠alexdeliu on GitHub · 2026-11-24 22:13 UTC · original
alexdeliu:fix/cube-ftz → main · +64 −1 · 2 files · 2 commits · merged 2026-11-25 21:51 UTC

v_cubeid/sc/tc/ma_f32 return one of the coordinates, or its negation. So a denormal coordinate comes out as the host chooses:

  • AMD keeps it: v_cubesc_f32(0, NaN, 0x00000001) gives 0x80000001 on an RX 9070.
  • WARP flushes it, to 0x80000000.
  • The console's float mode, as main models it since 77053a0 (32-bit denormals flushed on input and output), reads it as a zero of its sign.

min/max operands already go through ftz (77053a0). The cube coordinates didn't.

Change

The three coordinates go through self.ftz before the major-axis compare and the pick (lower.rs, the cube arm).

Test

semantics_tests::cube_faces_match_the_hardware adds a probe family in the existing framework:

  • the four cube ops over triples(F32_EDGES, F32_EDGES, F32_THIRD), i.e. 14,440 inputs with signed zeros, denormals, infinities and NaN in each coordinate;
  • checked against an RDNA2 model cube(): the major-axis rule from the ISA, with coordinates read through ftz.
RX 9070 vs model WARP vs model hardware vs WARP
main @ 70564ae 2,193 mismatches (v_cubesc_f32 alone) 1,276 differ on 917
this PR 0 0 agree

Checks

On Windows 11 with the RX 9070:

  • both CI clippy runs are clean;
  • cargo test --workspace --locked passes 475 (main: 474, plus this probe);
  • the only failures are the 2 PSV0 tests that fail on main itself with the SDK's 1.7 dxil.dll (rect::tests::rectangles_get_their_fourth_corner, tests::elements_sharing_a_row_keep_their_order; see #1744).

Found by the cross-device fuzzer in #1614. It is the remaining denormal case after 77053a0 (FIND-4 in #1633).

🤖 Generated with Claude Code

**@⁠alexdeliu** on GitHub · 2026-11-24 22:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1766) `alexdeliu:fix/cube-ftz` → `main` · +64 −1 · 2 files · 2 commits · merged 2026-11-25 21:51 UTC `v_cubeid/sc/tc/ma_f32` return one of the coordinates, or its negation. So a **denormal coordinate comes out as the host chooses**: - AMD keeps it: `v_cubesc_f32(0, NaN, 0x00000001)` gives `0x80000001` on an RX 9070. - WARP flushes it, to `0x80000000`. - The console's float mode, as `main` models it since 77053a0 (32-bit denormals flushed on input and output), reads it as a zero of its sign. `min`/`max` operands already go through `ftz` (77053a0). The cube coordinates didn't. ## Change The three coordinates go through `self.ftz` before the major-axis compare and the pick (`lower.rs`, the cube arm). ## Test `semantics_tests::cube_faces_match_the_hardware` adds a probe family in the existing framework: - the four cube ops over `triples(F32_EDGES, F32_EDGES, F32_THIRD)`, i.e. 14,440 inputs with signed zeros, denormals, infinities and NaN in each coordinate; - checked against an RDNA2 model `cube()`: the major-axis rule from the ISA, with coordinates read through `ftz`. | | RX 9070 vs model | WARP vs model | hardware vs WARP | |---|---|---|---| | `main` @ `70564ae` | 2,193 mismatches (`v_cubesc_f32` alone) | 1,276 | differ on 917 | | this PR | 0 | 0 | agree | ## Checks On Windows 11 with the RX 9070: - both CI clippy runs are clean; - `cargo test --workspace --locked` passes 475 (`main`: 474, plus this probe); - the only failures are the 2 PSV0 tests that fail on `main` itself with the SDK's 1.7 `dxil.dll` (`rect::tests::rectangles_get_their_fourth_corner`, `tests::elements_sharing_a_row_keep_their_order`; see #1744). Found by the cross-device fuzzer in #1614. It is the remaining denormal case after 77053a0 (FIND-4 in #1633). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
v_cubeid/sc/tc/ma_f32 pick a coordinate (or its negation) as the
result, so a denormal coordinate came out as the host's: kept on AMD,
flushed to -0 on WARP, where the console's float mode reads it as a zero
of its sign. The coordinates now go through ftz first, as min and max's
operands do (77053a0).

A semantics probe runs the four over signed zeros, denormals,
infinities and NaN in each coordinate (14,440 inputs) against the RDNA2
model. Without the change: 2,193 model mismatches on an RX 9070, 1,276
on WARP, and the two disagree on 917.

Found by the cross-device fuzzer (#1614).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:43:55 +00:00
github manually merged commit 054ecc8c5e into gh-pr/1766/base 2026-11-26 04:43:57 +00:00
Author
Owner

@⁠DesertGamer on GitHub · 2026-11-24 22:13 UTC · original

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

**@⁠DesertGamer** on GitHub · 2026-11-24 22:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1766#issuecomment-7145972205) ### VIctory V2: community PRs, merged and tested Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. **Where it stands today:** launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). :warning: Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk. Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: https://DesertGamer/VIctory-V2 *Unofficial community fork of Marvisak/VIctory, GPL-3.0.*
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 22:46 UTC · original

Overlap for the reviewers: #1709 (Calvix2k, opened 21:03, rebased onto 70564ae) makes the same change in lower.rs: let (x, y, z) = (self.ftz(x), self.ftz(y), self.ftz(z)); on the v_cube*_f32 inputs. It also passes the result through self.ftz(r). Its test is v_cube_flushes_subnormals_in_dxil in valu_tests.rs; this PR's is in semantics_tests.rs. Only one of the two code changes can merge as is. From reading both diffs; nothing built.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-24 22:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/1766#issuecomment-7146628200) Overlap for the reviewers: #1709 (Calvix2k, opened 21:03, rebased onto `70564ae`) makes the same change in `lower.rs`: `let (x, y, z) = (self.ftz(x), self.ftz(y), self.ftz(z));` on the `v_cube*_f32` inputs. It also passes the result through `self.ftz(r)`. Its test is `v_cube_flushes_subnormals_in_dxil` in `valu_tests.rs`; this PR's is in `semantics_tests.rs`. Only one of the two code changes can merge as is. From reading both diffs; nothing built. AI-assisted (Claude Code).
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 23:59 UTC · original

@⁠upipibi thanks. #1709 came first and makes the same input flush, so only one of the two should merge. The real difference is that #1709 also flushes the result. I will check on the RX 9070 and the gfx1036 whether the hardware flushes v_cube* results too, and post it on both PRs. If it does, #1709 is the more complete fix, and this PR's semantics_tests probe can move on top of it.

**@⁠alexdeliu** on GitHub · 2026-11-24 23:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/1766#issuecomment-7148012503) @⁠upipibi thanks. #1709 came first and makes the same input flush, so only one of the two should merge. The real difference is that #1709 also flushes the result. I will check on the RX 9070 and the gfx1036 whether the hardware flushes `v_cube*` results too, and post it on both PRs. If it does, #1709 is the more complete fix, and this PR's `semantics_tests` probe can move on top of it.
Author
Owner

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

Follow-up on the #1709 overlap: the two PRs behave the same. #1709's extra self.ftz(r) on the result is a no-op, so no hardware check is needed to choose between them.

  • Every v_cube*_f32 result is built from an input or a constant. cubesc/cubetc return a coordinate, possibly negated; cubema returns 2 × the major coordinate; cubeid returns a face index from 0 to 5. With the inputs flushed, every input is ±0 or normal, so no result can be denormal.
  • The only way to get a tiny result from a normal input is omod ×0.5 on a value near FLT_MIN. write_f already handles that: it flushes, multiplies, then turns a tiny product into +0 for every VALU op.

So either change is correct. #1709 was opened first. This PR adds a semantics_tests probe, which runs the GPU on both sides. #1709's test checks the DXIL text. If #1709 is the one taken, I'm happy to move the probe on top of it.

**@⁠alexdeliu** on GitHub · 2026-11-25 00:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1766#issuecomment-7148385964) Follow-up on the #1709 overlap: the two PRs behave the same. #1709's extra `self.ftz(r)` on the result is a no-op, so no hardware check is needed to choose between them. - Every `v_cube*_f32` result is built from an input or a constant. `cubesc`/`cubetc` return a coordinate, possibly negated; `cubema` returns 2 × the major coordinate; `cubeid` returns a face index from 0 to 5. With the inputs flushed, every input is ±0 or normal, so no result can be denormal. - The only way to get a tiny result from a normal input is `omod` ×0.5 on a value near FLT_MIN. `write_f` already handles that: it flushes, multiplies, then turns a tiny product into +0 for every VALU op. So either change is correct. #1709 was opened first. This PR adds a `semantics_tests` probe, which runs the GPU on both sides. #1709's test checks the DXIL text. If #1709 is the one taken, I'm happy to move the probe on top of it.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 00:41 UTC · original

Thanks for the cross-reference. #1709 was opened first and is still mergeable, so this is a duplicate of it. The GPU probe from this PR (semantics_tests on RX 9070 and gfx1036) is the useful extra piece; it would be welcome as a follow-up on top of #1709. Suggest closing this PR in favour of #1709.

**@⁠Calvix2k** on GitHub · 2026-11-25 00:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/1766#issuecomment-7148777353) Thanks for the cross-reference. #1709 was opened first and is still mergeable, so this is a duplicate of it. The GPU probe from this PR (semantics_tests on RX 9070 and gfx1036) is the useful extra piece; it would be welcome as a follow-up on top of #1709. Suggest closing this PR in favour of #1709.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:41 UTC · original · edited 2026-11-25 06:22 UTC

Automated triage for the maintainers.

Merge candidate. The new head only merges main; the change is the same. The v_cube*_f32 arm in crates/victory-shader/src/emit/lower.rs flushes the three coordinates through self.ftz before choosing the major axis. That matches main's model of the console's float mode, and main still lacks the flush there. The cube_faces_match_the_hardware probe in semantics_tests.rs compares the GPU against an ISA-based model over signed zeros, denormals, infinities and NaN. #1709 makes the same input flush (its extra result flush is a no-op, as argued here) and also merges cleanly. Only one of the two should land, and this one carries the hardware probe.

Agreed with the reply: either change is correct, and the choice between this and #1709 is the maintainer's.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/1766#issuecomment-7152151386) · edited 2026-11-25 06:22 UTC <!-- victory-triage v1 head=054ecc8c5e505645c5f8b8b05867454a01c14fa1 verdict=merge-candidate at=2026-11-25T06:22:49Z --> Automated triage for the maintainers. **Merge candidate.** The new head only merges `main`; the change is the same. The `v_cube*_f32` arm in `crates/victory-shader/src/emit/lower.rs` flushes the three coordinates through `self.ftz` before choosing the major axis. That matches `main`'s model of the console's float mode, and `main` still lacks the flush there. The `cube_faces_match_the_hardware` probe in `semantics_tests.rs` compares the GPU against an ISA-based model over signed zeros, denormals, infinities and NaN. #1709 makes the same input flush (its extra result flush is a no-op, as argued here) and also merges cleanly. Only one of the two should land, and this one carries the hardware probe. Agreed with the reply: either change is correct, and the choice between this and #1709 is the maintainer's. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-25 04:50 UTC · original

@⁠Calvix2k thanks. As I wrote above, the two behave the same. I'll leave the choice to the maintainer; whichever one lands, the other can be closed. If it's #1709, I'll move the semantics_tests probe on top of it.

**@⁠alexdeliu** on GitHub · 2026-11-25 04:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1766#issuecomment-7153210842) @⁠Calvix2k thanks. As I wrote above, the two behave the same. I'll leave the choice to the maintainer; whichever one lands, the other can be closed. If it's #1709, I'll move the `semantics_tests` probe on top of it.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 05:15 UTC · original

Understood — whichever the maintainer picks, the other closes. #1709 is green and mergeable; if it lands first, moving your semantics_tests probe on top of it is the right follow-up. The difference I saw on my side is only in what the tests compare (mine checks the four emitted sequences; yours measures the hardware's denormal output for v_cube*_f32), and both are useful.

**@⁠Calvix2k** on GitHub · 2026-11-25 05:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/1766#issuecomment-7153592774) Understood — whichever the maintainer picks, the other closes. #1709 is green and mergeable; if it lands first, moving your `semantics_tests` probe on top of it is the right follow-up. The difference I saw on my side is only in what the tests compare (mine checks the four emitted sequences; yours measures the hardware's denormal output for `v_cube*_f32`), and both are useful.
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!1766
No description provided.