Shaders: floor, ceil and fract read denormals as zeros #1994
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1994
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1994"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@astrosteveo on GitHub · 2026-11-25 02:33 UTC · original
astrosteveo:fix/shader-round-denormals→main· +6 −0 · 1 files · 1 commits · openv_floor_f32,v_ceil_f32andv_fract_f32hand their operand to the host as it is. A host that keeps 32-bit denormals then gives -1 forfloorof a tiny negative number, 1 forceilof a tiny positive one, and almost 1 forfract; the console reads the denormal as a zero of its sign.emit::semantics_tests::rounding_matches_the_hardwarealready covers this and fails on an RTX 5080 under vkd3d-proton 3.1 (Wine 11.22, driver 620.73.04), which reportsshaderDenormFlushToZeroFloat32 = falseandshaderDenormPreserveFloat32 = false:("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 throughftz, asv_cvt_flr_i32_f32's already do.v_trunc_f32andv_rndne_f32pass 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 onmainhere (no WARP, no digest check under vkd3d-proton, anda_heap_buffer_read_where_no_buffer_view_is_reads_zeros).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
@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 ofv_floor_f32,v_ceil_f32andv_fract_f32now go throughLower::ftzfirst. This matches the reference model the tests already use (semantics_tests.rs:round(...)appliesftzto its input andfractdoesftz(x), noted as measured on RDNA2) and the existing handling ofv_cvt_flr_i32_f32/v_cvt_rpi_i32_f32in the same file. So it is a portability fix for hosts that keep f32 denormals, and the PR body includes the failingrounding_matches_the_hardwareoutput. Leaving outv_trunc_f32/v_rndne_f32is 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
@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
e06bcf16ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 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).
@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.dll10.0.26100.10068): both adapters already flush these subnormal operands on parent940d32f. I got the same outputs one06bcf1. I selected each adapter in a separate process and checked its identity and dispatch readback.The existing
rounding_matches_the_hardwaretest passed all seven operations × 38 inputs on each adapter and revision. I also compared exact output bits forfloor,ceilandfracton 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) producedfloor = -0andfract = +0. The adjacent negative normal (0x80800000) producedfloor = -1andfract = 0x3f7fffff. The explicit flush preserves that boundary on native RTX/WARP and complements the before/after difference you measured under Wine.@fuzeofficlal on GitHub · 2026-11-26 00:51 UTC · original
Code review and RTX 5090 + WARP + DXIL verification at head
e06bcf16890dmerged cleanly ontomain(63bcca43c6a0;emit/lower.rs=520,835B,3,453B under the 512 KiB cap):crates/victory-shader/src/emit/lower.rs:2163-2176, 6333-6343):self.ftz(a)beforev_fract_f32,v_floor_f32, andv_ceil_f32matchesv_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, andNaNuntouched. (v_floor/ceil/fract_f16already widen throughhalf_fsrcto f32 where f16 denormals are normal.)±denormtest case invalu_testscoveringv_floor_f32/v_ceil_f32/v_fract_f32(existingv_fract_f32_never_returns_onebottoms out at normal-2^-25) would lock in the regression test directly.dxil.dll10.0.26100.0, Rust 1.98.1):cargo xtask policy:191 files ok;cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warningsfloor ceil fract emit::lower::tests: 37/37 passed across RTX 5090 (hardware) and WARP (warp+ explicitVICTORY_WARP=14/4).LGTM.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.