Skip to content

Shaders: lower RDNA2 lighting multiply in DXIL - #2938

Open
andrewpozdnakov7-jpg wants to merge 1 commit into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/mullit-f32
Open

andrewpozdnakov7-jpg wants to merge 1 commit into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/mullit-f32

Conversation

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

What changed

The DXIL lowerer now handles VOP3 opcode 0x150 in the default f32 mode used by VIctory. A positive, ordered third operand enables the multiplication. The right operand's negative maximum-finite, negative infinity or NaN encoding returns negative maximum-finite. The result then follows the measured priority of the legacy zero and left NaN rules.

The product's underflow check uses a scaled multiply so the decision at the smallest normal can be made after rounding to 24 significant bits. The lowering applies source abs/neg and output scale/clamp while preserving the relevant NaN payload and zero bits. The behavior comes from public physical RDNA2 reports. Operand rules and source modifiers, flushed inputs, product rounding, output modifiers.

Validation

  • The same 33-case synthetic fixture on main at 63bcca4 fails with Unsupported for v_mullit_f32. At this head it passes DXIL validation and D3D12 WARP SM 6.6 UAV readback for every case.
  • A CPU comparison between the scaled product and an independent integer rounding reference agreed on 4,558,800 pairs of normal operands.
  • WARP ran 36 VALU tests, 34 semantics tests with one ignored, and 33 lowerer tests. Strict Clippy passed with default and all features, and the asset policy passed.
  • The checks here used synthetic shader inputs and software WARP. The RDNA2 results cited above were measured by the linked authors. No claim is made for alternate f32 modes or game behavior.

AI-assisted.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review and RTX 5090 + WARP + DXIL verification at head 20352211afeb merged cleanly onto main (63bcca43c6a0; emit/lower.rs = 520,643 B, only +80 B thanks to splitting emit/lower/lighting_mul.rs):

  • Code review (crates/victory-shader/src/emit/lower/lighting_mul.rs):
    • Applying abs/neg bitwise (And !SIGN / Xor SIGN, lines 35-40) avoids quieting sNaNs prematurely.
    • Sentinel precedence is right: invalid_rhs (rhs_nan || rhs >= NEGATIVE_MAX) returns -f32::MAX (0xff7f_ffff) ahead of either_zero (|lhs| < MIN_NORMAL || |rhs| < MIN_NORMAL -> +0.0), so 0.0 * -Inf and 0.0 * qNaN produce -f32::MAX while 0.0 * +Inf / 0.0 * NaN_lhs produce +0.0.
    • Scaling the smaller normal operand by exact 2^64 (0x5f80_0000, lines 80-111) avoids host tininess/FTZ discrepancies around 2^-126, and omod (scale_lighting_result) runs before unsigned-clamping clamp ([0, 1.0], negatives/NaNs -> +0.0).
  • 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 (default + --all-features): 0 warnings
    • mullit lighting emit::tests emit::lower::tests: 51/51 passed on both RTX 5090 and WARP (including v_mullit_f32_applies_lighting_rules).

Clean submodule split and thorough special-value handling; LGTM.

@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::v_mullit: 1 passed, 0 failed (v_mullit_f32_applies_lighting_rules passes on both RTX 5090 hardware and WARP).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

The lowering in emit/lower/lighting_mul.rs cleanly handles abs/neg bit-level source modifiers, RDNA2 lighting sentinel/limit checks, post-rounding tininess near 2^-126 via 2^64 scaling, omod, and clamp.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

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.

Merge candidate. Adds a DXIL lowering for v_mullit_f32 (VOP3 0x150) in emit/lower/lighting_mul.rs, dispatched from Lower::valu. The main special case (S1 is -MAX_FLOAT, -INF or NaN, or S2 is not positive or is NaN, gives -MAX_FLOAT) matches the RDNA2 ISA guide; the gate's interaction with denormal flushing, abs/neg handling that keeps sNaN payloads, omod before clamp and the scaled-product tininess handling read correctly, and the test uses the cited measurements as expected values. Please cite the RDNA2 ISA guide in the doc comment next to the links for the finer rules. Merging this and #2942 leaves a trivial mod line conflict in emit/lower.rs.

CI: passing.


Generated by Claude Code

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.

4 participants