Repository navigation
Shaders: lower binary64 square root with 32-bit operations - #2791
andrewpozdnakov7-jpg wants to merge 3 commits into
Conversation
|
Stacked on the same FpMode16 refactor as #2743 (same author, codex2/* series) - the base reads consistently, and the sqrt approach (normalize the two-word significand, 24 root bits via integer ops, apply tracked rounding mode, handle subnormals per denorm mode) is the right way to do binary64 in 32-bit DXIL. The 2^29 ULP bound quoted is AMD's own sqrt_f64 spec, so matching it is the correct bar. Same merge-order note as #2743: whichever of this/#2743/#2782 lands second touches mode16. |
|
WARP/CPU verification of head Environment: Windows 11 x64, rustc/cargo 1.98.1, WARP/CPU only (VICTORY_WARP=1, VICTORY_D3D12_WARP=1), no physical GPU, no game files. DXIL validation with Windows SDK 10.0.26100.0 x64 dxil.dll 1.8.2502.11. PR head merged cleanly onto origin/main 13f91ca. Tests (
Negative control (each mutation applied alone, then reverted, new tests only)
Lint: Review: read the full diff. The MODE bits 3:2 / 7:6 tracking with per-field join is correct, and the sqrt lowering handles sign, abs/neg, non-finite, and subnormal operands (flush vs preserve) coherently. The tests check the 2^29-ULP bound and rounding direction, not bit-exactness against hardware, and I did not run any hardware. No game files, dumps, shader names, or retail hashes in the diff. AI disclosure: this verification was done by Claude Code (Claude Sonnet 5.5). |
|
Reviewed and verified Code review
Verification (Windows 11, RTX 5090 + WARP +
|
|
Automated triage for the maintainers. This PR replaces the round-only Notes for the maintainer:
This is a recommendation for a maintainer to look, not an approval. Generated by Claude Code |
Dukestar69
left a comment
There was a problem hiding this comment.
Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator active):
cargo test -p victory-shader --lib emit::valu_tests::sqrt: 2 passed, 0 failed (sqrt_f64_preserves_signed_zero_when_mode_flushes_subnormalsandsqrt_f64_tracks_binary64_range_and_roundingpass on both RTX 5090 hardware and WARP).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).
fuzeofficlal
left a comment
There was a problem hiding this comment.
Nice 32-bit fixed-point v_sqrt_f64 implementation — the 24-bit digit-recurrence math, rounding (within 2^28 ULP for RTE and 2^29 ULP for directed modes), special cases (including -0.0, NaN quietening/payloads, abs/neg, and all source kinds), and SFI0 (0x8001 == 0) check out cleanly. emit::valu_tests::sqrt (2/2 on RTX 5090 and WARP), emit::lower::tests (33/33), clippy, and xtask policy all pass, and sqrt.rs / the new valu_tests.rs lines pass rustfmt.
One live-reproduced silent miscompilation in FpMode16 tracking needs fixing before merge (plus two smaller items):
-
MODE writes inside whole-wave sections are skipped during lowering (
crates/victory-shader/src/emit/lower.rs:1383-1389)- When
self.sectionsrunssection_instforj in i + 1..endand jumpsi = end,self.mode16is not updated acrossi + 1..end(even thoughfp_modes16does walk every instruction in block order). - Reproduced on hardware (RTX 5090): placing
s_denorm_mode 8(flush FP16/FP64 inputs) betweens_or_saveexec_b32and theexecrestore left a subsequentv_sqrt_f64in the same block using stale preserve mode, returning0x1e60_0000_0000_0000and0xfff8_0000_0000_0000for1andSIGN | 1instead of+0.0and-0.0. Updatingself.mode16across the skipped section instructions fixes this.
- When
-
Partial-field MODE writes and mode
1/3joins drop known input-denorm state (lower.rs:311-333)s_setreg_imm32_b32 hwreg(MODE, 7, 1), 0writes only bit 7 (output denorm flush), leaving bit 6 (input denorm preserve) unchanged, yetFpMode16::afterrequiresoffset <= start && end >= start + 2and otherwise resets the entiredenormfield toNone. Similarly, joining paths withdenorm = 1anddenorm = 3loses the shared input-denorm bit.- Reproduced: a shader with
s_setreg_imm32_b32 hwreg(MODE, 7, 1), 0beforev_sqrt_f64fails to lower withbinary64 square root with unknown floating-point modes, even thoughsqrt_f64only depends on the input-denorm bit (denorm & 1). Tracking the input-denorm bit independently (or merging partial literal bitfield updates) avoids rejecting valid shaders.
-
Minor formatting (
lower.rs:296,:303,:319)rustfmt --edition 2024 --checkflags line wrapping on the addedFpMode16methods atcrates/victory-shader/src/emit/lower.rs:296,:303, and:319.
|
The follow-up ce63f02 carries MODE updates across whole-wave sections and tracks the input-denormal bit independently. A write to the output-denormal bit and a join of input-preserving modes now retain the known input mode. On the previous head, the synthetic whole-wave case returned nonzero/NaN for signed subnormal inputs that should flush to signed zero. The partial output-only write was rejected as an unknown mode. On the updated head, both regressions and the two existing binary64 square-root tests passed on app-local WARP with DXIL validation. Strict shader Clippy passed in the default and all-features configurations. Ready for another review. If reused, please retain Git authorship when cherry-picking or rebasing. If folded into another commit, please add AI-assisted with Codex. Synthetic shaders only. I also resolved the merge overlap with #2782 in b0dab3c on current |
|
Thanks @fuzeofficlal. The three cases from your review reproduced on I also checked the interaction you called out with #2782. The combined branch carries both published heads on main WARP passed all 42 VALU tests, including the sqrt and MODE-read cases. Strict all-features shader Clippy and asset policy passed on the combined tree. The branch is available for the second PR's rebase when the first lands. AI-assisted with Codex. Synthetic shaders only. |
Main stops translation on
V_SQRT_F64. The lowering normalizes the two-word significand, computes 24 root bits with integer arithmetic, and applies the known rounding mode. It handles subnormals according to the known input-denormal mode, preserves signed zeros and positive infinity, and quiets NaNs. The DXIL requires only 32-bit operations. AMD specifies an accuracy bound of 2^29 binary64 ULP for this instruction. RDNA 2 ISA referenceBoth synthetic readbacks fail on
13f91cawith unsupportedv_sqrt_f64. The same fixtures pass all 107 cases on app-local WARP SM 6.6 with the DXIL validator. They exercise VOP1 VGPR and VOP3 SGPR sources, all four rounding modes, a flush-input mode, special values, and the cross-dword normalization boundary. They also check the DXIL feature flags for optional doubles and int64. An independent integer model stayed within the specified bound in 262,016 comparisons against CPU binary64 square roots across all finite exponent fields.The full serial shader suite moved from 268 passed, 5 failed, and 3 ignored to 270 passed, 3 failed, and 3 ignored with both new tests present. The same gather-at-level, lane-permute, and edge-flagged triangle tests failed on both revisions. All 33 VALU tests in the patched run passed, including the runtime identity check. Strict shader Clippy and staged asset policy passed.
This uses the same FP16/FP64 mode analysis as #2743. Coordination claim
Please retain the Git author on cherry-pick or rebase. If you fold this change into another commit, please include
Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>.