Shaders: lower binary64 division fixup in DXIL #2953

Open
github-bot wants to merge 1 commit from github-bot/gh-2953 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 01:26 UTC · original
andrewpozdnakov7-jpg:codex2/div-fixup-f64 → main · +316 −1 · 3 files · 1 commits · open

The DXIL lowerer now handles VOP3 opcode 0x160. It repairs the supplied binary64 quotient using the original denominator and numerator. Both result dwords are selected with 32-bit integer operations, preserving subnormals and NaN payloads in the modeled float mode. A known FP_ROUND16_64 setting controls overflow and underflow. The lowering also handles abs, neg, clamp, and the measured rule that f64 ignores omod.

The implementation uses the convention already modeled by VIctory: IEEE mode off and f64 denormals kept. RDNA2 ISA, quotient repair measurements, modifier measurements, denormal measurements, directed rounding measurements.

Validation

  • The same synthetic fixture on main at 63bcca43 refuses opcode 0x160. The patch passes 57 exact readback cases across 15 forms on Windows WARP SM 6.6 with DXIL validation. These cover both dwords, the -1075/-1076 exponent boundary, all four round modes, signed zeros, NaN priority and payloads, clamp and literal/inline inputs.
  • The full targeted suites passed: 35 shader semantics tests with one ignored, 35 VALU tests, and 33 lowerer tests. The existing wide-shift test also passes through the shared unmodified pair reader.
  • Strict shader Clippy in both feature configurations and asset policy passed. The validation here used synthetic shaders on WARP.

AI-assisted.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 01:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2953) `andrewpozdnakov7-jpg:codex2/div-fixup-f64` → `main` · +316 −1 · 3 files · 1 commits · open The DXIL lowerer now handles VOP3 opcode 0x160. It repairs the supplied binary64 quotient using the original denominator and numerator. Both result dwords are selected with 32-bit integer operations, preserving subnormals and NaN payloads in the modeled float mode. A known FP_ROUND16_64 setting controls overflow and underflow. The lowering also handles abs, neg, clamp, and the measured rule that f64 ignores omod. The implementation uses the convention already modeled by VIctory: IEEE mode off and f64 denormals kept. [RDNA2 ISA](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf), [quotient repair measurements](https://github.com/boykopovar/AnyPS5/pull/474), [modifier measurements](https://github.com/boykopovar/AnyPS5/pull/610), [denormal measurements](https://github.com/boykopovar/AnyPS5/pull/7041), [directed rounding measurements](https://github.com/boykopovar/AnyPS5/pull/19563). **Validation** - The same synthetic fixture on main at 63bcca43 refuses opcode 0x160. The patch passes 57 exact readback cases across 15 forms on Windows WARP SM 6.6 with DXIL validation. These cover both dwords, the -1075/-1076 exponent boundary, all four round modes, signed zeros, NaN priority and payloads, clamp and literal/inline inputs. - The full targeted suites passed: 35 shader semantics tests with one ignored, 35 VALU tests, and 33 lowerer tests. The existing wide-shift test also passes through the shared unmodified pair reader. - Strict shader Clippy in both feature configurations and asset policy passed. The validation here used synthetic shaders on WARP. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:18:28 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:35 UTC · original

Code review and RTX 5090 + WARP + DXIL verification at head f0f5fb5bde44 on main (63bcca43c6a0; emit/lower.rs = 520,966 B, 3,322 B under the 512 KiB cap thanks to emit/lower/div_fixup.rs):

  • IEEE 754 binary64 & lowering audit (emit/lower/div_fixup.rs, lower.rs:6771-6780):
    • Lowers purely via 32-bit [lo, hi] integer bit-ops so it never requires or sets the DXIL DOUBLES (SFI0) flag.
    • Special-case precedence (div_fixup.rs:81-94) matches RDNA2: signed quotient base -> directed-rounding overflow saturation (mode16 1/2/3 -> ±DBL_MAX, else ±Inf) -> underflow (exp_delta < -1075 << 20, directed rounding to ±min_denorm or ±0.0) -> ±0.0 (den.inf | num.zero) -> ±Inf (den.zero | num.inf, bypasses mode16 clamp) -> canonical qNaN 0xfff8_0000_0000_0000 (0/0 or Inf/Inf) -> den.nan -> num.nan forwarding modified NaN payloads.
    • abs before neg on hi (div_fixup_source), operand64_dwords checked register-pair bounds, v.omod ignored for f64, and v.clamp mapping negatives/NaNs to +0.0 and (1.0, +Inf] to 1.0 all check out cleanly.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 192 files ok; cargo clippy -p victory-shader --all-targets -- -D warnings (default + --all-features): 0 warnings
    • binary64_division_fixup emit::tests emit::lower::tests: 51/51 passed on both RTX 5090 and WARP.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2953#issuecomment-7179920722) Code review and RTX 5090 + WARP + DXIL verification at head `f0f5fb5bde44` on `main` (`63bcca43c6a0`; `emit/lower.rs` = `520,966` B, `3,322` B under the 512 KiB cap thanks to `emit/lower/div_fixup.rs`): - **IEEE 754 binary64 & lowering audit (`emit/lower/div_fixup.rs`, `lower.rs:6771-6780`)**: - Lowers purely via 32-bit `[lo, hi]` integer bit-ops so it never requires or sets the DXIL `DOUBLES` (`SFI0`) flag. - Special-case precedence (`div_fixup.rs:81-94`) matches RDNA2: signed quotient base -> directed-rounding overflow saturation (`mode16` `1`/`2`/`3` -> `±DBL_MAX`, else `±Inf`) -> underflow (`exp_delta < -1075 << 20`, directed rounding to `±min_denorm` or `±0.0`) -> `±0.0` (`den.inf | num.zero`) -> `±Inf` (`den.zero | num.inf`, bypasses `mode16` clamp) -> canonical qNaN `0xfff8_0000_0000_0000` (`0/0` or `Inf/Inf`) -> `den.nan` -> `num.nan` forwarding modified NaN payloads. - `abs` before `neg` on `hi` (`div_fixup_source`), `operand64_dwords` checked register-pair bounds, `v.omod` ignored for f64, and `v.clamp` mapping negatives/NaNs to `+0.0` and `(1.0, +Inf]` to `1.0` all check out cleanly. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `dxil.dll` 10.0.26100.0, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1)**: - `cargo xtask policy`: `192 files ok`; `cargo clippy -p victory-shader --all-targets -- -D warnings` (default + `--all-features`): 0 warnings - `binary64_division_fixup emit::tests emit::lower::tests`: **51/51 passed** on both RTX 5090 and WARP. LGTM.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:35 UTC · original

Automated triage for the maintainers.

Merge candidate. The PR lowers v_div_fixup_f64 (VOP3 0x160), which main decodes but refuses, in a new emit/lower/div_fixup.rs (Lower::div_fixup_f64) using only 32-bit integer operations on the register pair. I checked the special-case order against the public RDNA2 ISA definition: numerator NaN, then denominator NaN, then 0/0 and inf/inf to the default NaN, then the signed infinity and signed zero cases, then the exponent-difference underflow at -1075, then overflow, else the quotient's magnitude with the XOR sign. The parts the ISA text leaves open (sNaN payloads kept with IEEE mode off, directed-rounding saturation from FP_ROUND16_64, f64 ignoring omod) are backed by linked hardware measurements from the same AnyPS5 oracle main already cites in semantics_tests.rs. Literal (high dword) and inline (f64 1/2pi) operands are handled, and binary64_division_fixup_preserves_pair_bits_and_limits covers both dwords, the -1075/-1076 boundary, all four round modes, modifiers and clamp.

CI: passing. Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2953#issuecomment-7183627119) <!-- victory-triage v1 head=f0f5fb5bde44d58f98efacfd755764e20ac434d7 verdict=merge-candidate at=2026-11-26T05:35:28Z --> Automated triage for the maintainers. **Merge candidate.** The PR lowers `v_div_fixup_f64` (VOP3 0x160), which `main` decodes but refuses, in a new `emit/lower/div_fixup.rs` (`Lower::div_fixup_f64`) using only 32-bit integer operations on the register pair. I checked the special-case order against the public RDNA2 ISA definition: numerator NaN, then denominator NaN, then 0/0 and inf/inf to the default NaN, then the signed infinity and signed zero cases, then the exponent-difference underflow at -1075, then overflow, else the quotient's magnitude with the XOR sign. The parts the ISA text leaves open (sNaN payloads kept with IEEE mode off, directed-rounding saturation from `FP_ROUND16_64`, f64 ignoring omod) are backed by linked hardware measurements from the same AnyPS5 oracle `main` already cites in `semantics_tests.rs`. Literal (high dword) and inline (f64 1/2pi) operands are handled, and `binary64_division_fixup_preserves_pair_bits_and_limits` covers both dwords, the -1075/-1076 boundary, all four round modes, modifiers and clamp. CI: passing. Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2953/head:github-bot/gh-2953'
git switch 'github-bot/gh-2953'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2953'
git switch 'github-bot/gh-2953'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2953'
git switch 'github-bot/gh-2953'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2953'
git switch 'main'
git merge --squash 'github-bot/gh-2953'
git switch 'main'
git merge --ff-only 'github-bot/gh-2953'
git switch 'main'
git merge 'github-bot/gh-2953'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2953
No description provided.