Shaders: lower binary64 reciprocal square root with dwords #2809
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2811"
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?
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T21:14:05Z.
Main stops translation on
V_RSQ_F64. This lowering normalizes a binary64 input, computes the square root of its significand to 28 bits, and divides to obtain a 26-bit reciprocal. The 32-bit DXIL arithmetic retains the known rounding direction and input-denormal mode, handles signed zeros and infinities, and quiets NaNs. AMD specifies a 2^29 binary64 ULP bound for this instruction. RDNA 2 ISA referenceBoth synthetic shaders stop on unsupported
v_rsq_f64at13f91ca. The same tests pass all 112 cases on app-local WARP SM 6.6 with the DXIL validator. They cover VOP1 VGPR and VOP3 SGPR sources, all four rounding modes, input-subnormal modes, special values, and the two-dword normalization boundary. Feature-flag checks confirm the 32-bit lowering. An independent integer model stayed within the bound for all 327,520 CPU comparisons across the finite exponent fields.The paired full shader suite moved from 268 passed, 5 failed and 3 ignored to 270 passed, 3 failed and 3 ignored. The other three failures were the same gather-at-level, lane-permute and edge-flagged-triangle tests in both runs. All 33 patched VALU tests including runtime identity passed. Strict shader Clippy and staged asset policy passed.
The mode analysis follows the same approach as #2743, #2791 and #2799. 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 <[email protected]>.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T21:19:25Z.
Review: COMMENTED
Same careful pattern as the rcp64 PR (#2799), shared FpMode16 base — sqrt-of-significand to 28 bits then dword division for a 26-bit quotient, with explicit subnormal normalization, signed-zero/inf handling, NaN quieting, and refusal on modifiers or unknown modes. The 2^29 ULP bound cited from the RDNA2 ISA is the right correctness bar for V_RSQ_F64, and 112 validator-checked cases across rounding modes/denorm modes/specials is solid coverage. LGTM; same merge-order note — whichever of the FpMode16 refactor PRs lands first wins the base.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:33:09Z.
Verified
e1de9799on Windows 11 (RTX 5090 + WARP + Windows SDK10.0.26100.0dxil.dll):cargo xtask policy: 185 files ok;cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default &--features host): 0 warnings.cargo test -p victory-shader --features host --lib --locked -- valu_tests::: 32/32 passed on RTX 5090 + WARP +dxil.dll, includingrsqrt_f64_tracks_binary64_range_and_roundingandrsqrt_f64_obeys_the_input_denormal_mode(andSFI0 & 0x8001 == 0confirms pure 32-bit DXIL with no double/int64 flags).lower/rsqrt.rs: special values (±0.0 -> ±Inf, negative/-Inf -> qNaN,+Inf -> +0.0, sNaN quieted preserving sign/payload,MODE[7:6]input denormal flush vs normalize viaunaryBits.i32op 33), 28-bit integer sqrt + opposite-direction rounding + 26-bit long division, and modifier rejection (clamp/omod/sdwa/dpp,absbeforeneg, 32-bit literal as high dword) all check out.git merge-tree: clean againstorigin/main13f91caand #2812; conflicts with #2743/#2791/#2799 inlower.rson the sharedFpMode16refactor, and shares the sameLower::mode16 -> FpMode16compile interaction with #2782 (lower.rs:3384needsself.mode16.round.ok_or(...)if both land).Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T02:32:45Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP,dxil.dllvalidator active):cargo test -p victory-shader --lib emit::valu_tests::rsqrt: 2 passed, 0 failed (rsqrt_f64_obeys_the_input_denormal_modeandrsqrt_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).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T02:19:48Z.
Automated triage for the maintainers.
This lowers
v_rsq_f64, which translation refuses today, in 32-bit integer DXIL (emit/lower/rsqrt.rs): it normalizes the input, takes a 28-bit integer square root of the significand, then divides. It handles signed zeros, infinities, negative inputs and NaN quieting, and refuses the modifiers it does not model. It also generalizesround16intoFpMode16, which now tracks the f64/f16 denorm bits (MODE 7:6) as well as the round mode. I read the mode tracking:s_denorm_mode's bits 3:2 and thes_setregfield arithmetic are right, and an unknown mode is refused rather than guessed. The accuracy target is AMD's public RDNA2 ISA bound, and the tests run on hardware and WARP. Note that it overlaps theFpMode16refactor in #2743/#2791/#2799, so whichever lands second needs a rebase.CI: passing.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:16:34Z.
Review: APPROVED
Reviewed
f6a7d2159dcf0427e97e12a5654499baa6aaeb78.LGTM —
Lower::rsqrt_f64cleanly decomposesv_rsq_f64into pure 32-bit integer arithmetic (rsqrt_denominator28-bit sqrt +rsqrt_quotient26-bit reciprocal, staying well inside RDNA2's2^29ULP bound across all normal and subnormal binary64 exponents without enablingINT64orDOUBLEinSFI0), handles special values (±0 -> ±Inf,+Inf -> +0, negative inputs ->qNaN,NaNquieting, andFpMode16input denormal flush vs preservation), and preserves existingnarrow16/v_fma_f16rounding behavior.Verified locally on RTX 5090 + WARP:
cargo xtask policy(192 files ok),cargo clippy -p victory-shader --all-targets/--all-features(-D warnings), andrustfmt --edition 2024 --checkonrsqrt.rspass cleanly (zero newrustfmtdiffs inlower.rs/valu_tests.rs;lower.rsis 521,361 bytes).emit::valu_tests::passed (37 passed, 0 failed), and bothrsqrt_f64_tracks_binary64_range_and_roundingandrsqrt_f64_obeys_the_input_denormal_modepass under bothVICTORY_WARP=0andVICTORY_WARP=1withSFI0 & 0x8001 == 0.Non-blocking note:
v_rsq_f64only depends on MODE bit 6 (input denormal preservation) since its finite outputs are never subnormal; tracking bits7:6as a singledenormfield means a write to bit 7 alone (or a join ofdenormmodes1and3) setsdenormtoNoneand rejectsv_rsq_f64.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.