Shaders: fix v_div_fixup_f32 turning 0.0/x and x/Inf into +/-Infinity #349

Open
AscilCH wants to merge 1 commit from upstream-pr/349 into main
AscilCH commented 2026-11-24 23:49:43 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-24T23:49:43Z.


Problem

In crates/victory-shader/src/emit/lower.rs, v_div_fixup_f32 ORed q_nan into make_inf and evaluated make_inf after make_zero.

In the console's IEEE f32 division sequence (v_div_scale_f32 -> v_rcp_f32 -> v_fma_f32 -> v_div_fmas_f32 -> v_div_fixup_f32):

  • 0.0 / x: v_div_scale_f32 sets r = qNaN when any_zero holds, so q_nan is true alongside n_zero.
  • x / ±Inf: v_rcp_f32(±Inf) = 0.0, then v_fma_f32(-den, 0.0, 1.0) = qNaN, so q_nan is true alongside d_inf.

Because make_inf ran after make_zero, both 0.0 / x and x / ±Inf returned ±Infinity instead of ±0.0.

Fix

  • Remove q_nan from make_inf (n_inf || d_zero) and apply select(q_nan, signed_inf, signed_q) before make_zero (d_inf || n_zero), matching the RDNA2/GFX10 V_DIV_FIXUP_F32 priority table (n_nan > d_nan > invalid > make_inf > make_zero > q_nan > signed_q).
  • Extend emit::tests::valu_div_f32_sequence_executes_on_gpu with 0.0/1.0, -0.0/1.0, 0.0/-2.0, 1.0/+Inf, -1.0/+Inf, +Inf/+Inf, and ±1e38 / 1e-38 across both hardware D3D12 and WARP (plus dxil.dll validation).

Verification

  • cargo test -p victory-shader --locked valu_div_f32_sequence_executes_on_gpu: passed (hardware D3D12 + WARP + dxil.dll)
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic tests only, no game data.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593802569 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/349). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-24T23:49:43Z. --- ## Problem In `crates/victory-shader/src/emit/lower.rs`, `v_div_fixup_f32` ORed `q_nan` into `make_inf` and evaluated `make_inf` *after* `make_zero`. In the console's IEEE f32 division sequence (`v_div_scale_f32` -> `v_rcp_f32` -> `v_fma_f32` -> `v_div_fmas_f32` -> `v_div_fixup_f32`): - `0.0 / x`: `v_div_scale_f32` sets `r = qNaN` when `any_zero` holds, so `q_nan` is true alongside `n_zero`. - `x / ±Inf`: `v_rcp_f32(±Inf) = 0.0`, then `v_fma_f32(-den, 0.0, 1.0) = qNaN`, so `q_nan` is true alongside `d_inf`. Because `make_inf` ran after `make_zero`, both `0.0 / x` and `x / ±Inf` returned `±Infinity` instead of `±0.0`. ## Fix - Remove `q_nan` from `make_inf` (`n_inf || d_zero`) and apply `select(q_nan, signed_inf, signed_q)` *before* `make_zero` (`d_inf || n_zero`), matching the RDNA2/GFX10 `V_DIV_FIXUP_F32` priority table (`n_nan > d_nan > invalid > make_inf > make_zero > q_nan > signed_q`). - Extend `emit::tests::valu_div_f32_sequence_executes_on_gpu` with `0.0/1.0`, `-0.0/1.0`, `0.0/-2.0`, `1.0/+Inf`, `-1.0/+Inf`, `+Inf/+Inf`, and `±1e38 / 1e-38` across both hardware D3D12 and WARP (plus `dxil.dll` validation). ## Verification - `cargo test -p victory-shader --locked valu_div_f32_sequence_executes_on_gpu`: passed (hardware D3D12 + WARP + `dxil.dll`) - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic tests only, no game data.)*
cafeoh commented 2026-11-25 13:05:58 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by cafeoh on 2026-11-25T12:15:56Z.


Tested in the game: this fixes a visible bug.

Setup: RTX 2080 Ti, Windows 10, diagnostics build of fork f85101b plus other open PRs, warm shader cache.

  • Before: in the prologue, from the bar scene on, the lens effect that softens and colour-splits the screen edges also covered a hard-edged circle in the middle of the screen. It was there in every run (8 runs).
  • After merging this PR (no other change): the circle is gone, and the effect at the edges is unchanged.

Guess at why: the effect's strength looks like max(r - r0, 0) / width, so inside r0 it is 0 / x, which came out as infinity.

Not tested: a second run, other scenes, other cards.

AI-assisted (Claude Code); the picture was checked by a person.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7162140118 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/349#issuecomment-7162140118). Originally posted by [cafeoh](https://github.com/cafeoh) on 2026-11-25T12:15:56Z. --- Tested in the game: this fixes a visible bug. Setup: RTX 2080 Ti, Windows 10, diagnostics build of fork `f85101b` plus other open PRs, warm shader cache. - Before: in the prologue, from the bar scene on, the lens effect that softens and colour-splits the screen edges also covered a hard-edged circle in the middle of the screen. It was there in every run (8 runs). - After merging this PR (no other change): the circle is gone, and the effect at the edges is unchanged. Guess at why: the effect's strength looks like `max(r - r0, 0) / width`, so inside `r0` it is `0 / x`, which came out as infinity. Not tested: a second run, other scenes, other cards. AI-assisted (Claude Code); the picture was checked by a person.
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/349:upstream-pr/349'
git switch 'upstream-pr/349'

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