Shaders: lower binary64 square root with 32-bit operations #2791
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!2791
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2791"
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-25 20:35 UTC · original
andrewpozdnakov7-jpg:codex2/sqrt-f64→main· +403 −49 · 3 files · 2 commits · openMain 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 <[email protected]>.@kotekompotek on GitHub · 2026-11-25 20:39 UTC · original
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.
@oni-swr on GitHub · 2026-11-25 20:58 UTC · original
WARP/CPU verification of head
8a53189143333bd54ecf2ae65885d581ccb36151Environment: 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
13f91caee2.Tests (
cargo test --no-fail-fast -p victory-shader)origin/mainbaseline: 267 passed, 3 failed, 3 ignored.sqrt_f64_tracks_binary64_range_and_rounding,sqrt_f64_preserves_signed_zero_when_mode_flushes_subnormals).origin/mainand unrelated to this PR:a_mask_joined_with_data_at_a_uniform_loop_is_its_number,gathers_at_a_level_match_the_hardware,permutes_read_the_lane_named_and_zero_from_lanes_left_out(they compare against hardware lane results and fail on WARP).Negative control (each mutation applied alone, then reverted, new tests only)
v_sqrt_f64dispatch removed: both new tests fail.if false && matches!(mode, 0 | 1)): range/rounding test fails.Lint:
cargo clippy --all-targets -- -D warningsclean.cargo fmt --check: +3 hunks incrates/victory-shader/src/emit/lower.rs(28 on main, 31 with the PR), all in the newFpMode16block (INITIAL, thes_round_mode/s_denorm_modearms, and the finalSelf { round: update(..), .. });sqrt.rsandvalu_tests.rsadd none. Note:cargo fmt --checkis already red onorigin/mainhere (891 hunks, none from these PRs), so I compared per-file hunk counts against that baseline.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).
@fuzeofficlal on GitHub · 2026-11-25 21:05 UTC · original
Reviewed and verified
8a531891on Windows 11 (RTX 5090 + WARP + Windows SDK10.0.26100.0dxil.dll) againstmain(13f91ca).Code review
SFI0 & 0x8001 == 0, no double/int64 capability needed).MODE[7:6]denorm handling check out cleanly:±0.0preserved, negative finite /-Inf-> canonical qNaN0xfff8_0000_0000_0000,sNaNquietened with payload intact (including low-word-only payloads), input subnormal flush (-denorm -> -0.0) vs.FirstbitHicross-dword normalization, and 24-bit integer square-root iteration across all 4 rounding modes (RNE/RTP/RTN/RTZ) meeting RDNA2's2^29ULP bound.git merge-treevs13f91ca,#2713,#2728, and#2782; conflicts inlower.rswith#2743(both introduce the identicalFpMode16/fp_modes16refactor).#2782: even thoughgit merge-treewith#2782is textually clean, changingLower::mode16fromOption<u8>toFpMode16 { round, denorm }means#2782'sself.mode16.ok_or(...)(lower.rs:3384) will need to becomeself.mode16.round.ok_or(...)when both land.Verification (Windows 11, RTX 5090 + WARP +
dxil.dll)cargo test --locked -p victory-shader --features host --lib -- valu_tests::: 32 passed, 0 failed (both newsqrt_f64_*tests pass on RTX 5090 and WARP withdxil.dll).cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default &--features host): 0 warnings;cargo xtask policy: 185 files ok.@Marvisak on GitHub · 2026-11-25 23:21 UTC · original
Automated triage for the maintainers.
This PR replaces the round-only
round16analysis incrates/victory-shader/src/emit/lower.rswithFpMode16, which tracks MODE bits 3:2 and 7:6 with a per-field join. It also lowersv_sqrt_f64(lower/sqrt.rs,sqrt_f64) with 32-bit integer operations to the 2^29 ULP bound the public RDNA2 ISA reference gives for V_SQRT_F64. I checked thes_round_mode/s_denorm_mode/s_setregbit extraction, the join, and the special-value ordering (zero overrides the negative-NaN path, so sqrt(-0) = -0). Input-denormal flushing uses bit 6, as the ISA defines. CI passes.Notes for the maintainer:
FpMode16::INITIALassumes subnormals are preserved at shader entry. That is an assumption, like the existing nearest-even round.FpMode16refactor is the same as in #2743 (same author), so whichever lands second needs a rebase. #2782'sself.mode16.ok_or(...)would have to becomeself.mode16.round.ok_or(...).FpMode16::afterare longer than rustfmt would leave them.This is a recommendation for a maintainer to look, not an approval.
Generated by Claude Code
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.