Shaders: opt-in VICTORY_NAN_SCRUB to zero NaN/Inf pixel and float image outputs #3397

Open
github-bot wants to merge 1 commit from github-bot/gh-3397 into main AGit
Owner

@⁠danielibabet on GitHub · 2026-11-26 22:06 UTC · original
danielibabet:pr/nan-scrub → main · +54 −10 · 3 files · 1 commits · open

Summary

Adds an opt-in VICTORY_NAN_SCRUB=1 switch (off by default) to replace NaN and +/-infinity with 0.0 in pixel colour exports and textureStore.f32 UAV writes, plus includes it in the shader_cache build key.

Why

On NVIDIA GPUs, a single NaN or +/-inf written by a pixel or compute shader propagates through bloom, blur, and temporal upscaling passes as persistent black patches or blown-out white regions. Keeping it behind an opt-in switch preserves exact console behaviour by default while making it easy to test and isolate on PC.

Credits

Adapted from trustno1-coder/VIctory-NVIDIA (VICTORY_NAN_SCRUB=1).

Verification

  • cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1 (4/4 passed)
  • cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings (clean)
  • cargo xtask policy (191 files ok)
**@⁠danielibabet** on GitHub · 2026-11-26 22:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/3397) `danielibabet:pr/nan-scrub` → `main` · +54 −10 · 3 files · 1 commits · open ## Summary Adds an opt-in `VICTORY_NAN_SCRUB=1` switch (off by default) to replace `NaN` and `+/-infinity` with `0.0` in pixel colour exports and `textureStore.f32` UAV writes, plus includes it in the `shader_cache` build key. ### Why On NVIDIA GPUs, a single `NaN` or `+/-inf` written by a pixel or compute shader propagates through bloom, blur, and temporal upscaling passes as persistent black patches or blown-out white regions. Keeping it behind an opt-in switch preserves exact console behaviour by default while making it easy to test and isolate on PC. ### Credits Adapted from `trustno1-coder/VIctory-NVIDIA` (`VICTORY_NAN_SCRUB=1`). ### Verification - `cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1` (4/4 passed) - `cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings` (clean) - `cargo xtask policy` (191 files ok)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:06:36 +00:00
Author
Owner

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

LGTM — verified on RTX 5090 (Windows / D3D12) against origin/main (63bcca4).

  • Opt-in VICTORY_NAN_SCRUB is cleanly isolated behind the switch, tracked in the shader cache key, and leaves default lowering untouched.
  • cargo test -p victory-shader --lib emit::tests:: -- --test-threads=1: 17 passed, 0 failed.
  • cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1: 4 passed, 0 failed.
  • cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 22:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3397#pullrequestreview-6081133581) · **approved these changes** LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Opt-in `VICTORY_NAN_SCRUB` is cleanly isolated behind the switch, tracked in the shader cache key, and leaves default lowering untouched. - `cargo test -p victory-shader --lib emit::tests:: -- --test-threads=1`: 17 passed, 0 failed. - `cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1`: 4 passed, 0 failed. - `cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Jackster on GitHub · 2026-11-26 22:44 UTC · original

Windows 11, 63bcca4 + this PR, Radeon RX 7900 XTX:

  • Full cargo test -p victory-shader --lib --features host: 302 passed / 0 failed / 3 ignored (145 s) — the same counts as unpatched 63bcca4 here.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

No test is added: the switch gates emit (VICTORY_NAN_SCRUB), and the whole shader suite — including the VALU and semantics tests that run on the device — is unchanged by it when the switch is off. I did not exercise the switch itself (that needs title shaders that produce NaN/Inf outputs). Synthetic only. AI-assisted.

**@⁠Jackster** on GitHub · 2026-11-26 22:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/3397#issuecomment-7204940102) Windows 11, `63bcca4` + this PR, Radeon RX 7900 XTX: - Full `cargo test -p victory-shader --lib --features host`: **302 passed / 0 failed / 3 ignored** (145 s) — the same counts as unpatched `63bcca4` here. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. No test is added: the switch gates emit (`VICTORY_NAN_SCRUB`), and the whole shader suite — including the VALU and semantics tests that run on the device — is unchanged by it when the switch is off. I did not exercise the switch itself (that needs title shaders that produce NaN/Inf outputs). Synthetic only. AI-assisted.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 23:15 UTC · original · approved these changes

Reviewed 1a2e72cc merged onto main (63bcca43) — clean opt-in NaN/Inf scrubbing scoped strictly to float pixel color exports and float image stores, with shader-cache isolation.

Verification

  • cargo xtask policy: 191 files ok (crates/victory-shader/src/emit/lower.rs is 521,704 bytes, within the 512 KiB cap); cargo clippy --locked -p victory-shader -p victory-gpu --all-targets -- -D warnings (both default and --features diagnostics): 0 warnings.
  • Confirmed victory_shader::emit::nan_scrub() (emit/mod.rs:270) is off by default and hashed into shader_cache::key (shader_cache.rs:71, 79-85) with unit-test coverage.
  • Confirmed scrubbing applies only to image_store (lower.rs:8621-8623, which exclusively emits textureStore.f32) and float pixel color exports (el.comp == 9 && self.s.pixel && matches!(e.target, Target::Color(_)) at lower.rs:10090-10103), leaving integer targets, depth exports, and non-pixel stages untouched.
  • Live GPU/WARP + dxil.dll probe (VICTORY_NAN_SCRUB=1 and =0):
    • Tested both compute image_store (into an RGBA32F UAV) and pixel SV_Target float exports with [+qNaN, -qNaN, +sNaN, +Inf, -Inf] and finite values [0.5, -1.25, f32::MAX, f32::MIN, -0.0, 42.0] on both RTX 5090 and WARP:
      • With VICTORY_NAN_SCRUB=1: all NaN and ±Inf lanes scrubbed to 0x00000000 on both RTX 5090 and WARP (confirming neither driver folds FAbs + fcmp uge + select), while finite values passed through unchanged.
      • With VICTORY_NAN_SCRUB=0: original NaN/±Inf bit patterns preserved unchanged on both adapters.
      • An integer SV_Target (comp = 5) pixel shader produced identical DXIL size (2182 bytes) under both settings; all emitted shaders passed dxil.dll validation.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 23:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/3397#pullrequestreview-6081392687) · **approved these changes** Reviewed `1a2e72cc` merged onto `main` (`63bcca43`) — clean opt-in NaN/Inf scrubbing scoped strictly to float pixel color exports and float image stores, with shader-cache isolation. ### Verification - `cargo xtask policy`: 191 files ok (`crates/victory-shader/src/emit/lower.rs` is `521,704` bytes, within the 512 KiB cap); `cargo clippy --locked -p victory-shader -p victory-gpu --all-targets -- -D warnings` (both default and `--features diagnostics`): 0 warnings. - Confirmed `victory_shader::emit::nan_scrub()` (`emit/mod.rs:270`) is off by default and hashed into `shader_cache::key` (`shader_cache.rs:71, 79-85`) with unit-test coverage. - Confirmed scrubbing applies only to `image_store` (`lower.rs:8621-8623`, which exclusively emits `textureStore.f32`) and float pixel color exports (`el.comp == 9 && self.s.pixel && matches!(e.target, Target::Color(_))` at `lower.rs:10090-10103`), leaving integer targets, depth exports, and non-pixel stages untouched. - **Live GPU/WARP + `dxil.dll` probe (`VICTORY_NAN_SCRUB=1` and `=0`)**: - Tested both compute `image_store` (into an `RGBA32F` UAV) and pixel `SV_Target` float exports with `[+qNaN, -qNaN, +sNaN, +Inf, -Inf]` and finite values `[0.5, -1.25, f32::MAX, f32::MIN, -0.0, 42.0]` on both RTX 5090 and WARP: - With `VICTORY_NAN_SCRUB=1`: all NaN and ±Inf lanes scrubbed to `0x00000000` on both RTX 5090 and WARP (confirming neither driver folds `FAbs + fcmp uge + select`), while finite values passed through unchanged. - With `VICTORY_NAN_SCRUB=0`: original NaN/±Inf bit patterns preserved unchanged on both adapters. - An integer `SV_Target` (`comp = 5`) pixel shader produced identical DXIL size (`2182` bytes) under both settings; all emitted shaders passed `dxil.dll` validation. LGTM.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 23:48 UTC · original

I exercised the switch on exact 1a2e72c with the same synthetic image-store program bound first to a float UAV and then to an integer UAV. At VICTORY_NAN_SCRUB=0, both kept all eight values. At =1, the float output correctly zeroed its four nonfinite values, but the integer UAV also zeroed the four bit patterns that would be nonfinite if read as floats. This reproduced in two app-local WARP processes per setting.

Combined follow-up c15289e uses the view-kind metadata from adopted #3403 1ac4502. It scrubs texture UAV stores when the descriptor names a known float or normalized format. Integer and unknown-format stores retain their values. Three WARP processes per switch setting matched all 24 expected outputs, including signed zero and finite values. The affected shader suite passed 46/46 in both modes. GPU format and cache-key tests, strict Clippy in both configurations, and asset policy passed.

@⁠danielibabet, could you take the format guard before the next NVIDIA test? If you fold in the change or regression, please retain the Git author or use Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 23:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3397#issuecomment-7205872863) I exercised the switch on exact `1a2e72c` with the same synthetic image-store program bound first to a float UAV and then to an integer UAV. At `VICTORY_NAN_SCRUB=0`, both kept all eight values. At `=1`, the float output correctly zeroed its four nonfinite values, but the integer UAV also zeroed the four bit patterns that would be nonfinite if read as floats. This reproduced in two app-local WARP processes per setting. [Combined follow-up `c15289e`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/c15289eea3283bae6793ebf66af2dddc4345b64f) uses the view-kind metadata from adopted #3403 `1ac4502`. It scrubs texture UAV stores when the descriptor names a known float or normalized format. Integer and unknown-format stores retain their values. Three WARP processes per switch setting matched all 24 expected outputs, including signed zero and finite values. The affected shader suite passed 46/46 in both modes. GPU format and cache-key tests, strict Clippy in both configurations, and asset policy passed. @⁠danielibabet, could you take the format guard before the next NVIDIA test? If you fold in the change or regression, please retain the Git author or use `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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