Skip to content

D3D12.X: the write-watch look scans 1.5 GiB before every submit while 4 pages are written (measurement and plan) #582

Backlog

Description

@Kalmarv

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 GetWriteWatch on 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 main in matched runs, inside the spread between runs (main with 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

  1. 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.
  2. 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::ensure in the ReadFile hook, DirectStorage and cpu_writes), and the title's own commit, decommit and protect calls warming the block first. ReadFile into 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.
  3. 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: main 508a0c7; the same with local counters around refresh_once (not in any PR); 508a0c7 with 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

Activity

  1. iggyvilla commented on Nov 24, 2026

    @iggyvilla
    Contributor

    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 VirtualQuery calls on the title's render thread. That is #501's mechanism through two other checks.

    Measured

    • On 9ce2070 with local counters around refresh_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.
    • The slow phase does not last. One run went back to 24–28 fps after about 10 minutes, and it is shorter when the file cache is warm. While it lasts the GPU is 3–7 % busy (Task Manager 3D) and one title thread uses a full core.
    • That thread, sampled for 20 s at 24 fps (4,422 samples): 97.5 % in NtQueryVirtualMemory. With the symbols resolved:
      • 70.9 %: list_x::gpu_va (list_x.rs:1810) → gpu::shader::readable, from ia_set_vertex_buffers_x
      • 7.8 %: the same check, from ia_set_index_buffer_x
      • 18.5 %: timestamp → cpu_writes::writable (list_x.rs:1169), from Write64BitValueBottomOfPipeX with a timestamp flag into memory outside unified memory
    • At the same moment the submit thread spent 28.7 % in NtGetWriteWatch (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 while GetWriteWatch waits) is an inference from the timing.
    • readable asks resident_and_readable first. On a cold address space the pages are not resident yet, so every bind falls through to the VirtualQuery walk. gpu_va makes 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_va part (look up the mirror first, keep readable for the first bind). Profiled at 125 s on dd2ae9a against #693: the render thread went from 92 % to 25 % of a core and the gpu_va walk 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 in title_textures::refresh and NtGetWriteWatch under ExecuteCommandLists. So for this issue the look's cost itself is what is left.

    Tested

    • AMD Radeon RX 6650 XT 8 GB (driver 32.0.21045.29003), Ryzen 7 5700X, 32 GB, Windows 11 26H2 (26300), release builds, XCL_NETWORK=0, a retail title (game files on a hard drive), Enter pressed past the first menu (50–75 s).
    • main 508a0c7: 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.
    • 9ce2070 plus 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

    AI use

    • Claude Code agents (Claude Opus 5.5) ran the measurements and wrote this comment. The numbers come from those runs.
  2. Kalmarv commented on Nov 24, 2026

    @Kalmarv
    ContributorAuthor

    @iggyvilla, thanks. This is the phase my runs never reached: they take no input.

    #693 and #501 (read at f44cc79 and 81c43fe, nothing run)

    Does the plan change? The direction stays; the order changes, and one detail.

    Not tested

    • Everything above is from reading the two PRs and main. No run past the first menus exists on this PC yet.

    🤖 Claude Fable 5.2

  3. AlexLopezDevelop commented on Nov 24, 2026

    @AlexLopezDevelop

    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) with XCL_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 showing 0 running pipeline compiles, and the periodic timing lines are:

    [ 44.793] sparse windows timing: write-watch   965 ms ( 305989 dirty pages), lock wait 2 ms, chunk scan 241 ms, upload 421 ms (39304 runs)
    [ 77.914] sparse windows timing: write-watch  6278 ms ( 537785 dirty pages), lock wait 2 ms, chunk scan 248 ms, upload 484 ms (41571 runs)
    [153.438] sparse windows timing: write-watch 18810 ms (1379493 dirty pages), lock wait 2 ms, chunk scan 302 ms, upload 675 ms (93597 runs)
    

    sparse 7447 MB in the same run's counters. So on this machine GetWriteWatch grows 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).

  4. AlexLopezDevelop commented on Nov 24, 2026

    @AlexLopezDevelop

    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:

    [ 81.925] sparse windows timing: write-watch  7291 ms ( 315467 dirty pages) … upload  322 ms
    [145.177] sparse windows timing: write-watch 16372 ms ( 331457 dirty pages) … upload  434 ms
    [244.285] sparse windows timing: write-watch 34010 ms ( 363478 dirty pages) … upload  628 ms
    [509.122] sparse windows timing: write-watch 81110 ms (1849969 dirty pages) … upload 1151 ms
    [633.791] unhandled exception 0xc0000005 in game_scarlett_master.exe+0x23cf683 (write at address 0x0)
    

    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).

  5. AlexLopezDevelop commented on Nov 24, 2026

    @AlexLopezDevelop

    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 like take_written (16,384-entry buffer, resume after the last page reported), median of 15:

    Pages written With WRITE_WATCH_FLAG_RESET Without
    0 1.38 ms 1.33 ms
    64 1.47 ms 1.44 ms
    1,024 1.66 ms 1.40 ms
    16,384 4.46 ms 1.44 ms
    65,536 13.44 ms 1.89 ms
    262,144 28.35 ms 1.86 ms

    So on this CPU:

    • The clean part is about 3× the 0.45 ms per GiB measured above on the 9950X: about 1.4 ms per GiB, which over the 7.4 GB of sparse windows my runs report is about 10 ms a look before any page is written. That is the part step 1 of the plan removes, and it explains why this machine sits at 2-6 fps through the menus while the issue's machine loses 10 %.
    • The reset adds about 0.1 µs per written page (262,144 pages: +26.5 ms). During the world load my runs report 300,000 to 1,850,000 dirty pages per timing window, so that part grows with the load whatever the plan does; it is the title writing, not the scan.

    @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).

  6. ivall commented on Nov 24, 2026

    @ivall
    Collaborator

    Yes to the direction, in the order you set out: the VirtualQuery walks 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 through kernelx::lazy::ensure as 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.

  7. AlexLopezDevelop commented on Nov 24, 2026

    @AlexLopezDevelop

    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::ensure as 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).

  8. AlexLopezDevelop commented on Nov 24, 2026

    @AlexLopezDevelop

    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, a smoke.ps1 pair with XCL_SPARSE_COOL=1 on #1034 would settle whether it costs anything there.

    AI-assisted (Claude Code, Claude Opus 5.5).

  9. zorde23 commented on Nov 24, 2026

    @zorde23

    cached_watch_ranges is 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.

  10. Krashgamer commented on Nov 24, 2026

    @Krashgamer

    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_ranges split in mind so the two merge cleanly.

    Measured (RTX 3080 10 GB, i7-10700K, main 4178e88 + #640 + #742 + #1791 and others, XCL_DIRECT_DXIL=1, with a local timer around title_textures::refresh):

    • Every refresh over 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.
    • In thread dumps taken while the title presented nothing and submitted nothing for 2 s windows, its submission thread (+0x24821e3) was inside refresh_once → cached_watch_ranges (the flat_map over by_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).

  11. added
    goal:world-load
    on Nov 24, 2026
  12. Krashgamer commented on Nov 24, 2026

    @Krashgamer

    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_ranges on main c4d37be (64 commits after 4178e88) + #742 + #1791 + #1765 + #1055, without #1102: a rebuild takes 0–4 ms even at 15–17k textures. The slow refresh calls 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 of refresh_once: the write-watch look, sparse::before_execute or 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.

  13. marquezinii commented on Nov 24, 2026

    @marquezinii

    For the before/after numbers asked above (ms per look, bytes per look): #1832 adds one line to XCL_ACTIVITY=1 every 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's sparse windows timing line 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).

  14. milesah3ad commented on Nov 24, 2026

    @milesah3ad

    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 like title_textures::take_written (16,384-entry buffer, resume).

    4 GiB, scattered writes, median of 5 (ms per look):

    strategy K=0 K=262,144 K=1,048,576 (663k unique)
    GetWriteWatch(FLAG_RESET) (what XCL does) 2.1 15.9 29.0
    no reset (the floor, not race-free) 2.1 4.5 6.6
    ResetWriteWatch over the region, no look 0.5 15.2 24.8
    look, then ResetWriteWatch per written 64 KiB block 2.3 47.8 77.3
    FLAG_RESET split over 2 / 4 / 8 threads – 15.1 / 16.2 / 16.6 29.5 (4 thr)
    • The reset itself costs about 33–40 ns per written page here, against about 160 ns from @AlexLopezDevelop's i9-9900K table. The API has no cheaper reset, and splitting it across threads gains nothing.
    • With busy sibling threads (1 GiB, K=65,536, threads of the same process spinning and touching their own memory): the reset part costs 44 ns per page with 0 busy, 84 ns with 4, 127 ns with 8, 115 ns with 15. That fits TLB shootdowns reaching the process's other cores. It is 2.5–3×, not the ~11 µs per dirty page that the game-run sparse windows timing lines work out to. So that gap is still unexplained: page faults on re-dirtied pages, VirtualQuery walks, or lock waits are left.
    • Since the cost is per written page, a design idea alongside Memory: sparse tiles the CPU leaves alone leave the write-watch look (#582, off by default) #1034's cold blocks: hot blocks. A 64 KiB block that was written in each of N looks goes out of the look, gets no reset, and is uploaded every submit, which it already was. When it stops being written it comes back with one reset. That saves the reset only while a block stays hot, at no extra copy. Measuring it needs a title.

    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.

  15. brandostrong commented on Nov 25, 2026

    @brandostrong
    Contributor

    PR #2090 removes this look for the buffer half: with XCL_SPARSE_DIRECT=1 each sparse window is an
    imported 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:

    tiled (main) XCL_SPARSE_DIRECT=1
    write-watch look 7 096 ms cumulative at t = 41 s (24 667 ms at t = 130 s in a longer run) none
    upload at the same point 240 ms none for buffers
    sparse video-memory pools 7 445 MB 0

    What 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 the
    watch 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    goal:world-load

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions