Shaders: floor, ceil and fract read denormals as zeros #1994

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

@⁠astrosteveo on GitHub · 2026-11-25 02:33 UTC · original
astrosteveo:fix/shader-round-denormals → main · +6 −0 · 1 files · 1 commits · open

v_floor_f32, v_ceil_f32 and v_fract_f32 hand their operand to the host as it is. A host that keeps 32-bit denormals then gives -1 for floor of a tiny negative number, 1 for ceil of a tiny positive one, and almost 1 for fract; the console reads the denormal as a zero of its sign.

emit::semantics_tests::rounding_matches_the_hardware already covers this and fails on an RTX 5080 under vkd3d-proton 3.1 (Wine 11.22, driver 620.73.04), which reports shaderDenormFlushToZeroFloat32 = false and shaderDenormPreserveFloat32 = false:

v_floor_f32 v5, v1: 38 inputs, model mismatches ["hardware 2", "warp 2"]
  hardware: in [80000001, ...] want [80000000] got [bf800000]
v_ceil_f32 v5, v1: 38 inputs, model mismatches ["hardware 2", "warp 2"]
  hardware: in [00000001, ...] want [00000000] got [3f800000]
v_fract_f32 v5, v1: 38 inputs, model mismatches ["hardware 2", "warp 2"]
  hardware: in [80000001, ...] want [00000000] got [3f7fffff]

("warp" is the same GPU here: DXVK has no WARP and returns the hardware adapter.)

Change (lower.rs, +6): the operands of these three go through ftz, as v_cvt_flr_i32_f32's already do. v_trunc_f32 and v_rndne_f32 pass as they are: a denormal rounds to a zero either way.

Tested on 940d32f, MinGW build under Wine on that GPU, no game data:

  • rounding_matches_the_hardware: fails without the change, passes with it.
  • cargo test -p victory-shader --lib -- --test-threads=1: 243 passed, 4 failed before; 244 passed, 3 failed after. The 3 also fail on main here (no WARP, no digest check under vkd3d-proton, and a_heap_buffer_read_where_no_buffer_view_is_reads_zeros).
  • Clippy for x86_64-pc-windows-msvc, also with --all-features: clean. cargo xtask policy: ok.

Not tested on Windows or in the title.

AI-assisted (Claude).

🤖 Generated with Claude Code

**@⁠astrosteveo** on GitHub · 2026-11-25 02:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1994) `astrosteveo:fix/shader-round-denormals` → `main` · +6 −0 · 1 files · 1 commits · open `v_floor_f32`, `v_ceil_f32` and `v_fract_f32` hand their operand to the host as it is. A host that keeps 32-bit denormals then gives -1 for `floor` of a tiny negative number, 1 for `ceil` of a tiny positive one, and almost 1 for `fract`; the console reads the denormal as a zero of its sign. `emit::semantics_tests::rounding_matches_the_hardware` already covers this and fails on an RTX 5080 under vkd3d-proton 3.1 (Wine 11.22, driver 620.73.04), which reports `shaderDenormFlushToZeroFloat32 = false` and `shaderDenormPreserveFloat32 = false`: ``` v_floor_f32 v5, v1: 38 inputs, model mismatches ["hardware 2", "warp 2"] hardware: in [80000001, ...] want [80000000] got [bf800000] v_ceil_f32 v5, v1: 38 inputs, model mismatches ["hardware 2", "warp 2"] hardware: in [00000001, ...] want [00000000] got [3f800000] v_fract_f32 v5, v1: 38 inputs, model mismatches ["hardware 2", "warp 2"] hardware: in [80000001, ...] want [00000000] got [3f7fffff] ``` ("warp" is the same GPU here: DXVK has no WARP and returns the hardware adapter.) **Change** (`lower.rs`, +6): the operands of these three go through `ftz`, as `v_cvt_flr_i32_f32`'s already do. `v_trunc_f32` and `v_rndne_f32` pass as they are: a denormal rounds to a zero either way. **Tested** on `940d32f`, MinGW build under Wine on that GPU, no game data: - `rounding_matches_the_hardware`: fails without the change, passes with it. - `cargo test -p victory-shader --lib -- --test-threads=1`: 243 passed, 4 failed before; 244 passed, 3 failed after. The 3 also fail on `main` here (no WARP, no digest check under vkd3d-proton, and `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`). - Clippy for `x86_64-pc-windows-msvc`, also with `--all-features`: clean. `cargo xtask policy`: ok. Not tested on Windows or in the title. AI-assisted (Claude). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
v_floor_f32, v_ceil_f32 and v_fract_f32 gave the host the operand as it
was, so a host that keeps 32-bit denormals gave -1 for floor of a tiny
negative number, 1 for ceil of a tiny positive one, and almost 1 for fract.
An RTX 5080 on vkd3d-proton keeps them: its driver offers no
flush-to-zero control. rounding_matches_the_hardware failed there.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:50:57 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 09:16 UTC · original

Automated triage for the maintainers.
Merge candidate.

In crates/victory-shader/src/emit/lower.rs (VOP1 float unary lowering), the operands of v_floor_f32, v_ceil_f32 and v_fract_f32 now go through Lower::ftz first. This matches the reference model the tests already use (semantics_tests.rs: round(...) applies ftz to its input and fract does ftz(x), noted as measured on RDNA2) and the existing handling of v_cvt_flr_i32_f32/v_cvt_rpi_i32_f32 in the same file. So it is a portability fix for hosts that keep f32 denormals, and the PR body includes the failing rounding_matches_the_hardware output. Leaving out v_trunc_f32/v_rndne_f32 is correct, since a denormal rounds to a signed zero either way. Small change with no new dependencies. I found no other open PR that makes the same change. Recommending a look, not approving.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 09:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1994#issuecomment-7158110050) <!-- victory-triage v1 head=e06bcf16890d06ea43601af24a84608ff6b230b7 verdict=merge-candidate at=2026-11-25T09:16:12Z --> Automated triage for the maintainers. **Merge candidate.** In `crates/victory-shader/src/emit/lower.rs` (VOP1 float unary lowering), the operands of `v_floor_f32`, `v_ceil_f32` and `v_fract_f32` now go through `Lower::ftz` first. This matches the reference model the tests already use (`semantics_tests.rs`: `round(...)` applies `ftz` to its input and `fract` does `ftz(x)`, noted as measured on RDNA2) and the existing handling of `v_cvt_flr_i32_f32`/`v_cvt_rpi_i32_f32` in the same file. So it is a portability fix for hosts that keep f32 denormals, and the PR body includes the failing `rounding_matches_the_hardware` output. Leaving out `v_trunc_f32`/`v_rndne_f32` is correct, since a denormal rounds to a signed zero either way. Small change with no new dependencies. I found no other open PR that makes the same change. Recommending a look, not approving. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 10:04 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head e06bcf16 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 10:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/1994#issuecomment-7159193936) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head e06bcf16 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-25 11:09 UTC · original

Native Windows A/B on an RTX 5080 and built-in Microsoft WARP (d3d10warp.dll 10.0.26100.10068): both adapters already flush these subnormal operands on parent 940d32f. I got the same outputs on e06bcf1. I selected each adapter in a separate process and checked its identity and dispatch readback.

The existing rounding_matches_the_hardware test passed all seven operations × 38 inputs on each adapter and revision. I also compared exact output bits for floor, ceil and fract on 64 subnormal magnitudes of each sign and 12 controls, including signed zeros and the smallest normal of each sign. All 420/420 results matched per adapter on each revision.

For example, the largest negative subnormal (0x807fffff) produced floor = -0 and fract = +0. The adjacent negative normal (0x80800000) produced floor = -1 and fract = 0x3f7fffff. The explicit flush preserves that boundary on native RTX/WARP and complements the before/after difference you measured under Wine.

**@⁠steven-seagull27** on GitHub · 2026-11-25 11:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/1994#issuecomment-7160670148) Native Windows A/B on an RTX 5080 and built-in Microsoft WARP (`d3d10warp.dll` 10.0.26100.10068): both adapters already flush these subnormal operands on parent `940d32f`. I got the same outputs on `e06bcf1`. I selected each adapter in a separate process and checked its identity and dispatch readback. The existing `rounding_matches_the_hardware` test passed all seven operations × 38 inputs on each adapter and revision. I also compared exact output bits for `floor`, `ceil` and `fract` on 64 subnormal magnitudes of each sign and 12 controls, including signed zeros and the smallest normal of each sign. All **420/420 results matched** per adapter on each revision. For example, the largest negative subnormal (`0x807fffff`) produced `floor = -0` and `fract = +0`. The adjacent negative normal (`0x80800000`) produced `floor = -1` and `fract = 0x3f7fffff`. The explicit flush preserves that boundary on native RTX/WARP and complements the before/after difference you measured under Wine.
Author
Owner

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

Code review and RTX 5090 + WARP + DXIL verification at head e06bcf16890d merged cleanly onto main (63bcca43c6a0; emit/lower.rs = 520,835 B, 3,453 B under the 512 KiB cap):

  • Code review (crates/victory-shader/src/emit/lower.rs:2163-2176, 6333-6343):
    • Applying self.ftz(a) before v_fract_f32, v_floor_f32, and v_ceil_f32 matches v_cvt_flr_i32_f32/v_cvt_rpi_i32_f32 (lower.rs:6354) while preserving sign bits (+denorm -> +0.0, -denorm -> -0.0) and leaving normal values, integers, ±Inf, and NaN untouched. (v_floor/ceil/fract_f16 already widen through half_fsrc to f32 where f16 denormals are normal.)
    • Minor non-blocking note: adding a ±denorm test case in valu_tests covering v_floor_f32/v_ceil_f32/v_fract_f32 (existing v_fract_f32_never_returns_one bottoms out at normal -2^-25) would lock in the regression test directly.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warnings
    • floor ceil fract emit::lower::tests: 37/37 passed across RTX 5090 (hardware) and WARP (warp + explicit VICTORY_WARP=1 4/4).

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/1994#issuecomment-7179183522) Code review and RTX 5090 + WARP + DXIL verification at head `e06bcf16890d` merged cleanly onto `main` (`63bcca43c6a0`; `emit/lower.rs` = `520,835` B, `3,453` B under the 512 KiB cap): - **Code review (`crates/victory-shader/src/emit/lower.rs:2163-2176, 6333-6343`)**: - Applying `self.ftz(a)` before `v_fract_f32`, `v_floor_f32`, and `v_ceil_f32` matches `v_cvt_flr_i32_f32`/`v_cvt_rpi_i32_f32` (`lower.rs:6354`) while preserving sign bits (`+denorm -> +0.0`, `-denorm -> -0.0`) and leaving normal values, integers, `±Inf`, and `NaN` untouched. (`v_floor/ceil/fract_f16` already widen through `half_fsrc` to f32 where f16 denormals are normal.) - Minor non-blocking note: adding a `±denorm` test case in `valu_tests` covering `v_floor_f32`/`v_ceil_f32`/`v_fract_f32` (existing `v_fract_f32_never_returns_one` bottoms out at normal `-2^-25`) would lock in the regression test directly. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `dxil.dll` 10.0.26100.0, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-shader --tests -- -D warnings`: 0 warnings - `floor ceil fract emit::lower::tests`: **37/37 passed** across RTX 5090 (`hardware`) and WARP (`warp` + explicit `VICTORY_WARP=1` 4/4). LGTM.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/1994/head:github-bot/gh-1994'
git switch 'github-bot/gh-1994'

Merge

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