Shaders: lower v_ldexp_f32 (VOP3 0x362) #1341

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

@⁠AscilCH on GitHub · 2026-11-24 17:33 UTC · original
AscilCH:fix/lower-v-ldexp-f32 → main · +130 −0 · 2 files · 1 commits · open

Gap

v_ldexp_f32 (VOP3 0x362, computing src0.f32 * 2^src1.i32) was not lowered in crates/victory-shader/src/emit/lower.rs, failing shader translation with:

lower: Unsupported { offset: 36, what: "v_ldexp_f32" }

Fix

  • Lowered v_ldexp_f32 in crates/victory-shader/src/emit/lower.rs using exact IEEE-754 exponent adjustment in pure 32-bit integer arithmetic (requiring no INT64 shader feature flag):
    • Clamps the signed exponent src1 to [-512, 512] so biased_exp + n never overflows i32 (including i32::MIN and i32::MAX) while still handling full-span shifts such as 2^-126 * 2^253 = 2^127 without intermediate overflow.
    • Overflows to signed infinity, underflows to signed zero (matching RDNA2/D3D12 f32 FTZ), preserves ±0.0 and ±inf regardless of exponent, and quiets sNaN to qNaN.
    • Applies VOP3 source abs/neg (via fsrc on src0) and output omod/clamp (via float()).
  • Added hardware + WARP + dxil.dll test emit::valu_tests::v_ldexp_f32_matches_rdna2 covering normal positive/negative scaling, full-span scaling, overflow to ±inf, underflow to ±0.0, i32::MIN/i32::MAX exponents, ±0.0/±inf/sNaN/qNaN, and VOP3 abs/neg/clamp/omod.

Verification

Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK dxil.dll:

  • rustfmt --edition 2024 --check on valu_tests.rs: clean
  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test -p victory-shader --locked -- v_ldexp_f32_matches_rdna2 --nocapture --test-threads=1: passed (hardware + WARP + dxil.dll)
  • VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 121 passed, 0 failed, 1 ignored
**@⁠AscilCH** on GitHub · 2026-11-24 17:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1341) `AscilCH:fix/lower-v-ldexp-f32` → `main` · +130 −0 · 2 files · 1 commits · open ### Gap `v_ldexp_f32` (`VOP3 0x362`, computing `src0.f32 * 2^src1.i32`) was not lowered in `crates/victory-shader/src/emit/lower.rs`, failing shader translation with: ```text lower: Unsupported { offset: 36, what: "v_ldexp_f32" } ``` ### Fix - Lowered `v_ldexp_f32` in `crates/victory-shader/src/emit/lower.rs` using exact IEEE-754 exponent adjustment in pure 32-bit integer arithmetic (requiring no `INT64` shader feature flag): - Clamps the signed exponent `src1` to `[-512, 512]` so `biased_exp + n` never overflows `i32` (including `i32::MIN` and `i32::MAX`) while still handling full-span shifts such as `2^-126 * 2^253 = 2^127` without intermediate overflow. - Overflows to signed infinity, underflows to signed zero (matching RDNA2/D3D12 `f32` FTZ), preserves `±0.0` and `±inf` regardless of exponent, and quiets `sNaN` to `qNaN`. - Applies VOP3 source `abs`/`neg` (via `fsrc` on `src0`) and output `omod`/`clamp` (via `float()`). - Added hardware + WARP + `dxil.dll` test `emit::valu_tests::v_ldexp_f32_matches_rdna2` covering normal positive/negative scaling, full-span scaling, overflow to `±inf`, underflow to `±0.0`, `i32::MIN`/`i32::MAX` exponents, `±0.0`/`±inf`/`sNaN`/`qNaN`, and VOP3 `abs`/`neg`/`clamp`/`omod`. ### Verification Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK `dxil.dll`: - `rustfmt --edition 2024 --check` on `valu_tests.rs`: clean - `cargo xtask policy`: `154 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test -p victory-shader --locked -- v_ldexp_f32_matches_rdna2 --nocapture --test-threads=1`: passed (hardware + WARP + `dxil.dll`) - `VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1`: `121 passed, 0 failed, 1 ignored`
Lower v_ldexp_f32 (src0.f32 * 2^src1.i32) in crates/victory-shader/src/emit/lower.rs
using exact IEEE-754 exponent adjustment in 32-bit integer arithmetic
(without requiring INT64):
- Clamps the signed exponent to [-512, 512] so biased_exp + n never
  overflows i32 (including i32::MIN and i32::MAX), handling full-range
  scaling like 2^-126 * 2^253 = 2^127 without intermediate overflow.
- Overflows to signed infinity, underflows to signed zero (matching
  RDNA2/D3D12 f32 FTZ), preserves +/-0.0 and +/-inf regardless of
  exponent, and quiets sNaN to qNaN.
- Supports VOP3 source abs/neg and output omod/clamp modifiers.
- Adds hardware + WARP + dxil.dll test emit::valu_tests::v_ldexp_f32_matches_rdna2.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:28:12 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 18:10 UTC · original

Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at 59e48eb. cargo test -p victory-shader --lib -- --test-threads=1 gives 121 passed, 0 failed, 1 ignored. v_ldexp_f32_matches_rdna2 passes on the hardware adapter and WARP.

One question on the denormal cases. The lowering returns a signed zero when the result exponent is <= 0, and it treats a denormal input (exp == 0) as zero. The test pins this down: 1.0 * 2^-127 should give 0. That is what RDNA2 does with f32 denormals flushed (MODE.FP_DENORM). With f32 denormals enabled, the hardware returns 0x0040_0000, and a denormal input is scaled rather than zeroed. Is flushing the intended mode for the console's shaders? If so, a comment saying it is an FTZ choice would help, because the test name suggests it matches RDNA2 in every mode.

**@⁠marquezinii** on GitHub · 2026-11-24 18:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1341#issuecomment-7140272950) Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `59e48eb`. `cargo test -p victory-shader --lib -- --test-threads=1` gives 121 passed, 0 failed, 1 ignored. `v_ldexp_f32_matches_rdna2` passes on the hardware adapter and WARP. One question on the denormal cases. The lowering returns a signed zero when the result exponent is `<= 0`, and it treats a denormal input (`exp == 0`) as zero. The test pins this down: `1.0 * 2^-127` should give `0`. That is what RDNA2 does with f32 denormals flushed (`MODE.FP_DENORM`). With f32 denormals enabled, the hardware returns `0x0040_0000`, and a denormal input is scaled rather than zeroed. Is flushing the intended mode for the console's shaders? If so, a comment saying it is an FTZ choice would help, because the test name suggests it matches RDNA2 in every mode.
Author
Owner

@⁠shortselow-byte on GitHub · 2026-11-24 19:06 UTC · original

On the denormal question above: #157 also lowers v_ldexp_f32 and takes the other side. It multiplies by three in-range powers of two so a denormal result is kept (its note: "a result that turns denormal before the last factor is rounded twice where denormals are kept"), where this PR flushes it to signed zero. So the choice of f32 denormal mode is open in two PRs at once, and is worth settling once for both.

**@⁠shortselow-byte** on GitHub · 2026-11-24 19:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1341#issuecomment-7141614547) On the denormal question above: #157 also lowers `v_ldexp_f32` and takes the other side. It multiplies by three in-range powers of two so a denormal result is kept (its note: "a result that turns denormal before the last factor is rounded twice where denormals are kept"), where this PR flushes it to signed zero. So the choice of f32 denormal mode is open in two PRs at once, and is worth settling once for both.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:23 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1341#issuecomment-7149495097) <!-- victory-triage v1 head=59e48eb90d8364ab9b25fafd673b4ec0a537f1db verdict=needs-rebase at=2026-11-25T01:23:24Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 01:48 UTC · original

Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 59e48eb onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 01:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1341#issuecomment-7149984412) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 59e48eb onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 11:47 UTC · original

I rebased the v_ldexp_f32 lowering and its existing readback test onto main at 940d32f. The conflict was in where the test was inserted. The lowering and test body are unchanged, and GitHub attributes the rebased commit to @⁠AscilCH.

The same test stops at Unsupported on 940d32f and passes on the rebased branch. All 29 VALU tests passed on Windows software WARP with DXIL validation. A separate local readback probe matched v_mul_f32 by 0.5 on four inputs at the underflow boundary, including a preserved negative zero and the smallest positive normal. Strict shader Clippy and the asset policy passed.

Claim. AI-assisted with Codex. Synthetic shaders only.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 11:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1341#issuecomment-7161507456) I rebased the `v_ldexp_f32` lowering and its existing readback test onto `main` at `940d32f`. The conflict was in where the test was inserted. The lowering and test body are unchanged, and GitHub attributes the [rebased commit](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/3f47e95b7a65d4384edbbc27d4275d050235099e) to @⁠AscilCH. The same test stops at `Unsupported` on `940d32f` and passes on the rebased branch. All 29 VALU tests passed on Windows software WARP with DXIL validation. A separate local readback probe matched `v_mul_f32` by 0.5 on four inputs at the underflow boundary, including a preserved negative zero and the smallest positive normal. Strict shader Clippy and the asset policy passed. [Claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633). AI-assisted with Codex. Synthetic shaders only.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1341/head:github-bot/gh-1341'
git switch 'github-bot/gh-1341'

Merge

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