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

Open
neonbyte1 wants to merge 1 commit from upstream-pr/2968 into main
neonbyte1 commented 2026-11-26 01:48:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-26T01:48:00Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6617665918 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2968). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-26T01:48:00Z. --- 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._
fuzeofficlal commented 2026-11-26 02:00:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:00:04Z.

Review: COMMENTED


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
<!-- greyfinch-sync:Marvisak/VIctory:review:6067554077 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2968#pullrequestreview-6067554077). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T02:00:04Z. **Review:** COMMENTED --- 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 commented 2026-11-26 02:01:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T02:01:22Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6067562911 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2968#pullrequestreview-6067562911). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T02:01:22Z. **Review:** APPROVED --- 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 commented 2026-11-26 02:19:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:19:08Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6067690789 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2968#pullrequestreview-6067690789). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T02:19:08Z. **Review:** COMMENTED --- 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.
neonbyte1 commented 2026-11-26 04:06:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-26T03:38:05Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181890245 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2968#issuecomment-7181890245). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-26T03:38:05Z. --- 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 commented 2026-11-26 05:04:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fyernald on 2026-11-26T05:04:08Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068811003 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2968#pullrequestreview-6068811003). Originally posted by [fyernald](https://github.com/fyernald) on 2026-11-26T05:04:08Z. **Review:** APPROVED --- 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.
Marvisak commented 2026-11-26 06:03:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:32:58Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183587212 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2968#issuecomment-7183587212). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T05:32:58Z. --- <!-- 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)_
Jackster commented 2026-11-26 16:24:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T16:24:52Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197613664 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2968#issuecomment-7197613664). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T16:24:52Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2968:upstream-pr/2968'
git switch 'upstream-pr/2968'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2968'
git switch 'upstream-pr/2968'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2968'
git switch 'upstream-pr/2968'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2968'
git switch 'main'
git merge --squash 'upstream-pr/2968'
git switch 'main'
git merge --ff-only 'upstream-pr/2968'
git switch 'main'
git merge 'upstream-pr/2968'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2966
No description provided.