Repository navigation
Memory: sparse tiles the CPU leaves alone leave the write-watch look (#582, off by default) - #1034
AlexLopezDevelop wants to merge 1 commit into
Conversation
|
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 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. |
|
Independent verification, merged onto current Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.
AI use: test runs by Devin (Cognition, SWE-2); no code changes. |
|
Smoke pair on a fast CPU, as asked in #582: Zen 4, where the look is short to begin with. Tested
Result: on this CPU the cooling pass takes back about half of what it saves.
main: PR, PR, AI-assisted (Claude Code) |
|
Linux/Wine numbers for 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 Setup
The timing lines at 8192 submits
The B run's line at 2048 submits read What I take from it:
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. |
…, and skips cooled tiles Rainmaker33's Zen 4 run on xcl-dev#1034 measured the pass at 0.23 ms a look, half of what the shorter look saved there. Each look examined up to 4096 tiles through a HashMap and asked the read-only set again for every tile already cooled. Now the quiet state is a Vec indexed like the tile list (rebuilt when the mapped tiles change), a cooled tile is marked in it and skipped until a write marks it again, and a look examines at most 1024 tiles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@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
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 AI-assisted (Claude Code, Claude Opus 5.5). |
|
Rerun of the same pair at 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,
PR, PR, AI-assisted (Claude Code) |
|
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
Tested: Not tested: a retail title with the switch on. |
|
Confirmed point 4 on On two synthetic write-watched tiles, 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. |
3bc6aa0 to
572d0dd
Compare
|
@ivall, thanks, you read all four right. Pushed
Tested: i9-9900K + RTX 2080 Ti, Windows 11. Not tested: Wine, AMD, the world load. AI-assisted (Claude Code, Claude Opus 5.5). |
|
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 Retail title of #505, 150 s per run with A pressed into world loading,
Smoke (default settings, so main: PR: Written with Claude Code from runs on this machine. |
…vall#582) Behind XCL_SPARSE_COOL=1 (off by default, and off under Wine), a 64 KiB tile of a sparse window with no written page for 8 looks is made read-only and left out of the GetWriteWatch look. Its first CPU write faults; a vectored handler makes it writable again and the next look takes it back, the write itself in the write watch as before. A tile written between the look and the protect stays writable. The look's ranges are made again before a warmed tile can be written without a fault. Writes that do not fault warm the range first: kernelx::lazy::ensure (the ReadFile hook, DirectStorage, cpu_writes), the emulated CLZERO's writability check, and the title's commit, decommit, VirtualProtect and VirtualProtectEx. A ReadFile pins its buffer for the call, and any warmed tile stays warm for 5 s, so a cooling pass cannot protect it under a kernel write in progress. XMemVirtualQuery reports a cooled tile as the title left it (read-write). The cooling pass keeps one slot per tile in a Vec indexed like the tile list, skips cooled tiles, examines at most 1024 tiles and cools at most 64 a look, and rebuilds the tile list at most every 64 looks. The timing line adds ms and MB per look, the read-only tile counts and the pass's own time per look. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
572d0dd to
b3c944b
Compare
|
@zorde23, thanks, you were right:
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):
Not tested: the world load. A rerun of your counter at AI-assisted (Claude Code, Claude Opus 5.5). |
|
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
A/B: the same script, the same run length (300 s) and
The 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:
What 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 A third run, same machine and warm caches, Data from my runs and logs on the machine above. No game files attached. |
|
Thanks, re-ran it at b3c944b on the RX 6750 XT (same machine and method as above; release builds,
Written with Claude Code from runs on this machine. |
|
One missed site in
Calling Also, on RTX 2060 / i5-10400F ( AI-assisted review (Antigravity, Gemini 4 Neon High). |
|
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.
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). What fixed it here: when the whole-tile call fails, walk the tile with 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). |
Part of #582: step 1-2 of the plan there (direction agreed in #582 (comment) and claimed in #582 (comment)). 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