D3D12.X: XCL_PIXEL_HISTORY (which draw writes a pixel) and XCL_SKIP_PS (leave out draws by pixel shader) #3509
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3509"
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?
Imported from ivall/xcl. Originally posted by CharlyRien on 2026-11-30T06:11:50Z.
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).sseconds (default 0) or more after the first one, and followsframesframes (default 1, at most 8).x,yof the presented picture in each bound render target that has the picture's shape. Each copy is a 1×1CopyTextureRegionbetween a RENDER_TARGET → COPY_SOURCE transition and its way back.XCL_PIXEL_HISTORY_SPACE=<w>x<h>: the size of the picture thatx,yare 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 aw×hcrop 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>.bmpnext toxcl.log, at mostna 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 wayXCL_SKIP_CSleaves out dispatches, and counts them in the log. Use it to confirm that the draw the history found is the one at fault.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).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 itscs), 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._CROP, anr2round 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_PSon 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: https://github.com/xcl-dev/xcl/pull/3281#issuecomment-7269873202. 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):
Cost
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.Tested
maind52ff48c+ this commit (89523904).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.mainwithout other changes than the start time, the doc comments and the log text.Regression run
Same machine as under Tested, same title, 60 s each (the
scripts/smoke.ps1default), both throughmaind52ff48'sscripts/smoke.ps1,XCL_PREPARE=0, the same scripted A presses (XCL_PRESS_A_AT),XCL_PIXEL_HISTORYandXCL_SKIP_PSunset. Each run started from its own copy of the same shader cache, made by anothermaincommit, so cold for both.maind52ff48:this head
8952390(maind52ff48+ this commit):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,main61 60 61 presents. 60 s covers the start of the title, not a long stay in its world.Not tested
DispatchMesh) and draws on bundles are not followed, andXCL_SKIP_PSdoes not apply to them.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
Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-30T12:05:57Z.
Ran the pixel-history and pixel-shader skip tests at
89523904on an NVIDIA Blackwell desktop part.System
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_HISTORYorXCL_SKIP_PSwas 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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:54:51Z.
merge-check
base:
7d86c5d2b7head:
8952390414merge: 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 inreal.rs/bind.rs) splits off cleanly, and the_CROPround could follow. (2) Cost when off:bind.rs~4183 evaluateswith(this, |s| s.pso)(a lock plus a state lookup) on every indexed draw beforepixel_history::beforechecksROUND, so "unset, a draw's hooks load one atomic" doesn't hold on that path;unset_pixel_history_changes_nothingcallsbefore()directly and misses it. CheckingROUNDfirst, or reusing the PSO already read forgpu_profile, would fix it. (3) WithXCL_PIXEL_HISTORY_ALSO,bound_targetspushes oneTargetper point with the same resource and subresource andcopy_texels(~410 / ~431) puts them all in oneResourceBarriercall, 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 whenXCL_TRACE_FRAMEis unset, soXCL_SKIP_PSsilently 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 usesskip_test, and "Not tested" is honest that the in-game run used an earlier form.performance: 60 s smoke of a retail title, main
7d86c5d2vs 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 pathshardware / 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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:06:00Z.
Triage (#1607) – head
8952390Only
XCL_SKIP_PSoverlaps #1827 (XCL_DEBUG_SKIP_SHADERS); both leave out draws by the console shader hash fromreal::pso_shaders. #1827 matches VS or PS but fills those hashes only withXCL_TRACE_FRAMEor the profilers. Herepixel_history::keeps_shadersfills them wheneverXCL_SKIP_PSis set. The pixel-history tool itself has no counterpart.Default cost checked: unset,
before/afterload one atomic and the creation hooks return onon(). No problems found in the diff.At about 1000 lines, the description should say why it cannot be split (for example,
XCL_SKIP_PSon 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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T09:44:51Z.
Code review location:
crates/xcl/src/hle/d3d12x/pixel_history.rs; line 410copy_texelsissues one RENDER_TARGET->COPY_SOURCE (and back) transition per Target, andbound_targetsmakes one Target per point for the same (resource, subresource). So with two or more points, one ResourceBarrier batch transitions the same subresource twice, and the second StateBefore is already wrong. With XCL_PIXEL_HISTORY=1900,700 and XCL_PIXEL_HISTORY_ALSO=2000,500 (the two-point setup used in game), each followed target gets [RT->CS, RT->CS] then [CS->RT, CS->RT]. That's a debug-layer error, and on stricter drivers corrupted state or device removal, while trying to diagnose a rendering bug. The GPU test also passes the samettwice (texel plus crop). Deduplicating barriers by (res, sub) would fix it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T09:44:51Z.
Code review location:
crates/xcl/src/hle/d3d12x/pixel_history.rs; line 641When Map fails in
read_out, onlys.rbgoes to RETIRED and the round-2 crop buffer (s.crops) is dropped. The session-replacement path inbefore()(~495) also retires onlyold.rb. That breaks the rule that buffers are kept because a list recorded in the round may still run. With XCL_PIXEL_HISTORY_CROP set, if Map fails or a stale session is replaced, the crop ID3D12Resource is released while recorded or re-executed lists still CopyTextureRegion into it, so the GPU writes into a freed resource (device removal or memory corruption).Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T09:44:51Z.
Code review location:
crates/xcl/src/hle/d3d12x/bind.rs; line 4268The new XCL_SKIP_PS early return in
graphics_boundskips the draw without callinglist_x::note_dropped_draw(this), unlike the other skip paths in the same function (pipeline unresolved, bind_abi_resolved Err). If the named PS's draws sit inside an occlusion query (common for world geometry), the query resolves as 0 samples, the title occlusion-culls objects, and new artifacts appear. That defeats the switch's purpose of confirming a skipped draw is the culprit.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T09:44:51Z.
Review: COMMENTED
Review of
89523904: 4 finding(s). 3 are inline. These are on lines outside the diff:crates/xcl/src/hle/d3d12x/real.rs:10035: PSO_SHADERS gained|| pixel_history::keeps_shaders()only intranslated_graphics_pso_once. The two-pass GS path (here) and the MS path (~9956) still record hashes only when gpu_times is on, and neither callsnote_pipeline. With XCL_SKIP_PS=, if that PS also appears in a geometry-shader (two-pass) pipeline,pso_shaders(real)returns None and those draws are silently not skipped, and the history logs them as "vs 0 ps 0". The user concludes the shader isn't at fault. One predicate for keeping hashes, used at every PSO_SHADERS insertion, would fix it.These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:12:29Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by Pipodi on 2026-12-03T01:28:11Z.
merge-check
base:
078358a058head:
8952390414merge: clean (
git merge --no-ffonto078358a0, merge 00906810; README.md +17, d3d12x/pixel_history.rs +914 new, real.rs +54/-1, bind.rs +18, present.rs +2/-1, mod.rs +1)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3012 passed, 0 failed, 52 ignored; failing: none (SKIPPED 25: 22 no wave64, 2 no heap windows, 1 cannot disable the driver cache). The six new tests ran and passed (
pixel_history::tests::*includinggpu_a_targets_texel_is_read_before_and_after_a_drawon the RTX 4090, andreal::skip_ps_tests::skip_ps_hashes_parse_and_unset_skips_nothing).title run: retail title on NVIDIA GeForce RTX 4090, no save, into the in-engine intro cutscenes, 420 s (ended by XCL_RUN_SECONDS),XCL_PIXEL_HISTORYandXCL_SKIP_PSunset (the default path), same env and frame presses as a run of main078358a0on this machine earlier tonight. This PR: 340 s in the cutscenes (from the first 2 s window with over 5000 dispatches, at 100 s, to the end), 2.03 presents/s there (690 presents), 2582 presents in the run, 0 device removals, 0 crashes (exit 0x0), peak video memory 21391 MB local, peak private 43.6 GB; no pixel-history or skip line in the log. Main078358a0: 334 s (from 99 s), 2.03 presents/s, 2614 presents, 0 removals, exit 0x0, 21546 MB local, 43.6 GB. It passed the warm gate on its first attempt. Title binary = merge result + local scripted-press commits (input only) and two local log-only diagnostics.review: read the whole diff. 1) Size: 1,006 lines with two independent diagnostics, and the description gives no reason it cannot be split, which CONTRIBUTING asks for over ~800 lines;
XCL_SKIP_PS(real.rsskip_ps_list/hash_list/skip_named_psand its two hooks in bind.rs) is self-contained and splits off cleanly, as the first check said. 2) Confirmed by reading (not run under the debug layer):copy_texelsbuilds one barrier per entry, andbound_targetspushes oneTargetper point for the same resource and subresource, so withXCL_PIXEL_HISTORY_ALSO(or one target bound in two slots) a singleResourceBarriercall transitions the same subresource RENDER_TARGET -> COPY_SOURCE twice (the second one's StateBefore is already wrong), and the same on the way back. The PR's own GPU test does this too: line ~892 passes the samettwice ((&t, SLOT, None)and the crop) to onecopy_texels. It passes on a release device, but the debug layer rejects it; deduplicate the barriers by (resource, subresource). 3)real.rs~8312 still recordsPSO_SHADERSonly whenXCL_TRACE_FRAMEis unset, so with both setXCL_SKIP_PSsilently skips nothing and the history logs vs/ps 0. 4) Off-path cost:emit_prepared_indexed_drawevaluateswith(this, |s| s.pso)(state map lookup plus the list's state mutex) forpixel_history::beforeon every indexed draw beforebeforelooks atROUND; the description's "a draw's hook loads one atomic" holds forbeforeitself, not this call site, andunset_pixel_history_changes_nothingdoes not cover it. Thegpu_profile::beginline above already reads the same value; reuse it. 5) Minor: the readout trusts 6 presents with no fence, so a list running at that moment can be read half-written (the sentinel only catches untouched slots); the GPU test spins onGetCompletedValuewith no time limit. Fine: off by default (before/note_dispatchreturn on one atomic, the creation hooks on a cachedon()), parsing and limits, slot and row-pitch alignment, per-mip point mapping, retired readback buffers kept, lock order (SESSION -> RTV_VIEWS / CROP_PSOS / PSO_SHADERS; CLOCK -> SESSION -> BLENDS / RETIRED) has no cycle.performance: default path measured: cutscene presents/s 2.03 vs 2.03 on main
078358a0, peak video memory 21391 vs 21546 MB, peak private 43.6 vs 43.6 GB. Per draw when off: one atomic and one cached check, plus the extra state lookup on indexed draws (finding 4). The opt-in path was not run here.verdict: not yet: split off
XCL_SKIP_PSor say in the description why the 1,006 lines cannot be split (CONTRIBUTING, over ~800), and fix the duplicate transition of one subresource in a barrier batch (finding 2, also in the PR's GPU test); findings 3 and 4 are small and could go with it. The default path is clean on the retail title.hardware / tool and model: NVIDIA GeForce RTX 4090 24 GB, driver 621.40; Intel Core i9-13900K, 32 GB; Windows 11 build 26300; rustc 1.100.0, debug (suite) / release (title run); Claude Code, Claude Opus 5.5
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.