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

Open
ESAT586 wants to merge 1 commit from upstream-pr/1190 into main
ESAT586 commented 2026-11-24 16:22:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-24T16:22:58Z.


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).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6586412114 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1190). Originally posted by [ESAT586](https://github.com/ESAT586) on 2026-11-24T16:22:58Z. --- > **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).
DenRakEiw commented 2026-11-24 17:03:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T16:27:26Z.

Review: APPROVED


Tested head d160854 (fast-forward on main ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP:

  • cargo test -p victory-shader valu_tests: 14 passed, 0 failed (including v_frexp_f32_and_f16_match_rdna2 on both RTX 5090 and WARP)
  • cargo clippy -p victory-shader --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean v_frexp_mant_{f32,f16} and v_frexp_exp_i{32_f32,16_f16} lowering verified on Blackwell hardware and WARP. Approving.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6043238447 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1190#pullrequestreview-6043238447). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T16:27:26Z. **Review:** APPROVED --- Tested head `d160854` (fast-forward on `main` `ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC) with **NVIDIA GeForce RTX 5090** (Blackwell) and **WARP**: - `cargo test -p victory-shader valu_tests`: **14 passed, 0 failed** (including `v_frexp_f32_and_f16_match_rdna2` on both RTX 5090 and WARP) - `cargo clippy -p victory-shader --all-targets`: **0 warnings** - `cargo xtask policy`: ok Clean `v_frexp_mant_{f32,f16}` and `v_frexp_exp_i{32_f32,16_f16}` lowering verified on Blackwell hardware and WARP. Approving. AI-assisted (Gemini 4 Neon).
nullmarsh commented 2026-11-24 17:04:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by nullmarsh on 2026-11-24T16:35:01Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137892334 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1190#issuecomment-7137892334). Originally posted by [nullmarsh](https://github.com/nullmarsh) on 2026-11-24T16:35:01Z. --- 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.
Zipettte commented 2026-11-24 18:06:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T18:00:28Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140021496 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1190#issuecomment-7140021496). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T18:00:28Z. --- 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)._
Marvisak commented 2026-11-25 01:08:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:39:25Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148739505 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1190#issuecomment-7148739505). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:39:25Z. --- <!-- 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)_
ESAT586 commented 2026-11-25 12:03:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T11:19:57Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160904789 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1190#issuecomment-7160904789). Originally posted by [ESAT586](https://github.com/ESAT586) on 2026-11-25T11:19:57Z. --- 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 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/1190:upstream-pr/1190'
git switch 'upstream-pr/1190'

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