Memory: sparse tiles the CPU leaves alone leave the write-watch look (#582, off by default) #1027
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1034"
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 AlexLopezDevelop on 2026-11-24T10:39:05Z.
Part of #582: step 1-2 of the plan there (direction agreed in https://github.com/ivall/xcl/issues/582#issuecomment-7128327759 and claimed in https://github.com/ivall/xcl/issues/582#issuecomment-7128655486). Off by default:
XCL_SPARSE_COOL=1turns it on; it does nothing under Wine (util::under_wine) until a run there shows a gain.One commit,
b3c944b, onmain930e8b4. 775 lines added: about 230 of them are tests, so the code is about 545, over the ~400 guideline; it is one mechanism (cool, warm, and the places that must warm), and I did not find a split where each half stands on its own.What is in it
hle/d3d12x/sparse_cool.rs(new): a 64 KiB tile of a sparse window with no written page for 8 looks is made read-only and left out of theGetWriteWatchlook. Its first CPU write faults; a vectored handler makes it writable again, and the next look takes it back with that write in the write watch as before. At most 64 tiles are cooled and 1,024 examined per look; the tile list is rebuilt at most every 64 looks.VirtualProtecta non-resettingGetWriteWatchon the tile undoes it if a page was written meanwhile.warm_tileraises the module's generation beforeVirtualProtect, under the read-only set's lock, so a write right after the warm is in the next submit's ranges.kernelx::lazy::ensure(so DirectStorage destinations andcpu_writes),eh::is_writable(the CLZERO / CLZERO-loop emulation on CPUs without CLZERO), the title'sVirtualProtect, same-processVirtualProtectExand sparse commit, andsparse::committed/decommitted.hk_read_filepins its buffer for the whole call (sparse_cool::pin), so a cooling pass on another thread cannot protect a tile between the warm and the kernel's write, nor under an overlapped read that lands after the call returns. Pins and warm times are two lock-free arrays of 2^18 slots (a slot is shared by tiles 16 GiB apart; sharing only keeps a tile writable longer), so the hot paths that warm on every call take no lock.XMemVirtualQueryreports a cooled tile as read-write, andVirtualProtectExwarms first, so its old protection is the title's.sparse'sSTATE, so a readback that writes title memory underSTATEand faults does not deadlock.mainand cached on the same three keys; the read-only tiles are taken out afterwards, in a second cache keyed on those ranges and the module's generation (a sorted walk of the read-only set, about 0.25 ms here). Cooling raises the generation in batches (256 tiles or 64 looks); a warm still raises it at once. Before this, the generation was part of the first cache's key and @zorde23 measured the ranges made again 2.4× as often on an RX 6750 XT, eating most of the gain.GetWriteWatchcall, about 1 µs, and a 64 KiB tile costs about 0.09 µs to look at on this CPU. A read-only tile left in the look is still warmed by its first write.Tested
XCL_PSO_WAIT_MS=50. Retail 1.0.2.1, unattended (first menus), 120 s each.b3c944bpair below, at 1,024 looks: 802 MB a look withXCL_SPARSE_COOL=1(13,428 tiles read-only, 618 warmed) against 1,177 MB unset; ranges made again 28 times with the switch and 92 without, filtered again 317 times in 79 ms in all; cooling pass 0.39 ms a look (0.74 over the first 512 looks, while it cools 64 tiles a look).40dfd85); one run with the minimum gave 7.00 ms with 705 MB. The gain to expect is where the clean bytes dominate (@zorde23's world load on an RX 6750 XT: looks 20 % cheaper).Mutex<HashMap>s and recorded every tile of every warm: the cooling pass went to 2.5 ms a look. The arrays above brought it back.main694, 462 and 332). The three blocks below were run back to back; the description check had compared an earliermainblock (462) with the 366 run and failed. Taken together these runs show no frame-rate change either way.cargo test --workspace -- --test-threads=4, debug, aftercargo build --workspace: 761 passed, 0 failed, 41 ignored. SKIPPED GPU tests:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64 on this GPU).sparse_cool, a cooled tile is warmed by its first write and the write is still watched; a tile written since the look is not cooled;warmrestores write access; a pinned or just-warmed tile is not cooled; a pin warms a cooled tile; only tiles quiet for several looks are cooled; only runs of 16 read-only tiles leave the look; a cut is exact at a run's ends.eh::is_writable_warms_a_cooled_sparse_tile.kernelx::a_cooled_sparse_tile_looks_read_write_to_the_title(XMemVirtualQueryreports read-write; same-processVirtualProtectExreturns read-write as the old protection and puts the tile back in the look), the control @thehollowedone described.Regression run
main:
PR (default,
XCL_SPARSE_COOLunset):PR with
XCL_SPARSE_COOL=1:Not tested
ERROR_NOACCESSrather than leave stale data; that is why it stays off by default.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by dcastell1 on 2026-11-24T10:51:44Z.
Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on
main@67a3735(baseline 735 passed, 0 failed, 41 ignored on this box):Four more passing tests than the baseline; the sparse-tile behaviour when the CPU leaves a tile alone ships its own coverage and it runs green here.
Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T11:32:36Z.
Independent verification, merged onto current
main384f7f7locally (clean merge).Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.
cargo test -p xcl --lib sparse: 20 passed, 0 failed, 1 ignored — all four newsparse_cooltests pass (a_tile_written_since_the_look_is_not_cooled,warm_restores_write_access_for_kernel_writes,a_cooled_tile_is_warmed_by_its_first_write_and_the_write_is_watched,only_tiles_quiet_for_several_looks_are_cooled), and the GPU testgpu_sparse_vram_descriptors_buffers_and_xmempassed on this run.sparse_cool.rsis 381), slightly over the ~400-line PR guideline in CONTRIBUTING — may be fine as one logical change, maintainer's call.AI use: test runs by Devin (Cognition, SWE-2); no code changes.
Imported from ivall/xcl. Originally posted by Rainmaker33 on 2026-11-24T12:03:41Z.
Smoke pair on a fast CPU, as asked in #582: Zen 4, where the look is short to begin with.
Tested
scripts/smoke.ps1:main6efdabc, then this PR's headc31cdfewithXCL_SPARSE_COOLunset and with it set to 1. No overlays running.Result: on this CPU the cooling pass takes back about half of what it saves.
XCL_SPARSE_COOL=1main(10,494 ms write-watch, 72 ms chunk scan).main:
PR,
XCL_SPARSE_COOLunset:PR,
XCL_SPARSE_COOL=1:AI-assisted (Claude Code)
Imported from ivall/xcl. Originally posted by sander110419 on 2026-11-24T12:19:16Z.
Linux/Wine numbers for
XCL_SPARSE_COOL=1on the newer retail title: the looks get smaller, but under Wine both the look and the chunk-scan phase take longer, so the submitting thread spends about twice as long in this code.Written by Claude (claude-opus-5-5) through Hermes, agent of the account owner, posted with his permission. These are Linux/Wine runs, not Windows
smoke.ps1runs.Setup
vm.max_map_countis 2147483642, so mprotect isn't limited by the map count.53aac418(#775's build).XCL_PSO_WAIT_MS=1000, the start screen dismissed automatically.XCL_SPARSE_COOL=1) plus #1119, #1124, #1127 and #1129, none of which touchessparseor the look.The timing lines at 8192 submits
XCL_SPARSE_COOL=1sparse windows: … ms spentThe B run's line at 2048 submits read
write-watch look: 9.044 ms and 3787 MB a look, with chunk scan at 9680 ms. In the earlier run without this PR, chunk scan was 289 ms at 2048 submits.What I take from it:
after_lookruns in. Spread over the 86737 cooled tiles, it comes to about 0.3 ms per tile, which would be theVirtualProtect+GetWriteWatchpair incool_tile, plus the warm-backs. That per-tile split is my estimate; I haven't timed the calls on their own./proc/<pid>/mapsduring a run yet; I will on the next run.+0x23cf683(A at 284 s, B at 272 s). In A the submitting thread is still insidetitle_textures::refresh→sparse::before_executein the thread dumps at 240 s and 298 s. The thread inXMemMapPhysicalPagesScatter→map_pages→release_atwaits onsparse'sSTATEat 298 s.So on Wine this PR's trade (protect calls instead of watched bytes) currently costs more than it saves. Run A has no watched-bytes line (that line comes with this PR), so I can't give A a per-GiB figure. In B the looks cost about 2.4 ms per GiB, both at 2048 submits (9.044 ms for 3787 MB) and at 8192 (6.954 ms for 2880 MB). That is about 1.7× the 1.4 ms per GiB of your Windows bench.
Imported from ivall/xcl. Originally posted by AlexLopezDevelop on 2026-11-24T12:35:06Z.
@Rainmaker33, thanks for the Zen 4 pair: it showed the cooling pass eating half the saving, which I had folded into the chunk-scan line. Pushed
3bc6aa0:cooling pass … ms a look).On the i9-9900K the pass is now 0.095-0.159 ms a look in two 120 s runs, against about 0.6 ms before. The description has the new smoke blocks for
3bc6aa0(default andXCL_SPARSE_COOL=1) and the suite (731 passed, 0 failed, 41 ignored). If you can rerun the same pair on the 8600G, thecooling passfigure in thewrite-watch look:line would show the cost there directly.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by Rainmaker33 on 2026-11-24T13:02:01Z.
Rerun of the same pair at
3bc6aa0on the 8600G: the cooling pass is now 0.015 ms a look here, against about 0.23 ms atc31cdfe, so almost all of the saving is kept.Tested: same machine and setup as above (Ryzen 5 8600G, RTX 3090, driver 32.0.16.1088, Windows 11 26300, rustc 1.92.0, release). Retail 1.0.2.1, unattended at the first menus, 120 s each,
scripts/smoke.ps1, no overlays running.mainis unchanged at6efdabc, so themainblock above still applies.XCL_SPARSE_COOL=1c31cdfe.PR,
XCL_SPARSE_COOLunset:PR,
XCL_SPARSE_COOL=1:AI-assisted (Claude Code)
Imported from ivall/xcl. Originally posted by ivall on 2026-11-24T13:47:27Z.
Thanks – this follows the direction agreed in #582, and the measurements in the description and from @Rainmaker33 and @sander110419 are what was needed. Not merged yet: with
XCL_SPARSE_COOL=1I see the following. Points 1–4 are from reading3bc6aa0, not reproduced in a run; tell me if I misread one.eh.rsis_writableasksVirtualQuery, so a cooled tile is "not writable":ConsoleOnly::ClzeroandClzeroLoopthenreturn 0, and the title gets the illegal instruction instead of a fault your handler could warm. AClzeroLooprange with one read-only tile in it also loses the fast path (the region ends there).is_writableshould warm the range first, with a test.ReadFileagainst the cooling pass.hk_read_filewarms the buffer and then calls the original. A tile that was not cooled yet but has been quiet forQUIET_LOOKScan be cooled by a submitting thread in between, and the kernel's write then fails withERROR_NOACCESS. Buffers a title reads into while it loads are just the kind of tile that has been quiet. A warm has to keep the range from being cooled until the call is done (a pin for the call), or at least for some time after it. The same holds for any other caller that warms for a kernel write.warm_tileraisesGENafterVirtualProtectand after the lock is dropped. Between the two another thread can write the tile without a fault and submit;cached_watch_rangesstill has the ranges of the oldGEN, without the tile, so that write is only seen at the submit after. RaisingGENbeforeVirtualProtect, under the lock, closes it.VirtualProtectExdoes not warm (and reports read-only as the old protection), andXMemVirtualQueryreports a cooled tile as read-only.3bc6aa0, so it is worth repeating; until it wins there, the switch should do nothing under Wine (util::under_wine).sparse_cool:commits into the first one.Tested:
3bc6aa0merged ontomain930e8b4(no conflict), AMD, debug:cargo test --workspace --no-fail-fast -- --test-threads=4: 755 passed, 0 failed, 41 ignored, withXCL_SPARSE_COOLat 0 and at 1. The suite hardly ever makes enough looks for a tile to be cooled, so that says little about the switch.Not tested: a retail title with the switch on.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-24T14:13:20Z.
Confirmed point 4 on
3bc6aa0applied to930e8b4. Windows 11 build 26300, Rust 1.99.1 MSVC, debug.On two synthetic write-watched tiles,
XMemVirtualQueryreturnedPAGE_READONLYfor the cooled tile andPAGE_READWRITEfor its neighbor. A same-processVirtualProtectEx(..., PAGE_READWRITE)also returnedPAGE_READONLYas the old protection. It made the tile writable, but the next CPU write still fell outside the ranges XCL would scan, even though nativeGetWriteWatchsaw the dirty page. Repeating with XCL’s existingVirtualProtectwrapper returnedPAGE_READWRITEas the old protection and kept the dirty tile in the scan. That gives a control for a same-processVirtualProtectExregression test.The stock first-write warming test passed. This was a synthetic memory check. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch fixture and drafted this report.
Imported from ivall/xcl. Originally posted by AlexLopezDevelop on 2026-11-24T14:27:41Z.
@ivall, thanks, you read all four right. Pushed
572d0dd(one commit, on930e8b4):eh::is_writablewarms the range first, so the emulated CLZERO and CLZERO loop see a cooled tile as writable and the loop keeps its fast path. Test:is_writable_warms_a_cooled_sparse_tile.hk_read_filepins its buffer for the whole call (sparse_cool::pin), and any warm keeps the tile from being cooled for 5 s after it, which also covers an overlapped read landing after the call returns and the other callers that warm for a kernel write. The cooling pass checks pins and warm times under the read-only set's write lock, which a warm waits for. Tests:a_pinned_or_just_warmed_tile_is_not_cooled,a_pin_warms_a_cooled_tile.My first version kept pins and warm times in two
Mutex<HashMap>s and recorded every tile of every warm, and the cooling pass went from about 0.1 to 2.5 ms a look on the i9-9900K. They are now two lock-free arrays of 2^18 slots. Tiles 16 GiB apart share a slot, which can only keep a tile writable longer. The pass is back to 0.1 to 0.3 ms a look.warm_tileraises the generation beforeVirtualProtect, under the lock.VirtualProtectExwarms first, so it returns the title's read-write as the old protection, andXMemVirtualQueryreports a cooled tile as read-write. Test:kernelx::a_cooled_sparse_tile_looks_read_write_to_the_title, built from the control @thehollowedone described (thanks).enabled()is false under Wine.Tested: i9-9900K + RTX 2080 Ti, Windows 11.
cargo test --workspace -- --test-threads=4twice: 759 passed, 0 failed, 41 ignored. Smoke pair frommainand572d0ddis in the description: 0 crashes in all three, 929 MB a look with the switch against 1,746 MB without. Frames in 120 s swing about 20 % between runs on this machine in both directions, so these runs show no frame-rate change either way.Not tested: Wine, AMD, the world load.
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by zorde23 on 2026-11-24T14:29:27Z.
AMD RX 6750 XT data point for #1034 (RDNA2, driver 32.0.21045.29003; Ryzen 7 5700X, 32 GB; Windows 11 Pro 26200; release builds, all on
6efdabc)Retail title of #505, 150 s per run with A pressed into world loading,
XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PSO_PRELOAD=0. A local diagnostic counter (not part of either change) sums, per run, the timerefresh_oncespends incached_watch_rangesand in the write-watch looks; two runs each:cached_watch_rangescomputed again6efdabc3bc6aa0,XCL_SPARSE_COOL=1sparse_cool::gen()is part of the cache key incached_watch_ranges, and each cooling pass that cools a tile and each warmed tile bump it, so on this card the extra recomputation (+3.4-3.8 s per run) eats most of what the looks save (-4.6-5.0 s). Keeping the cooled set out of the key (e.g. filtering it after the cached computation, or recomputing only the sparse part) would keep both gains.cargo test --workspace --no-fail-fast -- --test-threads=4at3bc6aa0: 728 passed, 3 failed, 41 ignored; the 3 failures (title_textures::placed_title_textures_share_vram_and_preserve_pixels,title_textures::transitions_apply_when_their_list_is_submitted,vram::d32s8_targets_take_their_own_size_of_video_memory) fail on this GPU on main too.Smoke (default settings, so
XCL_SPARSE_COOLoff; the ~52 GB peak is the preload of #1035, not this PR):main:
PR:
Written with Claude Code from runs on this machine.
Imported from ivall/xcl. Originally posted by AlexLopezDevelop on 2026-11-24T14:58:28Z.
@zorde23, thanks, you were right:
sparse_cool::gen()in the cache key made the ranges again on every cooling pass. Pushedb3c944b:main. The read-only tiles are taken out afterwards, in a second cache keyed on those ranges and ongen(), by a sorted walk of the cooled set.gen()in batches (256 tiles or 64 looks); a warm still raises it at once.GetWriteWatchcall, and that costs more than one 64 KiB tile does.Tested (i9-9900K + RTX 2080 Ti, Windows 11, release, the first menus of the same title as in the description, 120 s, at 1,024 looks):
XCL_SPARSE_COOL=1: ranges made again 28 times, filtered again 317 times in 79 ms in all, 802 MB a look.cargo test --workspace -- --test-threads=4: 761 passed, 0 failed, 41 ignored.Not tested: the world load. A rerun of your counter at
b3c944bwould show whether both gains now hold on the 6750 XT.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by z961089510-dev on 2026-11-24T16:03:57Z.
A heavier configuration than the 1080p runs already posted — 4K display target, a 16 GB NVIDIA card and 31 GB of RAM — and one outcome none of them had: with the feature on the run survives at 30 fps until memory ends it.
Machine
main930e8b4+ this PR (b3c944b), release build,cargo build --release --workspacedxcompiler/dxilfrom X:\game\dxc19\bin\x64)RockstarGamesInc.28872443D20A71.0.2.1, unpacked, on a spinning HDDXCL_NETWORK=0,XCL_ACTIVITY=1xcl shaders --precompile)A/B: the same script, the same run length (300 s) and
XCL_PSO_WAIT_MS=50in both; onlyXCL_SPARSE_COOLdiffers.XCL_SPARSE_COOL=1write-watch lookwrite-watchcumulativeThe look dominates enough here that the smaller scan set takes the run from 7-8 fps to 25-30; note that the baseline also sits at 43 GB by 300 s, so part of its slowdown is paging, not the look alone.
All three runs at the same point (4,096 looks, ~45 s), the third with the default pipeline waits:
XCL_SPARSE_COOL=1=1,XCL_PSO_WAIT_MSunsetwrite-watch lookWhat ends the run with it on: the process aborts, not the title's watchdog:
With the feature off the same title is still running at 300 s. So the growth is not caused by the cooling: it just runs long enough at a usable frame rate to hit it. 4K targets and 31 GB of RAM probably make this the first place it bites — worth knowing before
XCL_SPARSE_COOL=1becomes the default.A third run, same machine and warm caches,
XCL_SPARSE_COOL=1with the default pipeline waits (XCL_PSO_WAIT_MSunset, 600 s cap): 30.0 fps at 600 frames,4096 draws (0 skipped). Then commit runs 57,503 -> 60,579 -> 63,436 MB in four seconds (~1.5 GB/s) and the process is gone at ~50 s. So once the look is out of the way the run is memory-bound, and the faster the title gets, the sooner it reaches it: 15 MB/s while precompiling, ~89 MB/s in the A/B run above, ~1.5 GB/s here.Data from my runs and logs on the machine above. No game files attached.
Imported from ivall/xcl. Originally posted by zorde23 on 2026-11-24T16:30:32Z.
Thanks, re-ran it at
b3c944bon the RX 6750 XT (same machine and method as above; release builds,XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PSO_PRELOAD=0 XCL_SPARSE_COOL=1, A pressed into world loading). Main is930e8b4, the PR's base; both haveb8b1f49reverted locally, since with it memory grows ~1 GB/s here (#1307). A local memory cap stopped every run at 108-118 s on this 32 GB machine, so the numbers are for the first 102 s of each run; two runs each:cached_watch_ranges930e8b4b3c944b3bc6aa0). The second cache filters again ~3 500 times by the 8 192nd look (3 518 / 3 469 in 613 / 597 ms, your "filtered again" line), which is most of the +0.8-1.1 s left incached_watch_ranges.3bc6aa0over the same window of the earlier runs (on6efdabc).cargo test --workspace --no-fail-fast -- --test-threads=4atb3c944b(b8b1f49reverted): 757 passed, 3 failed, 41 ignored; the same 3 GPU tests as before fail on this card on main too.Written with Claude Code from runs on this machine.
Imported from ivall/xcl. Originally posted by 0x6461726B on 2026-11-24T18:23:47Z.
One missed site in
b3c944b(found by reading the code + testingXCL_SPARSE_COOL=1on a retail title):crates/xcl/src/hle/dstorage.rs(writable()) callscrate::hle::kernelx::lazy::ensure(p, n)and then checksVirtualQueryform.Protect & rw != 0(PAGE_READWRITE | ...) before copying into a virtual destination. If a sparse tile inp..p+nwas cooled toPAGE_READONLYbysparse_cool,writable()returnsfalseand the DirectStorage request fails withE_ACCESS_VIOLATION(0x89240009).Calling
crate::hle::d3d12x::sparse_cool::warm(p, n);right afterlazy::ensure(p, n);indstorage::writable()avoids that (same pattern aseh::is_writableandvfs_hooks.rs).Also, on RTX 2060 / i5-10400F (
XCL_SPARSE_COOL=1+#1075),GetWriteWatchover 4,096 submits dropped from ~34.5 s (~8.4 ms/look) to ~18.3 s (~4.5 ms/look) with ~66k sparse tiles cooled.AI-assisted review (Antigravity, Gemini 4 Neon High).
Imported from ivall/xcl. Originally posted by Cxrniani on 2026-11-24T19:26:14Z.
Test report on RDNA4, rebased onto current
main.Setup: AMD Radeon RX 9060 XT (RDNA4, 16 GB), Ryzen 5 5600, 16 GB RAM, Windows 11 Pro 26200, rustc 1.100.0, DXC 1.9.2602, release builds, retail title 1.0.2.1.
b3c944bcherry-picked ontomainc160d86with no conflicts (local commit1f43ebc). Both runs:scripts/smoke.ps1 -Seconds 300, the title's saved state restored before each run,XCL_PRESS_A_ATevery 4 s from 15 s (into world loading),XCL_NETWORK=0; the PR run withXCL_SPARSE_COOL=1.cargo test --release -p xcl --lib sparse_cool: 8 passed, 0 failed, 0 ignored. (Full workspace suite not run on this head.)From the logs (
sparse windows timing, cumulative):mainc160d861f43ebc+XCL_SPARSE_COOL=1DirectStorage: a request failedThe PR's own line at the end:
write-watch look: 1.163 ms and 1292 MB a look over 32768 looks … sparse tiles read-only 17518.Not seen / not tested: the
dstorage.rswritable()case from @0x6461726B's comment did not show up in these 300 s (0 failed requests), which does not rule it out. Presents are capped at 30, so the saved submit-thread time does not show as fps here; past ~300 s of world loading I measured onmain(a different build, with local counters) 9–11 GB per look and presents falling to ~14/s, which these runs do not reach. One run each.AI use: Claude Code (Claude Opus 5.5) ran the builds and measurements and wrote this report.
Imported from ivall/xcl. Originally posted by shelbykb2 on 2026-11-24T21:10:21Z.
A possible hole in the warm path, found on an AMD RX 6800 with a newer retail game. Read against head
b3c944b; my runs use an older head of this PR in a local branch with other changes, so please check it against your code rather than take my word.warm_tilerestores read-write with oneVirtualProtectover the whole 64 KiB tile, and its comment says a failure means the tile was decommitted and nothing is left to restore.VirtualProtectalso fails when only part of the range is no longer committed. The tile then leaves the read-only set while its still-committed pages stayPAGE_READONLY, and the next write there faults with no entry in the set, so the handler passes it on.What I saw: an access violation on a write into a sparse-window tile, from the layer's own code (a descriptor written into the title's heap).
VirtualQueryat the crash showed the read-only region starting 15 pages into the tile, which fits a tile whose first part had been given back. This was with a local experiment that cools far more eagerly than this PR (2 quiet looks, up to 2,048 tiles a look); one crash in one run at 219 s. I have not seen it with this PR's own settings, and I did not find which call decommitted part of the tile without warming it first (a physical-page remap is my guess).What fixed it here: when the whole-tile call fails, walk the tile with
VirtualQueryand restore each committed read-only run separately. Two unit tests: a cooled tile with a decommitted page in the middle is fully writable after the warm; one of them fails without the change. After that, one 300 s run with the eager setting had no crash and no leftover read-only pages.Separately, my numbers for this PR on the RX 6800 as it stands (no eager setting): the per-submit refresh went from 19.2 to 16.4 ms a call in one pair of runs, and I saw no picture change.
Measured in runs on my machine; the analysis and this report were written with Claude Code (Claude Opus 5.5, reviewed with Claude Fable 5.2).
upstream-sync referenced this pull request2026-11-24 23:06:49 +00:00
upstream-sync referenced this pull request2026-11-25 16:10:51 +00:00
Imported from ivall/xcl. Originally posted by 3L1A5-1 on 2026-11-25T21:21:31Z.
Test report on an 8 GB card, with #1034 ported onto current
main.Setup: RTX 2060 SUPER 8 GB, driver 617.14; i5-9400F (6 cores); 16 GB RAM; Windows 11 26300; retail title 1.0.2.1. Release build of
main68a284a+ #1055 + #1102 + #1514 + #640 + #1182, plus this PR cherry-picked (three trivial conflicts:d3d12x/mod.rsmodule line,sparse.rsnext to main'slock_state(),kernelx.rstests). Branch: https://github.com/3L1A5-1/xcl/tree/port/1034-on-main (1da8566= this PR).Measured (one 600 s run each, same exe,
XCL_SPARSE_COOLunset vs1, numbers from thewrite-watch lookline):That is 31-37 % less time per look and 31-43 % less memory watched. Write-watch time per wall second in the menus (29-47 s): 446 ms off vs 271 ms on. No access violations, no new DirectStorage failures, no device removal from the cooling; both runs later ended the same way (video memory), unrelated to this PR. The menu frame rate is capped at 30 fps here, so it shows no fps change.
Two small hardening changes (commit
032ff08on the same branch, +88/-1, ours, compiled and tested here but not yet in a game run that exercises them):dstorage::writable()warms a cooled tile before its protection check, with a test (a_cooled_sparse_tile_is_a_writable_destination). It probably passes without the change too:lazy::ensurealready warms in your head.warm_tile: when part of the tile is decommitted, the whole-tileVirtualProtectfails after the tile has left the cooled set.restore_committed_runsnow restores each committed read-only run (VirtualQuerywalk), with a test (warm_restores_a_cooled_tile_with_a_decommitted_page).Feel free to take either into the PR.
AI-assisted: yes (Claude Code, Claude Opus 5.5) — the port, the two changes and the runs above.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T03:41:00Z.
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T17:27:24Z.
Triage note: this no longer merges with current
main(mergeable=false,DIRTY), so it can't be built or tested as it stands.If it's still wanted, a rebase would make it testable. It's relevant to a present-path cost we're measuring on an RTX 5070 Ti: write-watch scans over title-texture pages reach about 2.1 M dirty pages and up to ~6 s of scan time per run, so tiles the CPU leaves alone are worth taking out of the watch.
If it has been superseded, saying so is enough and it can be closed.
AI use: an agent posted this triage note.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:40:45Z.
Triage (#1607) – head
b3c944bNo open or merged PR makes the same change. #2754 / #3242 also shrink the write-watch look, but they leave out VRAM-only sparse tiles and GPU-written textures; they do not make quiet tiles read-only. That is a different approach.
Points to check (off by default with
XCL_SPARSE_COOL): onlyReadFileis pinned for kernel writes. Other kernel paths that write title memory (ReadFileEx,NtReadFile,DeviceIoControloutput buffers, DirectStorage file reads that do not go throughhk_read_file) would fail with ERROR_NOACCESS on a cooled tile instead of faulting.as_title_seesfixes the protection only inXMemVirtualQuery; a plainVirtualQueryhook still shows PAGE_READONLY. The PR conflicts with main.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.