Shaders: lower RDNA2 lighting multiply in DXIL #2938

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

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 00:55 UTC · original
andrewpozdnakov7-jpg:codex2/mullit-f32 → main · +236 −0 · 3 files · 1 commits · open

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 63bcca43 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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 00:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2938) `andrewpozdnakov7-jpg:codex2/mullit-f32` → `main` · +236 −0 · 3 files · 1 commits · open **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](https://github.com/boykopovar/AnyPS5/pull/501), [flushed inputs](https://github.com/boykopovar/AnyPS5/pull/2046), [product rounding](https://github.com/boykopovar/AnyPS5/pull/2839), [output modifiers](https://github.com/boykopovar/AnyPS5/pull/25011). **Validation** - The same 33-case synthetic fixture on main at 63bcca43 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:17:57 +00:00
Author
Owner

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

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2938#issuecomment-7179469431) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:27 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-26 04:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2938#issuecomment-7182605803) <!-- victory-triage v1 head=20352211afeb6d5c9fa1557b6d82406a94651161 verdict=merge-candidate at=2026-11-26T04:26:56Z --> 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](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/2938/head:github-bot/gh-2938'
git switch 'github-bot/gh-2938'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2938'
git switch 'github-bot/gh-2938'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2938'
git switch 'github-bot/gh-2938'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2938'
git switch 'main'
git merge --squash 'github-bot/gh-2938'
git switch 'main'
git merge --ff-only 'github-bot/gh-2938'
git switch 'main'
git merge 'github-bot/gh-2938'
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!2938
No description provided.