Shaders: lower binary64 division fixup in DXIL #2951

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/2953 into main
andrewpozdnakov7-jpg commented 2026-11-26 01:26:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T01:26:29Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5502242319 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2953). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T01:26:29Z. --- 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.
fuzeofficlal commented 2026-11-26 02:07:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:35:12Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179920722 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2953#issuecomment-7179920722). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:35:12Z. --- 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.
Dukestar69 commented 2026-11-26 02:15:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T02:15:39Z.

Review: APPROVED


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::semantics_tests::binary64_division_fixup_preserves_pair_bits_and_limits: 1 passed, 0 failed (15 sub-programs across rounding modes 0–3, NaN/Inf/subnormals/zeros, abs/neg, omod, clamp, inline constants and literals; 0 mismatches on both RTX 5090 hardware and WARP, 0 hardware/WARP differences).
  • 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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6067659559 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2953#pullrequestreview-6067659559). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T02:15:39Z. **Review:** APPROVED --- 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::semantics_tests::binary64_division_fixup_preserves_pair_bits_and_limits`: **1 passed, 0 failed** (15 sub-programs across rounding modes 0–3, NaN/Inf/subnormals/zeros, `abs`/`neg`, `omod`, `clamp`, inline constants and literals; **0 mismatches** on both RTX 5090 hardware and WARP, 0 hardware/WARP differences). - `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).
kotekompotek commented 2026-11-26 02:29:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:29:26Z.

Review: COMMENTED


Verified against the RDNA2 semantics: override order is right — NaN forwarding wins last, invalid (0/0, inf/inf) beats yields_inf/yields_zero, and directed-rounding saturate/tiny-nonzero sign logic matches (toward-zero saturates both signs to max-finite; toward-inf only same-sign). Clamp maps NaN/negative/+inf correctly and keeps positive subnormals. Exponent-delta underflow threshold (-1075<<20) and the 1/(2pi) inline constant check out. omod ignored for f64 per ISA.

<!-- greyfinch-sync:Marvisak/VIctory:review:6067764203 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2953#pullrequestreview-6067764203). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T02:29:26Z. **Review:** COMMENTED --- Verified against the RDNA2 semantics: override order is right — NaN forwarding wins last, invalid (0/0, inf/inf) beats yields_inf/yields_zero, and directed-rounding saturate/tiny-nonzero sign logic matches (toward-zero saturates both signs to max-finite; toward-inf only same-sign). Clamp maps NaN/negative/+inf correctly and keeps positive subnormals. Exponent-delta underflow threshold (-1075<<20) and the 1/(2pi) inline constant check out. omod ignored for f64 per ISA.
Marvisak commented 2026-11-26 06:03:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:35:37Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183627119 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2953#issuecomment-7183627119). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T05:35:37Z. --- <!-- 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)_
fuzeofficlal commented 2026-11-27 01:58:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:58:27Z.

Review: APPROVED


Reviewed f0f5fb5bde44d58f98efacfd755764e20ac434d7.

LGTM — Lower::div_fixup_f64 faithfully models RDNA2 v_div_fixup_f64 behavior in crates/victory-shader/src/emit/lower/div_fixup.rs using pure 32-bit integer/predicate/select DXIL ops (without pulling in INT64 or DOUBLE SFI0 feature flags), applying source abs/neg before sign and NaN forwarding (src2 over src1), handling directed overflow/underflow limits, exponent delta -1075 boundary, DX10 clamp, inline constants/high-word 32-bit literals, and guarded destination writes.

Verified locally on RTX 5090 + WARP + SDK DXIL validator:

  • cargo xtask policy (192 files ok), cargo clippy -p victory-shader --all-targets / --all-features (-D warnings), and rustfmt --edition 2024 --check on div_fixup.rs pass cleanly (zero new rustfmt diffs in lower.rs / semantics_tests.rs; lower.rs stays under 512 KiB at 520,966 bytes).
  • emit::semantics_tests:: passed (35 passed, 1 pre-existing ignored, 0 hardware/WARP mismatches), and binary64_division_fixup_preserves_pair_bits_and_limits passes under both VICTORY_WARP=0 and VICTORY_WARP=1.

Non-blocking note:

  • When self.mode16 is None (joining paths with differing rounding modes), div_fixup_f64 falls back to round-to-nearest-even (0), consistent with narrow16 in lower.rs:2221-2224.
<!-- greyfinch-sync:Marvisak/VIctory:review:6082507047 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2953#pullrequestreview-6082507047). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T01:58:27Z. **Review:** APPROVED --- Reviewed `f0f5fb5bde44d58f98efacfd755764e20ac434d7`. **LGTM** — `Lower::div_fixup_f64` faithfully models RDNA2 `v_div_fixup_f64` behavior in `crates/victory-shader/src/emit/lower/div_fixup.rs` using pure 32-bit integer/predicate/select DXIL ops (without pulling in `INT64` or `DOUBLE` SFI0 feature flags), applying source `abs`/`neg` before sign and NaN forwarding (`src2` over `src1`), handling directed overflow/underflow limits, exponent delta `-1075` boundary, DX10 `clamp`, inline constants/high-word 32-bit literals, and guarded destination writes. Verified locally on RTX 5090 + WARP + SDK DXIL validator: - `cargo xtask policy` (`192 files ok`), `cargo clippy -p victory-shader --all-targets` / `--all-features` (`-D warnings`), and `rustfmt --edition 2024 --check` on `div_fixup.rs` pass cleanly (zero new `rustfmt` diffs in `lower.rs` / `semantics_tests.rs`; `lower.rs` stays under 512 KiB at 520,966 bytes). - `emit::semantics_tests::` passed (35 passed, 1 pre-existing ignored, 0 hardware/WARP mismatches), and `binary64_division_fixup_preserves_pair_bits_and_limits` passes under both `VICTORY_WARP=0` and `VICTORY_WARP=1`. Non-blocking note: - When `self.mode16` is `None` (joining paths with differing rounding modes), `div_fixup_f64` falls back to round-to-nearest-even (`0`), consistent with `narrow16` in `lower.rs:2221-2224`.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2953:upstream-pr/2953'
git switch 'upstream-pr/2953'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2953'
git switch 'upstream-pr/2953'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2953'
git switch 'upstream-pr/2953'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2953'
git switch 'main'
git merge --squash 'upstream-pr/2953'
git switch 'main'
git merge --ff-only 'upstream-pr/2953'
git switch 'main'
git merge 'upstream-pr/2953'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2951
No description provided.