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

Open
github-bot wants to merge 1 commit from github-bot/gh-2968 into main AGit
Owner

@⁠neonbyte1 on GitHub · 2026-11-26 01:48 UTC · original
neonbyte1:pr/ftz → main · +13 −1 · 1 files · 1 commits · open

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: #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.

**@⁠neonbyte1** on GitHub · 2026-11-26 01:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2968) `neonbyte1:pr/ftz` → `main` · +13 −1 · 1 files · 1 commits · open 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: #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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:18:53 +00:00
Author
Owner

@⁠neonbyte1 on GitHub · 2026-11-26 03:38 UTC · original

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.

**@⁠neonbyte1** on GitHub · 2026-11-26 03:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2968#issuecomment-7181890245) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:32 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-26 05:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2968#issuecomment-7183587212) <!-- victory-triage v1 head=e4a11fd5f90c2b614509acd5e8c3551d0ba4b4ed verdict=merge-candidate at=2026-11-26T05:32:50Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 02:00 UTC · original · reviewed

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
**@⁠fuzeofficlal** on GitHub · 2026-11-26 02:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2968#pullrequestreview-6067554077) · **reviewed** 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
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 02:01 UTC · original · approved these changes

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

**@⁠Dukestar69** on GitHub · 2026-11-26 02:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2968#pullrequestreview-6067562911) · **approved these changes** 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).
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 02:19 UTC · original · reviewed

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.

**@⁠kotekompotek** on GitHub · 2026-11-26 02:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2968#pullrequestreview-6067690789) · **reviewed** 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.
Author
Owner

@⁠fyernald on GitHub · 2026-11-26 05:04 UTC · original · approved these changes

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.

**@⁠fyernald** on GitHub · 2026-11-26 05:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/2968#pullrequestreview-6068811003) · **approved these changes** 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.
Author
Owner

@⁠Jackster on GitHub · 2026-11-26 16:24 UTC · original

Windows 11, Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010), victory-shader built with --features host so the hardware backend runs:

  • emit::semantics_tests::rounding_matches_the_hardware passes on unpatched 63bcca4 here, and with this PR. The 2-of-38 floor/ceil/fract mismatches you saw on the 5090 and on vkd3d-proton do not reproduce on RDNA3, so on this adapter the added flush is a no-op.

Synthetic only. AI-assisted.

**@⁠Jackster** on GitHub · 2026-11-26 16:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2968#issuecomment-7197613664) Windows 11, Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010), `victory-shader` built with `--features host` so the hardware backend runs: - `emit::semantics_tests::rounding_matches_the_hardware` **passes on unpatched `63bcca4`** here, and with this PR. The 2-of-38 floor/ceil/fract mismatches you saw on the 5090 and on vkd3d-proton do not reproduce on RDNA3, so on this adapter the added flush is a no-op. Synthetic only. AI-assisted.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2968/head:github-bot/gh-2968'
git switch 'github-bot/gh-2968'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2968'
git switch 'github-bot/gh-2968'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2968'
git switch 'github-bot/gh-2968'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2968'
git switch 'main'
git merge --squash 'github-bot/gh-2968'
git switch 'main'
git merge --ff-only 'github-bot/gh-2968'
git switch 'main'
git merge 'github-bot/gh-2968'
git push origin 'main'
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!2968
No description provided.