Skip to content

Title textures: the write watch scans in a few calls, not thousands - #551

Open
duudiis wants to merge 1 commit into
ivall:mainfrom
duudiis:pr-watch-gap
Open

duudiis wants to merge 1 commit into
ivall:mainfrom
duudiis:pr-watch-gap

Conversation

@duudiis

@duudiis duudiis commented Nov 24, 2026

Copy link
Copy Markdown

Before each submit, title_textures::refresh asks the write watch which pages the CPU wrote. The watched ranges (title textures and mapped sparse tiles) were merged only across gaps under 1 MiB, so on a retail game that streams its world the look made thousands of GetWriteWatch calls before every submit. A call costs about 3.5 µs however little it covers, while one call over 2 GiB of committed pages takes about 1.3 ms (a small GetWriteWatch benchmark on this machine), so the calls, not the bytes, were the cost: sampling the title's threads during its intro video put the submitting thread at 42 % in GetWriteWatch (on a local build with other changes, not on main).

This merges ranges up to 64 MiB apart into one scan. The pages in a gap are reported as written too, which the uploads already tolerate: they keep to the textures and tiles they track. The merged ranges are also clipped to the write-watched regions with a binary search per region instead of a pass over every merged range for each region; both lists run to thousands while a game streams.

I searched open and closed PRs for "write watch", "WATCH_GAP", "watch_ranges" and "GetWriteWatch calls" first. #486 (skip unchanged uploads) and #440 / #451 / #455 / #458 / #465 (faster detile and upload) work on the uploads after the look; none of them changes the look itself, so this should stack with them.

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs: WATCH_GAP 1 MiB → 64 MiB (with the measurements in its comment); watch_ranges clips with partition_point per region; watch_ranges_clip_and_merge checks the new gap, a merged range over two regions given in either order, and a region between and past the merged ranges.

Tested

  • Intel Core i7-14700KF, NVIDIA GeForce RTX 5070 (12 GB), Windows 11 Pro 10.0.26300, Rust stable (MSVC), release build.
  • cargo build --workspace then cargo test --workspace --release -- --test-threads=4 on 712bbbe: 677 passed, 0 failed, 41 ignored (lib 637 / 0 / 21).
  • SKIPPED on this adapter: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64).
  • A retail title, scripts/smoke.ps1 -Seconds 60, main and this PR in turns, five pairs (frames shown, main → PR): 469 → 536, 561 → 369, 555 → 524, 547 → 556, 944 → 1517. No device removal or crash in any of the ten runs; the PR's peak commit was at or below main's each time (14,604 – 15,067 MB vs 15,057 – 15,962 MB).
  • The 60 s runs end on the title's start screen and the loading before its intro video, where only ~2.6 GB is watched, and their frame counts vary more from run to run on this machine than the change can move them (I take the 561 → 369 pair for that noise: a cargo build may have run beside it, I did not check). The pair below is the fourth.

Regression run

main:

xcl-smoke v1
commit: 7ebf1b8044bef8f0ef296eb36e85010cceb4633a
gpu: NVIDIA GeForce RTX 5070
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 547 (PresentX 547)
presents per 2 s (last 3): 14 13 14
device removals: 0
crashes: 0
peak commit: 15057 MB

this PR's head:

xcl-smoke v1
commit: 712bbbe4e5163b5fe479cccfa0b3ff636ecf8fd8
gpu: NVIDIA GeForce RTX 5070
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 556 (PresentX 556)
presents per 2 s (last 3): 14 13 14
device removals: 0
crashes: 0
peak commit: 15055 MB

Not tested

  • AMD and other NVIDIA GPUs; an AMD CPU.
  • The effect on its own over longer play: the 60 s runs end on the title's start screen / loading, so they cover the look's cost there, not in its world.

AI use

  • Claude Code with Claude Opus 5.5: found the cost with a sampling profiler and a GetWriteWatch benchmark, wrote the change, its test and this description. I ran the tests and the smoke runs on the hardware above.

A write-watch call costs about 3.5 µs however little it covers, while one
call over 2 GiB of committed pages takes about 1.3 ms (measured with a
small GetWriteWatch benchmark on Windows 11). With ranges merged only
across gaps under 1 MiB, the look before each submit made thousands of
calls over a retail game's mapped sparse tiles: its intro video had the
submitting thread at 42 % in GetWriteWatch (sampled). Ranges under 64 MiB
apart are now one scan; the pages in a gap are reported written as well,
which the uploads already tolerate (they keep to what they track).

The ranges are clipped to the write-watched regions with a binary search
per region instead of a pass over every merged range for each region:
both lists run to thousands while a game streams its world.

Assisted-by: Claude Code (Claude Opus 5.5)
@thehollowedone

Copy link
Copy Markdown

I checked the boundary where a merged range produces more dirty pages than the 16,384-entry buffer. A scratch test used XCL’s watch_ranges on a Windows write-watch allocation with two one-page ranges separated by just under 64 MiB. They merged into one range. After writing all 16,385 pages, repeated GetWriteWatch calls with reset reported 16,384 pages, then 1, then 0. The returned addresses matched every written page exactly once. Tested commit 712bbbe

With the scratch test added, cargo test --offline --locked -p xcl --lib watch_ -- --test-threads=1 --nocapture reported 2 passed, 0 failed, 0 ignored, including the PR’s range test. Windows 11 build 26300, Ryzen 7 9800X3D, Rust 1.99.1 MSVC, debug. This run checked clipping and the Windows reset batches. It did not measure upload performance, run the full workspace, or use retail data.

AI use

Codex with GPT-6.2 Sol wrote and ran the scratch check and drafted this report.

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