Shaders: lower binary64 division fixup in DXIL #2951
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2953"
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-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
63bcca43refuses 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.AI-assisted.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:35:12Z.
Code review and RTX 5090 + WARP + DXIL verification at head
f0f5fb5bde44onmain(63bcca43c6a0;emit/lower.rs=520,966B,3,322B under the 512 KiB cap thanks toemit/lower/div_fixup.rs):emit/lower/div_fixup.rs,lower.rs:6771-6780):[lo, hi]integer bit-ops so it never requires or sets the DXILDOUBLES(SFI0) flag.div_fixup.rs:81-94) matches RDNA2: signed quotient base -> directed-rounding overflow saturation (mode161/2/3->±DBL_MAX, else±Inf) -> underflow (exp_delta < -1075 << 20, directed rounding to±min_denormor±0.0) ->±0.0(den.inf | num.zero) ->±Inf(den.zero | num.inf, bypassesmode16clamp) -> canonical qNaN0xfff8_0000_0000_0000(0/0orInf/Inf) ->den.nan->num.nanforwarding modified NaN payloads.absbeforenegonhi(div_fixup_source),operand64_dwordschecked register-pair bounds,v.omodignored for f64, andv.clampmapping negatives/NaNs to+0.0and(1.0, +Inf]to1.0all check out cleanly.dxil.dll10.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 warningsbinary64_division_fixup emit::tests emit::lower::tests: 51/51 passed on both RTX 5090 and WARP.LGTM.
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.dllvalidator 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).
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.
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), whichmaindecodes but refuses, in a newemit/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 fromFP_ROUND16_64, f64 ignoring omod) are backed by linked hardware measurements from the same AnyPS5 oraclemainalready cites insemantics_tests.rs. Literal (high dword) and inline (f64 1/2pi) operands are handled, andbinary64_division_fixup_preserves_pair_bits_and_limitscovers both dwords, the -1075/-1076 boundary, all four round modes, modifiers and clamp.CI: passing. Recommending a look, not approving.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:58:27Z.
Review: APPROVED
Reviewed
f0f5fb5bde44d58f98efacfd755764e20ac434d7.LGTM —
Lower::div_fixup_f64faithfully models RDNA2v_div_fixup_f64behavior incrates/victory-shader/src/emit/lower/div_fixup.rsusing pure 32-bit integer/predicate/select DXIL ops (without pulling inINT64orDOUBLESFI0 feature flags), applying sourceabs/negbefore sign and NaN forwarding (src2oversrc1), handling directed overflow/underflow limits, exponent delta-1075boundary, DX10clamp, 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), andrustfmt --edition 2024 --checkondiv_fixup.rspass cleanly (zero newrustfmtdiffs inlower.rs/semantics_tests.rs;lower.rsstays under 512 KiB at 520,966 bytes).emit::semantics_tests::passed (35 passed, 1 pre-existing ignored, 0 hardware/WARP mismatches), andbinary64_division_fixup_preserves_pair_bits_and_limitspasses under bothVICTORY_WARP=0andVICTORY_WARP=1.Non-blocking note:
self.mode16isNone(joining paths with differing rounding modes),div_fixup_f64falls back to round-to-nearest-even (0), consistent withnarrow16inlower.rs:2221-2224.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.