Skip to content

D3D12.X: a target dump says what its float targets hold (NaN, infinity, range, mean) - #3572

Open
imnicho wants to merge 2 commits into
xcl-dev:mainfrom
imnicho:dump-float-census
Open

imnicho wants to merge 2 commits into
xcl-dev:mainfrom
imnicho:dump-float-census

Conversation

@imnicho

@imnicho imnicho commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

A target dump (XCL_DUMP_TARGETS) now says what each float target it reads back holds: how many texels have a NaN or an infinity, the range and the mean of the finite ones, and the first texels. The pictures clamp, so a white one may hold 1.5 or 40,000. Nothing changes unless a target dump is asked for.

What is in it

A target dump writes a picture of each target and counts the texels that are not zero. For a picture that is black or white that is not enough to tell a NaN from a level that is merely too high or too low, and the passes that matter most for that (exposure, bloom) end in targets of a few texels.

  • targets.rs, float_census: for R32G32B32A32_FLOAT, R16G16B16A16_FLOAT, R32G32_FLOAT, R16G16_FLOAT, R32_FLOAT, R16_FLOAT and R11G11B10_FLOAT targets, the texels with a NaN in a channel, those with an infinity, the least and the largest finite channel, each channel's mean over its finite values (n/a for a channel that has none) and the first four texels as they are. A target of 4096 texels or fewer is read whole (a 1x1 or 7x4 target is the point); a larger one every 4th texel of every 4th row, as the existing count samples.
  • half, small_float, float_texel: the decoders (16-bit floats; the 11- and 10-bit unsigned floats of R11G11B10).
  • log_census logs the line after the existing one, for a float target only:
D3D12.X: target dump: target28_2897: float texels: 0 with a NaN and 0 with an infinity of 1 read; finite channels from -5.5e0 to 2.2097085e-2, mean [2.2097e-2, -5.5000e0, -5.5000e0, 0.0000e0]; first [[0.022097085, -5.5, -5.5, 0.0]]

Size: 1 file, 91 lines of code and 65 of tests (comments and blank lines not counted), in two commits: the second is the review's finding (a channel with no finite value was given a mean of 0).

Tested

  • cargo test -p xcl --lib -- --test-threads=1 d3d12x::targets::tests: 15 passed, 0 failed, no SKIPPED line. New: half_and_packed_floats_decode, a_float_targets_census_counts_nan_and_infinity_and_keeps_the_finite_range, a_channel_with_no_finite_value_has_no_mean, a_large_float_target_is_sampled_as_the_dumps_are.
  • What it was written for, on another tree: a retail title on this PC (RTX 5080) whose picture turns white and stays white. One dump of a white frame gave 29 float targets with no NaN and no infinity in any, a 1x1 exposure target that was plausible (the values in the line above are that dump's), and a 1280x720 scene target with a mean of about 100 and a largest value of 20,512: the white was light, not a NaN, and not the exposure. That took one run. That build was the draft Merge amd-dev into main #3547's branch (afeb3e551) with an earlier form of this change (the same counts, another wording of the line, a mean of 0 where a channel had no finite value) and D3D12.X: XCL_DUMP_WAIT_MS sets how long a dumped frame's present waits for the dump's copies #3571's, not this head.

Regression run

scripts/smoke.ps1, 60 s, XCL_PREPARE=0, each built in release from a clean worktree, the crate's outputs cleaned first. No target dump is asked for in these runs.

main (b2b1f109d):

xcl-smoke v1
commit: b2b1f109d27e746a62ec95b04dd1f9924452e682
gpu: NVIDIA GeForce RTX 5080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1479 (PresentX 1479)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 12698 MB

This PR (7a19282e6), its second run (the first run of a new binary fills its caches and is not kept, as for main):

xcl-smoke v1
commit: 7a19282e6c9dd13efe6f786ba1a082617a73c293
gpu: NVIDIA GeForce RTX 5080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1561 (PresentX 1561)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 12605 MB

Not tested

AI use

Claude Code with Claude Fable 5.2 wrote the code and the tests, ran the tests and the regression runs, and wrote this description.

🤖 Generated with Claude Code

A target dump (XCL_DUMP_TARGETS) writes a picture of each target and counts
the texels that are not zero. The pictures clamp: one that reads white may hold
1.5 or 40 000, and a NaN that a later pass spreads over the frame shows in no
picture. For each float target read back the dump now also logs how many texels
hold a NaN or an infinity, the least and the largest finite channel, each
channel's mean over its finite values and the first four texels. A target of
4096 texels or fewer (a 1x1 exposure target, the small end of a bloom chain) is
read whole, a larger one as the existing count samples it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026

@gut0to gut0to 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.

AI-assisted review: I used an AI assistant to inspect this diff and checked the finding against the implementation and existing tests.

Comment thread crates/xcl/src/hle/d3d12x/targets.rs Outdated
}
}
for (i, m) in out.mean.iter_mut().enumerate() {
*m = sum[i] / finite[i].max(1) as f64;

@gut0to gut0to Dec 1, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When one channel has no finite samples but another does, finite[i].max(1) reports the empty channel's mean as 0.0, and the log presents it as a measured value. For example, an R32G32_FLOAT texel (1.0, NaN) is reported with means [1.0, 0.0], even though the second channel has no finite samples. Could we preserve per-channel sample counts and print n/a for empty channels, with a mixed finite/non-finite-channel test? AI-assisted review: I used an AI assistant to inspect this code and checked the finding against the implementation and existing tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@gut0to thank you, that is right: a channel with no finite value was divided by 1 and logged with a mean of 0, which reads as a measurement.

Fixed in 7a19282e6: Floats::mean is Vec<Option<f64>>, a channel without a finite value has none, and the line prints n/a for it. Your case is the new test, a_channel_with_no_finite_value_has_no_mean: two R32G32_FLOAT texels (1, NaN) and (3, +inf) give mean [2.0000e0, n/a], a range of 1 to 3, one texel with a NaN and one with an infinity.

I kept one count per channel inside the function and did not add the counts to the line: n/a says what the count would, and the line is long already. Say if you would rather see them.

cargo test -p xcl --lib -- --test-threads=1 d3d12x::targets::tests: 15 passed. The description has the new head's regression run.

🤖 Generated with Claude Code

… the dump's line

The census divided a channel's sum by its count of finite values or by 1,
so a channel that had none was logged with a mean of 0. Such a channel
has no mean now and the line says n/a for it (review of xcl-dev#3572).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Review (head 7a19282, diff read, not a merge-check):

  • Duplicate float decoders. half and small_float (targets.rs ~769-789) re-implement present::half_float and present::small_float (present.rs ~1851, ~1918), which are already pub(super) and imported by lut3d.rs ~249 for the same job. That leaves two decoders per format to keep in step, and the new tests check the copy rather than the helpers the picture and the LUT dump use.
  • Typeless float targets get no line. float_texel (~791-806) takes only typed *_FLOAT formats, while the picture of the same target decodes R16G16B16A16_TYPELESS, R32G32B32A32_TYPELESS, R16G16_TYPELESS and R16_TYPELESS as float (present.rs ~1827-1836), and the footprint format comes from the resource desc (~1769). A target created typeless gets a tone-mapped picture but no NaN / infinity / range line.

Fine: only runs with XCL_DUMP_TARGETS; float_census runs before Unmap and stays in bounds through data.get like census; the half and 11/10-bit decodes handle subnormals, infinity and NaN; a channel with no finite value prints n/a; the unit tests cover NaN, infinity, sampling and the no-finite case.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants