Repository navigation
Shaders: round half add and subtract toward zero once - #2917
andrewpozdnakov7-jpg wants to merge 1 commit into
Conversation
fuzeofficlal
left a comment
There was a problem hiding this comment.
Verified head 1d1b066f cleanly on origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + Windows SDK 10.0.26100.0 dxil.dll).
Code & Numeric Review
- Using Knuth TwoSum (
f32_sum_errorin the newemit/lower/half_round.rs, also shared byfma_f16) to stepsum_bitsdown by 1 ULP toward zero when(error ^ signbit(sum)) < 0.0(pred::OLT) cleanly eliminates double-rounding undermode16 == Some(3)(RTZ) while preserving exact±0.0, signedInf, andNaN(whereOLT(NaN, 0.0)is false). - File size &
#2915compatibility: Net shrinkscrates/victory-shader/src/emit/lower.rsby 226 B (520,563 B->520,337 B,3,951 Bunder the 512 KiB cap) and composes cleanly with#2915'sfloat_resultomodchange without merge conflict.
Local Verification
cargo test --locked -p victory-shader --lib -- emit::lower::tests emit::semantics_testson RTX 5090 + WARP +dxil.dll: 68/68 passed (1 pre-existing ignored), includingf16_add_sub_round_to_zero_once.cargo clippy --locked -p victory-shader --tests -- -D warnings(default and--all-features) &cargo xtask policy(192 files ok): clean.
Looks clean and ready to merge.
|
Windows 11 / NVIDIA test run, head Setup: Windows 11 Home build 26300, RTX 5080, NVIDIA 621.40, rustc 1.98.1 MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100 (
Not run: the retail title, clippy, and other crates. AI-assisted (Claude Code) |
kotekompotek
left a comment
There was a problem hiding this comment.
Verified: the extracted f32_sum_error is the verbatim Fast2Sum tail from the FMA path (no behavior change there), and applying it to f16 add/sub is the right fix — a product of halves is exact in f32 but a sum isn't always representable as f32-rounded, so the error term is needed before the single round toward zero. LGTM.
|
Independent Windows WARP verification on PR head
All 458 baseline mismatches were in round-toward-zero outputs. Every nearest-even control matched. Both revisions ran with required DXIL validation and confirmed the Microsoft Basic Render Driver software adapter at shader model 6.6. The harness blocked physical adapter fallback. Verified with Codex (gpt-6.2-sol). |
|
Automated triage for the maintainers. Merge candidate. This makes CI: passing. Generated by Claude Code |
Dukestar69
left a comment
There was a problem hiding this comment.
Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):
- Diff review: Extracting
half_add_subandf32_sum_errorintoemit/lower/half_round.rscorrects double-rounding onv_add_f16/v_sub_f16/v_subrev_f16/v_pk_add_f16when rounding toward zero while keepinglower.rswithin the file-size policy limit. cargo test -p victory-shader f16_add_sub_round_to_zero_once -- --test-threads=1(RTX 5090 & WARP): 1 passed, 0 failed on both.cargo test -p victory-shader f16_arithmetic_rounds_once -- --test-threads=1(RTX 5090 & WARP): 1 passed, 0 failed on both.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
… toward zero once
…d merged tests with the branch Marvisak#2811 on this branch turned `Lower::mode16` into `FpMode16 { round, denorm }` and moved the MODE update into `FpMode16::after`. Three refreshed PRs still used the old `Option<u8>` and the removed `round16_after`, so victory-shader did not build: - Marvisak#2782 reads MODE[3:2] for `s_getreg_b32`: it now reads `mode16.round`. - Marvisak#2886 updates the mode inside whole-wave sections: it now calls `mode16.after`, as the main lowering loop does. - Marvisak#2917 rounds toward zero when FP_ROUND_16_64 is 3: it now checks `mode16.round`. Tests from Marvisak#2152, Marvisak#2817, Marvisak#2952, Marvisak#3038 and a `mod.rs` test used the older `lower::Parts`, `HostShader`, `Translated` and `emit::emit` signatures; they get the branch's fields (`Target::ANY`, no console flow, no native f16, `written_root_uavs`, `threads`, `atomics64`) as the other tests do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Round
v_add_f16,v_sub_f16,v_subrev_f16, andv_pk_add_f16toward zero when the program setsMODE.FP_ROUND_16_64. For example,4096 - 2^-14rounds to0x6c00in f32. The correct f16 result toward zero is0x6bff.Reuse the compensated sum already used by
v_fma_f16. When f32 rounded the sum away from zero, move one f32 step toward zero before the existing f16 conversion. An f16 boundary can only fall at an f32 point, so the step preserves the correct side for truncation. The previous emitted arithmetic is used in nearest-even mode. See AMD's RDNA 2 ISA, VOP2 and packed math.Verification
63bcca4and the patch covers 44 instruction/input combinations on app-local WARP SM 6.6 with DXIL validation. Mismatches drop from 10 to 0. In the packed caseec006c00 + 04008400, the toward-zero result changes fromec006c00toebff6bff. The nearest-even control staysec006c00.#2825 keeps its toward-zero arithmetic on the f32 path and currently filters the affected inputs from its native-path comparison. This change addresses that fallback.
Staged asset policy passed (192 files). The exact #2825 and #2891 heads merge textually cleanly. #2884 wraps the adjacent packed-f16 block. If both land, keep its FMA branch and use half_add_sub in the packed add fallback.