Skip to content

Preserve NaN in HDR diagnostic captures - #2052

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
DoubleD17:fix/hdr-capture-nan
Nov 25, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
DoubleD17:fix/hdr-capture-nan

Conversation

@DoubleD17

Copy link
Copy Markdown
Contributor

Preserve NaN when decoding HDR capture channels with exponent 31 and a nonzero mantissa. The existing conversion maps NaN to zero and positive infinity to 255 in the RGBA buffer.

Synthetic CPU tests on Windows 11 x64 with Rust 1.98.1 MSVC passed two of five cases on the base with the same fixture and five of five on candidate 86ac6c7. They cover both affected formats through RGBA conversion. The fixture stops at the RGBA buffer and does not exercise PNG output or GPU execution.

AI-assisted.

@Dathinel

Copy link
Copy Markdown
Contributor

I checked the saved PNGs at 86ac6c76 against 940d32f6. In each revision I compiled the conversion and PNG-writing functions from capture.rs in a standalone CPU harness. The input was two padded rows of ten texels, with each value repeated twice so it survives the writer's downsampling.

For R16G16B16A16_FLOAT, R11G11B10_FLOAT and R16_FLOAT, a positive NaN changed from white to black. For R16G16_FLOAT it changed from yellow to black (the missing blue channel is zero). The four controls (+infinity, 0.5, zero and one) kept their original RGB bytes. I checked the PNG header, chunk CRCs and decompressed scanline.

I also compared every input to both float helpers against Python's binary16 decoder, left-aligning the 5- and 6-bit mantissas for the unsigned formats. Base had 2,046 mismatches out of 65,536 half encodings, 31/1,024 for the 5-bit mantissa and 63/2,048 for the 6-bit mantissa. The PR had zero in all three sets. NaNs were compared by classification; all other outputs were compared as f32 bits.

AI-assisted. These checks cover the CPU capture path through PNG output; GPU readback was outside the test.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

NaN preserved in HDR diagnostic captures — diagnostic-path correctness; pairs with #1994's denormal handling theme.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --features diagnostics --lib capture:: — passed (including half_classifies_special_and_finite_values, packed_float_classifies_special_and_finite_values, and hdr_targets_render_nan_and_infinity_as_distinct_channel_values)
  • cargo clippy -p victory-gpu --features diagnostics --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean classification and distinct rendering of NaN and infinity values in HDR diagnostic captures. Looks good.

AI-assisted (Gemini 4 Neon).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.
Merge candidate.

This fixes a decoding bug in the diagnostic texture dumper. In crates/victory-gpu/src/capture.rs, half and small_float decoded every exponent-31 value as infinity. In colour dumps, to_rgba then shows a NaN as full white, the same as +Inf. The PR returns NaN when the exponent is 31 and the mantissa is nonzero, which follows the IEEE binary16 encoding and the R11G11B10 float encoding. In to_rgba, a NaN then scales to 0 (NaN as u8) and is already left out of the low/high/percentile statistics and counted in not_finite.

I worked through the new tests by hand: the bit patterns and expected bytes (including 0.5 → 127 at the p99 scale of 1.0) are right, and they check against the encoding rather than against what the code happens to output. The change only affects debug captures and does not change emulation behaviour. No other open PR changes these helpers.

CI: passing (check).

Recommending a look, not approving.


Generated by Claude Code

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@Marvisak
Marvisak merged commit 5cc48e9 into Marvisak:main Nov 25, 2026
1 check passed
notquiteog pushed a commit to notquiteog/VIctory that referenced this pull request Nov 26, 2026
(cherry picked from commit 5cc48e9)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants