D3D12.X: lower default watch gap to 4 MiB and add adaptive hot-block retention #3649
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3649"
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 iggyvilla on 2026-12-02T03:40:49Z.
TL;DR — Before vs After
#3649v1 /amd-dev41aa60ce)#3649split Part 1:amd-watch-tight-hot)title_textures.rs), strictly hot-block retention + default hot gap; range-building changes split into a separate standalone PRXCL_WATCH_GAP_MB64MiB (bridges up to 64 MiB of untouched cold memory into oneGetWriteWatchcall)4MiB (matches ~4–6 MiB per-call walk breakeven; overridable viaXCL_WATCH_GAP_MB)HotBlocks)1500 ms(XCL_WATCH_HOT_MS) for newly mapped, marked, walked, and write-once blocks150 ms(XCL_WATCH_HOT_BRIEF_MS) until written across>= 2distinct looks, then promoted to1500 ms(XCL_WATCH_HOT_MS)RX 6650 XT,amd-dev41aa60ce)1654frames (60 61 60,15902 MB)1642frames (60 60 60,16410 MB, 0 removals, 0 crashes)What is in it
Split out from the earlier #3649 bundle so hot-block scan retention and gap coalescing can be reviewed, measured, and bisected independently from watch-range construction:
XCL_WATCH_GAP_MBinhot_gap()from64MiB to4MiB sohot_runsstops bridging tens of megabytes of untouched cold memory between hot 2 MiB blocks into oneGetWriteWatchcall.HotBlocks::hot's(Instant, u8)value withHotEntry { at, why, writes }and two-tier retention (retain_hot/record_hot_written): newly mapped (HOT_NEW), marked (HOT_MARKED), walked (HOT_WALKED), or write-once blocks expire afterXCL_WATCH_HOT_BRIEF_MS(default150 ms), while blocks written across>= 2distinct looks promote toXCL_WATCH_HOT_MS(default1500 ms).hot_blocks_cool_briefly_until_written_across_two_looks.coarse/shown_blocksgranularity and call-budgeted coherent-UMA spans (usingplan_watch_ranges) are split into a separate standalone PR onamd-dev.Tested
cargo test -p xcl --lib -- hot_blocks_cool_briefly_until_written_across_two_looks): 1 passed, 0 failed.cargo test --workspace --no-fail-fast -- --test-threads=4): 2,957 passed, 15 pre-existing failed, 49 ignored (same pre-existing failures as cleanorigin/amd-dev41aa60ce: 3 RDNA2 f32/NaN tests, 6 parallelsparse/title_texturescontention tests, 4e2edebug-layer/title tests, 2two_pass_driver_cachetests).cargo build --release -p xcl): succeeded cleanly.Regression run
Baseline (
origin/maind8bd9a38):Baseline (
origin/amd-dev41aa60ce):PR head (
b1c4ef5a):Not tested
AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T03:48:20Z.
Review (head
b602d70e, diff read, not a merge-check):cached_watch_ranges(title_textures.rs~1854-1898) watches unshadowed committed UMA throughcoh_spanswithgap = 0, so each texture span that does not touch another becomes its own range, andhot_runs(~2301) merges only inside one range: a hot 2 MiB block holding N small textures costs NGetWriteWatchcalls per look, and withXCL_WATCH_HOT=0every span costs one.watch_blocks(~302) also bumpsCOARSE_GENfor every new span, so each texture placed in committed UMA throws away and rebuilds the range cache. The comment this PR removes ("by 16 MiB blocks, not by texture: a title has tens of thousands, and their sources change every submit while it loads") describes this cost; the numbers in the description are from one title in-world, with no loading phase and no call count. The existingplan_watch_ranges(regions, wanted, target_calls)already merges exact spans down to a call budget.Table::coarse/mirrors::shown_blocksgranularity (16 to 2 MiB), exactcoh_spansin coherent UMA, the defaulthot_gap(64 to 4 MiB), and adds the two-tierHotEntryretention (XCL_WATCH_HOT_BRIEF_MS, ~2188-2234). The retention does not touch how ranges are built and the gap default is a one-liner; exact spans and 2 MiB blocks have no switch. Separately they would be measurable and bisectable.add_coh_span/remove_coh_spanand the existing gap merge, but nothing tests theexact_cohsplit incached_watch_ranges, skipping coarse blocks in committed windows,shown_blocksgoing to the gap-0 set, the fallback whenu.shadowed()orbvh_want::watching()is true, or thatwatch_blocks/unwatch_blocksadd a span only in a committed window. A mistake there leaves CPU texture writes in coherent UMA unwatched.xcl-smokeblock isd8bd9a38onmain, 306 commits behind this PR's merge base onamd-dev(41aa60ce), so the 1618 vs 1653 frames include unrelated changes.Fine:
coh_spanschanges only throughwatch_blocks/unwatch_blocks, so its refcounts stay balanced withcoarse;bvh_want::watching()inwatch_keyinvalidates the cache when it flips; the gap-0 merge joins only spans that touch. The description says this stacks cleanly with #3639, but both change the samehot_forretain hunk intitle_textures.rs, so whichever lands second has a (small) conflict.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by iggyvilla on 2026-12-02T07:29:23Z.
Thanks for the detailed review! Addressed all points by splitting #3649 into two small, independent PRs on
amd-dev(41aa60ce):+89/-26intitle_textures.rs): strictly theXCL_WATCH_GAP_MBdefault (64 -> 4 MiB) and two-tier adaptiveHotEntryretention (XCL_WATCH_HOT_BRIEF_MS, default150 ms, promoting at>= 2distinct write looks), plus theamd-dev41aa60cebaseline smoke block alongsideorigin/maind8bd9a38.amd-watch-tight-ranges, opening next): the 2 MiBTable::coarse/shown_blocksgranularity andcoh_spansfor committed UMA — updated to bound coherent-UMA calls through the existingplan_watch_ranges(..., COH_WATCH_CALLS)instead of unboundedgap = 0calls, and backed by unit tests covering theexact_cohsplit, skipping coarse in committed UMA,shown_blocksrouting,shadowed/bvh_want::watching()fallback,watch_blocks/unwatch_blockscommitted-window gating, and call-budget merging.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T07:34:08Z.
Follow-up review (head
b1c4ef5a, sinceb602d70e, diff read, not a merge-check):coh_spans,exact_coh,kernelx.rsandbvh_want.rsare no longer touched (the description says that part moves to a PR usingplan_watch_ranges, not open yet).hot_blocks_cool_briefly_until_written_across_two_looks(~6663) testsrecord_hot_writtenandretain_hot, though the call-site changes (hot_runs~2196,mark_hot~2547) have none.amd-dev41aa60ce.title_textures.rs(hot_runs/refresh_hot,mark_hot).hot_gap, ~2088) and the two-tier retention (~2099-2145) are still one commit and both on by default;XCL_WATCH_GAP_MB=64/XCL_WATCH_HOT_BRIEF_MS=1500restore the old values, but they cannot be bisected apart.New:
9acc0314without measuring its reason. That commit raisedXCL_WATCH_GAP_MBfrom 4 to 64 MiB because "a call waits for the process's memory lock, which is busy while the title loads". This PR (~2084-2088) goes back to 4 MiB with one 60 s smoke run of frame counts as evidence, and no call count or look time while the title loads (XCL_LOOK_STATS), the case the 64 MiB was set for.mark_hotafter a texture is placed (~891, "the data the title is about to write there is for the next submit") now lasts onlybrief_hot_for, so a texture filled more than 150 ms after it was placed, common while loading, sits in a cold block until the walk finds its write, and the submits before that use old contents;all_hot(~3529) is also false more often, sowritten_pagesaddsGetWriteWatchcalls per texture on the submit path (~3582). Nowalk_staleor look-stats numbers are given.hot_runs(~2196) changedinserttoentry().or_insert, so a block withwrites < 2keeps its oldatand can expire milliseconds after the mapping, where the base kept it forhot_for("memory just mapped is often written and used at once").Fine:
record_hot_writtencounts a block once per look,retain_hotcaps the brief window at the long one,writessaturates, the walk still inserts only vacant blocks, andmark_hotkeeps a promoted block in the long tier.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T12:35:52Z.
merge-check
base:
41aa60ce84head:
b1c4ef5ad1merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2961 passed, 10 failed, 49 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 amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones, test_title_runs_and_game_folder_is_untouched (all but
test_title_runs_and_game_folder_is_untouchedfail on amd-dev41aa60cealone on this card; that one fails because of this PR, in both runs of this merge)review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3649#issuecomment-7338340399 and its findings stand. Most serious: by default
hot_gapgoes from 64 back to 4 MiB (~2088), undoing9acc0314without measuring the load-time case, and the 150 ms brief-hot tier lets a placed texture cool in 150 ms (stale texture risk on the default path).performance: 60 s smoke of a retail title, amd-dev
41aa60cevs this merge (b1c4ef5a): 1671 -> 1675 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 17366 MB, 0 device removals, 0 crashes. The smoke run is from the first of the two runs; the second ran the suite only.verdict: not yet: the e2e test title fails in both runs of this merge and passes on amd-dev alone:
[FAIL] D3D12.X: async ring-buffered sparse uploads (80 MiB across 20 submits + reused-tile zeroing): submit 9 tail mismatch: got 0x0, want 0xa50ffff9, i.e. an upload's data is missing, which fits the review's point that the shorter hot window lets just-written blocks cool too soon; alsohot_gapgoing back to 4 MiB by default is unmeasuredhardware / 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 bmjask on 2026-12-02T18:07:03Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 2124High: A block is only promoted when two looks find writes in it less than 150 ms apart, so whenever looks come more than 150 ms apart nothing is promoted and every hot block expires between looks. On a loading screen, a low-fps scene, or during XCL_LOOK_SKIP gaps with submits more than 150 ms apart, each look's
retain_hotdrops every entry with writes < 2, sohot_runsreturns only HOT_NEW blocks. Every CPU write then depends on the walk finding it before the submit, and writes the walk hasn't reached are missed, so the GPU reads stale buffer/texture data. The old 1500 ms window covered these cases. Counting looks rather than wall-clock time (cool a block after N consecutive empty looks) would behave the same at any submit rate.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T18:07:03Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 2196Medium: The new-block path changed from
inserttoentry().or_insert(), so a block new to the ranges no longer gets a fresh timestamp, andretain_hot, which runs right after, can drop it before the first look covers it. Ifmark_hotor an old mapping left an entry for block B with writes=0 and at=t0, and the ranges are rebuilt at a submit more than 150 ms later,new_blocksreturns B,or_insertdoes nothing, andretain_hotremoves B before runs are built. The first look after the mapping then skips the just-mapped block, which the comment calls "often written and used at once". Resetting it to (now, HOT_NEW) as before would fix it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T18:07:03Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 2458Medium: The walk only inserts when the entry is Vacant, so a write it finds in a block that already has a brief entry doesn't refresh
at, and the nextretain_hotcan drop that block just before the look that should take the write. With block B at writes=1, at=t-140ms, if the walk finds a new write in B at t, it skips it because the entry is occupied. The look at t+15ms runsretain_hot, drops B (age 155 ms), and doesn't cover it, so a submit in that window reads stale data. With a 150 ms window this happens far more often than with 1500 ms. Refreshingaton an occupied entry would fix it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T18:07:03Z.
Review: COMMENTED
Review of
b1c4ef5a: 4 finding(s) (2 high, 2 medium), most severe first.crates/xcl/src/hle/d3d12x/title_textures.rs:2124: A block is only promoted when two looks find writes in it less than 150 ms apart, so whenever looks come more than 150 ms apart nothing is promoted and every hot block expires between looks. (inline)crates/xcl/src/hle/d3d12x/title_textures.rs:891: see below.crates/xcl/src/hle/d3d12x/title_textures.rs:2196: The new-block path changed frominserttoentry().or_insert(), so a block new to the ranges no longer gets a fresh timestamp, andretain_hot, which runs right after, can drop it before the first look covers it. (inline)crates/xcl/src/hle/d3d12x/title_textures.rs:2458: The walk only inserts when the entry is Vacant, so a write it finds in a block that already has a brief entry doesn't refreshat, and the nextretain_hotcan drop that block just before the look that should take the write. (inline)On lines outside the diff:
crates/xcl/src/hle/d3d12x/title_textures.rs:891:mark_hotentries ("the data the title is about to write there is for the next submit") now expire after 150 ms instead of 1500 ms. If a title places or commits a texture and fills it more than 150 ms later (streaming, or a load-time fill before the next submit), the marked block has already cooled, so the next submit's look skips it and the upload depends on walk timing and can be stale, which is the casemark_hotexists to prevent. Keeping marked blocks on the long window would avoid 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-02T18:07:06Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
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.