Skip to content

D3D12.X: XCL_PIXEL_HISTORY (which draw writes a pixel) and XCL_SKIP_PS (leave out draws by pixel shader) - #3509

Open
CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:pr/pixel-history
Open

CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:pr/pixel-history

Conversation

@CharlyRien

@CharlyRien CharlyRien commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Two diagnostic switches to find which draw writes a wrong pixel. PIX and Nsight frame captures do not replay a title running under XCL, so we could not use their pixel history. These switches do the same job inside the process. Both are off by default. Unset, each one costs a draw one cached check.

What is in it

  • XCL_PIXEL_HISTORY=<x>,<y>[,<s>[,<frames>]] (d3d12x/pixel_history.rs, new).
    • It starts at the first present s seconds (default 0) or more after the first one, and follows frames frames (default 1, at most 8).
    • Around each draw on a direct list (direct and indirect draws), it copies one texel before and after the draw into a readback buffer: the texel at pixel x, y of the presented picture in each bound render target that has the picture's shape. Each copy is a 1×1 CopyTextureRegion between a RENDER_TARGET → COPY_SOURCE transition and its way back.
    • The point is mapped by each target's own size (its RTV's mip), so half- and quarter-size targets are followed too. A target counts as having the picture's shape when its aspect ratio is within 1 % and it is at least an eighth of the picture's width.
    • Six presents later, the values are read back and logged (see below).
    • Related switches:
      • XCL_PIXEL_HISTORY_SPACE=<w>x<h>: the size of the picture that x, y are given in (default 3840x2160).
      • XCL_PIXEL_HISTORY_ALSO=<x>,<y>[;<x>,<y>]: up to 3 more points.
      • XCL_PIXEL_HISTORY_CROP=<w>,<h>[,<n>]: a second round of as many frames. In it, only the draws whose pipeline changed a point in the first round also copy a w×h crop around the point after themselves. The crops of the draws that change the point are written as BMPs (pixel-history/<frame>_<event>_<ps>_p<point>rt<slot>.bmp next to xcl.log, at most n a frame, default 200).
      • XCL_PIXEL_HISTORY_SLOTS: the readback slots of a round (default 131072 slots of 512 bytes).
  • XCL_SKIP_PS=<hash>,<hash>: leaves out the draws (direct and indirect) whose console pixel shader has one of these hashes, the way XCL_SKIP_CS leaves out dispatches, and counts them in the log. Use it to confirm that the draw the history found is the one at fault.
  • Hooks: bind.rs (draw, indexed draw, ExecuteIndirect, dispatch), real.rs (RTV mip / slice, the pipeline's blend state, console VS / PS hashes kept while either switch is set), present.rs (one call at each present).
  • A README paragraph in the diagnostics list.

Reading the output (grep -a "pixel history" xcl.log)

  • XCL_PIXEL_HISTORY: points [...] of a WxH present, N frames from S s after the first present, ...: the settings, read once.
  • pixel history r1: point 0 (x, y) -> target 0x… sub S WxH format F at (tx, ty): once per target. It shows where the point landed in that target.
  • pixel history r1: f<frame> ev <seq> list 0x… #<i> [indirect ]draw vs <hash> ps <hash> pso 0x… p<k> rt<n> WxH fmt F at (tx, ty): (before) [raw] -> (after) [raw]; <blend state of that slot>: one line per draw that changed the texel. The values are decoded (RGBA8 / BGRA8, RGBA16 float, R11G11B10, R10G10B10A2, R32 float), with the raw bytes in brackets. Read the lines in (frame, list, #i) order. The last change before the present, on the scene's target, tells which draw wrote the final value, and the blend state tells how.
  • pixel history r1: f… list 0x… p<k> rt<n> …: changed BETWEEN draws #a (ev …) and #b (ev …): … -> …; dispatches between: #i cs <hash>, …: the texel changed between two draws of one list. This means a compute pass (named by its cs), a clear, a copy or a resolve wrote it.
  • pixel history r1 done: … events (… draws), … slots used; … changes by draws, … between draws, … copies not done (list not run yet); targets not followed: … by shape, … by format, … multisampled, … other; … slots full, … crops full; … crops written: the round's summary. "Copies not done" are copies whose list had not run by the readout (their slots still hold a 0xA5 sentinel). They are counted, not read.
  • With _CROP, an r2 round follows with the same lines, and its crops are written.

Measured use. On the retail title, a pose in front of a window where one diagonal half of the glass turns black. One run with two points (one on the dark half, one control) and one frame per round, plus 64×64 crops. The history named the depth-of-field composite, an indirect draw blending SRC_ALPHA / INV_SRC_ALPHA, as the draw that set the texel to RGB 0. It also showed the DoF downsample writing RGB 0 at every watched point. XCL_SKIP_PS on the composite's pixel shader then gave a clean window. That led to #3281's case: a R9G9B9E5 view placed over an R32_UINT texture. Report: #3281 (comment). That run used an earlier form of this tool, in which the start could also be counted from a busy-draws heuristic. This PR keeps only seconds after the first present, which does not depend on the title.

Numbers from that run (RTX 3090):

  • Round 1: 5635 events (664 draws on direct lists, the rest dispatches) and 1720 slots used. It logged 19 changes by draws and 1 between draws, with 0 copies not done. Targets not followed: 28 by shape, 305 by format.
  • Round 2: 1600 crops of 32 KiB were allocated and 15 were written.
  • The log line of each round came about 7 s after its first frame. At that pose the title ran at about one present a second, and the 2 s activity lines kept 1–2 presents through both rounds. One 2 s window at the start of round 1 had about half the usual draws (4790 against about 9000), which did not happen around round 2. We did not look further into it.

Cost

  • Off (the default): a draw's hook loads one atomic for the history and makes one cached check for XCL_SKIP_PS; a dispatch's hook loads the same atomic. The hooks at pipeline creation, RTV creation and present check cached values only. Nothing is allocated. A test checks that the hooks do not even look at the command list when the switch is unset.
  • On, outside the followed frames: the same per draw, plus one map entry per translated graphics pipeline (its blend state and shader hashes) and per RTV (its mip and slice).
  • On, in the followed frames: each draw on a direct list records, before itself and again after, one barrier batch to COPY_SOURCE, one 1×1 copy per followed target and point, and one barrier batch back. Round 2 adds one crop copy per point for the draws of the pipelines that matter. Recording also takes a few locks per draw (the round's session and the maps).
  • Memory: 64 MiB of readback memory a round with the default slots, plus at most 256 MiB for the crops. These buffers are kept until the process ends, because a list recorded in a round may still run after the readout.

Tested

  • Hardware: RTX 3090 (driver 616.56), Ryzen 9 5950X, Windows 11, rustc 1.100.0, release build, on main d52ff48 + this commit (8952390).
  • cargo test --release -p xcl --lib -- pixel_history:: skip_ps_tests::: 6 passed, 0 failed, 0 ignored. The 6 tests are:
    • pixel_history_settings_parse: the switches' parsing, including rejected values.
    • unset_pixel_history_changes_nothing: unset, no round, no session, no map, and a draw's hooks do not touch the list (a dangling pointer in the test).
    • points_map_by_each_targets_own_size: mapping a point to full, half, quarter and 2560x1440 targets; other shapes refused; crop placement at the edges.
    • followed_formats_decode_and_others_fail_closed.
    • skip_ps_hashes_parse_and_unset_skips_nothing.
    • gpu_a_targets_texel_is_read_before_and_after_a_draw: on the default adapter, else WARP. A texel copied before and after a "draw" (a clear) between the same barriers reads back as both values; an unreached slot still holds the sentinel; a crop around the point holds the new value and turns into a BMP.
  • In game: the run described above, on the same tool, rebased here onto main without other changes than the start time, the doc comments and the log text.
  • Read, CI: "Build and test (Windows, no GPU)" passed on this head.

Regression run
Same machine as under Tested, same title, 60 s each (the scripts/smoke.ps1 default), both through main d52ff48's scripts/smoke.ps1, XCL_PREPARE=0, the same scripted A presses (XCL_PRESS_A_AT), XCL_PIXEL_HISTORY and XCL_SKIP_PS unset. Each run started from its own copy of the same shader cache, made by another main commit, so cold for both.

main d52ff48:

xcl-smoke v1
commit: d52ff48caade1f5350d513bfffd370396dadfeb6
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 517 (PresentX 517)
presents per 2 s (last 3): 61 60 61
device removals: 0
crashes: 0
peak commit: 15968 MB

this head 8952390 (main d52ff48 + this commit):

xcl-smoke v1
commit: 895239041462ab51c15be990cbd63dd0838e5dac
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 554 (PresentX 554)
presents per 2 s (last 3): 61 61 60
device removals: 0
crashes: 0
peak commit: 16424 MB
  • Measured: no device removal and no crash in either run, both ended by themselves (exit 0x0). The head shows 554 frames against main's 517 (107.2 %; the check wants at least 80 %), peak commit 16,424 MB against 15,968 MB (102.9 %; at most 125 %). Last three 2 s slices: head 61 61 60, main 61 60 61 presents. 60 s covers the start of the title, not a long stay in its world.

Not tested

  • A title run of this exact head with the switches set: the in-game run above used the earlier form of the tool on our lab tree.
  • AMD and Intel GPUs, other NVIDIA generations, and other titles.
  • What the tool leaves out, by design (so nothing was tested there):
    • Multisampled render targets and depth buffers are not followed; they are counted in the summary. A copy out of a depth buffer must take its whole subresource, which is too costly per draw.
    • Formats other than the ones listed above are not followed either.
    • UAV writes (compute, or pixel shaders writing UAVs) show up only as a BETWEEN line. Copying around a dispatch would need the target's state, which is not known there.
    • Mesh-shader draws (DispatchMesh) and draws on bundles are not followed, and XCL_SKIP_PS does not apply to them.
    • Frames are counted at PresentX on the recording side, so lists recorded before the round's first present are not followed. In the run above, the round saw 664 draws of the roughly 4500 per frame that the activity lines count. We did not check which of these causes accounts for the rest.
    • Points are mapped by each target's size. A target drawn at a dynamic resolution (a viewport smaller than the target) would be mapped wrongly.
    • The order of events is the recording order within a list. Across lists, the log does not give the GPU's execution order.
    • The extra barriers per draw can hide a race. A defect that goes away while the history runs is a finding in itself.

AI use
AI use: the tool, its tests, the in-game run, the smoke runs and this description were done with Claude Code (Claude Opus 5.5), checked and posted by me.

🤖 Generated with Claude Code

…S (draws of named console pixel shaders left out)

PIX and Nsight captures do not replay a title under XCL. XCL_PIXEL_HISTORY=<x>,<y>[,<s>[,<frames>]]
(+ _ALSO, _SPACE, _CROP, _SLOTS): in the frames chosen, each draw on a direct list copies the texel at
the point of each bound render target before and after itself (1x1 CopyTextureRegion between
RENDER_TARGET <-> COPY_SOURCE transitions) into a readback buffer; a few presents later the changes are
logged with the draw's console VS / PS, the target, the values decoded and the slot's blend state, and
changes between two draws of a list with the dispatches in between. With _CROP a second round writes
crops of the draws that changed the point.

XCL_SKIP_PS=<hash>,...: draws (direct and indirect) whose translated pipeline's console PS is listed
are skipped as XCL_SKIP_CS skips dispatches, counted in the log.

Unset, each costs a draw one cached check. Documented in the README's diagnostics.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 30, 2026
@CharlyRien
CharlyRien marked this pull request as ready for review November 30, 2026 09:29
@Aniseto

Aniseto commented Nov 30, 2026

Copy link
Copy Markdown

Ran the pixel-history and pixel-shader skip tests at 89523904 on an NVIDIA Blackwell desktop part.

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2140 (621.40)
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5
  • Build: debug

Results

  • XCL_ADAPTER=NVIDIA cargo test -p xcl --lib pixel_history:: -- --test-threads=1: 5 passed, 0 failed, 0 ignored.
  • XCL_ADAPTER=NVIDIA cargo test -p xcl --lib skip_ps_tests:: -- --test-threads=1: 1 passed, 0 failed, 0 ignored.

What this adds
All six tests pass, including the check that with the switches unset a draw's hooks do not even look at the command list. The author ran the same six in release; this adds a debug run on driver 32.0.16.2140 from a second NVIDIA card. No title A/B with XCL_PIXEL_HISTORY or XCL_SKIP_PS was made here.

Not tested
A retail title with the switches set, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 7d86c5d
head: 8952390
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2902 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (new pixel_history.rs +914, real.rs +54, bind.rs +18, README, present.rs, mod.rs). Findings: (1) two independent diagnostics in one 1,006-line PR with no reason given for going past 800; XCL_SKIP_PS (~70 lines in real.rs / bind.rs) splits off cleanly, and the _CROP round could follow. (2) Cost when off: bind.rs ~4183 evaluates with(this, |s| s.pso) (a lock plus a state lookup) on every indexed draw before pixel_history::before checks ROUND, so "unset, a draw's hooks load one atomic" doesn't hold on that path; unset_pixel_history_changes_nothing calls before() directly and misses it. Checking ROUND first, or reusing the PSO already read for gpu_profile, would fix it. (3) With XCL_PIXEL_HISTORY_ALSO, bound_targets pushes one Target per point with the same resource and subresource and copy_texels (~410 / ~431) puts them all in one ResourceBarrier call, transitioning the same subresource RENDER_TARGET -> COPY_SOURCE more than once, which the debug layer rejects; deduplicate by (resource, subresource). (4) real.rs ~8268 records shader hashes only when XCL_TRACE_FRAME is unset, so XCL_SKIP_PS silently does nothing while it's set. Readout is timed (6 presents) with no fence, acceptable for a diagnostic given the sentinel. Fine: off by default, parsing and limits, 512 / 256-aligned slot offsets and row pitch, readback buffers kept until the process ends, per-mip point mapping, the GPU test uses skip_test, and "Not tested" is honest that the in-game run used an earlier form.
performance: 60 s smoke of a retail title, main 7d86c5d vs this merge (4b1b9daa): 1663 -> 1669 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17153 -> 17723 MB, 0 device removals, 0 crashes.
verdict: not yet: 1,006 lines with two separate diagnostics and no reason given for passing 800 (split off XCL_SKIP_PS); and the off path still takes a lock per indexed draw (finding 2). Findings 3 and 4 are bugs in the opt-in paths
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 8952390

Only XCL_SKIP_PS overlaps #1827 (XCL_DEBUG_SKIP_SHADERS); both leave out draws by the console shader hash from real::pso_shaders. #1827 matches VS or PS but fills those hashes only with XCL_TRACE_FRAME or the profilers. Here pixel_history::keeps_shaders fills them whenever XCL_SKIP_PS is set. The pixel-history tool itself has no counterpart.
Default cost checked: unset, before / after load one atomic and the creation hooks return on on(). No problems found in the diff.
At about 1000 lines, the description should say why it cannot be split (for example, XCL_SKIP_PS on its own).
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

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 area:docs-ci Documentation, scripts, workflows, repo governance 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.

3 participants