Shaders: lower v_div_fixup_f32 and v_div_fixup_f16 #1149

Closed
DenRakEiw wants to merge 1 commit from upstream-pr/1149 into main
DenRakEiw commented 2026-11-24 16:14:40 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6586247765 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1149). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T16:14:40Z. --- ## 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).
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:03Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137893021 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1149#issuecomment-7137893021). Originally posted by [nullmarsh](https://github.com/nullmarsh) on 2026-11-24T16:35:03Z. --- 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.
shortselow-byte commented 2026-11-24 18:05:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-24T17:23:38Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139125999 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1149#issuecomment-7139125999). Originally posted by [shortselow-byte](https://github.com/shortselow-byte) on 2026-11-24T17:23:38Z. --- 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`).
Zipettte commented 2026-11-24 18:06:13 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140040656 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1149#issuecomment-7140040656). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T18:01:15Z. --- 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)._
upstream-sync closed this pull request 2026-11-25 01:05:42 +00:00
Marvisak commented 2026-11-25 01:08:01 +00:00 (Migrated from github.com)

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


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148622816 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1149#issuecomment-7148622816). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:32:56Z. --- 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

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