Skip to content

Shaders: lower binary64 reciprocal square root with dwords - #2811

Open
andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/rsq-f64
Open

andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/rsq-f64

Conversation

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

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 reference

Both synthetic shaders stop on unsupported v_rsq_f64 at 13f91ca. 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 <andrewpozdnakov7-jpg@users.noreply.github.com>.

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Verified e1de9799 on Windows 11 (RTX 5090 + WARP + Windows SDK 10.0.26100.0 dxil.dll):

alesanfe added a commit to alesanfe/VIctory that referenced this pull request Nov 26, 2026
…t, sat mul24

- Marvisak#2953: v_div_fixup_f64 in 32-bit ops (quotient classification, overflow
  and underflow handling, DX10 clamp)
- Marvisak#2799: v_rcp_f64 (96/48-bit divisor refinement to 2^-53)
- Marvisak#2811: v_rsq_f64 (denormal normalization, guarded reciprocal)
- Marvisak#2791: v_sqrt_f64 (non-restoring refinement with sticky bits)
- Marvisak#2743: v_ldexp_f64 (52-bit significand scaling, subnormal rounds)
- Marvisak#2938: v_mullit_f32 lighting multiply (NaN/zero/limit handling)
- Marvisak#2926: v_mul_*_u24/v_mad_*_u24 via valu_mul24; the clamped form now
  saturates against the full 48-bit product instead of failing emit

Rounding-mode reads assume the console's initial 16/64-bit mode
(nearest even, denormals preserved): the MODE register is not modelled,
so shaders changing it already fail emit.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

Copy link
Copy Markdown
Owner

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 generalizes round16 into FpMode16, 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 the s_setreg field 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 the FpMode16 refactor in #2743/#2791/#2799, so whichever lands second needs a rebase.

CI: passing.


Generated by Claude Code

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::rsqrt: 2 passed, 0 failed (rsqrt_f64_obeys_the_input_denormal_mode and rsqrt_f64_tracks_binary64_range_and_rounding pass 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).

BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
…quare root with dwords

# Conflicts:
#	crates/victory-shader/src/emit/lower.rs
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
…atch merge

Reconcile four cross-PR interactions across the 32 merged PRs:
- Marvisak#2953/Marvisak#2975 vs Marvisak#2811: read `self.mode16.round` in `div_fixup.rs` and `div_scale.rs`
- Marvisak#2841 vs Marvisak#2177: pass `host_heap_views` in `pipeline.rs` partial-dispatch translation and `dispatch_threads.rs`
- Marvisak#2841 vs Marvisak#2999: use guest group dimensions (`self.rows.or(self.s.threads)`) in `dispatch_guard`
- Marvisak#2177 vs merged test fixtures: add `host_heap_views: 0` to `Parts` test initializers
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
…quare root with dwords

# Conflicts:
#	crates/victory-shader/src/emit/lower.rs
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
…atch merge

Reconcile four cross-PR interactions across the 32 merged PRs:
- Marvisak#2953/Marvisak#2975 vs Marvisak#2811: read `self.mode16.round` in `div_fixup.rs` and `div_scale.rs`
- Marvisak#2841 vs Marvisak#2177: pass `host_heap_views` in `pipeline.rs` partial-dispatch translation and `dispatch_threads.rs`
- Marvisak#2841 vs Marvisak#2999: use guest group dimensions (`self.rows.or(self.s.threads)`) in `dispatch_guard`
- Marvisak#2177 vs merged test fixtures: add `host_heap_views: 0` to `Parts` test initializers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants