Shaders: lower v_frexp_mant_{f32,f16} and v_frexp_exp_i{32_f32,16_f16} #1190

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

@⁠ESAT586 on GitHub · 2026-11-24 16:22 UTC · original
ESAT586:shader/frexp-f32-f16 → main · +188 −0 · 2 files · 1 commits · open

AI Disclosure — Generated & Verified by Gemini 4 Neon (High Mode) (Not Written by a Human Engineer)
This diagnosis, RDNA2 ISA implementation, and synthetic GPU/WARP test suite were authored and verified end-to-end by Gemini 4 Neon (High Mode), submitted transparently on behalf of @ESAT586. All builds, clippy checks, DXIL validation, and GPU/WARP tests below were executed locally on real hardware (NVIDIA GeForce RTX 3060 Ti, Windows 11, Rust 1.98.1). No game data was used.

What's wrong

v_frexp_mant_f32 (VOP1 0x40), v_frexp_exp_i32_f32 (VOP1 0x3f), v_frexp_mant_f16 (VOP1 0x59), and v_frexp_exp_i16_f16 (VOP1 0x5a) — the RDNA2 instructions emitted for HLSL frexp(x, exp) — are decoded in gfx10/opcodes.rs but not lowered in crates/victory-shader/src/emit/lower.rs, causing any shader using them to fail lowering.

Fix

  • Add Lower::frexp_f32 in crates/victory-shader/src/emit/lower.rs using pure 32-bit bitwise integer ops (no i64 capability needed):
    • Normal finite f32: extracts sign + mantissa with biased exponent 126 ((-1, -0.5] U [0.5, 1)) and exponent exp_raw - 126.
    • Subnormal finite f32: normalizes via DXIL FirstbitHi (unaryBits.i32 op 33), shifting the top mantissa bit to bit 23 and returning exponent -117 - lz.
    • Special values (±0, ±inf, NaN): mantissa preserves the input bits (including -0.0 sign and ±inf/NaN), exponent returns 0.
  • Wire v_frexp_mant_f32 and v_frexp_exp_i32_f32 in valu_op.
  • Wire v_frexp_mant_f16 (FLOAT1) and v_frexp_exp_i16_f16 (INT) in valu16/valu16_op: half_fsrc widens every f16 (including all f16 subnormals) into an exact normal f32, runs frexp_f32, and writes back via float_result / write_half (preserving the destination's other 16-bit half and honoring opsel/abs/neg).
  • Add emit::valu_tests::v_frexp_f32_and_f16_match_rdna2 in crates/victory-shader/src/emit/valu_tests.rs covering normals, subnormals (0x0040_0000, 0x0000_0003, 0x8000_0001, f16 0x0001, 0x8003), ±0, ±inf, NaN, max finite f16 (0x7BFF), and upper-half preservation.

Verification (Real GPU + WARP + CI Gates)

Tested on Windows 11, NVIDIA GeForce RTX 3060 Ti (driver 32.0.16.1656), Rust 1.98.1:

  • cargo test -p victory-shader --lib v_frexp_f32_and_f16_match_rdna2: ok (dxil.dll validator + RTX 3060 Ti hardware + Microsoft WARP)
  • cargo test -p victory-shader --locked: 121 passed, 0 failed, 1 ignored
  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass (0 warnings)
  • cargo xtask policy: asset policy: 154 files ok

Scope & Non-Overlap

  • Checked open PRs and issues before writing: no open PR or issue covers v_frexp_mant_* or v_frexp_exp_*.
  • Not tested: against retail title shader packages (synthetic fixtures only, no game data).
**@⁠ESAT586** on GitHub · 2026-11-24 16:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/1190) `ESAT586:shader/frexp-f32-f16` → `main` · +188 −0 · 2 files · 1 commits · open > **AI Disclosure — Generated & Verified by Gemini 4 Neon (High Mode) (Not Written by a Human Engineer)** > This diagnosis, RDNA2 ISA implementation, and synthetic GPU/WARP test suite were authored and verified end-to-end by **Gemini 4 Neon (High Mode)**, submitted transparently on behalf of `@ESAT586`. All builds, clippy checks, DXIL validation, and GPU/WARP tests below were executed locally on real hardware (`NVIDIA GeForce RTX 3060 Ti`, Windows 11, Rust `1.98.1`). **No game data was used.** ## What's wrong `v_frexp_mant_f32` (`VOP1 0x40`), `v_frexp_exp_i32_f32` (`VOP1 0x3f`), `v_frexp_mant_f16` (`VOP1 0x59`), and `v_frexp_exp_i16_f16` (`VOP1 0x5a`) — the RDNA2 instructions emitted for HLSL `frexp(x, exp)` — are decoded in `gfx10/opcodes.rs` but not lowered in `crates/victory-shader/src/emit/lower.rs`, causing any shader using them to fail lowering. ## Fix - Add `Lower::frexp_f32` in `crates/victory-shader/src/emit/lower.rs` using pure 32-bit bitwise integer ops (no `i64` capability needed): - **Normal finite f32:** extracts sign + mantissa with biased exponent `126` (`(-1, -0.5] U [0.5, 1)`) and exponent `exp_raw - 126`. - **Subnormal finite f32:** normalizes via DXIL `FirstbitHi` (`unaryBits.i32` op `33`), shifting the top mantissa bit to bit 23 and returning exponent `-117 - lz`. - **Special values (`±0`, `±inf`, `NaN`):** mantissa preserves the input bits (including `-0.0` sign and `±inf`/`NaN`), exponent returns `0`. - Wire `v_frexp_mant_f32` and `v_frexp_exp_i32_f32` in `valu_op`. - Wire `v_frexp_mant_f16` (`FLOAT1`) and `v_frexp_exp_i16_f16` (`INT`) in `valu16`/`valu16_op`: `half_fsrc` widens every f16 (including all f16 subnormals) into an exact normal f32, runs `frexp_f32`, and writes back via `float_result` / `write_half` (preserving the destination's other 16-bit half and honoring `opsel`/`abs`/`neg`). - Add `emit::valu_tests::v_frexp_f32_and_f16_match_rdna2` in `crates/victory-shader/src/emit/valu_tests.rs` covering normals, subnormals (`0x0040_0000`, `0x0000_0003`, `0x8000_0001`, f16 `0x0001`, `0x8003`), `±0`, `±inf`, `NaN`, max finite f16 (`0x7BFF`), and upper-half preservation. ## Verification (Real GPU + WARP + CI Gates) Tested on Windows 11, **NVIDIA GeForce RTX 3060 Ti** (driver `32.0.16.1656`), Rust `1.98.1`: - `cargo test -p victory-shader --lib v_frexp_f32_and_f16_match_rdna2`: **ok** (`dxil.dll` validator + RTX 3060 Ti hardware + Microsoft WARP) - `cargo test -p victory-shader --locked`: **121 passed, 0 failed, 1 ignored** - `cargo clippy --workspace --all-targets --locked -- -D warnings`: **pass (0 warnings)** - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: **pass (0 warnings)** - `cargo xtask policy`: **`asset policy: 154 files ok`** ## Scope & Non-Overlap - Checked open PRs and issues before writing: no open PR or issue covers `v_frexp_mant_*` or `v_frexp_exp_*`. - **Not tested:** against retail title shader packages (synthetic fixtures only, no game data).
AI-generated & verified with Gemini 4 Neon (High Mode) — not written by a human engineer.

Lower the four RDNA2 `frexp` instructions (`v_frexp_mant_f32`,
`v_frexp_exp_i32_f32`, `v_frexp_mant_f16`, `v_frexp_exp_i16_f16`) via a shared
32-bit bitwise `frexp_f32` helper:
- finite non-zero (normal and subnormal via DXIL `FirstbitHi` op 33):
  mantissa in `(-1, -0.5] U [0.5, 1)` and unbiased exponent `exp` where
  `a == mantissa * 2^exp`;
- `±0`, `±inf`, `NaN`: mantissa preserves the input (sign/special value),
  exponent is `0`.
- f16 variants widen through `half_fsrc` (exact even for all f16 subnormals),
  apply `frexp_f32`, and preserve the destination's untouched half via
  `write_half`.

Verified with synthetic GPU + WARP + dxil.dll tests in `valu_tests.rs` on
NVIDIA GeForce RTX 3060 Ti (Windows 11, Rust 1.98.1). No game data used.

Co-Authored-By: Gemini 4 Neon (High Mode) <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:23:02 +00:00
Author
Owner

@⁠ghost on GitHub · 2026-11-24 16:35 UTC · original

Ran on RDNA2 hardware through vkd3d-proton on a Steam Deck (not native Windows): AMD Van Gogh, RADV 26.1.99, SteamOS 3.8.28, Proton 11.0-3 (wine-11.0) with its vkd3d-proton 212991fc. Windows MSVC test binary (rustc 1.100.0) built from head d160854 on main ffe310e. Your report lists NVIDIA and WARP, so this adds AMD hardware.

  • v_frexp_f32_and_f16_match_rdna2 passes: mant/exp for f32 and f16, including the subnormal cases, +-0, +-inf, NaN, and the f16 high half kept.
  • victory-shader lib tests: 120 passed, 1 failed, 1 ignored (main on the same host: 119/1/1). The one failure, stub_pipeline_is_created, fails on main too (likely vkd3d-proton accepting the zero DXIL digest the test expects refused; environment, not this PR).
  • No hangs. A pass means the translated DXIL gives these values on RDNA2 through vkd3d-proton/RADV; it isn't a console measurement.

Not tested: native Windows AMD drivers; WARP (this setup has none, so the WARP leg ran on RADV too); whether the new test fails without the fix on this host.

AI-assisted (Claude Code, Claude Opus 5.5); no game data.

**@⁠ghost** on GitHub · 2026-11-24 16:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/1190#issuecomment-7137892334) Ran on RDNA2 hardware through vkd3d-proton on a Steam Deck (not native Windows): AMD Van Gogh, RADV 26.1.99, SteamOS 3.8.28, Proton 11.0-3 (wine-11.0) with its vkd3d-proton 212991fc. Windows MSVC test binary (rustc 1.100.0) built from head `d160854` on main `ffe310e`. Your report lists NVIDIA and WARP, so this adds AMD hardware. - `v_frexp_f32_and_f16_match_rdna2` passes: mant/exp for f32 and f16, including the subnormal cases, +-0, +-inf, NaN, and the f16 high half kept. - victory-shader lib tests: 120 passed, 1 failed, 1 ignored (main on the same host: 119/1/1). The one failure, `stub_pipeline_is_created`, fails on main too (likely vkd3d-proton accepting the zero DXIL digest the test expects refused; environment, not this PR). - No hangs. A pass means the translated DXIL gives these values on RDNA2 through vkd3d-proton/RADV; it isn't a console measurement. Not tested: native Windows AMD drivers; WARP (this setup has none, so the WARP leg ran on RADV too); whether the new test fails without the fix on this host. AI-assisted (Claude Code, Claude Opus 5.5); no game data.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:00 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at d160854: cargo test -p victory-shader passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 18:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1190#issuecomment-7140021496) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at d160854: `cargo test -p victory-shader` passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:39 UTC · original · edited 2026-11-25 12:16 UTC

Automated triage for the maintainers.

Proposed close: duplicate of #1659. Thanks for the rebase. It now merges cleanly, and CI check passes at 05044fa.

#1659 lowers the same four instructions (v_frexp_mant_{f32,f16}, v_frexp_exp_i{32_f32,16_f16}). It also merges cleanly and is already marked as a merge candidate. The two disagree on f32 denormal inputs, and #1659 matches main there:

  • main reads a 32-bit denormal as a zero of its sign, the way the console's float mode does (Lower::ftz in crates/victory-shader/src/emit/lower.rs, whose doc comment says so). #1659 applies that flush before splitting the value.
  • Lower::frexp_f32 here normalises f32 denormals instead, and v_frexp_f32_and_f16_match_rdna2 asserts those results (for example 0x0000_0003 → 0.75, -147). On the console's float mode, those inputs read as ±0.

The f16 handling (normalising denormals) agrees between the two PRs.

This PR will be closed in 48 hours unless you push a change or a maintainer removes the triage: proposed close label. If you think the f32 denormal behaviour here is the right one, please point to evidence (console output or an ISA reference for the float mode the title runs in).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/1190#issuecomment-7148739505) · edited 2026-11-25 12:16 UTC <!-- victory-triage v1 head=05044faa8dad25bf632ed4894d5eb8099836eda5 verdict=proposed-close at=2026-11-25T12:20:00Z --> Automated triage for the maintainers. **Proposed close: duplicate of #1659.** Thanks for the rebase. It now merges cleanly, and CI `check` passes at `05044fa`. #1659 lowers the same four instructions (`v_frexp_mant_{f32,f16}`, `v_frexp_exp_i{32_f32,16_f16}`). It also merges cleanly and is already marked as a merge candidate. The two disagree on f32 denormal inputs, and #1659 matches `main` there: - `main` reads a 32-bit denormal as a zero of its sign, the way the console's float mode does (`Lower::ftz` in `crates/victory-shader/src/emit/lower.rs`, whose doc comment says so). #1659 applies that flush before splitting the value. - `Lower::frexp_f32` here normalises f32 denormals instead, and `v_frexp_f32_and_f16_match_rdna2` asserts those results (for example `0x0000_0003` → `0.75`, `-147`). On the console's float mode, those inputs read as ±0. The f16 handling (normalising denormals) agrees between the two PRs. This PR will be closed in 48 hours unless you push a change or a maintainer removes the `triage: proposed close` label. If you think the f32 denormal behaviour here is the right one, please point to evidence (console output or an ISA reference for the float mode the title runs in). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠ESAT586 on GitHub · 2026-11-25 11:19 UTC · original

Rebased onto \main\ (\940d32f) at $sha. Verified on RTX 3060 Ti + WARP: \ _frexp_f32_and_f16_match_rdna2\ passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.

**@⁠ESAT586** on GitHub · 2026-11-25 11:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1190#issuecomment-7160904789) Rebased onto \main\ (\940d32f\) at \$sha\. Verified on RTX 3060 Ti + WARP: \ _frexp_f32_and_f16_match_rdna2\ passed, strict Clippy (\--all-targets\ and \--all-features\) clean, \cargo xtask policy\ ok.
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/1190/head:github-bot/gh-1190'
git switch 'github-bot/gh-1190'

Merge

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