Repository navigation
D3D12.X: XCL_WATCH_TRAP=1 leaves memory nobody writes out of the write-watch looks (off by default) - #2934
D3D12.X: XCL_WATCH_TRAP=1 leaves memory nobody writes out of the write-watch looks (off by default)#2934Kalmarv wants to merge 2 commits into
Conversation
|
Independent Windows check on The test starts with a read-only watched block, calls The fixture calls the watch-trap hooks directly around Win32 I/O. It does not exercise VFS import routing, GPU upload, or a retail title. The full lib build ran out of disk space before linking. OpenAI Codex (6.2sol) assisted with verification. |
|
Follow-up on In a local candidate, OpenAI Codex (6.2sol) assisted with verification. |
Every submit looks at all watched memory with GetWriteWatch, and the call is paid per byte looked at (about 0.5 ms per GiB). In a streamed world 17.6 GB are watched, and most of it is written once when it streams in and not again. With XCL_WATCH_TRAP=1 a 2 MiB block of a watched range that 64 looks in a row found clean is made read-only and left out of the looks. Its first write faults into a vectored handler, which gives the block its protection back and returns it to the looks; the write happens after that, so write-watch reports it as before. A block that cannot be made read-only (pinned, nothing committed, not all read-write) is tried again after another 64 looks, not at every look, and a block with nothing committed leaves the looks as a hole until a commit in it. A kernel write into a read-only page fails instead of faulting, so the title's ReadFile buffers get their protection back and stay pinned until the read is over, and their pages are then reported as written. A pending read is over when a look sees its OVERLAPPED done, or when the title uses that OVERLAPPED for its next read. Commits, decommits and protection changes through kernelx, lazy pages and sparse commits give the blocks they meet their protection back first, and so do XCL's own checks whether memory is writable. Off by default; without the variable only a sorted list gets a dedup. Measured on title ea3b5e4d on a tree with the driver-heap windows of xcl-dev#2844 (RTX 5070 Ti, one timed run per arm, the trap the only change): 5.79 against 4.01 presents/s over 107-223 s of the run, 8.45 against 4.60 over 187-229 s, the same draws per present, no device removal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A look copied the read-only spans into a new map and then made two map queries per span to find the pieces still to look at. In the late world of title ea3b5e4d that is about 9,000 spans a look and 20 looks a present. hot_pieces now walks the spans once, under the lock, while the ranges ascend (a look's are sorted and disjoint), and starts the walk again for a range that does not. Measured without a GPU, a look with a take that does nothing, 18 GiB watched in 64 ranges, 8,861 spans, 355 blocks left to look at: 336 us before, 40 us after (RTX 5070 Ti machine, release build). In the title, on a tree with the driver-heap windows of xcl-dev#2844 (one untimed run per arm): the write-watch part of a look 1.06 ms against 1.29 ms. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks @ettehn, both checks are useful, the real pending I took the second one.
As in your run, I have no case of a missed dirty page from the old behaviour: it cost a pinned block, not a write. |
|
@Kalmarv, an in-game data point for What ran:
Runs: MacieGx's #505 env, plus
Not covered: kernel writes by paths other than the hooked Setup: RTX 3090 24 GB (Resizable BAR off), driver 616.56, Ryzen 9 5950X, 32 GB RAM, Windows 11 22631. Translated cache fully precompiled; 2 GB shader heap profile (#2590). AI use: Claude Code, model Claude Opus 5.5. It ported the commits, ran the runs, read the logs and frames, and wrote and posted this. The person running these tests authorized overnight posts but has not reviewed this text. |
luckyteagirl
left a comment
There was a problem hiding this comment.
Could the VirtualProtectEx hook also retire watch-trap protection for real handles to the current process? The pseudo-handle comparison at kernelx.rs:503 skips the guard for a handle from OpenProcess targeting the current PID. Windows still applies the requested protection, so the cold entry survives. The next watch_trap::changed on that range can restore the saved protection in thaw and undo the title's change.
I reproduced this in a Windows CPU harness using this head's watch-trap module and the hook's implementation. On a trapped read-write page, VirtualProtectEx(..., PAGE_NOACCESS, ...) with a real self handle returned PAGE_READONLY, and a subsequent changed put the page back to PAGE_READWRITE. With the pseudo-handle control, the old protection was PAGE_READWRITE and the final protection remained PAGE_NOACCESS.
AI-assisted review (GPT-6.2 Sol).
|
In-game data point from a slow CPU (i7-8700): with Setup
Not tested: more than one run per arm; the trap with hot looks ( AI use: Claude Code (Claude Opus 5.5) ran the runs, read the logs and wrote this. |
|
Historical Intel Arc readback Tested clean Built with Both runs matched all 4,096 pixels at each of the five 64×64 R8 readbacks: initial Not tested Readback after a cooled block's first write, pending I/O behavior, performance, full workspace and retail smoke. AI use T3 Code / Codex ( |
Every submit looks at all watched memory with
GetWriteWatch, and the call is paid per byte looked at (about 0.5 ms per GiB here). In a streamed world 17.6 GB are watched, and most of it is written once when it streams in and not again. WithXCL_WATCH_TRAP=1a 2 MiB block that 64 looks in a row found clean is made read-only and left out of the looks; its first write faults into a vectored handler, which gives the block its protection back and returns it to the looks. Off by default. Part of #2688.Two open PRs work on the same cost in other ways: #1034 makes 64 KiB tiles of the sparse windows read-only (
XCL_SPARSE_COOL=1), and #2891 looks at cold 16 MiB chunks once a frame instead of at every submit. This one covers every watched range (sparse windows and title textures alike) and stops looking at a cold block altogether until it is written. It was not run together with either.What is in it
hle/d3d12x/watch_trap.rs(new, first commit): the cold blocks, the handler, the look. A block that cannot be made read-only (pinned, nothing committed, not all read-write) is tried again after another 64 looks; a block with nothing committed leaves the looks as a hole until a commit in it. At most 32 blocks are made read-only per look, and each gets a last look after the protection, for a write in between.ReadFilebuffers get their protection back and stay pinned until the read is over (vfs_hooks.rs:read_start/read_end; a pending read when a look sees its OVERLAPPED completed, or when the title uses that OVERLAPPED for its next read), and their pages are then reported as written. The reuse case is from @ettehn's named-pipe check in the comments: without it the first buffer stayed pinned until the second read ended.kernelx.rs(VirtualAlloc / VirtualFree / VirtualProtect(Ex), the physical-page homes),kernelx/lazy.rs,sparse.rs(commits and decommits), and XCL's own checks whether memory is writable:eh.rs,cpu_writes.rs,dstorage.rs,dstorage/parallel.rs.title_textures.rs:refresh_oncecallswatch_trap::lookinstead of its loop when the trap is on, and the sorted page list gets adedup(a finished read and write-watch can both report a page). Nothing else changes with the variable unset.watch_trap.rsonly: the look walks the read-only spans once instead of copying them into a new map and making two map queries per span (about 9,000 spans a look late in the world).Tested
c230aa1, release:cargo test --release -p xcl --lib -- watch_trap written_pages_past --test-threads=4: 8 passed, 0 failed. The sevenwatch_traptests 40 times in a row: 0 failures.dac9681(this head without the OVERLAPPED-reuse change: 28 lines inwatch_trap.rsand one test), debug, DXC 1.9.2609 throughXCL_DXC_DIR:cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1452 passed, 0 failed, 47 ignored. 25 SKIPPED: 21 no wave64, 3 refused f16 forms, 1 no heap windows.XCL_UMA_DRIVER=custom), not on main: one timed run per arm with the GPU alone, the trap the only difference. 5.79 against 4.01 presents/s over 107-223 s of the run (+44 %), 8.45 against 4.60 over 187-229 s; the same draws and dispatches per present (788 / 5,024 against 804 / 5,152), clean exit, no device removal. Late looks go over 0.5-1.8 GB of the 17.6 GB watched (5.4 GB read-only, about 4,400 holes); 4 blocks were refused in the run.Regression run
Not run on this head yet: a 480 s pair on title ea3b5e4d (main
8b957beand this head). Bothxcl-smokeblocks follow here before this leaves draft.Not tested
dac9681, see above), and the OVERLAPPED reuse with real overlapped I/O in this tree: the new test sets the status word by hand around the hooks. @ettehn ran the hooks around a real pendingReadFileon a named pipe in a standalone harness (comments below).VirtualProtecton write-watched memory; the Windows path only was run).ReadFilethrough the VFS hook or DirectStorage.AI use
🤖 Generated with Claude Code