Skip to content

Shaders: lower v_div_fixup_f32 and v_div_fixup_f16 - #1149

Closed
DenRakEiw wants to merge 1 commit into
Marvisak:mainfrom
DenRakEiw:shader/v-div-fixup
Closed

DenRakEiw wants to merge 1 commit into
Marvisak:mainfrom
DenRakEiw:shader/v-div-fixup

Conversation

@DenRakEiw

Copy link
Copy Markdown

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

@ghost

ghost commented Nov 24, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

@Marvisak

Copy link
Copy Markdown
Owner

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 Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants