shader: lower v_frexp_{exp,mant}_{f32,f16} in pure 32-bit DXIL #1658

Open
geiyiliyabumo wants to merge 1 commit from upstream-pr/1659 into main
geiyiliyabumo commented 2026-11-24 20:33:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T20:33:31Z.


Summary

  • Lowers RDNA2 v_frexp_exp_i32_f32 (VOP1 0x03f / VOP3 0x1bf), v_frexp_mant_f32 (VOP1 0x040 / VOP3 0x1c0), v_frexp_mant_f16 (VOP1 0x059 / VOP3 0x1d9), and v_frexp_exp_i16_f16 (VOP1 0x05a / VOP3 0x1da) in crates/victory-shader/src/emit/lower.rs (Lower::frexp).
  • Matches AMD RDNA 2 ISA §12.8 in pure 32-bit integer/f32 DXIL arithmetic (neither Double nor Int64 feature bits are set in SFI0):
    • Normalizes subnormals via bit-level FirstbitHi (unaryBits.i32 op 33) so DXIL f32 denormal flushing cannot corrupt subnormal inputs.
    • Preserves signed zero (±0.0), ±inf, and NaN in the mantissa (and flushes -0.0 to +0.0 under omod per RDNA2 ISA §6.2.2); returns 0 for their exponents.
    • Honors VOP3 abs/neg source modifiers, clamp/omod float output modifiers, and SDWA / VOP3 op_sel half selection while preserving the untouched VGPR half on 16-bit writes.

Verification

  • cargo test -p victory-shader --lib: 123 passed, 0 failed, 1 ignored on both AMD Radeon RX 9060 XT (D3D12 hardware) and Microsoft Basic Render Driver (WARP), including 3 new regression tests (v_frexp_f32_decomposes_normals_and_subnormals_and_handles_special_values, v_frexp_f16_decomposes_and_preserves_the_other_destination_half, v_frexp_vop3_applies_float_modifiers — 108 synthetic GPU dispatches per backend, asserting Double and Int64 SFI0 flags are clear).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: pass (154 files).

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6590861578 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1659). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T20:33:31Z. --- ## Summary - Lowers RDNA2 `v_frexp_exp_i32_f32` (`VOP1 0x03f` / `VOP3 0x1bf`), `v_frexp_mant_f32` (`VOP1 0x040` / `VOP3 0x1c0`), `v_frexp_mant_f16` (`VOP1 0x059` / `VOP3 0x1d9`), and `v_frexp_exp_i16_f16` (`VOP1 0x05a` / `VOP3 0x1da`) in `crates/victory-shader/src/emit/lower.rs` (`Lower::frexp`). - Matches AMD RDNA 2 ISA §12.8 in pure 32-bit integer/f32 DXIL arithmetic (neither `Double` nor `Int64` feature bits are set in `SFI0`): - Normalizes subnormals via bit-level `FirstbitHi` (`unaryBits.i32` op 33) so DXIL f32 denormal flushing cannot corrupt subnormal inputs. - Preserves signed zero (`±0.0`), `±inf`, and `NaN` in the mantissa (and flushes `-0.0` to `+0.0` under `omod` per RDNA2 ISA §6.2.2); returns `0` for their exponents. - Honors VOP3 `abs`/`neg` source modifiers, `clamp`/`omod` float output modifiers, and SDWA / VOP3 `op_sel` half selection while preserving the untouched VGPR half on 16-bit writes. ## Verification - `cargo test -p victory-shader --lib`: **123 passed, 0 failed, 1 ignored** on both **AMD Radeon RX 9060 XT (D3D12 hardware)** and **Microsoft Basic Render Driver (WARP)**, including 3 new regression tests (`v_frexp_f32_decomposes_normals_and_subnormals_and_handles_special_values`, `v_frexp_f16_decomposes_and_preserves_the_other_destination_half`, `v_frexp_vop3_applies_float_modifiers` — 108 synthetic GPU dispatches per backend, asserting `Double` and `Int64` `SFI0` flags are clear). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: pass (154 files). *AI-assisted; synthetic tests only, no game files.*
catminou4 commented 2026-11-24 22:01:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:42:44Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows.

v_frexp_{exp,mant}_{f32,f16} lowered in pure 32-bit DXIL: frexp() with src_bits + float_output_modifiers (omod/clamp), build_frexp_cs test builder.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047880986 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1659#pullrequestreview-6047880986). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:42:44Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows. v_frexp_{exp,mant}_{f32,f16} lowered in pure 32-bit DXIL: frexp() with src_bits + float_output_modifiers (omod/clamp), build_frexp_cs test builder.
Marvisak commented 2026-11-25 02:06:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:33:38Z.


Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main: main has moved since the last triage, and the branch now conflicts in crates/victory-shader/src/emit/valu_tests.rs. It will be reviewed again once it is rebased onto current main.

Previous verdict for this head: merge candidate.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149687444 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1659#issuecomment-7149687444). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:33:38Z. --- <!-- victory-triage v1 head=f9dda94f1286f269680f51925ffc87ebed12c571 verdict=needs-rebase at=2026-11-25T22:28:30Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main`: `main` has moved since the last triage, and the branch now conflicts in `crates/victory-shader/src/emit/valu_tests.rs`. It will be reviewed again once it is rebased onto current `main`. Previous verdict for this head: merge candidate. --- _Generated by [Claude Code](https://claude.ai/code)_
Headache3318 commented 2026-11-25 02:06:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Headache3318 on 2026-11-25T01:36:46Z.


Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head 79107fd applied cleanly onto current main ccfb029.

  • cargo test -p victory-shader --locked: 96 passed, 0 failed, 1 ignored. All tests pass.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 2 pre-existing unused-import errors in test code (fail identically on main ccfb029). The PR introduces no new clippy warnings.

Not tested: Windows MSVC build, the title itself. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149749930 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1659#issuecomment-7149749930). Originally posted by [Headache3318](https://github.com/Headache3318) on 2026-11-25T01:36:46Z. --- Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head `79107fd` applied cleanly onto current `main` `ccfb029`. - `cargo test -p victory-shader --locked`: 96 passed, 0 failed, 1 ignored. All tests pass. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 2 pre-existing unused-import errors in test code (fail identically on main `ccfb029`). The PR introduces no new clippy warnings. Not tested: Windows MSVC build, the title itself. AI-assisted.
geiyiliyabumo commented 2026-11-25 03:03:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-25T02:25:30Z.


Rebased cleanly onto \main\ (\ccfb029), preserving \main's \ tz/denormal-flush \omod\ handling inside \ loat_output_modifiers. \cargo test -p victory-shader --locked frexp\ (verified on physical AMD RX 9060 XT + WARP + Microsoft \dxil.dll), \cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings, and \cargo xtask policy\ all pass.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150701721 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1659#issuecomment-7150701721). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-25T02:25:30Z. --- Rebased cleanly onto \main\ (\ccfb029\), preserving \main\'s \ tz\/denormal-flush \omod\ handling inside \ loat_output_modifiers\. \cargo test -p victory-shader --locked frexp\ (verified on physical AMD RX 9060 XT + WARP + Microsoft \dxil.dll\), \cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings\, and \cargo xtask policy\ all pass.
geiyiliyabumo commented 2026-11-25 04:07:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-25T03:49:53Z.


Updated per triage feedback: applied \Lower::ftz\ to f32 \ _frexp_exp_i32_f32\ / \ _frexp_mant_f32\ inputs (preserving signed-zero mantissa and zero exponent for flushed f32 subnormals while keeping f16 subnormal decomposition unchanged) and updated the f32 subnormal tests. Rebased onto \main\ (\940d32f); verified on physical AMD RX 9060 XT + WARP + Microsoft \dxil.dll: \ rexp\ (3 passed, 0 failed), \semantics_tests\ (32 passed, 0 failed), \clippy -D warnings, and \xtask policy\ all pass.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152280971 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1659#issuecomment-7152280971). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-25T03:49:53Z. --- Updated per triage feedback: applied \Lower::ftz\ to f32 \ _frexp_exp_i32_f32\ / \ _frexp_mant_f32\ inputs (preserving signed-zero mantissa and zero exponent for flushed f32 subnormals while keeping f16 subnormal decomposition unchanged) and updated the f32 subnormal tests. Rebased onto \main\ (\940d32f\); verified on physical AMD RX 9060 XT + WARP + Microsoft \dxil.dll\: \ rexp\ (3 passed, 0 failed), \semantics_tests\ (32 passed, 0 failed), \clippy -D warnings\, and \xtask policy\ all pass.
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/1659:upstream-pr/1659'
git switch 'upstream-pr/1659'

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