Skip to content

Shaders: f32 floor, ceil and fract flush denormal operands - #2968

Open
neonbyte1 wants to merge 1 commit into
Marvisak:mainfrom
neonbyte1:pr/ftz
Open

neonbyte1 wants to merge 1 commit into
Marvisak:mainfrom
neonbyte1:pr/ftz

Conversation

@neonbyte1

Copy link
Copy Markdown

The console reads f32 denormals as zeros of their sign. DXIL floor, ceil and frac leave that to the host, and vkd3d-proton on NVIDIA does not advertise FP32 denorm flush, so v_floor_f32, v_ceil_f32 and v_fract_f32 of a denormal kept it. v_fract_f32 of 0x80000001 gave 0x3f7fffff (just under 1.0) instead of 0. The operand is now flushed on the bits first, as max/min and the float-to-int conversions already do.

Tests (Linux, Wine 11.22, vkd3d-proton 3.1-83 from GE-Proton11-14, RTX 5090, driver 620.73.04; run with cargo xtask wine-test from #1218):

  • emit::semantics_tests::rounding_matches_the_hardware failed before on the 5090 and on the vkd3d-proton software path, 2 of 38 inputs each for floor, ceil and fract. It passes with this change.
  • victory-shader: 299 passed, 3 failed, against 298/4 on main (63bcca4). The other 3 failures are Wine/vkd3d-proton gaps fixed elsewhere: Tests: keep the D3D12 pipeline smoke check portable under Wine #1266, and a PR of mine that follows.
  • cargo clippy --workspace --all-targets (with and without diagnostics) and cargo xtask policy are clean.

Translation over the whole shader pack: no program starts or stops translating. 11,157 programs emit different DXIL, all from the added flush. That's broad, so I ran it in game: two 7-minute runs on our NVIDIA/Wine test build, with no crash or new drops (556 against 558 dropped draws a frame, 86 against 90 indirect). Frame 1500 was still the loading screen in both, so this is not a visual comparison.

Not tested on Windows. On a host that flushes denormals already, the extra and/select is a no-op.

AI-assisted (Claude); measured on my machine, no game data shared.

The console reads f32 denormals as zeros, but DXIL floor/ceil/fract
leave that to the host. vkd3d on NVIDIA does not advertise FP32 denorm
flush, so both adapters returned the unfloored result. Flush on the
bits first, as the other denormal-sensitive lowerings do.

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

Reviewed and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP + dxil.dll) — clean fix and ready to merge:

  • Applying self.ftz(a) after source modifiers (abs/neg) in v_fract_f32, v_floor_f32, and v_ceil_f32 (crates/victory-shader/src/emit/lower.rs:6340-6347) flushes subnormals to signed zero (±0.0) while leaving NaN and ±Inf untouched, matching RDNA2 behavior on NVIDIA drivers (where -denorm otherwise produced -1.0 for floor and 0x3F7F_FFFF for fract).
  • emit/lower.rs size on 63bcca43: 521,164 B (+601 B, 3,124 B under the 512 KiB policy limit).
  • (Minor non-blocking note: adding a ±denorm regression case to valu_tests for v_floor_f32/v_ceil_f32/v_fract_f32 would lock this behavior in directly.)

Local verification:

  • cargo test --locked -p victory-shader -- fract floor ceil denorm: 7/7 passed (GPU + WARP + dxil.dll)
  • cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warnings
  • cargo xtask policy: 191 files ok

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator active):

  • cargo test -p victory-shader --lib emit::semantics_tests::arithmetic_matches_the_hardware: 1 passed, 0 failed (hardware + WARP, 0 mismatches).
  • cargo test -p victory-shader --lib emit::lower::tests: 33 passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Flushing f32 denormal operands via self.ftz(a) before fract (op 22), floor (op 27), and ceil (op 28) matches RDNA2 FTZ behavior and avoids vkd3d/NVIDIA denormal retention.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified: flushing the operand to zero before DXIL floor/ceil/fract matches the console's denormal-as-zero reads and the existing ftz treatment for max/min and the floor conversions in this same lowering — needed precisely because vkd3d can't request FP32 denormal flush on NVIDIA. ops 27/28/22 are the right sites.

notquiteog added a commit to notquiteog/victory-nvidia that referenced this pull request Nov 26, 2026
…l operands (by neonbyte1)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@neonbyte1

Copy link
Copy Markdown
Author

Thanks for checking. On a ±denormal case: emit::semantics_tests::rounding_matches_the_hardware already covers it. It feeds 0x80000001, 0x807fffff and 0x007fffff (and their neighbours) to v_floor_f32, v_ceil_f32 and v_fract_f32, and compares against the hardware and WARP. Under vkd3d-proton on NVIDIA it failed on exactly those inputs before this change (fract of 0x80000001 gave 0x3f7fffff) and passes with it. So I'd leave valu_tests as is, unless a maintainer prefers a dedicated case.

@fyernald fyernald left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A native Windows data point, since this was tested under vkd3d-proton: RTX 3080 (driver 617.42), Windows 10 22H2. Base is main 63bcca4 + #486 (Agility opt-in) + #2596 (so the suite gets past the #2571 crash).

base + this PR (e4a11fd)
emit::semantics_tests::rounding_matches_the_hardware passes passes
cargo test -p victory-shader --lib -- --test-threads=1 298 passed, 4 failed, 3 ignored 298 passed, 4 failed, 3 ignored (same 4)

So the native NVIDIA D3D12 driver already gives the console's results for those denormal inputs here. The failure you saw is specific to vkd3d-proton. The change doesn't move anything on Windows, and it stops the result from depending on the driver's denorm mode, the same as max/min already do.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. In lower.rs, in the VOP1 float arm, v_fract_f32 (DXIL op 22) and v_floor_f32 / v_ceil_f32 (27 / 28) now pass their operand through ftz first. The v_cvt_flr_i32_f32 / v_cvt_rpi_i32_f32 path already does this. The evidence is the hardware-referenced rounding_matches_the_hardware test already on main, which feeds these ops ±denormals. A host that keeps denormals fails it, and with this change it passes. trunc and rndne are rightly left alone, since a denormal gives ±0 from them either way. On hosts that already flush, the change costs one compare and select.

CI: passing. Recommending a look, not approving.


Generated by Claude Code

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