Skip to content

D3D12.X: port @Saksukella's write-watch changes #2754 and #2891 to main - #3242

Open
KOLESNiii wants to merge 2 commits into
xcl-dev:mainfrom
KOLESNiii:d3d12x-write-watch-port-2754-2891
Open

KOLESNiii wants to merge 2 commits into
xcl-dev:mainfrom
KOLESNiii:d3d12x-write-watch-port-2754-2891

Conversation

@KOLESNiii

@KOLESNiii KOLESNiii commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Credit: this is @Saksukella's work

Everything in this PR is a port of two pull requests by @Saksukella (github.com/Saksukella):

The problem analysis, the rules (which tiles and textures need no write-watch, the gap size) and the measurements behind them are @Saksukella's. My part was only to re-express them on main's newer write-watch code so they apply without conflicts. Both commits name @Saksukella in their message and carry Co-authored-by: Saksukella <98151720+Saksukella@users.noreply.github.com>, so GitHub lists them as co-author. @Saksukella, if you'd rather rebase #2754 / #2891 onto main yourself, or take these commits into your own PRs, please do. This draft will step aside, and your review of the port is very welcome.


Port of two write-watch changes by @Saksukella to main. Both were written for amd-dev: #2754 (commits 60bc047, 891c97a) and #2891 (commits 0246ae4, b570a92). The ideas, rules and measurements are theirs. Main's write-watch code has changed a lot since then (sparse runs, coarse texture blocks, the XCL_WATCH_HOT hot/cold walk), so this re-implements them on main's structures rather than cherry-picking. Both commits carry Co-authored-by: Saksukella. Please credit them first; this PR only carries the work to main, and it is not meant to replace #2754 / #2891 if they are rebased onto main themselves.

What is in it

  • D3D12.X: write-watch leaves out VRAM-only tiles and GPU-written textures, a port of @Saksukella's D3D12.X: omit VRAM-only sparse tiles and GPU-written textures from write-watch ranges #2754, in crates/xcl/src/hle/d3d12x/sparse.rs and title_textures.rs:
    • Sparse windows: a window's own tile with video memory and no CPU page (holes == 0xFFFF) takes no CPU write, but main added it to State::runs, so write-watch scanned it. Such a tile now joins the runs at its first CPU page (commit_range_with_protection, with a MAPPED_GEN bump). Tiles over a CPU view (src != 0) are unchanged.
    • Textures: a GPU-written texture is never uploaded from its source (texture_needs_upload), but Table::coarse counted every active texture. It now counts only those that are not gpu_written. A texture moves in or out wherever that flag flips: a published GPU write, a mapping change, a download that makes the CPU copy current.
    • Tests: a_tile_with_no_cpu_page_is_not_watched, a_tile_with_no_cpu_page_is_watched_from_its_first_commit (GPU), gpu_written_textures_leave_the_watched_blocks_until_they_are_current_again. The runs_of helper follows the new invariant.
  • D3D12.X: write-watch ranges merge across gaps of up to 4 MiB, not 8, a port of @Saksukella's D3D12.X: tighten write-watch merge gap to 4 MiB and add opt-in cold-chunk tiering #2891, in title_textures.rs:
    • @Saksukella's 4 MiB merge gap from D3D12.X: tighten write-watch merge gap to 4 MiB and add opt-in cold-chunk tiering #2891 (they measured a 1.5 GiB resident write-watch benchmark at 2.28x faster with a 4 MiB gap than with 64 MiB) (WATCH_GAP). Its opt-in 16 MiB hot/cold tiering and cold sweep on resubmit are not ported: main already does the tiering as XCL_WATCH_HOT (on by default), and the sweep would bring back the full looks that walk replaced. The commit message gives the reasons.
    • Test: watch_ranges_merge_at_the_gap_limit_and_split_past_it, now at 4 MiB (fails at 8).

Tested

Regression run

xcl-smoke v1
commit: 9dfbe3ea6653a9c76ef3ea0d66187a4b5407483b
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1591 (PresentX 1591)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 17442 MB
xcl-smoke v1
commit: 5f3fdbe49bf008823ad2c648c480705e1d63f69a
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1508 (PresentX 1508)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 17524 MB

Both runs: XCL_PRESS_AT=25:A, XCL_PREPARE=0. This head is based on main 81bfbf0d; the main run is on the newer 9dfbe3ea.

Not tested

  • Frame time and look time against main on a retail title: the regression run above counts frames and peak commit only
  • AMD GPUs
  • Risk: a CPU commit that XCL never sees would leave its tile unwatched, where main watched it from the GPU mapping.

AI use

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 28, 2026
@KOLESNiii

Copy link
Copy Markdown
Contributor Author

Cold full preparation data point, this PR together with #3241 (NVIDIA)

One cold run of full shader preparation (XCL_PREPARE_ALL=1) on a retail game:

Results

  • Translation and DXC phase: all 26,503 records done in 54.4 min.
  • Driver pipeline phase: 22,474 records checked at 60 min, 23,003 at 90 min and 23,624 at 117 min. I stopped the run there, with about 2,900 pipelines left.
  • At the stop the cache held 14,716 DXIL files and 4,981 driver blobs.

What this does not show

  • This PR's effect on its own. There is no matched main run or run of this PR alone: both were planned but cancelled for time.
  • What this PR changes on its own. It changes write-watch behaviour, not shader preparation. So this run mainly shows that it co-exists with Recompiler: the DXIL cache key leaves out comments and indentation #3241 through a full preparation: no crash or device removal before the stop.
  • Other GPUs. One run, NVIDIA only.

A matched cold-run comparison against main from anyone would settle it.

Measured and written with Claude Code (Claude Opus 5.5).

KOLESNiii and others added 2 commits November 29, 2026 16:21
Port of xcl-dev#2754 by Saksukella (amd-dev commits 60bc047 and 891c97a) to
main, re-implemented for main's sparse runs and coarse texture blocks;
the idea and the rules are theirs.

Sparse windows: a window's own tile with video memory and no CPU page
(holes == 0xFFFF) takes no CPU write, yet main added it to State::runs
at ensure_listed (XCL_SPARSE_LAZY), ensure_mapped (a placed buffer over
uncommitted pages) and the CPU-view unlink, so write-watch scanned it.
Such a tile now enters the runs at its first CPU page
(commit_range_with_protection, with a MAPPED_GEN bump). Tiles over a CPU
view (src != 0) are tracked by src_runs and unchanged.

Textures: a GPU-written texture is never uploaded from its source
(texture_needs_upload), but Table::coarse counted every active texture.
It now counts only those that are not gpu_written, and a texture moves
in or out where that flips: a published GPU write, a mapping change that
undoes one (recheck_gpu_view_sources), and a download that makes the
CPU's copy current. GPU-owned textures (gpu_written from the start) are
no longer watched at all. Shadowed entries never count.

Risk: a CPU commit XCL never sees leaves its tile unwatched, where main
watched it from the GPU mapping. A block that comes back into the
watched ranges may report pages written while it was out; that costs at
most one extra upload of a texture there, as main's always-watched block
would.

Tests: a_tile_with_no_cpu_page_is_not_watched,
a_tile_with_no_cpu_page_is_watched_from_its_first_commit (GPU),
gpu_written_textures_leave_the_watched_blocks_until_they_are_current_again;
the runs_of helper follows the new invariant.

Co-authored-by: Saksukella <98151720+Saksukella@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port of what remains of xcl-dev#2891 by Saksukella (amd-dev commits 0246ae4
and b570a92) on main: its 4 MiB merge gap. They measured a 1.5 GiB
resident write-watch benchmark at 2.28x faster with a 4 MiB gap than
with amd-dev's 64 MiB; main had already gone to 8 MiB.

Not ported: xcl-dev#2891's opt-in hot/cold 16 MiB chunk tiering and its cold
sweep on resubmitted lists. Main has the tiering in another form
(XCL_WATCH_HOT, on by default: a look takes the 2 MiB blocks written
recently and a thread walks the rest), and xcl-dev#2891 forced the cold sweep
only under its own opt-in switch; on main it would bring back the full
look (4-7 ms) the walk replaced.

With XCL_WATCH_HOT on, a look's calls use hot_gap (64 MiB); this gap
shapes the watched ranges whose blocks the walk takes, and every look
with XCL_WATCH_HOT=0. Main's comment puts the break-even of one call at
5-9 MiB of gap, so the effect is expected to be small either way: to be
measured.

Test: watch_ranges_merge_at_the_gap_limit_and_split_past_it (ranges
6 MiB apart are two scans; fails at 8 MiB).

Co-authored-by: Saksukella <98151720+Saksukella@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KOLESNiii
KOLESNiii force-pushed the d3d12x-write-watch-port-2754-2891 branch from 3023748 to 5f3fdbe Compare November 29, 2026 16:30
@github-actions github-actions Bot removed the needs-rebase Has merge conflicts with its base branch label Nov 29, 2026
@brainhay5

Copy link
Copy Markdown

Retest with the write-watch scan measured — RTX 5070 Ti 16 GB, driver 610.88, retail 1.0.2.1

We retested this branch. Earlier we could only report "still stalls"; we now measure what the presenting
thread spends inside GetWriteWatch, because a thread dump put that thread here:

take_written            <- GetWriteWatch(WRITE_WATCH_FLAG_RESET, ...)
title_textures::refresh_parts
title_textures::refresh_for
real::prepare_title_submission
real::q_execute_command_lists
real::queue_dispatch
build frames presented last present max dirty pages max single scan
main 0fe06eb 1500 63.8 s 2,189,084 653 ms
this PR 5f3fdbe 1500 67.6 s 2,165,780 723 ms

So on this workload the change removes about 1% of the watched page set (2,165,780 vs 2,189,084)
and moves the stop by 3.8 s, inside the 59.6–68.7 s spread we see across ten runs on this card.

What that suggests: the pages filling the scan are ordinary CPU-written title-texture pages, not the
VRAM-only tiles or GPU-written textures this PR excludes. Excluding those classes does not shrink the set
that dominates here.

Where the scan does seem to matter, across eight runs on this card in the same configuration: the
discriminator is a single scan reaching ~6 s.

max single scan   6101 / 5563 / 6241 / 6101 / 6353 ms   ->  presenting stops at 49.4-50.4 s
max single scan    653 /  723 /  580 ms                 ->  1500 frames, stops at 63.8-67.6 s

This branch does not change that; PR #2484, #1513 and #1702 (all measured the same way) did not either.

One observation that may be useful: the scan walks far more pages than are written in the same
window — up to 2.1 M pages (≈8.6 GB) against ~1.7 GB actually uploaded by the sparse-window path in the
same run. That looks like the watched range being the whole window rather than the live tile set, which
a tile-class filter cannot fix.

Full logs for every row are available on request.

AI use: an agent ran the builds and runs, read the dumps and wrote this comment.

@brainhay5

Copy link
Copy Markdown

Follow-up: the range hypothesis is still untested, and the scan is bigger than the window

Correcting my own speculation in the comment above ("the watched range is the whole window").

I tried to test it by shrinking the window: XCL_UMA_MB=512, same build, same configuration.

log line:  UMA opened (3 sparse VRAM window(s), 4095 MB coherent window)   <- unchanged
result:    1200 frames, last present 50.3 s, 1,986,405 dirty pages, worst scan 6386 ms

XCL_UMA_MB does not size that window — it is fixed at 4095 MiB in gpu/uma.rs ("4095 MiB works,
exactly 4 GiB is rejected"). So that test says nothing about the range.

It also shows my framing was wrong: 2.1 M pages ≈ 8.6 GB, which is larger than the 4095 MiB coherent
window, so the scan is spanning the sparse windows (3 × 4 GiB), not that one window. Bounding "the
window" is not available as a knob.

What has held across nine runs on this card, all measured the same way:

worst single scan  ~6 s (5563-6386 ms)  ->  presenting stops at 49.4-50.4 s
worst single scan  <1 s (580-723 ms)    ->  1500 frames, stops at 63.8-74.6 s

so the scan remains the discriminator, but how the watched range is sized is still unknown to me.
If anyone knows what decides which pages end up in the GetWriteWatch range for the sparse windows —
or whether a bound on pages scanned per present is feasible — that is the question I would chase next.

AI use: an agent ran the measurement and wrote this comment.

@brainhay5

Copy link
Copy Markdown

Correction: those scan numbers are cumulative since process start, not per-scan

Both of my comments above say "max single scan 6101 ms". That is wrong. sparse::note_watch
accumulates into a static:

pub fn note_watch(t: Duration, pages: usize) {
    WATCH[0].fetch_add(t.as_micros() as u64, ...);   // total time in write-watch
    WATCH[1].fetch_add(pages as u64, ...);           // total pages found
}

so the timing line reports totals for the whole run, and the page figure is likewise a total, not a
peak. Restated correctly, all nine of my runs:

build frames last present total write-watch total pages found
main 0fe06eb 1500 63.8 s 0.653 s 2,189,084
main 1bd9cee 1500 58.8 s 0.728 s 2,114,162
this PR 5f3fdbe 1500 67.6 s 0.723 s 2,165,780
PR #3052 1500 66.2 s 0.580 s 2,115,358
PR #2590 1200 49.4 s 6.101 s 1,959,761
PR #851 1200 50.4 s 5.563 s 1,858,538
PR #2484 1200 49.4 s 6.241 s 1,979,630
PR #1513 1500 71.4 s 6.101 s 1,975,649
PR #1702 1500 74.6 s 6.353 s 1,990,948

The correlation survives the correction and is arguably stronger: the runs that stop at ~50 s spend
~6 s of a ~50 s run in write-watch, while the runs that reach 1500 frames spend ~0.7 s of ~64 s.
Same order of pages found either way (1.86–2.19 M), so what differs is cost per page, not the size
of the set.

One consequence for anyone thinking about a fix: I tried a per-call page cap (XCL_WW_CAP_PAGES, a
diagnostic patch, reverted). It does not help — pages merely turn up in later calls; the total stayed
2.22 M. Bounding per call is not the same as bounding total work.

Sorry for the noise; the underlying observation stands, the description of the number did not.

AI use: an agent ran these measurements and wrote this correction.

@brainhay5

Copy link
Copy Markdown

Triage note: this is mergeable but BLOCKED, and it is the only route that currently carries the write-watch range changes onto current main — the originals (#2754, #2891) are both DIRTY, and #2484 / #1034 are as well.

If the block is waiting on something specific (a review, a check, a rebase), naming it would help: several people are trying to measure whether the write-watch range is the present-path cost, and this PR is the only way to do that on today's tree.

Not asking for anything to be merged — just flagging what is standing in the way.

AI use: an agent posted this triage note.

@KOLESNiii

Copy link
Copy Markdown
Contributor Author

@brainhay5 thanks for flagging it. The block was the missing regression run, and it should be good now. Both xcl-smoke blocks are in Regression run: main 9dfbe3ea and this head 5f3fdbe4, retail game, 60 s, RTX 2070 SUPER. Neither run had a device removal or a crash. This head showed 1508 frames against main's 1591 and a peak commit of 17524 MB against 17442 MB. CI and PR description are both green.

— Claude Code (Claude Opus 5.5), on behalf of the PR author

@brainhay5

Copy link
Copy Markdown

merge-check claim
base: 493dbd3 (current main)
head: 5f3fdbe
Running: merge into current main on a scratch worktree, cargo build --workspace, cargo test --workspace --no-fail-fast -- --test-threads=4, every failure re-run on the base alone, and the diff read in full for safety. Will post the result in the queue's format.

AI use: an agent is running this check.

@github-actions github-actions Bot added the needs-1st-check Passes gates; needs first independent merge-check (#3041) label Dec 1, 2026
@github-actions github-actions Bot added the needs:amd-test Needs a test report or merge-check on an AMD GPU label Dec 1, 2026
@brainhay5

Copy link
Copy Markdown

merge-check
base: 493dbd3
head: 5f3fdbe
merge: clean into current main (merge 17392668; parents verified as exactly base + head before anything was built or tested)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2902 passed, 1 failed, 51 ignored; 29 SKIPPED lines; 2786 lib tests present. The first attempt ended early at 147 passed (the known background-PSO flake that truncates the lib binary), so this is the completed rerun. Failing: test_title_runs_and_game_folder_is_untouched — also FAILED when run on the base alone with the same command, so it is pre-existing on this machine, not this PR's.
review: two files, +195/-29, both in the write-watch path: sparse.rs and title_textures.rs. The change watches a window's own tile only from its first CPU page (watch_own_tile skips tiles with no CPU page, holes == 0xFFFF), adds rewatch/unwatch_src so a tile that gains its first page is watched from then on, and bumps MAPPED_GEN when that happens. It ports #2754 and #2891 onto current main. Contained, no unrelated edits, no new dependency, nothing touching build.rs, Cargo.*, the toolchain, .cargo, .github or scripts.
performance: it removes work rather than adding it — tiles with no CPU page are no longer watched (write-watch would only scan them), so the scan set shrinks. No new per-frame or per-draw path.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 5f3fdbe

This is a port to main of #2754 and #2891, which target amd-dev and are credited, so it is not a duplicate of them. The draft #3547 (merge of amd-dev into main, +23871) would bring the amd-dev versions too.
sparse.rs:watch_own_tile / commit_range_with_protection (with the MAPPED_GEN bump) and title_textures.rs:rewatch follow every place where main clears or sets gpu_written: a published GPU write, recheck_gpu_view_sources, and publish_download. That fits texture_needs_upload never uploading a GPU-written texture. No problems found in the diff.
Recommendation: keep open.

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

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 493dbd3
head: 5f3fdbe
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 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 (+195/-29) and compared it with #2754 and #2891 (both open, against amd-dev). Findings: (1) Two changes in one PR, and the gap change is unmeasured on main. One change leaves a sparse window's own GPU tiles out of the watched ranges until their first CPU page. The other cuts WATCH_GAP from 8 to 4 MiB (title_textures.rs ~3210). The 2.28x cited for 4 MiB was measured on amd-dev going from 64 MiB, with no hot/cold walk; main's own comment puts break-even at 5-9 MiB. hot_runs never joins runs across ranges (~1592), so smaller gaps can mean more write-watch calls per look. brainhay5's numbers on the PR (0.723 s vs 0.653 / 0.728 s on main) show no gain. (2) A test assertion that can flake: sparse.rs ~11407 asserts mapped_gen() == gen on the global MAPPED_GEN, which other sparse tests running in parallel also bump; the existing tests only assert > (unverified that nothing serialises them). (3) The port is narrower than #2754. It leaves out only a window's own tiles (src == 0, ~3197) and adds them back at their first CPU page (~5829). That is safe only if every CPU commit in a window reaches commit_range_with_protection. I found no path that doesn't (query_tile_holes and the shadow insert are fine, and ~6812 / ~6948 only touch src != 0), but a commit XCL never sees would leave writes unuploaded where main kept watching. (4) The earlier "safe to merge" on the PR was written with DeepSeek, which CONTRIBUTING excludes, and it doesn't mention the gap change. Fine: Windows keeps a page's write-watch bit until it is scanned, every change to the watched set bumps MAPPED_GEN / COARSE_GEN, and blocks new to the ranges start hot, so nothing is missed. All three places gpu_written flips re-link the texture. #2891's cold-chunk tiering isn't ported, so nothing new becomes default beyond the two changes above. Both commits credit Saksukella.
performance: 60 s smoke of a retail title, main 493dbd3 vs this merge (bfb05fe8): 1670 -> 1671 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17083 -> 17635 MB, 0 device removals, 0 crashes. The smoke run is capped at 60 presents per second and doesn't report write-watch time, so it can't show the look cost either way.
verdict: not yet: two changes in one PR (the own-tile exclusion and the 4 MiB gap), and the gap change shows no gain on main (brainhay5's numbers, and the break-even main's own comment puts at 5-9 MiB). Splitting off the gap change, or measuring write-watch time on main with it, would settle it
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.

@github-actions github-actions Bot added checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Dec 1, 2026
@brainhay5

Copy link
Copy Markdown

Amendment to my check above, after Foniass's: I should not have returned safe to merge on this PR, and the technical objection is the stronger one.

My check covered the merge (parents verified), the build, the full suite, and the shape of the diff. It did not test whether the second change in that diff — WATCH_GAP 8→4 MiB — is justified on main. Foniass is right that it is unmeasured here: the 2.28× figure comes from amd-dev at 64 MiB, while main's own comment puts break-even at 5–9 MiB, and the write-watch timings I have (0.653–0.728 s) show no gain from it. So one verdict covering both changes overreached: the own-tile part may be sound while the gap change is not demonstrated. A not yet that names the unmeasured half is a better answer than mine was, and I withdraw the safe to merge.

Two things I should also say plainly, since they affect every check I have posted:

  • I disclosed the model in each comment. CONTRIBUTING.md's AI section names DeepSeek among the models whose PRs are closed without review. That rule is written for PRs rather than for review comments, so I do not think it was written about this; but if the maintainers intend it to cover community checks as well, then these checks are not wanted and I will stop posting them unless someone says otherwise.
  • The MAPPED_GEN assertion Foniass flagged as flaky is in the code this PR touches; a check that only runs the suite once can miss exactly that.

AI use: an agent (DeepSeek V4.1 Flash) ran the check and wrote this comment.

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:memory Virtual/physical memory, arenas, VRAM budget, UMA checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs:amd-test Needs a test report or merge-check on an AMD GPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants