Repository navigation
Backlog
Labels
goal:world-loadBears on the retail title getting past world loading
Description
For HANDOFF's open item ("a write-watch scan of textures in the 4 GiB coherent window costs in proportion to their size at every submit; a page guard … was tried and reverted pending measurement past the menus") and @srcamarda's numbers in #347 (comment): where the look's time goes on main 508a0c7, and a plan. No code yet; @ivall, a yes or no on the direction first, since it is the read-only idea again.
Measured on a retail title's first menus (30 presents and 120 looks a second, 30 s of them):
- A look takes 0.83 ms, 10 % of wall time, and 99.7 % of that is inside
GetWriteWatch: the range cache costs 0.2 µs, the sort 0.04 µs, no range was rebuilt. - It makes 69 calls over 1,641 MB: 879 MB of sparse tiles with video memory, 545 MB of kept-in-step textures in the coherent window and 199 MB in the title's graphics reservations (745 textures), 18 MB of gaps.
- 4 pages a look come back written. Counted in 2 MiB blocks: 1.1 blocks a look, and 7 or 8 of the 844 blocks in any 2 s.
- Nothing waits: a one-page
GetWriteWatchon a page of our own took 1.5 µs (8 µs at most), so this phase has none of the stalls of Memory: writes into a sparse window are checked without VirtualQuery #501. - No texture is marked GPU-written, so leaving those out of the ranges would save nothing.
- A synthetic bench (no XCL code): a clean call costs 1.15 µs plus 0.45 ms per GiB of committed pages, the same with or without the reset flag, and no faster split over 2 to 8 threads. That gives 0.77 ms for the ranges above. So about 90 % of the look is pages nobody wrote.
- Title textures: the write watch scans in a few calls, not thousands #551 (fewer calls, wider gaps) is the other 10 % here: 19 calls over 2,218 MB instead of 69 over 1,641 MB, and 0.96 ms a look against 0.94 ms on
mainin matched runs, inside the spread between runs (mainwith only the counters added took 0.83). It should help where there are thousands of ranges; this phase has 69. The two changes do not overlap.
Plan
- A 64 KiB block of the watched ranges with no written page for N looks is made read-only and leaves the look. Its first write faults; a vectored handler sets an atomic bit, makes the block writable, and the next look scans it again. Measured: 3 µs for such a first write, 1 µs to protect a block; a bounded number of blocks cooled per look bounds the cost when everything is written. On these menus about 16 MiB would stay in the look: about 0.02 ms instead of 0.83.
- First PR: the sparse windows only (54 % of the bytes), off by default behind an environment variable, with the kernel's writes routed where lazy pages already route them (
kernelx::lazy::ensurein the ReadFile hook, DirectStorage andcpu_writes), and the title's own commit, decommit and protect calls warming the block first.ReadFileinto a read-only page fails with error 998 in the bench, as HANDOFF says; a call XCL does not route would fail loudly, not leave stale data. - Then the textures in the reservations, and the coherent window only after a GPU test shows that the imported heap takes read-only pages.
Tested
- RTX 5070 Ti (NVIDIA 610.74), Ryzen 9 9950X, Windows 11 26200, release builds,
XCL_NETWORK=0, 60 s, no input, one run each:main508a0c7; the same with local counters aroundrefresh_once(not in any PR);508a0c7with Title textures: the write watch scans in a few calls, not thousands #551 (712bbbe) merged. No crash or device removal in the three. - The synthetic numbers: a standalone program on the same PC, 1 GiB of write-watched memory, medians of 5 to 25.
Not tested
- World loading and anything after the first menus: the runs take no input. The design itself: no code exists.
- AMD GPUs and CPUs, Wine, a debug build.
🤖 Claude Fable 5.2
Metadata
Metadata
Assignees
Labels
goal:world-loadBears on the retail title getting past world loading
Activity
iggyvilla commentedon Nov 24, 2026
Past the first menus, on an 8 GB AMD card with the game on a hard drive, the look gets slower while the bytes it scans stay the same, and the time goes to
VirtualQuerycalls on the title's render thread. That is #501's mechanism through two other checks.Measured
9ce2070with local counters aroundrefresh_once(not in any PR), after the account prompt: a look went from about 1 ms to 7–8 ms with the same 1.57 GB scanned every look. Once the title recovered it was 2.3 ms for the same 1.57 GB. So the extra time is not the byte count, and wider gaps (Title textures: the write watch scans in a few calls, not thousands #551) or fewer bytes (the read-only plan above) would not remove it. The read-only plan still applies to the 2.3 ms that is left.NtQueryVirtualMemory. With the symbols resolved:list_x::gpu_va(list_x.rs:1810) →gpu::shader::readable, fromia_set_vertex_buffers_xia_set_index_buffer_xtimestamp→cpu_writes::writable(list_x.rs:1169), fromWrite64BitValueBottomOfPipeXwith a timestamp flag into memory outside unified memoryNtGetWriteWatch(refresh_once). We took no thread dumps of single waits the way Memory: writes into a sparse window are checked without VirtualQuery #501 did, so the link between the two (the walks holding the address space whileGetWriteWatchwaits) is an inference from the timing.readableasksresident_and_readablefirst. On a cold address space the pages are not resident yet, so every bind falls through to theVirtualQuerywalk.gpu_vamakes that check before it looks for the buffer's existing mirror, so a buffer that already has a mirror still pays for the walk at every bind.#693 fixes the
gpu_vapart (look up the mirror first, keepreadablefor the first bind). Profiled at 125 s ondd2ae9aagainst #693: the render thread went from 92 % to 25 % of a core and thegpu_vawalk was no longer sampled, but fps stayed at 10–11. With the render thread mostly waiting, the limit is now the submit thread, at 86–89 % of a core on both builds intitle_textures::refreshandNtGetWriteWatchunderExecuteCommandLists. So for this issue the look's cost itself is what is left.Tested
XCL_NETWORK=0, a retail title (game files on a hard drive), Enter pressed past the first menu (50–75 s).main508a0c7: 30 fps for the first ~55 s, then 12 fps at 80 s and 3.5 fps at 261 s. Another CPU-heavy job was running during that run.9ce2070plus the local counters, machine quiet: the look numbers above. Profile with a stack sampler of our own, symbols from the build's PDB.Not tested
timestamppath (D3D12.X: honour OS QPC timestamp flags and atomic 64-bit CPU writes (#103) #317), any change to the look.AI use
Kalmarv commentedon Nov 24, 2026
@iggyvilla, thanks. This is the phase my runs never reached: they take no input.
#693 and #501 (read at
f44cc79and81c43fe, nothing run)dstorage::writableandeh::is_writable, from the sparse windows' record, and only for an address inside a sparse window. D3D12.X: a vertex or index buffer with a mirror is bound without VirtualQuery #693 is ingpu_va, which returns early for any address inside unified memory, so its buffers are ones that record never holds.list_x.rsagainstsparse.rs,dstorage.rs,eh.rs,kernelx.rs). D3D12.X: a vertex or index buffer with a mirror is bound without VirtualQuery #693 merges cleanly onto Memory: writes into a sparse window are checked without VirtualQuery #501 merged ontomain63cdc25.mainf4ce27c:gpu::shader::readableasks the working set for at most 16 pages. A range over 64 KiB goes to theVirtualQuerywalk even when every page is resident, so it is not only the cold address space. After D3D12.X: a vertex or index buffer with a mirror is bound without VirtualQuery #693 that is left at the first bind of a range and insync_title_buffers, which callsreadableat each draw for the part it reads.cpu_writes::writable, your 18.5 % on the timestamp path, is oneVirtualQuerywith nothing before it.Does the plan change? The direction stays; the order changes, and one detail.
refreshandNtGetWriteWatchat 10–11 fps. Three counters at that point would say what it is made of: looks a second, bytes a look and milliseconds a look. If the time follows the bytes, the plan is the fix for that phase; if it follows the number of calls, Title textures: the write watch scans in a few calls, not thousands #551 is; if neither, something else is inGetWriteWatchthere and the plan should wait for it. Do you still have the build with the counters?known_writable, a resident page without a writable protection: the check falls back to the walk, and the walk answers no. So the warm-up has to come beforeknown_writableindstorage::writable, andeh::is_writable(emulated CLZERO) has to be added to the places the plan routes; it lists DirectStorage,ReadFileandcpu_writesonly.Not tested
main. No run past the first menus exists on this PC yet.🤖 Claude Fable 5.2
AlexLopezDevelop commentedon Nov 24, 2026
A data point where the look is the whole frame budget: RTX 2080 Ti + Intel i9-9900K (Coffee Lake), Windows 11, 32 GB, retail 1.0.2.1, #891 (
8cada26) withXCL_PSO_WAIT_MS=50, first-run setup and into the world load, walked by hand. The title sits at 2-3.4 fps the whole run, with the window caption showing0 runningpipeline compiles, and the periodic timing lines are:sparse 7447 MBin the same run's counters. So on this machineGetWriteWatchgrows with the dirty-page count far past the 0.83 ms a look measured above, and nothing else in the timing line comes close. For comparison, on the same PC another loader for this title that copies only changed title memory runs the same menus at about 30 fps.Not measured: per-look time (only these aggregates), and the same run on
main.AI-assisted (Claude Code, Claude Opus 5.5).
AlexLopezDevelop commentedon Nov 24, 2026
Follow-up to my numbers above, a longer run on the same machine (RTX 2080 Ti + i9-9900K), now #891 + #631 so neither the pipeline waits (#846) nor the BVH address (#585) stop it. The look keeps growing, and the title's watchdog fires anyway:
Presents fell from 6.0 to 3-4 fps over the same span. Every pipeline bind was bounded at 50 ms (
still being built after 50 ms … 513 so far), so on this machine the thread held long enough for the watchdog is most likely the one doing the look before its submit. Not proven: I have the aggregate timing lines, not a per-look time or the stack of the held thread.AI-assisted (Claude Code, Claude Opus 5.5).
AlexLopezDevelop commentedon Nov 24, 2026
The synthetic bench from the issue text, rerun on the machine from my two comments above (Intel i9-9900K, Coffee Lake, Windows 11, 32 GB): 1 GiB committed with
MEM_WRITE_WATCH, K pages written before each look, the look done liketake_written(16,384-entry buffer, resume after the last page reported), median of 15:WRITE_WATCH_FLAG_RESETSo on this CPU:
@ivall, if the direction in the issue text is a yes, I can write step 1-2 (sparse windows only, off by default behind an environment variable) and test it on this machine, where the gain is largest; unless the issue's author wants to. I will wait for a yes before writing it.
AI-assisted (Claude Code, Claude Opus 5.5).
ivall commentedon Nov 24, 2026
Yes to the direction, in the order you set out: the
VirtualQuerywalks first (#693 and #551 are merged now, #501 needs a rebase onto #532's parked tiles), then step 1-2 of the plan - read-only blocks for the sparse windows only, off by default behind an environment variable, with the kernel's writes routed throughkernelx::lazy::ensureas for lazy pages. @AlexLopezDevelop, go ahead with it if @Kalmarv does not want to - please say here who takes it, so it is written once. The PR should carry the look's numbers (ms per look, bytes per look) before and after on a CPU where the look dominates, plus a run on a fast CPU to show it costs nothing there.AlexLopezDevelop commentedon Nov 24, 2026
Taking step 1-2 (read-only blocks for the sparse windows only, off by default behind an environment variable, the kernel's writes routed through
kernelx::lazy::ensureas for lazy pages), unless @Kalmarv says otherwise in the next hour. The PR will carry ms and bytes per look before and after on this i9-9900K, and I'll ask for a run on a fast CPU there.AI-assisted (Claude Code, Claude Opus 5.5).
AlexLopezDevelop commentedon Nov 24, 2026
Step 1-2 is up as #1034 (off by default,
XCL_SPARSE_COOL=1). On the i9-9900K the look goes from 1,780 to 951 MB and from 8.98 to 7.10 ms a look in 120 s of the first menus, with the cooling still ramping up. It needs a run on a fast CPU, as asked above: anyone with a Zen 4/5 or a recent Intel, asmoke.ps1pair withXCL_SPARSE_COOL=1on #1034 would settle whether it costs anything there.AI-assisted (Claude Code, Claude Opus 5.5).
zorde23 commentedon Nov 24, 2026
cached_watch_rangesis computed again on nearly every submit while a title streams (up to 574 ms every 2 s on an RX 6750 XT, main 6efdabc). An AMD data point for #1034, which was measured on NVIDIA/Intel. Recomputing it in place, only adding new textures and tiles (full computation kept for removals), brought it to 19 recomputations and 5 ms peak per 2 s in a local test; happy to test #1034 on this card.Written with Claude Code from runs on this machine.
Memory: sparse tiles the CPU leaves alone leave the write-watch look (i…
Memory: sparse tiles the CPU leaves alone leave the write-watch look (i…
Krashgamer commentedon Nov 24, 2026
The same cost on NVIDIA, and it is what holds the title's submissions during the world load here. @zorde23, are you opening your in-place recomputation as a PR? If I don't hear back within an hour, I'll take it. I'll credit your approach and keep #1034's
all_watch_rangessplit in mind so the two merge cleanly.Measured (RTX 3080 10 GB, i7-10700K,
main4178e88+ #640 + #742 + #1791 and others,XCL_DIRECT_DXIL=1, with a local timer aroundtitle_textures::refresh):refreshover 50 ms rebuilt the watch ranges. 128 of them by 158 s, taking 50 to 899 ms each. They grew with the number of textures kept in step: 60–229 ms at 25–735 textures in the first seconds, 53–293 ms at 15–17k during the world load, 322 ms at 23.6k and 899 ms at 25k.+0x24821e3) was insiderefresh_once→cached_watch_ranges(theflat_mapoverby_res, then freeing it) in both dumps, 6 s apart.Plan: rebuild only what changed. Textures added since the last build add their ranges to the cached list; a removal or a sparse or reservation change still rebuilds it all, as today. One small PR in
title_textures.rs, with a test that the incremental list equals a full rebuild after adds and removes.AI use: Claude Code (Claude Opus 5.5).
Krashgamer commentedon Nov 24, 2026
Correction to my comment above: the range rebuild is not where the time goes. I'm withdrawing that claim. @zorde23, your in-place recomputation stays yours if you want it, but on this machine it would save little.
I timed the parts of
cached_watch_rangesonmainc4d37be(64 commits after4178e88) + #742 + #1791 + #1765 + #1055, without #1102: a rebuild takes 0–4 ms even at 15–17k textures. The slowrefreshcalls are still there (50 ms to 1.7 s, 64 of them by 135 s), and some of them rebuilt nothing. So the time is in the rest ofrefresh_once: the write-watch look,sparse::before_executeor the texture uploads. I'm timing those next and will post where it goes. If it's the uploads waiting on the CPU, that is #455's part, not mine.marquezinii commentedon Nov 24, 2026
For the before/after numbers asked above (ms per look, bytes per look): #1832 adds one line to
XCL_ACTIVITY=1every 2 s. It gives the looks of the last 2 s, their total time and share of the 2 s, the write-watch part with the MB watched per look and the pages found, the copies into sparse video memory, and the rest. Today'ssparse windows timingline is cumulative and logged at power-of-two submit counts, so per-period figures had to be worked out by hand. It needs a smoke pair from someone with a title before it can be merged. @AlexLopezDevelop, if you run #1034 on your i9-9900K again, this gives the per-2-s figures directly.AI use: Claude Code (Claude Opus 5.5).
D3D12.X: XCL_ACTIVITY logs the CPU time of the looks before each submit
milesah3ad commentedon Nov 24, 2026
Write-watch reset strategies on a fast CPU (Ryzen 7 9800X3D, Zen 5, Windows 11 26300): every way of resetting costs about the same per written page, threads don't help, and sibling threads make each reset 2.5–3× dearer. A synthetic bench, no game files: a region committed with
MEM_WRITE_WATCH, K pages written before each look, looks liketitle_textures::take_written(16,384-entry buffer, resume).4 GiB, scattered writes, median of 5 (ms per look):
GetWriteWatch(FLAG_RESET)(what XCL does)ResetWriteWatchover the region, no lookResetWriteWatchper written 64 KiB blockFLAG_RESETsplit over 2 / 4 / 8 threadssparse windows timinglines work out to. So that gap is still unexplained: page faults on re-dirtied pages,VirtualQuerywalks, or lock waits are left.Not tested: any title, Intel / other AMD, how many pages a world-load look really resets. Bench source and raw output can be shared if useful.
AI use: Claude Code (Claude Opus 5.5) wrote and ran the bench on the machine above and wrote this. I checked the numbers against the output.
brandostrong commentedon Nov 25, 2026
PR #2090 removes this look for the buffer half: with
XCL_SPARSE_DIRECT=1each sparse window is animported heap and a buffer the title places in one is that memory, so there are no mapped tiles to
scan and the look does not run at all.
Matched 180 s runs, same title, RTX 4090, warm caches, same profile copy, same driving:
main)XCL_SPARSE_DIRECT=1What still needs the look afterwards: textures the title places in sparse windows are still detiled PC
copies — that is why the windows stay write-watched and why only
mapped_ranges()goes empty, not thewatch itself. #1034 and #1058 shrink the same look from the scan side; they are complementary to this,
not alternatives.
Claude Code, Claude Opus 5.5 — the numbers are from runs made here.
D3D12.X: the sparse windows' buffers live on the title's own pages