Skip to content

D3D12.X: every draw re-syncs buffer mirrors on the CPU (VirtualQuery, whole-buffer copies, index scan) #2389

Backlog

Description

@KOLESNiii

Some titles bind vertex and index buffers in their own memory, outside the unified-memory windows. XCL gives each such buffer a mirror in unified memory (#637), and list_x::sync_title_buffers (crates/xcl/src/hle/d3d12x/list_x.rs:3539 on main 3f4495a) brings the mirror up to date on every draw. Once one mirror exists, every DrawInstanced, DrawIndexedInstanced and DrawIndexedX on every list goes through it. Per draw, it:

  • checks the source with readable(), which falls back to a VirtualQuery walk for more than 64 KiB. D3D12.X: a vertex or index buffer with a mirror is bound without VirtualQuery #693 removed this check from the bind because it was too expensive there;
  • copies the whole vertex buffer for instanced draws, and the used range otherwise, even when the title has not written it;
  • reads every index of an indexed draw on the CPU to find the vertex range;
  • writes the copy into a mirror that usually sits in a sparse window, so the next submit's write-watch look finds the pages dirty and uploads them again.

Seen: in my title's menus (RTX 2070 SUPER, Ryzen 5 3600XT, Windows 11 26300, main 3f4495a release), the first two mirrors appear 36 s in: a 384 KiB index buffer and a 1.1 MiB vertex buffer. Draw counts in a world are far higher than the ~600 a second in those menus. I have no measurement of the function's cost yet, which is why the first part below is a counter.

None of the open work changes this path: #825 frees idle mirrors, #1995 re-keys MIRRORS, and #1488 covers the DrawIndexedX re-sync as a correctness bug.

Parts (one PR each, in this order):

Found by code reading with Claude Code (Claude Opus 5.5).

Activity

  1. KOLESNiii commented on Nov 25, 2026

    @KOLESNiii
    ContributorAuthor

    Measured: the sync is cheap on average, but readable() stalls the render thread for ~5 ms every few seconds. The copies are all redundant. Mirrors only appear while the coherent window is too small.

    Setup: my title; main 3f4495a plus local timers and counters (not committed); release; RTX 2070 SUPER (32.0.16.2140), Ryzen 5 3600XT, Windows 11 26300. Two scripts/smoke.ps1 runs of 120 s each, both in menus (30 fps, ~390 draws/s).

    When mirrors exist at all. With the learned coherent window (uma_coherent.txt, 4095 MB), the run made no mirrors, so sync_title_buffers returned at its first check. Mirrors only appeared after I removed that file for one run, which gives the 512 MB first-run window of #284. That run made two mirrors at 32.7 s, the same as my first report: a 448 KiB index buffer and a 1.2 MiB vertex buffer, both in a sparse window. So on this title, this issue is a first-run problem.

    First-run window, 50–118 s, per 2 s, very steady:

    per 2 s
    draws through the sync / with a mirror 780 / 660
    copies (whole buffers) 1,200 (0)
    bytes copied 10.5 MiB, in 2.5 ms
    indices scanned for the vertex range 1.98 M, in 0.55 ms
    readable() calls (over 16 pages) 1,800 (0), 1.3 ms when none is slow
    total time in the function 4.7 ms typically (~7 µs a mirrored draw), 9–18.6 ms with a slow readable()

    What this means for each part:

    Not measured: the world (never reached), and any draw with instances (none here, so no whole-buffer copies).

    Measured and written with Claude Code (Claude Opus 5.5).

  2. KOLESNiii commented on Nov 25, 2026

    @KOLESNiii
    ContributorAuthor

    Result so far: the stack (#2416 → #2437 → #2478) makes the mirror sync slower on my title, not faster. #2478 is the reason.

    Compared: bb01e85 (#2416's head, the counters on main 3f4495a) against 2bdfb90 (#2478's head, which holds #2437 too).

    Setup:

    • RTX 2070 SUPER (32.0.16.2140), Ryzen 5 3600XT, Windows 11 26300, release builds.
    • Four scripts/smoke.ps1 runs of 120 s each, alternating bb01e85, 2bdfb90, bb01e85, 2bdfb90, each built from a clean tree of its commit.
    • Each run started without uma_coherent.txt, so the two mirrors of my first report are made (at 35–41 s).
    • Menus only. Numbers are the means of the XCL_ACTIVITY lines per 2 s once the mirrors exist (~40 windows a run).
    bb01e85 run 1 bb01e85 run 2 2bdfb90 run 1 2bdfb90 run 2
    frames shown (120 s) 2433 2451 1889 2056
    draws through the sync 702 697 533 583
    copies / KB copied 1,079 / 9,704 1,072 / 9,644 819 / 7,369 895 / 8,047
    indices scanned 1.78 M 1.77 M 1.35 M 1.48 M
    readable() calls, time 1,619, 29.6 ms 1,609, 24.5 ms 0 0
    slowest readable() / windows with one over 1 ms 18.4 ms / 41 of 41 11.2 ms / 33 of 39 – –
    time in the sync: median, mean, max 23.1, 33.3, 126 ms 21.8, 28.1, 116 ms 103.8, 101.2, 228 ms 41.4, 75.3, 243 ms
    device removals / crashes 0 / 0 0 / 0 0 / 0 0 / 0

    These are not comparable with my first report's numbers (4.7 ms in the sync per 2 s, 1.3 ms in readable()). This machine has been much slower since this afternoon, with a device hang on main as well. The four runs above were made back to back and alternated, so they compare with each other.

    What each part did:

    Next:

    Not measured:

    Measured and written with Claude Code (Claude Opus 5.5).

  3. GXLD-N commented on Nov 26, 2026

    @GXLD-N

    #2437 on its own, on a second machine: removing readable() saves about 1.1 ms of render-thread time per 2 s here, and the sync as a whole costs ~4 ms per 2 s. Frames don't move, because the menus are capped at 30 fps and the sync is ~0.2 % of the frame budget on this CPU.

    This is the run of #2437 alone that #2389's last comment lists as not done, on different hardware.

    Setup

    fdbb6fe run 1 c24fbbf run 1 fdbb6fe run 2 c24fbbf run 2
    frames shown (120 s) 2,939 2,925 2,949 2,948
    draws through the sync 778 765 764 764
    copies / KB copied 1,197 / 10,757 1,177 / 10,577 1,175 / 10,563 1,175 / 10,559
    indices scanned 1.98 M 1.94 M 1.94 M 1.94 M
    readable() calls, time 1,795, 1.05 ms 0 1,763, 1.11 ms 0
    slowest readable() (max over the run) 0.12 ms – 0.56 ms –
    sync time in all 4.24 ms 3.69 ms 4.23 ms 4.26 ms
    peak commit 14,781 MB 14,811 MB 14,808 MB 14,830 MB

    No device removal and no crash in any run.

    The four xcl-smoke blocks
    xcl-smoke v1
    commit: fdbb6fe7ec0027a5b0274364475f0204684a8c5e
    gpu: NVIDIA GeForce RTX 4070 Ti SUPER
    title: 333fa394
    seconds: 120
    exit: 0x0
    frames shown: 2939 (PresentX 2939)
    presents per 2 s (last 3): 60 60 60
    device removals: 0
    crashes: 0
    peak commit: 14781 MB
    
    xcl-smoke v1
    commit: c24fbbff5e1bcebfee2b24fd4399592664927da6
    gpu: NVIDIA GeForce RTX 4070 Ti SUPER
    title: 333fa394
    seconds: 120
    exit: 0x0
    frames shown: 2925 (PresentX 2925)
    presents per 2 s (last 3): 61 60 60
    device removals: 0
    crashes: 0
    peak commit: 14811 MB
    
    xcl-smoke v1
    commit: fdbb6fe7ec0027a5b0274364475f0204684a8c5e
    gpu: NVIDIA GeForce RTX 4070 Ti SUPER
    title: 333fa394
    seconds: 120
    exit: 0x0
    frames shown: 2949 (PresentX 2949)
    presents per 2 s (last 3): 60 60 60
    device removals: 0
    crashes: 0
    peak commit: 14808 MB
    
    xcl-smoke v1
    commit: c24fbbff5e1bcebfee2b24fd4399592664927da6
    gpu: NVIDIA GeForce RTX 4070 Ti SUPER
    title: 333fa394
    seconds: 120
    exit: 0x0
    frames shown: 2948 (PresentX 2948)
    presents per 2 s (last 3): 60 60 60
    device removals: 0
    crashes: 0
    peak commit: 14830 MB
    

    What this shows

    Not tested

    Measured and written with Claude Code (Claude Opus 5.5).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions