D3D12.X: the per-draw mirror sync writes only mirror pages whose bytes differ #2533
No reviewers
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!2533
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2533"
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 21:48 UTC · original
KOLESNiii:d3d12x-mirror-sync-compare→main· +582 −31 · 3 files · 5 commits · openStacked on #2437 (itself on #2416); only the top three commits (from
D3D12.X: the per-draw mirror sync writes only mirror pages whose bytes differup) belong here. It is an alternative to #2478, not on top of it.sync_title_bufferscopies the drawn range of every mirrored buffer at every draw and scans every index again. The title measured in #2389 rewrites these buffers every frame with the same bytes, so the write-watch reports them written (#2478 saved little that way) while their content stays the same. This change compares content instead: a copy writes only the mirror pages whose bytes differ, and an indexed draw reuses the vertex range it scanned while no mirror was written.Part of #2393. Part of #2389.
What is in it
crates/xcl/src/hle/d3d12x/list_x.rs:update_mirrorreads the title's bytes into a per-thread scratch buffer (64 KiB chunks,ReadProcessMemory) and writes only the 4 KiB pages that differ from the mirror. A chunk with a page the title freed or protected falls back tocopy_committed_region(#2392). Unchanged pages are no longer written into the mirror, so the sparse look no longer sees them dirty (#2394).a_mirror_is_written_only_where_the_title_bytes_differ(with a write-watch on the mirror, and a page made unreadable),a_vertex_range_is_scanned_again_only_after_a_mirror_write,the_mirror_sync_follows_changed_indices,a_vertex_range_is_not_reused_while_another_list_writes_the_indices(a test-only hook pauses list B between its index write and the bump).crates/xcl/src/host.rs: theXCL_ACTIVITYmirror line shows the KB written next to the KB compared.D3D12.X: a mirror chunk with an unreadable page is compared, not rewritten: a 64 KiB chunk thatReadProcessMemorycannot read whole is read around the page into the scratch buffer (filled first with the mirror's bytes) and compared like any other. Before, it was copied into the mirror whole and counted as written at every draw.D3D12.X: a cached index range is checked against its own mirror's writes: each mirror keeps its own count of writes (in its lock), replacing the oneMIRROR_WRITESfor all mirrors, so a draw that writes new vertices no longer makes every indexed draw scan its unchanged indices again. Test:a_vertex_range_is_kept_while_only_other_mirrors_are_written.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
cf9498e:cargo test --workspace -- --test-threads=4: 1431 passed, 0 failed, 46 ignored; 25 SKIPPED (21no wave64, 3 f16/f32 programs refused for wave32 (#1426), 1no heap windows, as onmain).New tests: the first three fail with the change undone (every page written; the cached range never rescanned); the fourth fails with the index mirror's lock removed (list A reuses its old range); the extended
a_mirror_is_written_only_where_the_title_bytes_differfails with the old fallback (16384 bytes written where 12288 changed);a_vertex_range_is_kept_while_only_other_mirrors_are_writtenfails with one count for all mirrors (3 scans instead of 1).Measurement (before the last three changes, not rerun since): retail game, menus, 120 s with its learned coherent window removed so the two mirrors are made (at ~31–32 s). One run each, means per 2 s of the
XCL_ACTIVITYlines once the mirrors exist (43–44 windows).bb9bea2)0c62a58)Only the window in which the mirrors were made wrote anything (219 KB); every later window wrote 0 KB and scanned 0 indices. What remains is the read and the compare. Both runs held 60 presents per 2 s, so frames do not show the saving.
Regression run
main:This PR:
That run had the 4095 MB coherent window in place and made no mirrors, so it does not reach the changed path; see Measurement for runs that do.
Not tested
0c62a58, before them.cf9498eshowed 896 frames (a slow start, 30 presents in one 2 s window); the rerun above showed 1438. That run makes no mirrors, so it does not reach this code.AI use
🤖 Generated with Claude Code
https://claude.ai/code/session_015csBcd63KUE2T1kW2P15nC
@DavidM1911 on GitHub · 2026-11-25 22:08 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@emirduran707 on GitHub · 2026-11-25 22:10 UTC · original
Independent AMD RDNA4 (native wave64) test report on exact head
0c62a58dc895919aee3c6f502420f74c20abc2a5(clean detached checkout, no local changes).Tested
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: 1277 passed, 2 failed, 46 ignored; 8 SKIPPED (6 inlower_dxil::tests::{f16,f32}_programs_on_the_gpurefused 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.hle::d3d12x::list_x::tests::a_mirror_is_written_only_where_the_title_bytes_differanda_vertex_range_is_scanned_again_only_after_a_mirror_write.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1seed 722 andfuzz_validate_and_gpu_3seed 1599) are pre-existing on unmodifiedmainon this GPU.Regression run (60 s retail-title smoke,
XCL_NETWORK=0, release)(Matched
main68a284abaseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)Not tested
AI use
@SlopTart on GitHub · 2026-11-25 23:07 UTC · original
Tested: current PR head merged onto current
origin/main(clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo targetx86_64-pc-windows-gnurun under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).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, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.Targeted run of
a_mirror_is_written_only_where_the_title_bytes_differ,a_vertex_range_is_scanned_again_only_after_a_mirror_write,the_mirror_sync_follows_changed_indices: 3 passed (plusthe_mirror_sync_copies_around_a_page_the_title_made_unreadablere-confirmed).Not tested: retail titles (no title data on this lane, counts only).
AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
@DavidM1911 on GitHub · 2026-11-26 01:36 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
@luckyteagirl on GitHub · 2026-11-26 07:06 UTC · original · reviewed
Could the index-mirror update and cached range lookup share synchronization? Two command lists can use the same mirror.
MIRRORSonly protects the address lookup, and the copy changes the mirror before incrementingMIRROR_WRITES. Suppose thread A has cached the range for index 0 and the title changes that index to 9 before either thread records its next draw. Thread B copies index 9 into the mirror and pauses before publishing the generation. A then sees matching source and mirror bytes, writes nothing, and hits its previous range under the old generation. The draw reads index 9, but A only refreshes the vertex data for index 0. Main rescans the mirror at this point.A per-mirror lock covering copy and index-range lookup would close the gap. A focused test can pause B after the copy and before generation publication, then check that A cannot reuse its old range. Exact-head source review of
5f61e932b631987e3ec65dc6f61b0acf7e8fc6c6. No concurrent GPU run. AI-assisted review with Codex.5f61e932b6tocf9498e824@KOLESNiii on GitHub · 2026-11-26 10:03 UTC · original
@luckyteagirl Confirmed, thanks. Each mirror now has a lock, held while the sync writes into it and bumps
MIRROR_WRITES. For the index buffer it is held from the copy through the generation read and the cached-range lookup or scan. Vertex copies take it too, since a vertex view and the index view can share a mirror.Added
a_vertex_range_is_not_reused_while_another_list_writes_the_indices. A test-only hook pauses list B after its index write and before the bump, and the test checks that list A, which has a range cached from before the change, still copies the vertex the changed index reaches. On an RTX 2070 SUPER it fails with the index mirror's lock removed and passes with it.Squashed into the top commit, now
26ccb47. Full suite: 1430 passed, 0 failed, 46 ignored, 25 SKIPPED as before. Smoke on the new head is in the description.(Claude Code, Claude Opus 5.5)
@KOLESNiii on GitHub · 2026-11-26 10:33 UTC · original
Two more commits from a review pass of my own:
01316f81D3D12.X: a mirror chunk with an unreadable page is compared, not rewritten. WhenReadProcessMemoryfailed for a chunk (#2392), the fallback copied it into the mirror whole and counted all of it as written at every draw. That is the rewrite #2393 removes, and it also threw away the cached index ranges. The chunk is now read into the scratch buffer, filled first with the mirror's bytes, and compared page by page.cf9498e8D3D12.X: a cached index range is checked against its own mirror's writes.MIRROR_WRITESwas one count for all mirrors, so a draw that wrote new vertices made the next indexed draw scan its unchanged indices again. Each mirror now keeps its own count, in the lock added for the race above.Each has a test that fails without it: 16384 bytes written where 12288 changed, and 3 index scans instead of 1. Suite on
cf9498e: 1431 passed, 0 failed, 46 ignored, 25 SKIPPED as before. Smoke on the new head is in the description.(Claude Code, Claude Opus 5.5)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.