D3D12.X: the per-draw mirror sync copies only the pages the title wrote #2478
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!2478
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2478"
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 19:45 UTC · original
KOLESNiii:d3d12x-mirror-sync-written-pages→main· +554 −17 · 4 files · 3 commits · openStacked 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_bufferscopies 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 theGetWriteWatchcall 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:GetWriteWatchwithout reset), plus the pages a look took off it since the mirror's last copy (MIRROR_STALE, besideMIRRORSand not in it, to stay clear of #1995).MIRROR_LOOK_SEQ).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 ofWATCH_CACHE's key) and hands the pages it takes off the write-watch tolist_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, andthe_look_before_a_submit_lets_the_mirror_sync_skip_unwritten_pages, which goes throughrefresh.crates/xcl/src/hle/kernelx.rs:reserve_watchedispub(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 (21no wave64, 3 f16/f32 programs refused for wave32 (#1426), 1no heap windows, as onmain).New tests:
the_mirror_sync_copies_only_the_pages_the_title_wrotefails on #2437's code ("unchanged since: nothing copied").a_look_runs_for_buffer_mirrors_alonefails with the old early return.the_look_before_a_submit_lets_the_mirror_sync_skip_unwritten_pagespasses 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.Measurement: retail game, menus, 120 s with its learned coherent window removed so mirrors are made.
XCL_ACTIVITYcounters 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 of2bdfb90, before the review fix. That fix changes only the case with no sparse window, and every run here had three.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 ofmain, and neither rerun of this commit hung, so it is not counted against this change. The cause is not known.Regression run
main:This PR:
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
AI use
🤖 Generated with Claude Code
@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
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 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::the_mirror_sync_copies_around_a_page_the_title_made_unreadableandthe_mirror_sync_copies_only_the_pages_the_title_wrote.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 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. Notegpu_depth_buffer_created_for_unordered_access_is_placedis 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).@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!
@KOLESNiii on GitHub · 2026-11-25 20:45 UTC · original
@bmjask thanks, you're right. With no sparse window and no title texture,
refresh_oncereturned before the look, so mirror sources were never reset and every draw copied every page ever written. Fixed ina6ec51e(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_alonecovers that condition and fails with the old early return.the_look_before_a_submit_lets_the_mirror_sync_skip_unwritten_pagesgoes end to end throughrefresh, 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.gpu::uma; tell me if you want one.cargo test --workspace -- --test-threads=4ona6ec51e: 1279 passed, 0 failed, 46 ignored, 25 SKIPPED (RTX 2070 SUPER). The regression run fora6ec51eis still to come; the machine was short of commit memory for the one I tried.Written with Claude Code (Claude Opus 5.5).
@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, andgit merge-treereports a conflict between their heads. Beyond the text conflict:MIRRORS(title_start, cpu_src_start, len, mirror), so a mirror of a GPU-view address copies from its CPU backing.mirror_sources, theGetWriteWatchinwritten_pages,MIRROR_STALE) works on the title address.Combined as they are, a GPU-view mirror's
GetWriteWatchfails, 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 tocpu_src_startwhen resolving would keep both. (Read from the diffs a6ec51e /bdfb2fb, not run.)@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
GetWriteWatchrange, theMIRROR_STALEkey andmirror_sources()tocpu_src_starttogether. 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.@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
@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.
@luckyteagirl on GitHub · 2026-11-26 07:35 UTC · original · reviewed
list_x.rs:3756–3758:written_pagesclears a stale bit for an entire 4 KiB page, butcopy_writtencopies only the current draw's byte range (:3791–3801,3819). Afterrefreshresets write-watch and records that page inMIRROR_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.77e48ea4bato1e5ab11396@KOLESNiii on GitHub · 2026-11-26 10:24 UTC · original
@luckyteagirl thanks, you're right. Once
written_pagescleared a page's stale bit,copy_writtencopied only the draw's bytes of it, so a second draw on another part of the page read old mirror bytes. Fixed in1e5ab11(squashed into the PR's commit):written_pagesalso returns the mirror's source range.copy_writtencopies 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_pagesnow 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=4on1e5ab11: 1429 passed, 0 failed, 46 ignored, 25 SKIPPED (RTX 2070 SUPER). The regression run in the description is now of1e5ab11. As before, it made no mirrors, so it doesn't reach the changed path.Written with Claude Code (Claude Opus 5.5).
1e5ab11396to7e1d4261c5View 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.