shader: use bitwise IUGE in scrub_nan and zero NaN in clamp_hdr #2432
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!2432
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2432"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 · openWhat 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 inLower::scrub_nan(VICTORY_NAN_SCRUB=1): Replaces FPfcmp uge(fabs(f), +inf)with integer(as_int(f) & 0x7FFF_FFFF) >= 0x7F80_0000(pred::IUGE), matchingis_nan_f32directly below it so NVIDIA fast-math cannot fold away NaN detection while still catching bothNaNand+/-Inf. 2. Zero NaN inLower::clamp_hdr(VICTORY_HDR_CLAMP): Changes the NaN branch frommax(+65024.0) to0.0so a NaN channel in a pixel shader colour export does not turn into a blazing+65024.0neon HDR flash whenVICTORY_NAN_SCRUBis 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 testemit::lower::tests::scrub_nan_uses_bitwise_iuge_and_clamp_hdr_replaces_nan_with_zerochecks emitted bitcode predicates (pred::IUGE, nopred::UGE) andselectoperands (0.0instead of65024.0). -cargo testpassed 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 forscrub_nan,clamp_hdr,HDR_CLAMP, andNAN_SCRUB; no overlapping open PR found.Fixes #2057
@Dukestar69 on GitHub · 2026-11-29 13:05 UTC · original · approved these changes
Tested locally merged onto
main(829188e9).bitcode.rs,lower.rs, andlower/tests.rs.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 newscrub_nan_uses_bitwise_iuge_and_clamp_hdr_replaces_nan_with_zerotest).Clean bitwise
IUGENaN/Inf scrubbing and NaN-safe HDR clamping. LGTM.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@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
>=inscrub_nanscrubs infinities and NaNs; the>inclamp_hdrzeroes 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:1184passes 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.
@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.@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.@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(soVICTORY_NAN_SCRUBis 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.fbe3dc20: gone in both.clamp_hdrchange alone (NaN to 0.0) onf889bb07: gone too.If you add
Fixes #2057to the description, that issue closes when this is merged.Measured with AI assistance (Claude Code); the runs were made on my machine.
3e2f46c9fftodd376781a7@qlfu on GitHub · 2026-11-29 23:54 UTC · original
Rebased onto
41adb551and updated the unit test per @fainty0's review:eval_i32_condnow evaluates the emittedscrub_nanandclamp_hdrselect 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 the0x7FFF_FFFFsign mask is dropped). Also addedFixes #2057per @Robotniq's confirmation.@qlfu on GitHub · 2026-11-30 14:30 UTC · original · edited 2026-11-30 15:27 UTC
Updated
scrub_nan_valueand pixel colour export ordering based on live gameplay testing withVICTORY_NAN_SCRUB=1:scrub_nanran beforeclamp_hdrand mapped bothNaNand±Inf(IUGE 0x7F80_0000) to0.0, turning bright HDR light highlights into black spots on lit surfaces.scrub_nan_valuenow distinguishesNaN(IUGT 0x7F80_0000->0.0) from±Inf(EQ 0x7F80_0000->±HDR_MAXpreserving sign).clamp_hdrdirectly (which clamps±Inf/overflows to[-HDR_MAX, HDR_MAX], mapsNaNto0.0, and falls back toscrub_nanwhenVICTORY_HDR_CLAMP=0), eliminating the redundant pass.victory-shaderunit tests and cleanmerge-treeonto41adb551.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.Merge
Merge the changes and update on Forgejo.