D3D12.X: XCL_WATCH_TRAP=1 leaves memory nobody writes out of the write-watch looks (off by default) #2934

Closed
Kalmarv wants to merge 2 commits from upstream-pr/2934 into main
Kalmarv commented 2026-11-27 00:51:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-27T00:51:22Z.


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. With XCL_WATCH_TRAP=1 a 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.
  • A kernel write into a read-only page fails with ERROR_NOACCESS instead of faulting, so the handler cannot catch it. The title's ReadFile buffers 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.
  • Hooks, one line each (a guard that gives the blocks it meets their protection back and keeps them writable while it lives): 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_once calls watch_trap::look instead of its loop when the trap is on, and the sorted page list gets a dedup (a finished read and write-watch can both report a page). Nothing else changes with the variable unset.
  • Second commit, watch_trap.rs only: 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).
  • Size: 493 lines of code and 286 of tests in the new file, about 40 lines of hooks in ten files. It is over the ~400 guideline and not split because it is one switch: the handler, the pins and every hook are needed before the first block may be made read-only.

Tested

  • RTX 5070 Ti (16 GB), driver 610.74, Ryzen 9 9950X, 31 GB RAM, Windows 11 Pro 26200, Rust 1.99.0.
  • On this head c230aa1, release: cargo test --release -p xcl --lib -- watch_trap written_pages_past --test-threads=4: 8 passed, 0 failed. The seven watch_trap tests 40 times in a row: 0 failures.
  • Whole suite on dac9681 (this head without the OVERLAPPED-reuse change: 28 lines in watch_trap.rs and one test), debug, DXC 1.9.2609 through XCL_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.
  • Title ea3b5e4d, on our integration tree of that time, which has the driver-heap windows of #2844 (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.
  • The first form, which tried a refused block again at every look, was 32 % slower than without the trap (2.72 against 4.01); that is why refused blocks wait and empty blocks become holes.
  • A threshold of 8 looks instead of 64 (tried on our tree, not in this PR, one untimed run per arm) doubled the look: about 2.1 ms against 1.1, of it 1.3 ms protecting, about 11 faults a look.
  • Second commit: a look with a take that does nothing, 18 GiB watched in 64 ranges, 8,861 spans, 355 blocks left to look at, no GPU: 336 us before, 40 us after. In the title (same tree, one untimed run per arm): the write-watch part of a look 1.06 ms against 1.29 ms.

Regression run

Not run on this head yet: a 480 s pair on title ea3b5e4d (main 8b957be and this head). Both xcl-smoke blocks follow here before this leaves draft.

Not tested

  • The whole suite on this head (it ran on 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 pending ReadFile on a named pipe in a standalone harness (comments below).
  • AMD and Intel GPUs, Wine / Proton (a vectored handler and VirtualProtect on write-watched memory; the Windows path only was run).
  • Main alone with the trap on, beyond the regression run above: the fps numbers above are from a tree with #2844's windows.
  • Any title other than ea3b5e4d.
  • Together with #1034 or #2891.
  • Picture correctness: the title's frames are grey with and without the trap on this GPU, so a missed write would not show in the picture; the draws and dispatches per present are the same in both arms.
  • A title that reads files into watched memory by another route than ReadFile through the VFS hook or DirectStorage.

AI use

  • Claude Code with Claude Opus 5.5 wrote the trap and its tests; Claude Code with Claude Fable 5 wrote the second commit and the OVERLAPPED-reuse change, ran the tests and wrote this description.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5519283902 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2934). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-27T00:51:22Z. --- 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. With `XCL_WATCH_TRAP=1` a 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. - A kernel write into a read-only page fails with ERROR_NOACCESS instead of faulting, so the handler cannot catch it. The title's `ReadFile` buffers 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. - Hooks, one line each (a guard that gives the blocks it meets their protection back and keeps them writable while it lives): `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_once` calls `watch_trap::look` instead of its loop when the trap is on, and the sorted page list gets a `dedup` (a finished read and write-watch can both report a page). Nothing else changes with the variable unset. - Second commit, `watch_trap.rs` only: 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). - Size: 493 lines of code and 286 of tests in the new file, about 40 lines of hooks in ten files. It is over the ~400 guideline and not split because it is one switch: the handler, the pins and every hook are needed before the first block may be made read-only. **Tested** - RTX 5070 Ti (16 GB), driver 610.74, Ryzen 9 9950X, 31 GB RAM, Windows 11 Pro 26200, Rust 1.99.0. - On this head `c230aa1`, release: `cargo test --release -p xcl --lib -- watch_trap written_pages_past --test-threads=4`: 8 passed, 0 failed. The seven `watch_trap` tests 40 times in a row: 0 failures. - Whole suite on `dac9681` (this head without the OVERLAPPED-reuse change: 28 lines in `watch_trap.rs` and one test), debug, DXC 1.9.2609 through `XCL_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. - Title ea3b5e4d, on our integration tree of that time, which has the driver-heap windows of #2844 (`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. - The first form, which tried a refused block again at every look, was 32 % slower than without the trap (2.72 against 4.01); that is why refused blocks wait and empty blocks become holes. - A threshold of 8 looks instead of 64 (tried on our tree, not in this PR, one untimed run per arm) doubled the look: about 2.1 ms against 1.1, of it 1.3 ms protecting, about 11 faults a look. - Second commit: a look with a take that does nothing, 18 GiB watched in 64 ranges, 8,861 spans, 355 blocks left to look at, no GPU: 336 us before, 40 us after. In the title (same tree, one untimed run per arm): the write-watch part of a look 1.06 ms against 1.29 ms. **Regression run** Not run on this head yet: a 480 s pair on title ea3b5e4d (main `8b957be` and this head). Both `xcl-smoke` blocks follow here before this leaves draft. **Not tested** - The whole suite on this head (it ran on `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 pending `ReadFile` on a named pipe in a standalone harness (comments below). - AMD and Intel GPUs, Wine / Proton (a vectored handler and `VirtualProtect` on write-watched memory; the Windows path only was run). - Main alone with the trap on, beyond the regression run above: the fps numbers above are from a tree with #2844's windows. - Any title other than ea3b5e4d. - Together with #1034 or #2891. - Picture correctness: the title's frames are grey with and without the trap on this GPU, so a missed write would not show in the picture; the draws and dispatches per present are the same in both arms. - A title that reads files into watched memory by another route than `ReadFile` through the VFS hook or DirectStorage. **AI use** - Claude Code with Claude Opus 5.5 wrote the trap and its tests; Claude Code with Claude Fable 5 wrote the second commit and the OVERLAPPED-reuse change, ran the tests and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ettehn commented 2026-11-27 02:18:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ettehn on 2026-11-27T02:18:37Z.


Independent Windows check on dac9681: I compiled the PR’s watch_trap.rs directly in a standalone Rust harness (only the log macro is stubbed) and added a local test with a real overlapped ReadFile on a local named pipe. XCL_WATCH_TRAP=1, 7 module tests passed. The added test also passed 20/20 runs in fresh processes.

The test starts with a read-only watched block, calls read_start and submits a read with no pipe data yet. Windows returns ERROR_IO_PENDING. Across 65 looks the destination remains pinned and does not get frozen. The writer then sends 32 bytes. After GetOverlappedResultEx confirms completion, the next look reports the destination page exactly once and the block can be frozen again. The usual GetWriteWatch callback is a no-op in this fixture, so the dirty page comes from the pending-read completion path.

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.

<!-- greyfinch-sync:ivall/xcl:comment:7208011220 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2934#issuecomment-7208011220). Originally posted by [ettehn](https://github.com/ettehn) on 2026-11-27T02:18:37Z. --- Independent Windows check on `dac9681`: I compiled the PR’s `watch_trap.rs` directly in a standalone Rust harness (only the log macro is stubbed) and added a local test with a real overlapped `ReadFile` on a local named pipe. `XCL_WATCH_TRAP=1`, 7 module tests passed. The added test also passed 20/20 runs in fresh processes. The test starts with a read-only watched block, calls `read_start` and submits a read with no pipe data yet. Windows returns `ERROR_IO_PENDING`. Across 65 looks the destination remains pinned and does not get frozen. The writer then sends 32 bytes. After `GetOverlappedResultEx` confirms completion, the next look reports the destination page exactly once and the block can be frozen again. The usual GetWriteWatch callback is a no-op in this fixture, so the dirty page comes from the pending-read completion path. 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.
ettehn commented 2026-11-27 02:37:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ettehn on 2026-11-27T02:37:12Z.


Follow-up on dac9681b57cb64f749d7977cf4ee477d83ca3aa7: I used a real local named pipe and two destination buffers in separate watched blocks. I waited for the first ReadFile to complete with GetOverlappedResultEx, then submitted the second using the same OVERLAPPED before the next look. While the second read was pending, the look kept both records pending and the first block could not go read-only. It became eligible again after the second read completed. Native GetWriteWatch independently reported the first page in this buffered-pipe case, so I did not observe a missed dirty page.

In a local candidate, read_start retires the previous record for that OVERLAPPED before the next ReadFile replaces its status. The first block can then go read-only while the second read stays pinned. The standalone comparison reproduced the expected distinction in 20/20 fresh processes per variant, and all seven harness tests passed with the candidate. This uses the watch-trap hooks directly and does not measure title performance or demonstrate a failure on unbuffered reads. OVERLAPPED lifetime

OpenAI Codex (6.2sol) assisted with verification.

<!-- greyfinch-sync:ivall/xcl:comment:7208287374 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2934#issuecomment-7208287374). Originally posted by [ettehn](https://github.com/ettehn) on 2026-11-27T02:37:12Z. --- Follow-up on `dac9681b57cb64f749d7977cf4ee477d83ca3aa7`: I used a real local named pipe and two destination buffers in separate watched blocks. I waited for the first `ReadFile` to complete with `GetOverlappedResultEx`, then submitted the second using the same `OVERLAPPED` before the next look. While the second read was pending, the look kept both records pending and the first block could not go read-only. It became eligible again after the second read completed. Native `GetWriteWatch` independently reported the first page in this buffered-pipe case, so I did not observe a missed dirty page. In a local candidate, `read_start` retires the previous record for that `OVERLAPPED` before the next `ReadFile` replaces its status. The first block can then go read-only while the second read stays pinned. The standalone comparison reproduced the expected distinction in 20/20 fresh processes per variant, and all seven harness tests passed with the candidate. This uses the watch-trap hooks directly and does not measure title performance or demonstrate a failure on unbuffered reads. [OVERLAPPED lifetime](https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-overlapped#remarks) OpenAI Codex (6.2sol) assisted with verification.
Kalmarv commented 2026-11-27 03:39:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-27T03:39:04Z.


Thanks @ettehn, both checks are useful, the real pending ReadFile most of all: the tests here only call the hooks.

I took the second one. read_start now retires a pending record whose OVERLAPPED the title is about to use again (retire_reused in watch_trap.rs): its buffer is reported as written and unpinned there, so its block can go read-only again while the second read stays pinned. A record whose status still says pending is left to the looks, in case a title reuses an OVERLAPPED too early.

  • Folded into the first commit; the head is now c230aa1.
  • New test an_overlapped_used_again_retires_its_earlier_read. It sets the status word by hand around the hooks and does no real I/O, so your named-pipe fixture still covers a side this tree does not.
  • Run here on c230aa1, release: cargo test --release -p xcl --lib -- watch_trap written_pages_past --test-threads=4: 8 passed, 0 failed; the seven watch_trap tests 40 times in a row: 0 failures.
  • Not rerun on this head: the whole suite (it ran on dac9681) and the title pair. The PR stays a draft until both smoke blocks are in.

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.

<!-- greyfinch-sync:ivall/xcl:comment:7209161255 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2934#issuecomment-7209161255). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-27T03:39:04Z. --- Thanks @ettehn, both checks are useful, the real pending `ReadFile` most of all: the tests here only call the hooks. I took the second one. `read_start` now retires a pending record whose `OVERLAPPED` the title is about to use again (`retire_reused` in `watch_trap.rs`): its buffer is reported as written and unpinned there, so its block can go read-only again while the second read stays pinned. A record whose status still says pending is left to the looks, in case a title reuses an `OVERLAPPED` too early. - Folded into the first commit; the head is now `c230aa1`. - New test `an_overlapped_used_again_retires_its_earlier_read`. It sets the status word by hand around the hooks and does no real I/O, so your named-pipe fixture still covers a side this tree does not. - Run here on `c230aa1`, release: `cargo test --release -p xcl --lib -- watch_trap written_pages_past --test-threads=4`: 8 passed, 0 failed; the seven `watch_trap` tests 40 times in a row: 0 failures. - Not rerun on this head: the whole suite (it ran on `dac9681`) and the title pair. The PR stays a draft until both smoke blocks are in. 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.
CharlyRien commented 2026-11-27 04:16:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CharlyRien on 2026-11-27T04:16:47Z.


@Kalmarv, an in-game data point for XCL_WATCH_TRAP=1 on an RTX 3090 with the retail title: the write-watch look per title submit went from 14.4 to 5.6 ms. Heavy-slice presents/s went up 13 %. I saw no missed-write errors and no stale-texture artefacts in the frames I checked.

What ran: 7692dd87 + c230aa1b cherry-picked onto MacieGx's lab tree 59986ef, which already had his XCL_CHAIN_WHOLE commit (47d0eac, see #505).

  • Two conflicts, resolved by hand.
    • mod.rs: the pub mod watch_trap; line.
    • title_textures.rs refresh_once: the lab's XCL_LOOK_JOIN / XCL_WATCH_HOT branches are kept; the trap replaces only the full-look loop, as in the PR.
  • The other 9 files carry the PR's lines; watch_trap.rs is byte-identical. The translated identity is unchanged.

Runs: MacieGx's #505 env, plus XCL_PAGE_BUDGET_MB=4096, XCL_LOOK_JOIN=0 and XCL_CHAIN_WHOLE=1. One run per arm, 420 s in the world.

off (CW1) XCL_WATCH_TRAP=1 (WT1)
write-watch look, ms per title submit 14.4 5.6
whole submit cost, ms 37.6 27.8
ExecuteCommandLists busy 100 % 83 %
heavy-slice presents/s (> 2000 draws) 1.54 1.74
PresentMon median present interval 547 ms 480 ms
  • Trap lines at the end: about 12,200 spans (9.3 GB) read-only, 18,459 faults, 44,213 made read-only, 13,535 given back by changes.
  • ERROR_NOACCESS / 998, access-violation and 0x80070005 lines in the log: 0. Device removals and GPU wait timeouts: 0.
  • Frames: I compared 3 world frames per run (at 25 / 50 / 90 % of the world) by eye, and saw no stretched or stale textures. One more thing changed between the two runs: the whole-form shader blobs for XCL_CHAIN_WHOLE were warmed in between. CW1 already ran every split dispatch whole, so I read that difference as small.

Not covered: kernel writes by paths other than the hooked ReadFile / DirectStorage ones (your note), a title-installed first vectored handler, AMD / Intel.

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.

<!-- greyfinch-sync:ivall/xcl:comment:7209669260 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2934#issuecomment-7209669260). Originally posted by [CharlyRien](https://github.com/CharlyRien) on 2026-11-27T04:16:47Z. --- @Kalmarv, an in-game data point for `XCL_WATCH_TRAP=1` on an RTX 3090 with the retail title: the write-watch look per title submit went from 14.4 to 5.6 ms. Heavy-slice presents/s went up 13 %. I saw no missed-write errors and no stale-texture artefacts in the frames I checked. **What ran:** `7692dd87` + `c230aa1b` cherry-picked onto MacieGx's lab tree `59986ef`, which already had his `XCL_CHAIN_WHOLE` commit (`47d0eac`, see #505). - Two conflicts, resolved by hand. - `mod.rs`: the `pub mod watch_trap;` line. - `title_textures.rs` `refresh_once`: the lab's `XCL_LOOK_JOIN` / `XCL_WATCH_HOT` branches are kept; the trap replaces only the full-look loop, as in the PR. - The other 9 files carry the PR's lines; `watch_trap.rs` is byte-identical. The translated identity is unchanged. **Runs:** MacieGx's #505 env, plus `XCL_PAGE_BUDGET_MB=4096`, `XCL_LOOK_JOIN=0` and `XCL_CHAIN_WHOLE=1`. One run per arm, 420 s in the world. | | off (CW1) | `XCL_WATCH_TRAP=1` (WT1) | |---|---:|---:| | write-watch look, ms per title submit | 14.4 | **5.6** | | whole submit cost, ms | 37.6 | 27.8 | | `ExecuteCommandLists` busy | 100 % | 83 % | | heavy-slice presents/s (> 2000 draws) | 1.54 | **1.74** | | PresentMon median present interval | 547 ms | 480 ms | - Trap lines at the end: about 12,200 spans (9.3 GB) read-only, 18,459 faults, 44,213 made read-only, 13,535 given back by changes. - `ERROR_NOACCESS` / 998, access-violation and `0x80070005` lines in the log: 0. Device removals and GPU wait timeouts: 0. - Frames: I compared 3 world frames per run (at 25 / 50 / 90 % of the world) by eye, and saw no stretched or stale textures. One more thing changed between the two runs: the whole-form shader blobs for `XCL_CHAIN_WHOLE` were warmed in between. CW1 already ran every split dispatch whole, so I read that difference as small. Not covered: kernel writes by paths other than the hooked `ReadFile` / DirectStorage ones (your note), a title-installed first vectored handler, AMD / Intel. **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 commented 2026-11-27 06:14:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-27T06:14:41Z.

Review: COMMENTED


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.

Hook · Thaw

AI-assisted review (GPT-6.2 Sol).

<!-- greyfinch-sync:ivall/xcl:review:6084270289 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2934#pullrequestreview-6084270289). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-27T06:14:41Z. **Review:** COMMENTED --- 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`. [Hook](https://github.com/xcl-dev/xcl/blob/c230aa1b206a93e6ee81f7edb7d71343c0d5c6cc/crates/xcl/src/hle/kernelx.rs#L502-L505) · [Thaw](https://github.com/xcl-dev/xcl/blob/c230aa1b206a93e6ee81f7edb7d71343c0d5c6cc/crates/xcl/src/hle/d3d12x/watch_trap.rs#L100-L119) AI-assisted review (GPT-6.2 Sol).
VolenNakov commented 2026-11-27 11:59:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by VolenNakov on 2026-11-27T11:59:57Z.


In-game data point from a slow CPU (i7-8700): with XCL_WATCH_TRAP=1 the world's present rate went from 1.16 to 3.34 presents/s, and the GPU became the busy side. One run per arm, same tree, same caches; the only difference is XCL_WATCH_TRAP=1.

Setup

  • RTX 4060 Ti 16 GB (driver 610.88, no Resizable BAR); i7-8700 (6 cores / 12 threads, 2017); 32 GB RAM; Windows 11 26200; release. Retail title ea3b5e4d of #505, Series X profile.
  • Tree: main 08db802 + #2526, #2097, #2404, #2590, #2615, #2618, #751, #2753, #2759, #759 / #1826, #2844 (fc007a9); + this PR's 7692dd87 and c230aa1b, cherry-picked clean.
  • Env: XCL_NETWORK=0 XCL_DIRECT_DXIL=all XCL_TEXTURE_LEVEL_PAGES=1 XCL_SPLIT_INDIRECT_ROUNDS=2 XCL_DIRECT_SPLIT_INSTRUCTIONS=0, 2 GiB shader heap (#2590), warm caches, 900 s, A pressed from 6 to 300 s.
without with XCL_WATCH_TRAP=1
world presents/s, mean from entry to ~760 s 1.16 3.34
300-frame lines in the world 1.1, 1.2 3.7, 3.8, 4.5, 1.9, 4.1
sparse windows timing: write-watch, cumulative 617 s by 796 s (78 %) 116 s by 508 s (23 %)
GPU busy in the world (nvidia-smi every 5 s, 200–880 s) 26 % mean, ≥ 95 % in 0 of 107 75 % mean, ≥ 95 % in 64 of 97
peak commit / video memory 30.8 / 13.2 GB 34.2 / 12.1 GB
errors / removals / GPU wait timeouts 0 / 0 / 0 0 / 0 / 0
  • The last trap line, at 791 s: look 49152, 9133 spans read-only (5897 MB) or holes (4537), this look 551 of 18664 MB looked at in 282 pieces; so far 35425 faults, 66744 made read-only, 22186 given back by changes, 0 pending reads, 0 regions not given back, 2 refused.
  • On this CPU the submitting thread had spent most of the run in GetWriteWatch. #2844 alone halved the GPU's busy time and did not move the present rate. With the trap the time goes to the GPU instead, so on a CPU of this class the two are needed together.
  • Peak commit is 3.4 GB higher with the trap. One run each, so this may be noise.
  • This tree draws the world grey, as on #2938's runs, so the frames cannot be checked for stale textures. "0 regions not given back" and no errors are all I can show for missed writes.

Not tested: more than one run per arm; the trap with hot looks (XCL_WATCH_HOT, not on main); the stale-texture side, in a tree that draws the world.

AI use: Claude Code (Claude Opus 5.5) ran the runs, read the logs and wrote this.

<!-- greyfinch-sync:ivall/xcl:comment:7217717230 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2934#issuecomment-7217717230). Originally posted by [VolenNakov](https://github.com/VolenNakov) on 2026-11-27T11:59:57Z. --- **In-game data point from a slow CPU (i7-8700): with `XCL_WATCH_TRAP=1` the world's present rate went from 1.16 to 3.34 presents/s, and the GPU became the busy side.** One run per arm, same tree, same caches; the only difference is `XCL_WATCH_TRAP=1`. **Setup** - RTX 4060 Ti 16 GB (driver 610.88, no Resizable BAR); i7-8700 (6 cores / 12 threads, 2017); 32 GB RAM; Windows 11 26200; release. Retail title `ea3b5e4d` of #505, Series X profile. - Tree: `main` `08db802` + #2526, #2097, #2404, #2590, #2615, #2618, #751, #2753, #2759, #759 / #1826, #2844 (`fc007a9`); + this PR's `7692dd87` and `c230aa1b`, cherry-picked clean. - Env: `XCL_NETWORK=0 XCL_DIRECT_DXIL=all XCL_TEXTURE_LEVEL_PAGES=1 XCL_SPLIT_INDIRECT_ROUNDS=2 XCL_DIRECT_SPLIT_INSTRUCTIONS=0`, 2 GiB shader heap (#2590), warm caches, 900 s, A pressed from 6 to 300 s. | | without | with `XCL_WATCH_TRAP=1` | |---|---|---| | world presents/s, mean from entry to ~760 s | 1.16 | **3.34** | | 300-frame lines in the world | 1.1, 1.2 | 3.7, 3.8, 4.5, 1.9, 4.1 | | `sparse windows timing: write-watch`, cumulative | 617 s by 796 s (78 %) | **116 s by 508 s (23 %)** | | GPU busy in the world (`nvidia-smi` every 5 s, 200–880 s) | 26 % mean, ≥ 95 % in 0 of 107 | **75 % mean, ≥ 95 % in 64 of 97** | | peak commit / video memory | 30.8 / 13.2 GB | 34.2 / 12.1 GB | | errors / removals / GPU wait timeouts | 0 / 0 / 0 | 0 / 0 / 0 | - The last trap line, at 791 s: `look 49152, 9133 spans read-only (5897 MB) or holes (4537), this look 551 of 18664 MB looked at in 282 pieces; so far 35425 faults, 66744 made read-only, 22186 given back by changes, 0 pending reads, 0 regions not given back, 2 refused`. - On this CPU the submitting thread had spent most of the run in `GetWriteWatch`. #2844 alone halved the GPU's busy time and did not move the present rate. With the trap the time goes to the GPU instead, so on a CPU of this class the two are needed together. - Peak commit is 3.4 GB higher with the trap. One run each, so this may be noise. - This tree draws the world grey, as on #2938's runs, so the frames cannot be checked for stale textures. "0 regions not given back" and no errors are all I can show for missed writes. **Not tested:** more than one run per arm; the trap with hot looks (`XCL_WATCH_HOT`, not on `main`); the stale-texture side, in a tree that draws the world. AI use: Claude Code (Claude Opus 5.5) ran the runs, read the logs and wrote this.
JJAutoCompare commented 2026-11-27 12:21:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-27T12:21:08Z.


Historical Intel Arc readback

Tested clean dac9681b57cb64f749d7977cf4ee477d83ca3aa7 on Windows 11 build 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust 1.100.0 MSVC debug. Current head c230aa1b206a93e6ee81f7edb7d71343c0d5c6cc was outside this run.

Built with cargo test --locked -j 2 -p xcl --lib --no-run. Ran hle::d3d12x::title_textures::tests::gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes --exact --test-threads=1 --nocapture twice with XCL_ADAPTER=A770, once at XCL_WATCH_TRAP=0 and once at 1. Each process used a separate shared Arc mutex acquisition and the binary hash held.

Both runs matched all 4,096 pixels at each of the five 64×64 R8 readbacks: initial 0x3D, CPU write 0x9A, untouched physical mapping 0x00, write to that mapping 0xC7, and restored CPU view 0x9A after unmap. The enabled run logged watch-trap scans at looks 1, 2 and 4 with zero cold spans and zero faults. Two passed, zero failed, ignored, or skipped.

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 (gpt-6.2-sol) ran and independently reran both readback cases and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7218139709 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2934#issuecomment-7218139709). Originally posted by [JJAutoCompare](https://github.com/JJAutoCompare) on 2026-11-27T12:21:08Z. --- **Historical Intel Arc readback** Tested clean `dac9681b57cb64f749d7977cf4ee477d83ca3aa7` on Windows 11 build 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust 1.100.0 MSVC debug. Current head `c230aa1b206a93e6ee81f7edb7d71343c0d5c6cc` was outside this run. Built with `cargo test --locked -j 2 -p xcl --lib --no-run`. Ran `hle::d3d12x::title_textures::tests::gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes --exact --test-threads=1 --nocapture` twice with `XCL_ADAPTER=A770`, once at `XCL_WATCH_TRAP=0` and once at `1`. Each process used a separate shared Arc mutex acquisition and the binary hash held. Both runs matched all 4,096 pixels at each of the five 64×64 R8 readbacks: initial `0x3D`, CPU write `0x9A`, untouched physical mapping `0x00`, write to that mapping `0xC7`, and restored CPU view `0x9A` after unmap. The enabled run logged watch-trap scans at looks 1, 2 and 4 with zero cold spans and zero faults. Two passed, zero failed, ignored, or skipped. **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 (`gpt-6.2-sol`) ran and independently reran both readback cases and wrote this report.
throny commented 2026-11-27 15:38:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-27T15:38:07Z.


Triage note (from https://github.com/xcl-dev/xcl/issues/1607#issuecomment-7222291116, a check from the outside against CONTRIBUTING.md, not a code review):

PR description is red: the main/head xcl-smoke pair is missing. At 819 lines it is also over the size where the description should say why it cannot be split.

AI use: Claude Code (Claude Fable 5.2).

<!-- greyfinch-sync:ivall/xcl:comment:7222297021 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2934#issuecomment-7222297021). Originally posted by [throny](https://github.com/throny) on 2026-11-27T15:38:07Z. --- Triage note (from https://github.com/xcl-dev/xcl/issues/1607#issuecomment-7222291116, a check from the outside against CONTRIBUTING.md, not a code review): `PR description` is red: the main/head `xcl-smoke` pair is missing. At 819 lines it is also over the size where the description should say why it cannot be split. AI use: Claude Code (Claude Fable 5.2).
Kalmarv commented 2026-11-27 17:19:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-27T17:19:03Z.


Closing stale draft (nvidia-dev uses XCL_WATCH_HOT on a rewritten title_textures.rs).

<!-- greyfinch-sync:ivall/xcl:comment:7224270845 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2934#issuecomment-7224270845). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-27T17:19:03Z. --- Closing stale draft (`nvidia-dev` uses `XCL_WATCH_HOT` on a rewritten `title_textures.rs`).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2934
No description provided.