Shaders: f16 results round to nearest even, and min/max/med3 read denormal operands as zeros #135
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!135
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-135"
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?
@alexdeliu on GitHub · 2026-11-25 16:00 UTC · original
alexdeliu:fix/f16-round-nearest→main· +236 −25 · 2 files · 1 commits · openWhat
narrow16) instead of by DXILlegacyF32ToF16, whose rounding is left to the host. The rounding is to nearest even, the console's default, or toward zero where the program's MODE says so. The round mode is tracked per block throughs_round_modeands_setreg(round16).v_cvt_f16_f32,v_fma_mix{lo,hi}_f16, the 16-bit VOP results, packed f16 math, this fork'sv_pk_fmac_f16, and the f16 interpolation channels.v_min/max/min3/max3/med3_f32read as zeros of their sign (ftz,max_min_flushed), as the console's default float mode does, whatever the host's own denormal mode is.Ported from upstream Marvisak/VIctory
77053a0. Only these parts are taken: not its discard/helper-lane, FMA-probe,v_cvt_*_i32or cndmask changes.Why
On main, the RX 9070, the RDNA2 iGPU and WARP all round f16 results toward zero:
v_cvt_f16_f32(1 + 0.75 ulp)gives0x3C00, where the console gives0x3C01. Every f16 result is off by up to one ulp, and some results differed between AMD generations.Tested
One machine: RX 9070 (RDNA4, 32.0.32029.2010), Ryzen 7 7700 iGPU (gfx1036, RDNA2, 32.0.21045.29003) and WARP. Windows 11 Pro 26200;
VICTORY_DXIL= dxil.dll 1.8.2502.11. No game data.New GPU tests in
valu_tests.rs:01aadd1v_cvt_f16_f32_rounds_to_nearest_even(ties to even, both signs)0x3C00, want0x3C01max_and_min_read_denormal_operands_as_zeros-0, want+0cargo test -p victory-shader --lib -- --test-threads=1:01aadd1The cross-device fuzzer from #129 (307 opcodes, 160 inputs each, all three adapters):
v_add/sub/subrev_f16,v_pk_add_f16,v_fma_f16,v_fmac_f16,v_pk_fma_f16,v_pk_fmac_f16,v_fma_mixlo/mixhi_f16,v_min/max/min3/max3/med3_f32.v_add_f64andv_mul_f64, are the AMD shared-dword bug reported at https://devcommunity.amd.com/t/1518.v_sin_f16, approximate by definition, now differs from WARP on 12 of 160 inputs instead of 9.Not tested
AI use: Claude Code (Claude Opus 5.5) ported the change from upstream and ran the tests on my machine.
🤖 Generated with Claude Code
@KernelSmoker on GitHub · 2026-11-25 19:51 UTC · original
Independent A/B verification on NVIDIA GeForce RTX 3090 (Ampere, 32-lane warp, Bazzite Linux 45 x86_64, driver 620.73.04, GE-Proton 10-34 / Wine 10.0 / vkd3d-proton 3.0.0
bd3f5e3d245c3ad, Rust 1.98.1) on PR head8807970:emit::valu_tests)01aadd1(lower.rsreverted) on RTX 30908807970) on RTX 3090v_cvt_f16_f32_rounds_to_nearest_evenlegacyF32ToF16nearest-even)max_and_min_read_denormal_operands_as_zerosop 0x110 [1, 80000000, 0, 0]: got1/ denormal preserved, expected0)Full
emit::valu_testson RTX 3090 (--test-threads=1, vkd3d-proton 3.0.0): 25 passed, 4 failed (the 4 failures are the pre-existing 64-lane/wave32 testsloop_exit_mask_counted_after_the_loop,mask_grown_inside_a_branch_counted_after_it,scalar_counted_in_a_divergent_loop_read_after_it, andscalar_counted_in_nested_divergent_loops, unrelated to this PR; noteEnumWarpAdapterin DXVK/vkd3d-proton falls back to the RTX 3090 rather than Windows WARP).Additional checks on
8807970:cargo test --locked -p victory-shader: 185 passed, 0 failed, 6 ignored (lib) + 3 passed, 0 failed, 1 ignored (tests/resource_tracking.rs).cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-gnu: 0 new warnings (10 pre-existing warnings).@adrianmjim on GitHub · 2026-11-25 19:52 UTC · original
Corpus data from the game's
shaders.rpfon an RX 7900 XT (Windows 11 build 26300, dxil.dll 10.0.26100.0), head8807970on01aadd1,victory translate --validate --list --host-lanes 32-64, comparing a hash of each program's DXIL with01aadd1:cargo test -p victory-shader --lib -- --test-threads=1: 268 passed, 0 failed, 6 ignored.So nearly every host shader is retranslated with this change, and every cached pipeline is rebuilt on first run. Pipelines were not created and the game was not run here.
@MamaLeVrai on GitHub · 2026-11-26 05:00 UTC · original
RDNA2 data point. This PR (
8807970) merged onmain4f62c2a,cargo test --release -p victory-shader --libon an RX 6950 XT (Windows 11 build 26300, Rust 1.98.1):main: 275 passed, 2 failed.The 2 failures are the same as on
main: the RDNA2 wave-size testsscalar_counted_in_a_divergent_loop_read_after_itandscalar_counted_in_nested_divergent_loops, fixed by #110 and #204. No regression here. One run ended without a result line, which this test binary does now and then on this machine, onmaintoo. Not run in the game.harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300
AI-assisted (Claude Code); no game data.
@ -3438,0 +3534,4 @@// shortcut: rounding toward +-infinity, or a mode not known at this// point (paths that set it differently join), rounds to nearest even.fn narrow16(&mut self, f: V) -> V {let rtz = self.mode16 == Some(3);@gut0to on GitHub · 2026-11-27 15:03 UTC · original
AI-assisted review:
round16_afterpreserves the MODE value, and the comment above acknowledges rounding toward both infinities, butnarrow16selects only between RTZ (Some(3)) and nearest-even. A shader that sets either directed mode before a half conversion therefore gets a different result. Could the two modes be implemented here and covered with values on both sides of zero that are not halfway ties?@gut0to on GitHub · 2026-11-27 15:03 UTC · original · reviewed
AI-assisted static review; I traced the MODE propagation and the half-conversion path. I did not run the test suite.
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.