Shaders: lower RDNA2 lighting multiply in DXIL #2936

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

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T00:55:50Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5501923476 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2938). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T00:55:50Z. --- **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.
fuzeofficlal commented 2026-11-26 02:06:53 +00:00 (Migrated from github.com)

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


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179469431 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2938#issuecomment-7179469431). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:08:14Z. --- 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 commented 2026-11-26 02:07:30 +00:00 (Migrated from github.com)

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

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::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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6067605377 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2938#pullrequestreview-6067605377). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T02:07:30Z. **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::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).
Marvisak commented 2026-11-26 05:04:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:27:02Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182605803 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2938#issuecomment-7182605803). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:27:02Z. --- <!-- 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)_
fuzeofficlal commented 2026-11-27 02:16:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:16:33Z.

Review: APPROVED


Reviewed 20352211afeb6d5c9fa1557b6d82406a94651161.

LGTM — Lower::lighting_mul cleanly models RDNA2 v_mullit_f32 for the default f32 mode: bitwise abs/neg without quieting src0 sNaNs, exact [MIN_NORMAL, INFINITY] limit validation, invalid_rhs (rhs_nan || rhs >= 0xff7f_ffff) precedence over either_zero and lhs_nan, the 2^64 post-rounding underflow scaling boundary at 2^-126, and omod scaling before DX10 clamp.

Verified locally on RTX 5090 + WARP:

  • cargo xtask policy (192 files ok), cargo clippy -p victory-shader --all-targets / --all-features (-D warnings), and rustfmt --edition 2024 --check on lighting_mul.rs pass cleanly (zero new rustfmt diffs in lower.rs / valu_tests.rs; lower.rs is 520,643 bytes).
  • emit::valu_tests:: passed (36 passed, 0 failed), and v_mullit_f32_applies_lighting_rules passes under both VICTORY_WARP=0 and VICTORY_WARP=1.
<!-- greyfinch-sync:Marvisak/VIctory:review:6082622207 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2938#pullrequestreview-6082622207). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T02:16:33Z. **Review:** APPROVED --- Reviewed `20352211afeb6d5c9fa1557b6d82406a94651161`. **LGTM** — `Lower::lighting_mul` cleanly models RDNA2 `v_mullit_f32` for the default f32 mode: bitwise `abs`/`neg` without quieting `src0` sNaNs, exact `[MIN_NORMAL, INFINITY]` `limit` validation, `invalid_rhs` (`rhs_nan || rhs >= 0xff7f_ffff`) precedence over `either_zero` and `lhs_nan`, the `2^64` post-rounding underflow scaling boundary at `2^-126`, and `omod` scaling before DX10 `clamp`. Verified locally on RTX 5090 + WARP: - `cargo xtask policy` (`192 files ok`), `cargo clippy -p victory-shader --all-targets` / `--all-features` (`-D warnings`), and `rustfmt --edition 2024 --check` on `lighting_mul.rs` pass cleanly (zero new `rustfmt` diffs in `lower.rs` / `valu_tests.rs`; `lower.rs` is 520,643 bytes). - `emit::valu_tests::` passed (36 passed, 0 failed), and `v_mullit_f32_applies_lighting_rules` passes under both `VICTORY_WARP=0` and `VICTORY_WARP=1`.
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/2938:upstream-pr/2938'
git switch 'upstream-pr/2938'

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/2938'
git switch 'upstream-pr/2938'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2938'
git switch 'upstream-pr/2938'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2938'
git switch 'main'
git merge --squash 'upstream-pr/2938'
git switch 'main'
git merge --ff-only 'upstream-pr/2938'
git switch 'main'
git merge 'upstream-pr/2938'
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!2936
No description provided.