Shaders: honor directed rounding in V_CVT_F16_F32 #3159
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!3159
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3159"
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?
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 10:33 UTC · original
andrewpozdnakov7-jpg:fix/directed-half-rounding→main· +112 −13 · 2 files · 2 commits · open
V_CVT_F16_F32uses the half-precision rounding mode. On main the bitwise narrowing helper treats both directed modes as nearest-even. Make the direct conversion use the two directed modes in the bitwise narrowing helper. Arithmetic callers keep their existing rounding behavior. Increment the magnitude only when the discarded bits are nonzero and the sign matches the rounding direction. Finite overflow chooses signed infinity or signed max finite by the same direction. AMD RDNA 2 ISA, section 6.4On main, converting the smallest normal f32 in mode 1 returns 0x0000 instead of 0x0001. With the patch, the same WARP fixture passes 136 cases across all four modes and both signs, including subnormals, exact values, ties, overflow, infinity, and NaN. All 36 VALU tests passed on WARP, including a control checking that V_FRACT_F16 still returns 0x3bff for -3 * 2^-13 with mode 1 selected. Strict shader Clippy and the asset policy passed.
AI-assisted with Codex. Please retain the Git author when cherry-picking or rebasing. If folded into another commit, please add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.@andrewpozdnakov7-jpg on GitHub · 2026-11-26 10:41 UTC · original
Updated to
872b1baso the directed narrowing path applies toV_CVT_F16_F32. The broader first commit madeV_FRACT_F16(-3 * 2^-13)return0x3c00with mode 1 selected. The added control reads the expected0x3bffon this head, and all 136 conversion cases and 36 WARP VALU tests pass. Strict shader Clippy and the asset policy pass.@Dukestar69 on GitHub · 2026-11-26 10:50 UTC · original · approved these changes
Verified on RTX 5090 & WARP against
origin/main(63bcca4):cargo test -p victory-shader --lib v_cvt_f16_f32_obeys_all_four_rounding_modes -- --test-threads=1: passed on RTX 5090 and WARP.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly honors all four IEEE 754 directed rounding modes in
V_CVT_F16_F32.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@Lyrnc on GitHub · 2026-11-26 17:21 UTC · original
Checked
872b1baagainst RDNA2 hardware, with the same instruction words on both sides.s_denorm_mode, thens_round_mode, then threev_cvt_f16_f32per lane. The destinations are preset, so the high half is checked too. There are 330 f32 inputs:build_valu_csharness (a local test, not part of this PR). I ran it onmain63bcca4and on the PR merged onto it, on the RTX 5080 (610.88) and on the same Radeon (picked with a local adapter-name filter inhardware_adapter).v_cvt_f16_f32in all four f16 round modes, with f16 denormals kept (s_denorm_mode15 and 12): 2,640 results.0x3f800001gives0x3c00where the hardware gives0x3c01, and0x477fe001gives0x7bffwhere the hardware gives0x7c00.s_denorm_mode 15).0x0001for0x00000001,0x00400000and0x007fffff. In mode 2 it gives0x8001for their negatives.narrow16_in_modereads f32 denormals as zero.s_denorm_mode 12), the hardware also gives ±0, and the PR matches all 1,320 directed-mode results.v_fract_f16control (0x8e00in mode 1) is0x3bffon the hardware too.Two more things I saw, outside this PR. Both are the same on main and on the PR, so neither is a regression:
s_denorm_mode3 or 0), the hardware flushes a subnormal f16 result ofv_cvt_f16_f32to a signed zero, in every round mode:0x33800000gives0x0000. The translator keeps0x0001. This affects 592 of the 2,640 results in those two modes.v_fract_f16andv_add_f16round as MODE says on the hardware. In modes 1 and 2 they differ by 1 ulp in 21 and 130 of 600 results, plus 6v_add_f16results in toward-zero mode. As your description says, the arithmetic paths are left as they were.No game data was used.
AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them on the GPUs above; the numbers come from those runs.
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.