Repository navigation
Title textures: the write watch scans in a few calls, not thousands - #551
Conversation
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)
|
I checked the boundary where a merged range produces more dirty pages than the 16,384-entry buffer. A scratch test used XCL’s With the scratch test added, AI use Codex with GPT-6.2 Sol wrote and ran the scratch check and drafted this report. |
|
One point on the wider gap, not covered by the boundary test above: a write to a page in a merged gap is reset by a look that watches it for nobody. If the page is wanted later, the first look that watches it no longer reports that write. With a 1 MiB gap the same happens only within 1 MiB of a watched range. The test below, CPU only, on
It passes on test (in title_textures.rs's tests)/// A page the CPU writes while no texture or mapped tile wants it, and that is wanted later (a
/// tile mapped after the write), is reported by the first look that watches it.
#[test]
fn a_write_before_its_page_is_wanted_is_found_once_it_is() {
use windows_sys::Win32::System::Memory::{VirtualAlloc, VirtualFree, MEM_COMMIT, MEM_RELEASE, MEM_RESERVE, PAGE_READWRITE};
const MEM_WRITE_WATCH: u32 = 0x20_0000;
const SIZE: usize = 64 << 20;
unsafe {
let base = VirtualAlloc(std::ptr::null(), SIZE, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE) as usize;
assert!(base != 0);
let regions = [(base, SIZE)];
let look = |ranges: &[(usize, usize)]| {
let mut found = Vec::new();
let mut buf = vec![std::ptr::null_mut::<c_void>(); 16384];
let mut page = 0u32;
for &(b, s) in ranges {
let mut n = buf.len();
assert_eq!(GetWriteWatch(WRITE_WATCH_FLAG_RESET, b as *const c_void, s, buf.as_mut_ptr(), &mut n, &mut page), 0);
found.extend(buf[..n].iter().map(|&p| p as usize));
}
found
};
// two wanted pages 32 MiB apart; `p` between them, wanted by nobody yet
let (a, b, p) = (base, base + (32 << 20), base + (16 << 20));
let wanted = vec![(a, a + 0x1000), (b, b + 0x1000)];
look(&watch_ranges(®ions, wanted.clone())); // a clean start
(p as *mut u8).write_volatile(1);
look(&watch_ranges(®ions, wanted.clone())); // a look before `p` is wanted
let mut later = wanted;
later.push((p, p + 0x1000));
let found = look(&watch_ranges(®ions, later));
VirtualFree(base as *mut c_void, 0, MEM_RELEASE);
assert!(found.contains(&p), "the write to {p:#x} was reset by a look that watched it for nobody");
}
}Where XCL relies on that report (from the code on
Question for @duudiis: does "the uploads keep to what they track" in the new The cost side, on a retail title (RTX 5070 Ti, Ryzen 9 9950X, release, 60 s of the first menus with no input, one run each;
Tested
Not tested
🤖 Claude Opus 5.5 |
|
Thanks, both of you. @Kalmarv, you're right: "the uploads keep to what they track" does not cover a tile that gets video memory after its page was written. A look that watches that page for nothing resets its report, and I'm turning this into a draft. The fix I'm testing follows your first option: each tile AI use: Claude Code with Claude Opus 5.5 checked the review against the code, wrote the fix and its test, and drafted this reply. |
|
Test run of Tested
Review: The new loop gives the same pieces as the old one: each region looks up the first merged range ending after its base and takes those starting before its end, so every piece stays inside one region, now with a binary search instead of a pass over all merged ranges per region. A question rather than a finding: Not tested: no retail title or regression run (I have no unpacked game), no Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code. |
|
Test report for Setup: AMD Radeon RX 9070 XT 16 GB, driver 32.0.32015.2008, AMD Ryzen 7 9800X3D, 31 GB RAM, Windows 11 25H2 build 26200.9974, rustc 1.100.0 Tests: Title runs:
Regression run:
PR merged onto PR head: Not tested: the time spent in AI use: Claude Code with Claude Opus 5.5 built the commits, ran the tests and the title runs, read the logs, and wrote this report. The runs were made on my machine. |
|
@Chrysana, thanks for the AMD runs. One correction: the 🤖 Claude Opus 5.5 |
…-watch merge Integrates upstream PRs ivall#594, ivall#640, and ivall#551: - Order reserved-texture tile unmaps behind known title queues with GPU fences before releasing tiles back to pools (ivall#594). - Add opt-in XCL_PAGE_BUDGET_MB to evict LRU CPU-filled title textures when texture page pools hit the cap, remapping and re-uploading on use (ivall#640), preventing unbounded VRAM growth during world streaming. - Merge write-watch scan gaps up to 64 MiB and clip regions with binary search to cut GetWriteWatch overhead during streaming (ivall#551).
…-watch merge Integrates upstream PRs xcl-dev#594, xcl-dev#640, and xcl-dev#551: - Order reserved-texture tile unmaps behind known title queues with GPU fences before releasing tiles back to pools (xcl-dev#594). - Add opt-in XCL_PAGE_BUDGET_MB to evict LRU CPU-filled title textures when texture page pools hit the cap, remapping and re-uploading on use (xcl-dev#640), preventing unbounded VRAM growth during world streaming. - Merge write-watch scan gaps up to 64 MiB and clip regions with binary search to cut GetWriteWatch overhead during streaming (xcl-dev#551).
…-watch merge Integrates upstream PRs xcl-dev#594, xcl-dev#640, and xcl-dev#551: - Order reserved-texture tile unmaps behind known title queues with GPU fences before releasing tiles back to pools (xcl-dev#594). - Add opt-in XCL_PAGE_BUDGET_MB to evict LRU CPU-filled title textures when texture page pools hit the cap, remapping and re-uploading on use (xcl-dev#640), preventing unbounded VRAM growth during world streaming. - Merge write-watch scan gaps up to 64 MiB and clip regions with binary search to cut GetWriteWatch overhead during streaming (xcl-dev#551).
|
Test report for Tested
All four runs: exit
Base block (pair 1): Head block (pair 1): Not tested
AI use |
|
Regression run of Tested
main (e50836b): this PR (712bbbe): What this does and does not say
Not tested
AI use
|
…-watch merge Integrates upstream PRs ivall#594, ivall#640, and ivall#551: - Order reserved-texture tile unmaps behind known title queues with GPU fences before releasing tiles back to pools (ivall#594). - Add opt-in XCL_PAGE_BUDGET_MB to evict LRU CPU-filled title textures when texture page pools hit the cap, remapping and re-uploading on use (ivall#640), preventing unbounded VRAM growth during world streaming. - Merge write-watch scan gaps up to 64 MiB and clip regions with binary search to cut GetWriteWatch overhead during streaming (ivall#551).
…copy A compute pipeline's first bind waits for its build. When a worker is already building it, the title's thread waited on that one build for as long as it took: on a retail title's world loading (RTX 5060 Ti, main f4ce27c) cdb showed 10 of 11 DXC threads and 10 of 11 pipeline workers parked, one build in flight, and the render thread in resolve_wait's condvar. Frames stopped, and the title's watchdog crashed it at +0x23cf683 at 93-101 s on four runs (xcl-dev#232, xcl-dev#581), with and without xcl-dev#690's preloading. After a grace period (250 ms; XCL_PSO_HELP_MS, 0 = off) the waiting thread builds a second copy itself, and the first of the two to finish is the pipeline (complete: the later one is released). go_background supplies the second copy's build; the descriptor is shared read-only (SharedDesc). A pipeline no run used still waits for its worker as before. Measured, same input and caches, 300 s runs that reach world loading: crash at 152.6 s instead of 93.4 / 100.4 s; 2669 frames instead of 1324 / 1443; background pipelines built 50987 against 121 / 866 on main. It does not reach gameplay: the next wait on the title's thread is the title-texture write-watch refresh (xcl-dev#551) and XMemMapPhysicalPagesScatter (xcl-dev#156). Assisted-by: Claude Code (Claude Opus 5.5)
|
Correction: please disregard the speed-up and write-watch numbers in my first version of this comment. I attributed them to this PR and that was wrong. The earlier text is replaced by what I can actually support. I ran this PR merged onto Tested
Not tested
AI use
|
…-watch merge Integrates upstream PRs ivall#594, ivall#640, and ivall#551: - Order reserved-texture tile unmaps behind known title queues with GPU fences before releasing tiles back to pools (ivall#594). - Add opt-in XCL_PAGE_BUDGET_MB to evict LRU CPU-filled title textures when texture page pools hit the cap, remapping and re-uploading on use (ivall#640), preventing unbounded VRAM growth during world streaming. - Merge write-watch scan gaps up to 64 MiB and clip regions with binary search to cut GetWriteWatch overhead during streaming (ivall#551).
|
Tested on RTX 2080 Ti (Turing, driver 621.24) + Intel i9-9900K, Windows 11, 32 GB, retail 1.0.2.1, merged onto #891 + #631 (
Not tested: the full AI-assisted (Claude Code, Claude Opus 5.5). |
|
Merged (02bfd1d), from the draft: AlexLopezDevelop's run shows the menus going from 2-4 to ~6.8 fps on a CPU where the look dominates, and it stacks with #693. Checked on main 02bfd1d together with #891, #693, #551 and #631: |
Before each submit,
title_textures::refreshasks 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 ofGetWriteWatchcalls 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 smallGetWriteWatchbenchmark 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 % inGetWriteWatch(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_GAP1 MiB → 64 MiB (with the measurements in its comment);watch_rangesclips withpartition_pointper region;watch_ranges_clip_and_mergechecks the new gap, a merged range over two regions given in either order, and a region between and past the merged ranges.Tested
cargo build --workspacethencargo test --workspace --release -- --test-threads=4on712bbbe: 677 passed, 0 failed, 41 ignored (lib 637 / 0 / 21).gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64).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).Regression run
main:
this PR's head:
Not tested
AI use
GetWriteWatchbenchmark, wrote the change, its test and this description. I ran the tests and the smoke runs on the hardware above.