D3D12.X: the per-draw mirror sync copies only the pages the title wrote #2478

Open
github-bot wants to merge 3 commits from github-bot/gh-2478 into main AGit
Owner

@⁠KOLESNiii on GitHub · 2026-11-25 19:45 UTC · original
KOLESNiii:d3d12x-mirror-sync-written-pages → main · +554 −17 · 4 files · 3 commits · open

Stacked on #2437 (itself on #2416); only the top commit (D3D12.X: the per-draw mirror sync copies only the pages the title wrote) belongs here.

sync_title_buffers copies the drawn range of every mirrored buffer at every draw, whether or not the title wrote it. For a source in write-watched memory (kernelx reserves GPU-visible title memory that way), a draw now copies only the pages written since they were last copied. On the one title measured, this is slower, not faster (see Tested): the title rewrites these pages every frame, so few copies are saved, and the GetWriteWatch call per draw costs more than they did. Opened as a draft for review of the approach and for numbers from other titles.

Part of #2393 (the copies). Part of #2389.

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs:
    • Which pages a draw copies: the pages on the write-watch (GetWriteWatch without reset), plus the pages a look took off it since the mirror's last copy (MIRROR_STALE, beside MIRRORS and not in it, to stay clear of #1995).
    • When it copies the whole range: when the source is not write-watched, or when a look overlapped the draw (MIRROR_LOOK_SEQ).
    • How much of a page: a page it copies is copied as far as it is in the mirror's source, not only the draw's part: its stale bit is cleared there, so another draw on the rest of the page would otherwise read old bytes (review below).
    • Test: the_mirror_sync_copies_only_the_pages_the_title_wrote.
  • crates/xcl/src/hle/d3d12x/title_textures.rs: the look watches the mirror sources (a new part of WATCH_CACHE's key) and hands the pages it takes off the write-watch to list_x::mirror_pages_written. Without that, a page written after a draw's copy and reset by the look would never be copied again. The look also runs when mirrors exist with no sparse window and no title texture (look_needed; review below). Tests: a_look_runs_for_buffer_mirrors_alone, and the_look_before_a_submit_lets_the_mirror_sync_skip_unwritten_pages, which goes through refresh.
  • crates/xcl/src/hle/kernelx.rs: reserve_watched is pub(crate), for that test's write-watched title memory.

Tested

  • Hardware: NVIDIA RTX 2070 SUPER (driver 32.0.16.2140), AMD Ryzen 5 3600XT, Windows 11 build 26300, Rust 1.100.0. Tests in debug, runs in release.

  • Suite on 7e1d426 (rebased onto #2416's review fix): cargo test --workspace -- --test-threads=4: 1430 passed, 0 failed, 46 ignored; 25 SKIPPED (21 no wave64, 3 f16/f32 programs refused for wave32 (#1426), 1 no heap windows, as on main).

  • New tests:

    • the_mirror_sync_copies_only_the_pages_the_title_wrote fails on #2437's code ("unchanged since: nothing copied").
    • a_look_runs_for_buffer_mirrors_alone fails with the old early return.
    • the_look_before_a_submit_lets_the_mirror_sync_skip_unwritten_pages passes with and without the early-return fix on this machine: the test process has a sparse window, so it never reaches that return. It covers the path through the real look.
    • Its two draws on disjoint halves of one page after a look fail without the whole-page copy ("each draw on the page reads the title's bytes").
  • Measurement: retail game, menus, 120 s with its learned coherent window removed so mirrors are made. XCL_ACTIVITY counters from #2416, means per 2 s. The machine got slower during the day: #2437's head gave very different numbers in the morning and the afternoon, so only the afternoon runs compare with each other. These runs are of 2bdfb90, before the review fix. That fix changes only the case with no sparse window, and every run here had three.

    #2437, morning #2437, afternoon this PR, afternoon (2 runs)
    presents 60 steady 60, ~35 from 66 s ~35–50 / ~26–46
    copies / KB copied 1,197 / 10,766 871 / 7,833 747 / 6,714 and 720 / 6,473
    time in the sync: median, mean 4.74, 4.74 ms 30, 38 ms 65, 76 ms and 45, 80 ms
  • Write-watch vs. content: a temporary check, run once and not in this commit, compared every mirror with its source after each draw. It found no stale pages. Copies stayed at ~1,100–1,200 per 2 s, because the write-watch reports these pages written every frame, although #2389 found their bytes unchanged.

  • Device hang: one earlier 120 s run of this commit ended in a device hang (0x887a0006), and the title drew ~200 draws per 2 s instead of ~780 from the moment the mirrors appeared. The author saw the same hang on a run of main, and neither rerun of this commit hung, so it is not counted against this change. The cause is not known.

Regression run

main:

xcl-smoke v1
commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1415 (PresentX 1415)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15388 MB

This PR:

xcl-smoke v1
commit: 7e1d4261c56c52aee1e952a44af45ec8bb4792ed
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1485 (PresentX 1485)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15442 MB

That run made no mirrors (the 4095 MB coherent window was in place), so it doesn't reach the changed path; see Measurement for runs that do.

Not tested

  • Other titles: a title that does not rewrite its mirrored buffers every frame, where this should save the copies. None was available.
  • Writes the write-watch does not see: GPU writes into the source, and a title that resets the write-watch on its own memory. In both cases a draw would use stale data.
  • Other hardware: AMD and Intel GPUs, wave64.

AI use

  • Claude Code with Claude Opus 5.5: wrote the code, the test, the commit message and this description, and ran the tests and the runs.

🤖 Generated with Claude Code

**@⁠KOLESNiii** on GitHub · 2026-11-25 19:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/2478) `KOLESNiii:d3d12x-mirror-sync-written-pages` → `main` · +554 −17 · 4 files · 3 commits · open Stacked on #2437 (itself on #2416); only the top commit (`D3D12.X: the per-draw mirror sync copies only the pages the title wrote`) belongs here. `sync_title_buffers` copies the drawn range of every mirrored buffer at every draw, whether or not the title wrote it. For a source in write-watched memory (kernelx reserves GPU-visible title memory that way), a draw now copies only the pages written since they were last copied. **On the one title measured, this is slower, not faster** (see Tested): the title rewrites these pages every frame, so few copies are saved, and the `GetWriteWatch` call per draw costs more than they did. Opened as a draft for review of the approach and for numbers from other titles. Part of #2393 (the copies). Part of #2389. **What is in it** - `crates/xcl/src/hle/d3d12x/list_x.rs`: - **Which pages a draw copies:** the pages on the write-watch (`GetWriteWatch` without reset), plus the pages a look took off it since the mirror's last copy (`MIRROR_STALE`, beside `MIRRORS` and not in it, to stay clear of #1995). - **When it copies the whole range:** when the source is not write-watched, or when a look overlapped the draw (`MIRROR_LOOK_SEQ`). - **How much of a page:** a page it copies is copied as far as it is in the mirror's source, not only the draw's part: its stale bit is cleared there, so another draw on the rest of the page would otherwise read old bytes (review below). - **Test:** `the_mirror_sync_copies_only_the_pages_the_title_wrote`. - `crates/xcl/src/hle/d3d12x/title_textures.rs`: the look watches the mirror sources (a new part of `WATCH_CACHE`'s key) and hands the pages it takes off the write-watch to `list_x::mirror_pages_written`. Without that, a page written after a draw's copy and reset by the look would never be copied again. The look also runs when mirrors exist with no sparse window and no title texture (`look_needed`; review below). Tests: `a_look_runs_for_buffer_mirrors_alone`, and `the_look_before_a_submit_lets_the_mirror_sync_skip_unwritten_pages`, which goes through `refresh`. - `crates/xcl/src/hle/kernelx.rs`: `reserve_watched` is `pub(crate)`, for that test's write-watched title memory. **Tested** - **Hardware:** NVIDIA RTX 2070 SUPER (driver 32.0.16.2140), AMD Ryzen 5 3600XT, Windows 11 build 26300, Rust 1.100.0. Tests in debug, runs in release. - **Suite** on `7e1d426` (rebased onto #2416's review fix): `cargo test --workspace -- --test-threads=4`: 1430 passed, 0 failed, 46 ignored; 25 SKIPPED (21 `no wave64`, 3 f16/f32 programs refused for wave32 (#1426), 1 `no heap windows`, as on `main`). - **New tests:** - `the_mirror_sync_copies_only_the_pages_the_title_wrote` fails on #2437's code ("unchanged since: nothing copied"). - `a_look_runs_for_buffer_mirrors_alone` fails with the old early return. - `the_look_before_a_submit_lets_the_mirror_sync_skip_unwritten_pages` passes with and without the early-return fix on this machine: the test process has a sparse window, so it never reaches that return. It covers the path through the real look. - Its two draws on disjoint halves of one page after a look fail without the whole-page copy ("each draw on the page reads the title's bytes"). - **Measurement:** retail game, menus, 120 s with its learned coherent window removed so mirrors are made. `XCL_ACTIVITY` counters from #2416, means per 2 s. The machine got slower during the day: #2437's head gave very different numbers in the morning and the afternoon, so only the afternoon runs compare with each other. These runs are of `2bdfb90`, before the review fix. That fix changes only the case with no sparse window, and every run here had three. | | #2437, morning | #2437, afternoon | this PR, afternoon (2 runs) | |---|---|---|---| | presents | 60 steady | 60, ~35 from 66 s | ~35–50 / ~26–46 | | copies / KB copied | 1,197 / 10,766 | 871 / 7,833 | 747 / 6,714 and 720 / 6,473 | | time in the sync: median, mean | 4.74, 4.74 ms | 30, 38 ms | 65, 76 ms and 45, 80 ms | - **Write-watch vs. content:** a temporary check, run once and not in this commit, compared every mirror with its source after each draw. It found no stale pages. Copies stayed at ~1,100–1,200 per 2 s, because the write-watch reports these pages written every frame, although #2389 found their bytes unchanged. - **Device hang:** one earlier 120 s run of this commit ended in a device hang (`0x887a0006`), and the title drew ~200 draws per 2 s instead of ~780 from the moment the mirrors appeared. The author saw the same hang on a run of `main`, and neither rerun of this commit hung, so it is not counted against this change. The cause is not known. **Regression run** `main`: ``` xcl-smoke v1 commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea gpu: NVIDIA GeForce RTX 2070 SUPER title: retail game seconds: 60 exit: 0x0 frames shown: 1415 (PresentX 1415) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15388 MB ``` This PR: ``` xcl-smoke v1 commit: 7e1d4261c56c52aee1e952a44af45ec8bb4792ed gpu: NVIDIA GeForce RTX 2070 SUPER title: retail game seconds: 60 exit: 0x0 frames shown: 1485 (PresentX 1485) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15442 MB ``` That run made no mirrors (the 4095 MB coherent window was in place), so it doesn't reach the changed path; see Measurement for runs that do. **Not tested** - **Other titles:** a title that does not rewrite its mirrored buffers every frame, where this should save the copies. None was available. - **Writes the write-watch does not see:** GPU writes into the source, and a title that resets the write-watch on its own memory. In both cases a draw would use stale data. - **Other hardware:** AMD and Intel GPUs, wave64. **AI use** - Claude Code with Claude Opus 5.5: wrote the code, the test, the commit message and this description, and ran the tests and the runs. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Once any buffer mirror exists, sync_title_buffers runs on every draw and
nothing reported what it costs. With XCL_ACTIVITY=1 it now logs, every 2 s
in which it ran: draws synced and those with a mirror, copies (whole
buffers), bytes copied, indices scanned for the vertex range, readable()
calls (those over 16 pages, which can take the VirtualQuery walk), the time
in readable() and its slowest call, and the time in the function.

The slowest readable() is not in #2391's list: measuring on #2389 found
single calls of 16 pages or fewer taking 1-9 ms, which the other counters
average away.

The counters cost nothing without XCL_ACTIVITY: host_main turns them on
(enable_sync_activity) before it starts the activity thread, and until then
sync_title_buffers, sync_readable() and sync_count() check one relaxed
bool and take no time stamps and touch no shared counter.

No change in behaviour: the old body is sync_mirrors, unchanged apart
from the counters, and sync_title_buffers still returns first when no
mirror exists.

Fixes #2391. Part of #2389.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sync_title_buffers checked every copy's source, and the indices it scans,
with gpu::shader::readable. For a range with a page that is not resident,
or over 16 pages, that walks the region with VirtualQuery. Measured on
#2389, in 18 of 43 two-second windows one such call took 1.1-8.8 ms on
the render thread inside a draw.

The copy now uses title_textures::copy_committed_region (ReadProcessMemory,
which cannot fault), so a page the title freed or protected since keeps
what the mirror had. The indices are scanned from the index buffer's
mirror once copied there; an index buffer without a mirror is still
checked.

#2392 proposed checking once per mirror and again after kernelx frees or
reprotects memory. kernelx does not see HeapFree, which releases large
heap blocks inside ntdll, so that still needed a copy that cannot fault,
and with one the check has nothing left to protect.

Fixes #2392. Part of #2389.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sync_title_buffers copied the drawn range of every mirrored buffer at
every draw. On a retail game's menus that was ~1,200 copies and 10.7 MB
per 2 s, of buffers the title never rewrites (#2389).

A mirror's source in write-watched memory (kernelx reserves GPU-visible
title memory that way) now has its written pages copied only: a draw asks
GetWriteWatch without reset for the pages written since the last look,
and adds the pages the look took off the write-watch since the mirror's
last copy. title_textures' look watches the mirror sources and hands
those pages on (list_x::mirror_pages_written), so a page written after a
draw's copy and reset by the look is still copied at the next draw. A
draw that overlaps a look (MIRROR_LOOK_SEQ odd or changed) copies its
whole range, as does one whose source is not write-watched.

The stale-page bits live beside MIRRORS, not in it, so as not to conflict
with #1995, which re-keys MIRRORS.

The look also runs when mirrors exist with no sparse window and no title
texture (it returned at once there, so the sources were never reset and
every draw copied every page ever written; review on #2478).

Part of #2393 (the copies; the index scan is cached in the next change).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:31:42 +00:00
Author
Owner

@⁠emirduran707 on GitHub · 2026-11-25 20:24 UTC · original

Independent AMD RDNA4 (native wave64) test report on exact head 2bdfb908c671fc488b7846ebbca198951ffb0114 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1275 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • Both PR tests passed: hle::d3d12x::list_x::tests::the_mirror_sync_copies_around_a_page_the_title_made_unreadable and the_mirror_sync_copies_only_the_pages_the_title_wrote.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: 2bdfb908c671fc488b7846ebbca198951ffb0114
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1614 (PresentX 1614)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 13922 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.
**@⁠emirduran707** on GitHub · 2026-11-25 20:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/2478#issuecomment-7173619951) Independent AMD RDNA4 (native wave64) test report on exact head `2bdfb908c671fc488b7846ebbca198951ffb0114` (clean detached checkout, no local changes). **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2602.17; tests debug, smoke release. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4`: **1275 passed, 2 failed, 46 ignored; 8 SKIPPED** (6 in `lower_dxil::tests::{f16,f32}_programs_on_the_gpu` refused by per-lane form; `heap_window_out_of_memory_falls_back_to_the_switch_form`; `pso_measurement_compiles_an_exact_synthetic_record`). All native wave64 GPU tests ran and passed. - Both PR tests passed: `hle::d3d12x::list_x::tests::the_mirror_sync_copies_around_a_page_the_title_made_unreadable` and `the_mirror_sync_copies_only_the_pages_the_title_wrote`. - The 2 failures (`gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` seed 722 and `fuzz_validate_and_gpu_3` seed 1599) are pre-existing on unmodified `main` on this GPU. **Regression run** (60 s retail-title smoke, `XCL_NETWORK=0`, release) ``` xcl-smoke v1 commit: 2bdfb908c671fc488b7846ebbca198951ffb0114 gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1614 (PresentX 1614) presents per 2 s (last 3): 60 60 61 device removals: 0 crashes: 0 peak commit: 13922 MB ``` (Matched `main` `68a284a` baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.) **Not tested** - D3D12 debug layer; Intel GPUs. **AI use** - Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 20:37 UTC · original

gpu_ suite (cold cache): 164 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, and the promoted-UAV-clear driver gap, PR #2490); none caused by this PR. Note gpu_depth_buffer_created_for_unordered_access_is_placed is green on main now, #2466 did its job on this lane.
Targeted run of the two mirror-sync tests (the_mirror_sync_copies_only_the_pages_the_title_wrote, the_mirror_sync_copies_around_a_page_the_title_made_unreadable): 2 passed. Same lane this feature's earlier tests were verified on (#2437).

**@⁠SlopTart** on GitHub · 2026-11-25 20:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/2478#issuecomment-7173938358) `gpu_` suite (cold cache): 164 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, and the promoted-UAV-clear driver gap, PR #2490); none caused by this PR. Note `gpu_depth_buffer_created_for_unordered_access_is_placed` is green on main now, #2466 did its job on this lane. Targeted run of the two mirror-sync tests (`the_mirror_sync_copies_only_the_pages_the_title_wrote`, `the_mirror_sync_copies_around_a_page_the_title_made_unreadable`): 2 passed. Same lane this feature's earlier tests were verified on (#2437).
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 20:37 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 20:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/2478#issuecomment-7173956355) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun. Thanks!
Author
Owner

@⁠KOLESNiii on GitHub · 2026-11-25 20:45 UTC · original

@⁠bmjask thanks, you're right. With no sparse window and no title texture, refresh_once returned before the look, so mirror sources were never reset and every draw copied every page ever written. Fixed in a6ec51e (squashed into the PR's commit):

  • title_textures::look_needed: the look also runs when a mirror exists (list_x::mirror_sources_gen() != 0).
  • a_look_runs_for_buffer_mirrors_alone covers that condition and fails with the old early return.
  • the_look_before_a_submit_lets_the_mirror_sync_skip_unwritten_pages goes end to end through refresh, on write-watched title memory from kernelx (reserve_watched): unchanged pages are skipped after a look, and a page written before the look is copied.
    • It doesn't cover the zero-texture, non-sparse case on my machine: the test process always has sparse windows here, so it passes with and without the fix. The predicate test is what covers that case. I don't see a way to force a non-sparse UMA in the shared test process without a test-only switch in gpu::uma; tell me if you want one.

cargo test --workspace -- --test-threads=4 on a6ec51e: 1279 passed, 0 failed, 46 ignored, 25 SKIPPED (RTX 2070 SUPER). The regression run for a6ec51e is still to come; the machine was short of commit memory for the one I tried.

Written with Claude Code (Claude Opus 5.5).

**@⁠KOLESNiii** on GitHub · 2026-11-25 20:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/2478#issuecomment-7174156528) @⁠bmjask thanks, you're right. With no sparse window and no title texture, `refresh_once` returned before the look, so mirror sources were never reset and every draw copied every page ever written. Fixed in `a6ec51e` (squashed into the PR's commit): - `title_textures::look_needed`: the look also runs when a mirror exists (`list_x::mirror_sources_gen() != 0`). - `a_look_runs_for_buffer_mirrors_alone` covers that condition and fails with the old early return. - `the_look_before_a_submit_lets_the_mirror_sync_skip_unwritten_pages` goes end to end through `refresh`, on write-watched title memory from kernelx (`reserve_watched`): unchanged pages are skipped after a look, and a page written before the look is copied. - It doesn't cover the zero-texture, non-sparse case on my machine: the test process always has sparse windows here, so it passes with and without the fix. The predicate test is what covers that case. I don't see a way to force a non-sparse UMA in the shared test process without a test-only switch in `gpu::uma`; tell me if you want one. `cargo test --workspace -- --test-threads=4` on `a6ec51e`: 1279 passed, 0 failed, 46 ignored, 25 SKIPPED (RTX 2070 SUPER). The regression run for `a6ec51e` is still to come; the machine was short of commit memory for the one I tried. *Written with Claude Code (Claude Opus 5.5).*
Author
Owner

@⁠Oliwettoo on GitHub · 2026-11-25 22:33 UTC · original

Heads-up for whichever of these merges second: #1995 and #2478 (stacked on #2437) both rewrite the per-draw mirror sync in list_x.rs, and git merge-tree reports a conflict between their heads. Beyond the text conflict:

  • #1995 makes MIRRORS (title_start, cpu_src_start, len, mirror), so a mirror of a GPU-view address copies from its CPU backing.
  • #2478's page tracking (mirror_sources, the GetWriteWatch in written_pages, MIRROR_STALE) works on the title address.

Combined as they are, a GPU-view mirror's GetWriteWatch fails, so the draw copies the whole range every time. That stays correct, but it loses #2478's saving for exactly the buffers #1995 adds. Switching the write-watch and stale-page lookups to cpu_src_start when resolving would keep both. (Read from the diffs a6ec51e / bdfb2fb, not run.)

**@⁠Oliwettoo** on GitHub · 2026-11-25 22:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/2478#issuecomment-7176518026) Heads-up for whichever of these merges second: #1995 and #2478 (stacked on #2437) both rewrite the per-draw mirror sync in `list_x.rs`, and `git merge-tree` reports a conflict between their heads. Beyond the text conflict: - #1995 makes `MIRRORS` `(title_start, cpu_src_start, len, mirror)`, so a mirror of a GPU-view address copies from its CPU backing. - #2478's page tracking (`mirror_sources`, the `GetWriteWatch` in `written_pages`, `MIRROR_STALE`) works on the title address. Combined as they are, a GPU-view mirror's `GetWriteWatch` fails, so the draw copies the whole range every time. That stays correct, but it loses #2478's saving for exactly the buffers #1995 adds. Switching the write-watch and stale-page lookups to `cpu_src_start` when resolving would keep both. (Read from the diffs a6ec51e / bdfb2fb, not run.)
Author
Owner

@⁠KOLESNiii on GitHub · 2026-11-25 22:58 UTC · original

Thanks, confirmed from the diffs: merged as is, a GPU-view mirror falls back to a full copy per draw (still correct). Whoever rebases second should move the GetWriteWatch range, the MIRROR_STALE key and mirror_sources() to cpu_src_start together. Moving only the copy source would make the stale-page lookup miss, and pages taken off the write-watch by a look would never be copied. I'll do that in #2478's rebase if #1995 lands first.

**@⁠KOLESNiii** on GitHub · 2026-11-25 22:58 UTC · [original](https://github.com/xcl-dev/xcl/pull/2478#issuecomment-7177000692) Thanks, confirmed from the diffs: merged as is, a GPU-view mirror falls back to a full copy per draw (still correct). Whoever rebases second should move the `GetWriteWatch` range, the `MIRROR_STALE` key and `mirror_sources()` to `cpu_src_start` together. Moving only the copy source would make the stale-page lookup miss, and pages taken off the write-watch by a look would never be copied. I'll do that in #2478's rebase if #1995 lands first.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 01:50 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 01:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/2478#issuecomment-7180182403) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
Author
Owner

@⁠bmjask on GitHub · 2026-11-25 20:16 UTC · original · reviewed

P2: the optimization is bypassed for a valid non-sparse UMA configuration with mirrored buffers but no title textures. refresh_once returns at title_textures.rs:722-727 before buffer mirror ranges are added/reset at :731-747. list_x.rs:3547-3565 then calls GetWriteWatch without RESET, so every page ever written stays dirty and is recopied on every draw. The new test calls the look helper directly and bypasses this return. Please run refresh when a mirror exists and add an end-to-end zero-texture/non-sparse coverage case.

**@⁠bmjask** on GitHub · 2026-11-25 20:16 UTC · [original](https://github.com/xcl-dev/xcl/pull/2478#pullrequestreview-6064333987) · **reviewed** P2: the optimization is bypassed for a valid non-sparse UMA configuration with mirrored buffers but no title textures. refresh_once returns at title_textures.rs:722-727 before buffer mirror ranges are added/reset at :731-747. list_x.rs:3547-3565 then calls GetWriteWatch without RESET, so every page ever written stays dirty and is recopied on every draw. The new test calls the look helper directly and bypasses this return. Please run refresh when a mirror exists and add an end-to-end zero-texture/non-sparse coverage case.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 07:35 UTC · original · reviewed

list_x.rs:3756–3758: written_pages clears a stale bit for an entire 4 KiB page, but copy_written copies only the current draw's byte range (:3791–3801,3819). After refresh resets write-watch and records that page in MIRROR_STALE, two draws can use disjoint vertex ranges on it: draw A clears the page bit and copies only A; with no new title write, draw B sees neither a write-watch page nor a stale bit and uses old mirror bytes for B. Main's unconditional per-draw copy would update B, so this is a correctness regression from the page optimization even for ordinary CPU-written vertices.

Could the stale page be cleared only after its mirrored bytes have all been refreshed (for example by copying the dirty page's full intersection with the mirror allocation), and could the existing look/submit fixture assert two disjoint draws on one page? This is an exact-head source interleaving at 77e48ea4ba7dd7492d14b237655279f8f083f0dc; I have not run the proposed GPU fixture or a title. AI-assisted review with Codex.

**@⁠luckyteagirl** on GitHub · 2026-11-26 07:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/2478#pullrequestreview-6070120637) · **reviewed** `list_x.rs:3756–3758`: `written_pages` clears a stale bit for an entire 4 KiB page, but `copy_written` copies only the current draw's byte range (`:3791–3801,3819`). After `refresh` resets write-watch and records that page in `MIRROR_STALE`, two draws can use disjoint vertex ranges on it: draw A clears the page bit and copies only A; with no new title write, draw B sees neither a write-watch page nor a stale bit and uses old mirror bytes for B. Main's unconditional per-draw copy would update B, so this is a correctness regression from the page optimization even for ordinary CPU-written vertices. Could the stale page be cleared only after its mirrored bytes have all been refreshed (for example by copying the dirty page's full intersection with the mirror allocation), and could the existing look/submit fixture assert two disjoint draws on one page? This is an exact-head source interleaving at `77e48ea4ba7dd7492d14b237655279f8f083f0dc`; I have not run the proposed GPU fixture or a title. AI-assisted review with Codex.
github-bot force-pushed github-bot/gh-2478 from 77e48ea4ba to 1e5ab11396 2026-11-26 11:16:18 +00:00 Compare
Author
Owner

@⁠KOLESNiii on GitHub · 2026-11-26 10:24 UTC · original

@⁠luckyteagirl thanks, you're right. Once written_pages cleared a page's stale bit, copy_written copied only the draw's bytes of it, so a second draw on another part of the page read old mirror bytes. Fixed in 1e5ab11 (squashed into the PR's commit):

  • written_pages also returns the mirror's source range. copy_written copies each page it found written or stale as far as the page lies in that range, not only the draw's part. That is the whole-page copy you suggested. The full-range fallback (source not write-watched, or a look overlapped the draw) still copies the draw's range only.
  • the_look_before_a_submit_lets_the_mirror_sync_skip_unwritten_pages now writes two bytes in different halves of one page, runs the look (refresh), and makes two draws over those halves with no write in between. It fails without the fix ("each draw on the page reads the title's bytes") and passes with it.

cargo test --workspace -- --test-threads=4 on 1e5ab11: 1429 passed, 0 failed, 46 ignored, 25 SKIPPED (RTX 2070 SUPER). The regression run in the description is now of 1e5ab11. As before, it made no mirrors, so it doesn't reach the changed path.

Written with Claude Code (Claude Opus 5.5).

**@⁠KOLESNiii** on GitHub · 2026-11-26 10:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/2478#issuecomment-7189323775) @⁠luckyteagirl thanks, you're right. Once `written_pages` cleared a page's stale bit, `copy_written` copied only the draw's bytes of it, so a second draw on another part of the page read old mirror bytes. Fixed in `1e5ab11` (squashed into the PR's commit): - `written_pages` also returns the mirror's source range. `copy_written` copies each page it found written or stale as far as the page lies in that range, not only the draw's part. That is the whole-page copy you suggested. The full-range fallback (source not write-watched, or a look overlapped the draw) still copies the draw's range only. - `the_look_before_a_submit_lets_the_mirror_sync_skip_unwritten_pages` now writes two bytes in different halves of one page, runs the look (`refresh`), and makes two draws over those halves with no write in between. It fails without the fix ("each draw on the page reads the title's bytes") and passes with it. `cargo test --workspace -- --test-threads=4` on `1e5ab11`: 1429 passed, 0 failed, 46 ignored, 25 SKIPPED (RTX 2070 SUPER). The regression run in the description is now of `1e5ab11`. As before, it made no mirrors, so it doesn't reach the changed path. *Written with Claude Code (Claude Opus 5.5).*
github-bot force-pushed github-bot/gh-2478 from 1e5ab11396 to 7e1d4261c5 2026-11-26 11:35:09 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2478/head:github-bot/gh-2478'
git switch 'github-bot/gh-2478'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2478'
git switch 'github-bot/gh-2478'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2478'
git switch 'github-bot/gh-2478'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2478'
git switch 'main'
git merge --squash 'github-bot/gh-2478'
git switch 'main'
git merge --ff-only 'github-bot/gh-2478'
git switch 'main'
git merge 'github-bot/gh-2478'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.