D3D12.X, KernelX: wire watch_cold into texture looks and memory guards #3676
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3676"
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-02T07:21:56Z.
Stacked on #3639; only the top commit belongs here.
TL;DR — Before vs After
#3639core only)amd-watch-cold-wire)watch_cold.rscore module (#[allow(dead_code)], not yet called)watch_coldintotitle_textures,kernelx,lazy, andsparsemark_hot/all_hot/ sibling warmingwatch_cold::on()becausehot_looks()wasfalsetracks_hot_blocks() = hot_looks() || watch_cold::on(), pluslook_coldwarmsopened_rangeswatch_coldmodehot_looks()(watch_cold::look_withalready scans all non-cold pieces)default flags, RX 6650 XT)1654frames (60 61 60,15902 MB) onamd-dev1652frames (60 60 60,16000 MB, 0 removals, 0 crashes)XCL_GUEST_WRITE_GUARD=1 XCL_WATCH_COLD=1)1653frames (60 61 60,16324 MB, 0 removals, 0 crashes)What is in it
Wires the opt-in
watch_coldcore module from #3639 into D3D12.X texture write-watch looks and KernelX/sparse memory transitions (still off by default; requiresXCL_GUEST_WRITE_GUARD=1 XCL_WATCH_COLD=1):title_textures.rs: routesrefresh_partsthroughlook_coldwhenwatch_cold::on(), keepsstart_walkoff inwatch_coldmode, and introducestracks_hot_blocks() = hot_looks() || watch_cold::on()somark_hot(newly created textures, sparse commits, and multi-blockopened_rangessibling warming) andall_hot(upload_allcross-block safety check) stay active whenwatch_coldis enabled (addressing the review finding on #3639).kernelx.rs,kernelx/lazy.rs,sparse.rs: guardsVirtualAlloc/VirtualFree/VirtualProtect/ home commit & decommit / lazy page commits / sparse commit & decommit paths against concurrent read-only freezing.watch_cold_tracks_hot_blocks_and_warms_opened_siblings_across_looksverifying thatmark_hot,all_hot, and 4 MiB fault-window sibling warming work across consecutive looks.Tested
cargo test -p xcl --lib -- watch_cold --test-threads=1): 5 passed, 0 failed (4watch_cold::tests+title_textures::tests::watch_cold_tracks_hot_blocks_and_warms_opened_siblings_across_looks).cargo test --workspace --no-fail-fast -- --test-threads=4): 2,967 passed, 16 pre-existing failed, 49 ignored (same pre-existing failures as cleanorigin/amd-dev41aa60ce: 3 RDNA2 f32/NaN tests, 6 parallelsparse/title_texturescontention tests, 5e2edebug-layer/title tests, 2two_pass_driver_cachetests).cargo build --release -p xcl): succeeded cleanly.XCL_GUEST_WRITE_GUARD=1 XCL_WATCH_COLD=1):1653frames (60 61 60),0device removals,0crashes,16324 MBpeak commit.Regression run
Baseline (
origin/maind8bd9a38):Baseline (
origin/amd-dev41aa60ce):PR head (
0362c226, default flags):Not tested
AI use
watch_coldwiring out of #3639, added thetracks_hot_blocks()fix and cross-look regression test, ran unit/workspace tests and both default andXCL_WATCH_COLD=160 s smoke runs on local AMD hardware, and wrote this description.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T07:26:41Z.
Review (head
0362c226, diff read, not a merge-check):VirtualFree(addr, 0, MEM_RELEASE)clears only part of the cold map. The hook atkernelx.rs~1245 callsguard_free(addr, 0), andguard_free(watch_cold.rs~430-440) takes the length fromVirtualQuery'sRegionSize, which is only the first run of pages with the same protection. In a partly frozen watched reservation, theCOLDspans after that run stay behind after the release; ifreserve_watchedhands the address out again (VirtualAlloc(NULL, …), ~1160, whose hook at ~934 callsguard(0, size)and never covers the returned range), the new read-write memory is still listed as cold, sohot_piecesleaves it out of everyGetWriteWatchandfreezerefuses it (~487): CPU writes to those textures are never uploaded. The release path already knows the full length (whole, ~1327).watch_cold_tracks_hot_blocks_and_warms_opened_siblings_across_looks(title_textures.rs~8563-8587) passesenabled = truetoall_hot_if/mark_hot_atdirectly and never goes throughtracks_hot_blocks(), which is the actual fix for themark_hot/all_hotproblem raised on #3639; it would pass with the oldhot_looks()gate too.watch_cold::tests. It holdstitle_textures'TEST_LOCK, while thewatch_coldtests hold their ownSERIAL, and both use the same statics (OPENED,OPENED_RANGES,FAULTED,LOOKS,COLD);look_cold→look_withdrainsOPENED_RANGES, so under the parallel runner either test can lose its window to the other.Fine: own commit only (+134/-11); with
XCL_WATCH_COLDunset, or withoutXCL_GUEST_WRITE_GUARD=1,hot_looks(),mark_hot,all_hotand therefresh_partsdispatch behave as before and everyguard/guard_free/changedhook returns early; with it on,look_withis reached only throughlook_cold,start_walkand look-ahead stay off, andtracks_hot_blocks()turnsmark_hot/all_hotback on, which fixes the point raised on #3639.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-02T13:29:19Z.
merge-check
base:
41aa60ce84head:
0362c226d6merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2973 passed, 9 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 (the same tests fail on amd-dev
41aa60cealone on this card, so none is from this PR)review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3676#issuecomment-7338190206 and its findings stand. Most serious:
VirtualFree(addr, 0, MEM_RELEASE)->guard_free(addr, 0)takes its length fromVirtualQuery'sRegionSize(watch_cold.rs~430-440), so cold spans after the first protection run outlive the release, andVirtualAlloc(NULL, …)guards[0, size)instead of the returned address.performance: 60 s smoke of a retail title, amd-dev
41aa60cevs this merge (0362c226): 1671 -> 1674 frames shown (100 %; last presents per 2 s: 60 60 61), peak commit 16722 -> 16842 MB, 0 device removals, 0 crashes.verdict: not yet:
VirtualFree(addr, 0, MEM_RELEASE)->guard_free(addr, 0)takes its length fromVirtualQuery'sRegionSize(watch_cold.rs~430-440), so cold spans after the first protection run outlive the release, andVirtualAlloc(NULL, …)guards[0, size)instead of the returned address (see the review)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.
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.