Skip to content

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

Merged
Marvisak merged 2 commits into
Marvisak:mainfrom
alexdeliu:fix/cube-ftz
Nov 25, 2026
Merged

Marvisak merged 2 commits into
Marvisak:mainfrom
alexdeliu:fix/cube-ftz

Conversation

@alexdeliu

Copy link
Copy Markdown
Contributor

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:

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

🤖 Generated with 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 (Marvisak#1614).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DesertGamer

Copy link
Copy Markdown

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.

@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 (70564ae), cargo test -p victory-shader --locked → 118 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows.

Cube-map face coordinates read denormals as zeros: cube()/cube_probes() + cube_faces_match_the_hardware pins face-coordinate denormal behavior against hardware. Small, precise fix with a hardware test.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown

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

@alexdeliu

Copy link
Copy Markdown
Contributor Author

@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

Copy link
Copy Markdown
Contributor Author

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.

@Calvix2k

Copy link
Copy Markdown
Contributor

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.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@alexdeliu

Copy link
Copy Markdown
Contributor Author

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

@Calvix2k

Copy link
Copy Markdown
Contributor

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.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@Marvisak
Marvisak merged commit 77fd819 into Marvisak:main Nov 25, 2026
1 check passed
Gandalem added a commit to Gandalem/VIctory that referenced this pull request Nov 26, 2026
Apply complete, uniquely matching upstream hunks in dependency order, preserving fork-specific raw structured buffer lowering and configurable descriptor capacity. Defer incompatible shader ABI and cross-module changes until GPU reconciliation.

704d25e Shaders: v_mul_legacy_f32 treats denormal operands as zero (Marvisak#682)
cc7ec2a Shaders: 64-bit integer compares on their dwords (AMD orders a shared-dword i64 compare wrong) (Marvisak#1599)
77fd819 Shaders: cube-map face coordinates read denormals as zeros (Marvisak#1766)
084d4ff Shaders: round full-width unsigned integer conversions once (Marvisak#2186)
f3578e3 Shaders: decode f16 inline float constants in whole-wave v_add_f16 simulation (Marvisak#2493)
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