Repository navigation
Conversation
Port upstream PR #2478 (by KOLESNiii, commit 2bdfb90) cleanly onto amd-dev. sync_title_buffers previously copied the full drawn range of every mirrored buffer on every draw even when the title never rewrote it (#2389 / #2393). Track write-watched mirror source pages via GetWriteWatch (without reset) plus MIRROR_STALE bits handed off by title_textures' write-watch look (mirror_look_begin / mirror_pages_written), falling back to full-range copy if a look overlaps the draw or the source is not write-watched. Includes regression test. Part of #2393. Assisted-by: Antigravity (Gemini 4 Neon High)
bmjask
left a comment
There was a problem hiding this comment.
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.
|
Independent AMD RDNA4 (native wave64) test report on exact head Tested
Regression run (60 s retail-title smoke, (Matched Not tested
AI use
|
|
|
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
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 (xcl-dev#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 xcl-dev#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 xcl-dev#2478). Part of xcl-dev#2393 (the copies; the index scan is cached in the next change). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2bdfb90 to
a6ec51e
Compare
|
@bmjask thanks, you're right. With no sparse window and no title texture,
Written with Claude Code (Claude Opus 5.5). |
|
Heads-up for whichever of these merges second: #1995 and #2478 (stacked on #2437) both rewrite the per-draw mirror sync in
Combined as they are, a GPU-view mirror's |
|
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 |
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 (xcl-dev#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 xcl-dev#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 xcl-dev#2478). Part of xcl-dev#2393 (the copies; the index scan is cached in the next change). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a6ec51e to
77e48ea
Compare
…s differ `sync_title_buffers` copied the drawn range of every mirrored buffer at every draw and scanned every index again. The retail game measured in xcl-dev#2389 rewrites these buffers every frame with the same bytes, so the write-watch sees them written (xcl-dev#2478 found no saving that way) while their content does not change. Each copy now reads 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's. A chunk with a page the title freed or protected is copied with `copy_committed_region` as before (xcl-dev#2392). Unchanged pages are no longer written into the mirror, so the sparse look no longer sees them dirty. An indexed draw whose indices are in a mirror keeps the vertex range it scanned, per thread, keyed by (index buffer, bytes, format, first, count, base vertex), and scans again only after any mirror was written (`MIRROR_WRITES`). `XCL_ACTIVITY` reports the bytes written next to the bytes compared. Part of xcl-dev#2393. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…written pages) Reconciles copy_committed_region with xcl-dev#751 (zero_unreadable=false for mirror sync, zero_unreadable=true for reusable TITLE_BYTES) and preserves xcl-dev#2384 gpu_view::sources in cached_watch_ranges. Assisted-by: Antigravity (Gemini 4 Neon)
|
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
Thanks! — Devin |
luckyteagirl
left a comment
There was a problem hiding this comment.
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.
xcl-dev#2478 + xcl-dev#2533) (cherry picked from commit 0af1f31de2adc6acb4a407176142bcab777fabd8)
…s differ `sync_title_buffers` copied the drawn range of every mirrored buffer at every draw and scanned every index again. The retail game measured in xcl-dev#2389 rewrites these buffers every frame with the same bytes, so the write-watch sees them written (xcl-dev#2478 found no saving that way) while their content does not change. Each copy now reads 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's. A chunk with a page the title freed or protected is copied with `copy_committed_region` as before (xcl-dev#2392). Unchanged pages are no longer written into the mirror, so the sparse look no longer sees them dirty. An indexed draw whose indices are in a mirror keeps the vertex range it scanned, per thread, keyed by (index buffer, bytes, format, first, count, base vertex), and scans again only after any mirror was written (`MIRROR_WRITES`). Each mirror 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 range lookup or scan: otherwise another list that has written new indices but not yet bumped the count is seen as "nothing differs", and the old range is reused. Vertex copies take it too, since a vertex view and the index view can share a mirror. `XCL_ACTIVITY` reports the bytes written next to the bytes compared. Part of xcl-dev#2393. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015csBcd63KUE2T1kW2P15nC
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 (xcl-dev#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 xcl-dev#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 xcl-dev#2478). A page a draw 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 mirror bytes (review on xcl-dev#2478). Part of xcl-dev#2393 (the copies; the index scan is cached in the next change). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77e48ea to
1e5ab11
Compare
|
@luckyteagirl thanks, you're right. Once
Written with Claude Code (Claude Opus 5.5). |
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. A row is logged whenever any of these moved, also with no draw synced: the counters of a sync still running at the sample (or stalled for over 2 s) land before its draw is counted, and its slowest readable() would otherwise be dropped with the skipped row. The slowest readable() is not in xcl-dev#2391's list: measuring on xcl-dev#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 xcl-dev#2391. Part of xcl-dev#2389. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 xcl-dev#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. xcl-dev#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 xcl-dev#2392. Part of xcl-dev#2389. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 (xcl-dev#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 xcl-dev#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 xcl-dev#2478). A page a draw 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 mirror bytes (review on xcl-dev#2478). Part of xcl-dev#2393 (the copies; the index scan is cached in the next change). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s differ `sync_title_buffers` copied the drawn range of every mirrored buffer at every draw and scanned every index again. The retail game measured in xcl-dev#2389 rewrites these buffers every frame with the same bytes, so the write-watch sees them written (xcl-dev#2478 found no saving that way) while their content does not change. Each copy now reads 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's. A chunk with a page the title freed or protected is copied with `copy_committed_region` as before (xcl-dev#2392). Unchanged pages are no longer written into the mirror, so the sparse look no longer sees them dirty. An indexed draw whose indices are in a mirror keeps the vertex range it scanned, per thread, keyed by (index buffer, bytes, format, first, count, base vertex), and scans again only after any mirror was written (`MIRROR_WRITES`). Each mirror 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 range lookup or scan: otherwise another list that has written new indices but not yet bumped the count is seen as "nothing differs", and the old range is reused. Vertex copies take it too, since a vertex view and the index view can share a mirror. `XCL_ACTIVITY` reports the bytes written next to the bytes compared. Part of xcl-dev#2393. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015csBcd63KUE2T1kW2P15nC
1e5ab11 to
7e1d426
Compare
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_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 D3D12.X: stage GPU-view CopyMemoryToMemoryX sources and shift newer CL1 remaps #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
1e5ab11(run on the working tree, then committed unchanged):cargo test --workspace -- --test-threads=4: 1429 passed, 0 failed, 46 ignored; 25 SKIPPED (21no wave64, 3 f16/f32 programs refused for wave32 (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426), 1no heap windows, as onmain).New tests:
the_mirror_sync_copies_only_the_pages_the_title_wrotefails on D3D12.X: the per-draw mirror sync copies without asking readable() #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 D3D12.X: XCL_ACTIVITY counts and times the per-draw buffer mirror sync #2416, means per 2 s. The machine got slower during the day: D3D12.X: the per-draw mirror sync copies without asking readable() #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 D3D12.X: every draw re-syncs buffer mirrors on the CPU (VirtualQuery, whole-buffer copies, index scan) #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