shader: use bitwise IUGE in scrub_nan and zero NaN in clamp_hdr #2432

Open
github-bot wants to merge 2 commits from github-bot/gh-2432 into main AGit
Owner

@⁠qlfu on GitHub · 2026-11-29 12:59 UTC · original
qlfu:pr/fix-nan-scrub-and-clamp-hdr → main · +215 −17 · 3 files · 2 commits · open

What it changes Fixes two NaN-handling bugs on pixel float colour outputs and float image stores in crates/victory-shader/src/emit/lower.rs: 1. Bitwise NaN/Inf check in Lower::scrub_nan (VICTORY_NAN_SCRUB=1): Replaces FP fcmp uge(fabs(f), +inf) with integer (as_int(f) & 0x7FFF_FFFF) >= 0x7F80_0000 (pred::IUGE), matching is_nan_f32 directly below it so NVIDIA fast-math cannot fold away NaN detection while still catching both NaN and +/-Inf. 2. Zero NaN in Lower::clamp_hdr (VICTORY_HDR_CLAMP): Changes the NaN branch from max (+65024.0) to 0.0 so a NaN channel in a pixel shader colour export does not turn into a blazing +65024.0 neon HDR flash when VICTORY_NAN_SCRUB is off or bypassed. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): unit/compiler verification on Windows x64 (RTX 4070 Ti host); no gameplay FPS claims for this correctness fix. - For shader changes, the wave sizes tested (32 and/or 64 lanes): applies identically to Wave32/Wave64 pixel & compute float outputs; new unit test emit::lower::tests::scrub_nan_uses_bitwise_iuge_and_clamp_hdr_replaces_nan_with_zero checks emitted bitcode predicates (pred::IUGE, no pred::UGE) and select operands (0.0 instead of 65024.0). - cargo test passed for the crates it touches: yes (cargo test -p victory-shader --lib --locked lower::tests -- --test-threads=1: 26 passed, 0 failed, 1 ignored; cargo clippy -p victory-shader --lib --tests --locked: 0 new warnings). ## Checked for overlap - [x] I searched open pull requests for scrub_nan, clamp_hdr, HDR_CLAMP, and NAN_SCRUB; no overlapping open PR found.

Fixes #2057

**@⁠qlfu** on GitHub · 2026-11-29 12:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2432) `qlfu:pr/fix-nan-scrub-and-clamp-hdr` → `main` · +215 −17 · 3 files · 2 commits · open ## What it changes Fixes two NaN-handling bugs on pixel float colour outputs and float image stores in `crates/victory-shader/src/emit/lower.rs`: 1. **Bitwise NaN/Inf check in `Lower::scrub_nan` (`VICTORY_NAN_SCRUB=1`):** Replaces FP `fcmp uge(fabs(f), +inf)` with integer `(as_int(f) & 0x7FFF_FFFF) >= 0x7F80_0000` (`pred::IUGE`), matching `is_nan_f32` directly below it so NVIDIA fast-math cannot fold away NaN detection while still catching both `NaN` and `+/-Inf`. 2. **Zero NaN in `Lower::clamp_hdr` (`VICTORY_HDR_CLAMP`):** Changes the NaN branch from `max` (`+65024.0`) to `0.0` so a NaN channel in a pixel shader colour export does not turn into a blazing `+65024.0` neon HDR flash when `VICTORY_NAN_SCRUB` is off or bypassed. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): unit/compiler verification on Windows x64 (RTX 4070 Ti host); no gameplay FPS claims for this correctness fix. - For shader changes, the wave sizes tested (32 and/or 64 lanes): applies identically to Wave32/Wave64 pixel & compute float outputs; new unit test `emit::lower::tests::scrub_nan_uses_bitwise_iuge_and_clamp_hdr_replaces_nan_with_zero` checks emitted bitcode predicates (`pred::IUGE`, no `pred::UGE`) and `select` operands (`0.0` instead of `65024.0`). - `cargo test` passed for the crates it touches: yes (`cargo test -p victory-shader --lib --locked lower::tests -- --test-threads=1`: 26 passed, 0 failed, 1 ignored; `cargo clippy -p victory-shader --lib --tests --locked`: 0 new warnings). ## Checked for overlap - [x] I searched open pull requests for `scrub_nan`, `clamp_hdr`, `HDR_CLAMP`, and `NAN_SCRUB`; no overlapping open PR found. Fixes #2057
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 13:00:41 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-29 13:05 UTC · original · approved these changes

Tested locally merged onto main (829188e9).

  • Merge: Clean merge across bitcode.rs, lower.rs, and lower/tests.rs.
  • Tests (RTX 5090):
    • cargo test -p victory-shader --lib emit::tests:: passed (26 passed; 0 failed; 1 ignored).
    • cargo test -p victory-shader --lib emit::lower::tests:: passed (26 passed; 0 failed; 1 ignored, including the new scrub_nan_uses_bitwise_iuge_and_clamp_hdr_replaces_nan_with_zero test).
  • 0 new warnings.

Clean bitwise IUGE NaN/Inf scrubbing and NaN-safe HDR clamping. LGTM.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-29 13:05 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2432#pullrequestreview-6102995776) · **approved these changes** Tested locally merged onto `main` (`829188e9`). - **Merge**: Clean merge across `bitcode.rs`, `lower.rs`, and `lower/tests.rs`. - **Tests (RTX 5090)**: - `cargo test -p victory-shader --lib emit::tests::` passed (`26 passed; 0 failed; 1 ignored`). - `cargo test -p victory-shader --lib emit::lower::tests::` passed (`26 passed; 0 failed; 1 ignored`, including the new `scrub_nan_uses_bitwise_iuge_and_clamp_hdr_replaces_nan_with_zero` test). - 0 new warnings. Clean bitwise `IUGE` NaN/Inf scrubbing and NaN-safe HDR clamping. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠fainty0 on GitHub · 2026-11-29 14:45 UTC · original · requested changes

Review: Request changes (coverage)

The semantics look right: both wave widths share the same lowering. The masked unsigned >= in scrub_nan scrubs infinities and NaNs; the > in clamp_hdr zeroes only NaNs. FTZ doesn't change classification. DXIL min/max alone would yield −65024 for NaN, so the fix is needed.

However, the test at crates/victory-shader/src/emit/lower/tests.rs:1184 passes even without the sign mask. Please make it check the select condition against signed NaNs, infinities and subnormals.

Checks: Linux shader tests 295 → 296 passed. Windows Clippy unchanged (workspace 5 → 5 / 4 → 4; shader-only 3 → 3 / 4 → 4). No asset violations. NVIDIA driver behaviour and runtime not verified.

**@⁠fainty0** on GitHub · 2026-11-29 14:45 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2432#pullrequestreview-6103365332) · **requested changes** ## Review: Request changes (coverage) The semantics look right: both wave widths share the same lowering. The masked unsigned `>=` in `scrub_nan` scrubs infinities and NaNs; the `>` in `clamp_hdr` zeroes only NaNs. FTZ doesn't change classification. [DXIL min/max](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#fmax) alone would yield −65024 for NaN, so the fix is needed. However, the test at `crates/victory-shader/src/emit/lower/tests.rs:1184` passes even without the sign mask. Please make it check the select condition against signed NaNs, infinities and subnormals. **Checks:** Linux shader tests 295 → 296 passed. Windows Clippy unchanged (workspace 5 → 5 / 4 → 4; shader-only 3 → 3 / 4 → 4). No asset violations. NVIDIA driver behaviour and runtime not verified.
Author
Owner

@⁠remie1529 on GitHub · 2026-11-29 14:56 UTC · original

Tested on RTX 4070 (driver 616.92, Windows 11, Series X 2560x1440, DLSS Performance, DLSS FG 2x, release build on \829188e). Built with this PR applied (unit test \scrub_nan_uses_bitwise_iuge_and_clamp_hdr_replaces_nan_with_zero\ passed) and the white single-pixel HDR sparkles indoors are gone.

**@⁠remie1529** on GitHub · 2026-11-29 14:56 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2432#issuecomment-7257690741) Tested on RTX 4070 (driver 616.92, Windows 11, Series X 2560x1440, DLSS Performance, DLSS FG 2x, release build on \829188e\). Built with this PR applied (unit test \scrub_nan_uses_bitwise_iuge_and_clamp_hdr_replaces_nan_with_zero\ passed) and the white single-pixel HDR sparkles indoors are gone.
Author
Owner

@⁠dyshay on GitHub · 2026-11-29 15:40 UTC · original

Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series X 1440p, and Series S with ray tracing, DLSS Quality). Frame times will follow here.

**@⁠dyshay** on GitHub · 2026-11-29 15:40 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2432#issuecomment-7258272369) Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series X 1440p, and Series S with ray tracing, DLSS Quality). Frame times will follow here.
Author
Owner

@⁠Robotniq on GitHub · 2026-11-29 21:56 UTC · original

Tested in-game: this fixes #2057 (red speckles on the police officers' dark uniforms in the opening). I bisected that issue to #534's clamp_hdr, which turns a NaN into +65024.

RTX 3070 Ti 8 GB, Windows 11, Series S profile, DLSS Quality, scripts/play-foxhound.ps1 (so VICTORY_NAN_SCRUB is off). Diagnostics build for the frame captures, with the build fix from #2974's first item. Same save and the same two shots (the officers by the car, then in the coffee shop):

  • f889bb07: speckles in both shots.
  • This PR merged into fbe3dc20: gone in both.
  • The clamp_hdr change alone (NaN to 0.0) on f889bb07: gone too.

If you add Fixes #2057 to the description, that issue closes when this is merged.

Measured with AI assistance (Claude Code); the runs were made on my machine.

**@⁠Robotniq** on GitHub · 2026-11-29 21:56 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2432#issuecomment-7263278207) Tested in-game: this fixes #2057 (red speckles on the police officers' dark uniforms in the opening). I bisected that issue to #534's `clamp_hdr`, which turns a NaN into +65024. RTX 3070 Ti 8 GB, Windows 11, Series S profile, DLSS Quality, `scripts/play-foxhound.ps1` (so `VICTORY_NAN_SCRUB` is off). Diagnostics build for the frame captures, with the build fix from #2974's first item. Same save and the same two shots (the officers by the car, then in the coffee shop): - f889bb07: speckles in both shots. - This PR merged into fbe3dc20: gone in both. - The `clamp_hdr` change alone (NaN to 0.0) on f889bb07: gone too. If you add `Fixes #2057` to the description, that issue closes when this is merged. Measured with AI assistance (Claude Code); the runs were made on my machine.
github-bot force-pushed github-bot/gh-2432 from 3e2f46c9ff to dd376781a7 2026-11-29 23:55:06 +00:00 Compare
Author
Owner

@⁠qlfu on GitHub · 2026-11-29 23:54 UTC · original

Rebased onto 41adb551 and updated the unit test per @⁠fainty0's review: eval_i32_cond now evaluates the emitted scrub_nan and clamp_hdr select conditions directly across signed zeros (±0.0), signed subnormals (±0x0000_0001, ±0x007F_FFFF), finite extremes (±f32::MAX), ±Inf, and signed sNaN/qNaN payloads (fails immediately if the 0x7FFF_FFFF sign mask is dropped). Also added Fixes #2057 per @⁠Robotniq's confirmation.

**@⁠qlfu** on GitHub · 2026-11-29 23:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2432#issuecomment-7264821065) Rebased onto `41adb551` and updated the unit test per @⁠fainty0's review: `eval_i32_cond` now evaluates the emitted `scrub_nan` and `clamp_hdr` select conditions directly across signed zeros (`±0.0`), signed subnormals (`±0x0000_0001`, `±0x007F_FFFF`), finite extremes (`±f32::MAX`), `±Inf`, and signed sNaN/qNaN payloads (fails immediately if the `0x7FFF_FFFF` sign mask is dropped). Also added `Fixes #2057` per @⁠Robotniq's confirmation.
Author
Owner

@⁠qlfu on GitHub · 2026-11-30 14:30 UTC · original · edited 2026-11-30 15:27 UTC

Updated scrub_nan_value and pixel colour export ordering based on live gameplay testing with VICTORY_NAN_SCRUB=1:

  • Previously, scrub_nan ran before clamp_hdr and mapped both NaN and ±Inf (IUGE 0x7F80_0000) to 0.0, turning bright HDR light highlights into black spots on lit surfaces.
  • scrub_nan_value now distinguishes NaN (IUGT 0x7F80_0000 -> 0.0) from ±Inf (EQ 0x7F80_0000 -> ±HDR_MAX preserving sign).
  • Pixel shader colour exports now call clamp_hdr directly (which clamps ±Inf/overflows to [-HDR_MAX, HDR_MAX], maps NaN to 0.0, and falls back to scrub_nan when VICTORY_HDR_CLAMP=0), eliminating the redundant pass.
  • Verified with victory-shader unit tests and clean merge-tree onto 41adb551.
**@⁠qlfu** on GitHub · 2026-11-30 14:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2432#issuecomment-7281483211) · edited 2026-11-30 15:27 UTC Updated `scrub_nan_value` and pixel colour export ordering based on live gameplay testing with `VICTORY_NAN_SCRUB=1`: - Previously, `scrub_nan` ran before `clamp_hdr` and mapped both `NaN` and `±Inf` (`IUGE 0x7F80_0000`) to `0.0`, turning bright HDR light highlights into black spots on lit surfaces. - `scrub_nan_value` now distinguishes `NaN` (`IUGT 0x7F80_0000` -> `0.0`) from `±Inf` (`EQ 0x7F80_0000` -> `±HDR_MAX` preserving sign). - Pixel shader colour exports now call `clamp_hdr` directly (which clamps `±Inf`/overflows to `[-HDR_MAX, HDR_MAX]`, maps `NaN` to `0.0`, and falls back to `scrub_nan` when `VICTORY_HDR_CLAMP=0`), eliminating the redundant pass. - Verified with `victory-shader` unit tests and clean `merge-tree` onto `41adb551`.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/bitcode.rs
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/lower/tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2432/head:github-bot/gh-2432'
git switch 'github-bot/gh-2432'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2432'
git switch 'github-bot/gh-2432'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2432'
git switch 'github-bot/gh-2432'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2432'
git switch 'main'
git merge --squash 'github-bot/gh-2432'
git switch 'main'
git merge --ff-only 'github-bot/gh-2432'
git switch 'main'
git merge 'github-bot/gh-2432'
git push origin 'main'
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/trustno1-coder--VIctory-NVIDIA!2432
No description provided.