Shaders: lower v_div_fixup_f32 and v_div_fixup_f16 #1149

Closed
github-bot wants to merge 1 commit from gh-pr/1149/head into gh-pr/1149/base
Owner

@⁠DenRakEiw on GitHub · 2026-11-24 16:14 UTC · original
shader/v-div-fixup → main · +166 −1 · 2 files · 1 commits · closed without merging

## Summary

Lowers RDNA2's IEEE-754 division-finalization instructions v_div_fixup_f32 (VOP3 0x15F) and v_div_fixup_f16 (VOP3 0x35F) in crates/victory-shader/src/emit/lower.rs:

  • Adds Lower::div_fixup(quot, denom, num) implementing the full RDNA2 GFX10.3 special-case priority table in pure integer bit operations (immune to host-driver float NaN-folding differences):
    1. denom is NaN → quiet(denom) (highest priority, preserving payload)
    2. num is NaN → quiet(num)
    3. (denom == ±0 && num == ±0) or (denom == ±inf && num == ±inf) → canonical qNaN (0x7FC0_0000)
    4. num == ±inf or denom == ±0 → ±inf with sign(denom) ^ sign(num)
    5. denom == ±inf or num == ±0 → ±0.0 with sign(denom) ^ sign(num)
    6. Otherwise: if quot is NaN (overflow in division sequence) → ±inf with sign(denom) ^ sign(num), else copysign(quot, sign(denom) ^ sign(num)).
  • Wires v_div_fixup_f32 through f(self, 0..=2) and float(self, r) (preserving VOP3 abs/neg/omod/clamp) and v_div_fixup_f16 through valu16_op's FLOAT3 path (half_fsrc + float_result).

Tests

Added two end-to-end synthetic GFX10 compute shader tests in crates/victory-shader/src/emit/valu_tests.rs (validated via dxil.dll and executed on both host GPU and WARP):

  • v_div_fixup_f32_matches_rdna2: 19 cases covering normal copysign, NaN quotient overflow, ±x / ±0, ±inf / finite, finite / ±inf, ±0 / finite, 0/0, inf/inf, and sNaN priority/quieting.
  • v_div_fixup_f16_matches_rdna2: 9 cases covering f16 copysign, NaN quotient overflow, ±0/±inf sign rules, 0/0, inf/inf, and NaN propagation.

Verification

  • cargo test -p victory-shader v_div_fixup: 2 passed, 0 failed on Windows 11 x64 / NVIDIA GeForce RTX 5090 (Blackwell) + WARP
  • cargo clippy -p victory-shader --all-targets: 0 warnings
  • cargo xtask policy: asset policy: 155 files ok

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-24 16:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1149) `shader/v-div-fixup` → `main` · +166 −1 · 2 files · 1 commits · closed without merging ## Summary Lowers RDNA2's IEEE-754 division-finalization instructions **`v_div_fixup_f32`** (VOP3 `0x15F`) and **`v_div_fixup_f16`** (VOP3 `0x35F`) in `crates/victory-shader/src/emit/lower.rs`: - Adds `Lower::div_fixup(quot, denom, num)` implementing the full RDNA2 GFX10.3 special-case priority table in pure integer bit operations (immune to host-driver float NaN-folding differences): 1. `denom` is NaN → `quiet(denom)` (highest priority, preserving payload) 2. `num` is NaN → `quiet(num)` 3. `(denom == ±0 && num == ±0)` or `(denom == ±inf && num == ±inf)` → canonical qNaN (`0x7FC0_0000`) 4. `num == ±inf` or `denom == ±0` → `±inf` with `sign(denom) ^ sign(num)` 5. `denom == ±inf` or `num == ±0` → `±0.0` with `sign(denom) ^ sign(num)` 6. Otherwise: if `quot` is NaN (overflow in division sequence) → `±inf` with `sign(denom) ^ sign(num)`, else `copysign(quot, sign(denom) ^ sign(num))`. - Wires `v_div_fixup_f32` through `f(self, 0..=2)` and `float(self, r)` (preserving VOP3 `abs`/`neg`/`omod`/`clamp`) and `v_div_fixup_f16` through `valu16_op`'s `FLOAT3` path (`half_fsrc` + `float_result`). ## Tests Added two end-to-end synthetic GFX10 compute shader tests in `crates/victory-shader/src/emit/valu_tests.rs` (validated via `dxil.dll` and executed on both host GPU and WARP): - `v_div_fixup_f32_matches_rdna2`: 19 cases covering normal `copysign`, `NaN` quotient overflow, `±x / ±0`, `±inf / finite`, `finite / ±inf`, `±0 / finite`, `0/0`, `inf/inf`, and `sNaN` priority/quieting. - `v_div_fixup_f16_matches_rdna2`: 9 cases covering f16 `copysign`, `NaN` quotient overflow, `±0`/`±inf` sign rules, `0/0`, `inf/inf`, and `NaN` propagation. ## Verification - `cargo test -p victory-shader v_div_fixup`: **2 passed, 0 failed** on Windows 11 x64 / **NVIDIA GeForce RTX 5090 (Blackwell)** + **WARP** - `cargo clippy -p victory-shader --all-targets`: **0 warnings** - `cargo xtask policy`: `asset policy: 155 files ok` AI-assisted (Gemini 4 Neon).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:21:12 +00:00
github-bot closed this pull request 2026-11-26 04:21:12 +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 4e35c96 on main ffe310e. Your report lists NVIDIA and WARP, so this adds AMD hardware.

  • v_div_fixup_f32_matches_rdna2 and v_div_fixup_f16_matches_rdna2 pass: signs, x/0, inf, 0/0, inf/inf, and NaN priority (denominator before numerator).
  • victory-shader lib tests: 121 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/1149#issuecomment-7137893021) 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 `4e35c96` on main `ffe310e`. Your report lists NVIDIA and WARP, so this adds AMD hardware. - `v_div_fixup_f32_matches_rdna2` and `v_div_fixup_f16_matches_rdna2` pass: signs, x/0, inf, 0/0, inf/inf, and NaN priority (denominator before numerator). - victory-shader lib tests: 121 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

@⁠shortselow-byte on GitHub · 2026-11-24 17:23 UTC · original

For triage: this overlaps two open PRs, #200 (v_div_scale_f32, v_div_fmas_f32 and v_div_fixup_f32) and #379 (v_div_fixup_f16).

**@⁠shortselow-byte** on GitHub · 2026-11-24 17:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1149#issuecomment-7139125999) For triage: this overlaps two open PRs, #200 (`v_div_scale_f32`, `v_div_fmas_f32` and `v_div_fixup_f32`) and #379 (`v_div_fixup_f16`).
Author
Owner

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

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 4e35c96: cargo test -p victory-shader passes, 122 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:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1149#issuecomment-7140040656) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 4e35c96: `cargo test -p victory-shader` passes, 122 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:32 UTC · original

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #200. Lowers v_div_fixup_f32 and v_div_fixup_f16, which the title does not use. Both are covered by PRs that merge clean: #200 (f32, with v_div_scale/v_div_fmas) and #379 (f16).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1149#issuecomment-7148622816) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #200. Lowers v_div_fixup_f32 and v_div_fixup_f16, which the title does not use. Both are covered by PRs that merge clean: #200 (f32, with v_div_scale/v_div_fmas) and #379 (f16). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!1149
No description provided.