D3D12.X: every draw re-syncs buffer mirrors on the CPU (VirtualQuery, whole-buffer copies, index scan) #2389
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#2389
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@KOLESNiii on GitHub · 2026-11-25 17:43 UTC · original
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:3539onmain3f4495a) brings the mirror up to date on every draw. Once one mirror exists, everyDrawInstanced,DrawIndexedInstancedandDrawIndexedXon every list goes through it. Per draw, it:readable(), which falls back to aVirtualQuerywalk for more than 64 KiB. #693 removed this check from the bind because it was too expensive there;Seen: in my title's menus (RTX 2070 SUPER, Ryzen 5 3600XT, Windows 11 26300,
main3f4495arelease), 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 theDrawIndexedXre-sync as a correctness bug.Parts (one PR each, in this order):
XCL_ACTIVITY(diagnostics, first)readable()per drawFound by code reading with Claude Code (Claude Opus 5.5).
@KOLESNiii on GitHub · 2026-11-25 17:54 UTC · original
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;
main3f4495aplus local timers and counters (not committed); release; RTX 2070 SUPER (32.0.16.2140), Ryzen 5 3600XT, Windows 11 26300. Twoscripts/smoke.ps1runs 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, sosync_title_buffersreturned 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:
readable()calls (over 16 pages)readable()What this means for each part:
readableper draw): no range was over 16 pages, so theVirtualQueryfallback I expected for large ranges never fired. But in 18 of the 43 2-s windows that had mirrors (34–118 s), a singlereadable()call on ≤16 pages took 1.1–8.8 ms, most of them 4–5 ms. That is presumablyresident_and_readablefailing on a page that is not resident, followed by theVirtualQuerywalk. It happens on the render thread inside a draw, so it is a hitch worth ~15 % of a 33 ms frame roughly every 4 s. This is the largest cost found here.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).
@KOLESNiii on GitHub · 2026-11-25 20:28 UTC · original
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 onmain3f4495a) against2bdfb90(#2478's head, which holds #2437 too).Setup:
scripts/smoke.ps1runs of 120 s each, alternatingbb01e85,2bdfb90,bb01e85,2bdfb90, each built from a clean tree of its commit.uma_coherent.txt, so the two mirrors of my first report are made (at 35–41 s).XCL_ACTIVITYlines per 2 s once the mirrors exist (~40 windows a run).bb01e85run 1bb01e85run 22bdfb90run 12bdfb90run 2readable()calls, timereadable()/ windows with one over 1 msThese 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 onmainas well. The four runs above were made back to back and alternated, so they compare with each other.What each part did:
readable()per draw): the stalls show up clearly in this state of the machine: 25–30 ms per 2 s, single calls of 11–18 ms, a call over 1 ms in almost every window. #2437 removes all of it. I have no run of #2437 alone from this session, so I can't say how much of that comes back as the cost of its fault-tolerant copy (ReadProcessMemory). In this morning's runs, on a faster machine, the total stayed the same: 4.74 ms before and after.GetWriteWatchcall per draw costs more than the copies it saves. The sync time went up 2–4×, and frames fell 19 % (2433/2451 → 1889/2056), with the title also drawing fewer draws per 2 s.Next:
Not measured:
Measured and written with Claude Code (Claude Opus 5.5).
@GXLD-N on GitHub · 2026-11-26 01:40 UTC · original
#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(#2416's head, counters only) againstc24fbbf(#2437's head, which holds #2416), each built from a clean tree of its commit.scripts/smoke.ps1runs of 120 s, alternatingfdbb6fe,c24fbbf,fdbb6fe,c24fbbf. Each started withoutuma_coherent.txt, and there was no input (menus only).buffer mirrors (2 s)lines from the first window with a mirror on (47–48 windows a run).fdbb6ferun 1c24fbbfrun 1fdbb6ferun 2c24fbbfrun 2readable()calls, timereadable()(max over the run)No device removal and no crash in any run.
The four
xcl-smokeblocksWhat this shows
readable()calls, the same work otherwise (copies, KB and indices match within 2 %).readable()was cheap: about 1.1 ms per 2 s, never over 0.56 ms in a single call, and no calls over 16 pages. That is far from the 1.1–8.8 ms single calls (18.4 ms at worst) on the Ryzen 5 3600XT in #2389.ReadProcessMemorycopy seems to cost about what the check saved here; two runs a side can't separate a 0.5 ms difference from noise.Not tested
uma_coherent.txt" is the only restart here.readable()costs more.Measured and written with Claude Code (Claude Opus 5.5).