Skip to content

[upstream #1034] Memory: sparse tiles the CPU leaves alone leave the write-watch look (#582, off by default) - #107

Closed
ufoptg wants to merge 3 commits into
mainfrom
upstream-pr/1034
Closed

ufoptg wants to merge 3 commits into
mainfrom
upstream-pr/1034

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Part of xcl-dev#582: step 1-2 of the plan there (direction agreed in xcl-dev#582 (comment) and claimed in xcl-dev#582 (comment)). Off by default: XCL_SPARSE_COOL=1 turns it on.

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 the GetWriteWatch look. 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 4,096 examined per look, so the extra cost of a look is bounded.
  • A tile written between the look and the protect is not cooled: after VirtualProtect a non-resetting GetWriteWatch on the tile undoes it if a page was written meanwhile (test a_tile_written_since_the_look_is_not_cooled).
  • Writes that do not fault are warmed first: kernelx::lazy::ensure (so the ReadFile hook, DirectStorage destinations and cpu_writes), the title's VirtualProtect and sparse commit, and sparse::committed / decommitted.
  • The handler only takes the module's own lock, never sparse's STATE, so a readback that writes title memory under STATE and faults does not deadlock.
  • sparse::mapped_ranges leaves the read-only tiles out, and the look's range cache (title_textures::cached_watch_ranges) is keyed on the module's generation too.
  • The sparse timing line gets a second line: ms and MB per look, and the read-only / cooled / warmed tile counts. These are the numbers D3D12.X: the write-watch look scans 1.5 GiB before every submit while 4 pages are written (measurement and plan) xcl-dev/xcl#582 asked the PR to carry.

Tested

XCL_SPARSE_COOL unset XCL_SPARSE_COOL=1
MB looked at per look 1,780 951
ms per look (mean over the run, cooling ramps up at 64 tiles a look) 8.98 7.10
write-watch total 18,400 ms 14,535 ms
chunk scan (now includes the cooling pass) 176 ms 1,452 ms
presents per 2 s (last 3) 7 9 11 11 13 15
tiles read-only at the end (cooled / warmed) 0 13,429 (14,318 / 889)

What stays in the look (951 MB) is the kept-in-step textures and the graphics reservations, step 3 of the plan. The cooling pass costs about 0.6 ms a look here (chunk scan line), which is the next thing to trim.

  • Update (3bc6aa0), after Rainmaker33's Zen 4 run measured the cooling pass at 0.23 ms a look: the quiet state is a Vec indexed like the tile list instead of a HashMap, cooled tiles are skipped until a write marks them again, a look examines at most 1,024 tiles, and the tile list is rebuilt at most every 64 looks (the title maps and unmaps tiles all through a load). The timing line now prints the pass's own time: 0.095 to 0.159 ms a look on the i9-9900K in two 120 s runs, against about 0.6 ms before (the chunk-scan difference above). Same machine, 3bc6aa0, 120 s, at 1,024 looks: 1,351 MB a look unset, 862 MB a look with XCL_SPARSE_COOL=1 (13,427 tiles read-only, 621 warmed); ms per look were about equal in this pair (6.22 / 6.30), with the dirty-page count differing between the runs (520,462 / 321,431), so on this CPU the reset of written pages, not the bytes, set the time in these two runs.
  • cargo test --workspace -- --test-threads=4: 731 passed, 0 failed, 41 ignored (debug, after cargo build --workspace). SKIPPED GPU tests: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64 on this GPU).
  • New unit tests in sparse_cool: a cooled tile is warmed by its first write and the write is still in the write watch; a tile written since the look is not cooled; warm restores write access for kernel writes; only tiles quiet for several looks are cooled.

Regression run

main:

xcl-smoke v1
commit: 6efdabcdaac93ce5cc123a85e85deba5d49cb294
gpu: NVIDIA GeForce RTX 2080 Ti
title: GTA6.Xbox exported
seconds: 120
exit: 0x0
frames shown: 373 (PresentX 373)
presents per 2 s (last 3): 6 6 6
device removals: 0
crashes: 0
peak commit: 16632 MB

PR (default, XCL_SPARSE_COOL unset):

xcl-smoke v1
commit: 3bc6aa062e57e4e7beaf0698cec96727f33ffc96
gpu: NVIDIA GeForce RTX 2080 Ti
title: GTA6.Xbox exported
seconds: 120
exit: 0x0
frames shown: 420 (PresentX 420)
presents per 2 s (last 3): 7 7 7
device removals: 0
crashes: 0
peak commit: 16747 MB

PR with XCL_SPARSE_COOL=1:

xcl-smoke v1
commit: 3bc6aa062e57e4e7beaf0698cec96727f33ffc96
gpu: NVIDIA GeForce RTX 2080 Ti
title: GTA6.Xbox exported
seconds: 120
exit: 0x0
frames shown: 414 (PresentX 414)
presents per 2 s (last 3): 5 5 5
device removals: 0
crashes: 0
peak commit: 16776 MB

Not tested

AI use

  • Claude Code (Claude Opus 5.5): wrote the code and the tests, ran the builds, the tests, the bench and the smoke runs on the machine above, and wrote this description; reviewed and run by me.

🤖 Generated with Claude Code


Mirror of xcl-dev#1034 (auto-synced, do not edit).

AlexLopezDevelop and others added 3 commits November 24, 2026 11:26
…cl-dev#582)

Behind XCL_SPARSE_COOL=1 (off by default), 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 kernel's writes (kernelx::lazy::ensure: ReadFile, DirectStorage,
cpu_writes) and the title's commit, decommit and protect calls warm the range
first. At most 64 tiles are cooled and 4096 examined per look.

The timing line adds ms and MB per look and the read-only tile counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, 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>
…ooling pass

The title maps and unmaps tiles all through a load, and each change rebuilt
the list of ~118,000 tiles and its index. Now a changed list is rebuilt at
most every 64 looks; a tile mapped meanwhile waits for the next rebuild, one
unmapped meanwhile fails cool_tile's query. The timing line now gives the
cooling pass's own time per look (0.095 ms on an i9-9900K).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1034 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1034 branch November 25, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants