Skip to content

D3D12.X: the per-draw mirror sync copies without asking readable() - #2437

Open
KOLESNiii wants to merge 2 commits into
xcl-dev:mainfrom
KOLESNiii:d3d12x-mirror-sync-no-readable
Open

KOLESNiii wants to merge 2 commits into
xcl-dev:mainfrom
KOLESNiii:d3d12x-mirror-sync-no-readable

Conversation

@KOLESNiii

@KOLESNiii KOLESNiii commented Nov 25, 2026 •

Copy link
Copy Markdown

Stacked on #2416; only the top commit (D3D12.X: the per-draw mirror sync copies without asking readable()) belongs here.

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; the measurement on #2389 saw single calls take 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), and the indices are scanned from the index buffer's mirror once copied there.

Fixes #2392. Part of #2389.

This differs from the proposal in #2392 (check once per mirror, again after kernelx frees or reprotects memory): kernelx does not see HeapFree, which releases large heap blocks inside ntdll, so that design still needed a copy that cannot fault, and with one the check had nothing left to protect. No kernelx change.

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs: the copy goes through copy_committed_region; a page the title freed or protected since keeps what the mirror had (before, readable failed and none of the range was copied). Indices are read from the mirror; an index buffer without a mirror is still checked with readable. Two tests: the_mirror_sync_copies_around_a_page_the_title_made_unreadable, and the_mirror_sync_copies_whole_buffers_around_a_page_the_title_made_unreadable for the other paths with a vertex page made unreadable (an index buffer without a mirror giving the vertex range, a draw with instances, an unreadable index buffer without a mirror: both copy the whole buffer around the page).
  • crates/xcl/src/hle/d3d12x/title_textures.rs: copy_committed_region is pub(super).

Tested

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: c24fbbff5e1bcebfee2b24fd4399592664927da6
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1479 (PresentX 1480)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15369 MB

Not tested

  • In a title: a draw whose source is actually unreadable, instanced or whole-buffer copies, and an index buffer without a mirror (none in these menus; only in the unit tests).
  • The game's world; 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

raylitebull added a commit that referenced this pull request Nov 25, 2026
Port upstream PR #2437 (by KOLESNiii, commit bb9bea2) onto amd-dev.

sync_title_buffers checked every copy's source and scanned indices with gpu::shader::readable. For a range with a non-resident page or over 16 pages, that walked the region with VirtualQuery, stalling the render thread for 1.1-8.8 ms inside draws (#2389 / #2392).

Use title_textures::copy_committed_region (ReadProcessMemory, which cannot fault) so freed or protected pages keep what the mirror already holds, and scan indices from the index buffer's mirror once copied (keeping readable() only when an index buffer has no mirror). Includes regression test.

Fixes #2392. Part of #2389.

Assisted-by: Antigravity (Gemini 4 Neon High)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…#2414, xcl-dev#2415

Integrates per-draw mirror sync fast path (xcl-dev#2437), PresentX compositor
hardening (xcl-dev#2418), XAudio2 GetState buffer context fix (xcl-dev#2410), and Wine
test fixes (xcl-dev#2414, xcl-dev#2415).

Assisted-by: Antigravity (Gemini 4 Neon)
@SlopTart

Copy link
Copy Markdown

gpu_ suite (cold cache): 160 passed / 4 failed, no crashes. Three are the known baseline trio on this lane; the fourth is gpu_promoted_uav_clear_values_pass_create_committed_resource, newly red on main since #2280 (report), unrelated to this PR.
Targeted run of the_mirror_sync_copies_around_a_page_the_title_made_unreadable: passed.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@KOLESNiii
KOLESNiii marked this pull request as ready for review November 25, 2026 19:57
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…#2414, xcl-dev#2415

Integrates per-draw mirror sync fast path (xcl-dev#2437), PresentX compositor
hardening (xcl-dev#2418), XAudio2 GetState buffer context fix (xcl-dev#2410), and Wine
test fixes (xcl-dev#2414, xcl-dev#2415).

Assisted-by: Antigravity (Gemini 4 Neon)

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No concrete source-level defect found. copy_committed_region preserves prior mirror bytes for inaccessible pages while copying surrounding committed data, and mirrored-index range selection matches what the GPU draws; the focused test is useful. Merge evidence is incomplete: no current Windows build/test, and title validation did not exercise inaccessible sources, whole-buffer copies, instancing, or unmirrored indices. The XCL_ACTIVITY overhead is inherited from stacked #2416 and should be addressed there.

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head bb9bea21b5ab3520e4f8cfa1ffe5f4afd988efeb (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: 1274 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.
    • The PR's test passed: hle::d3d12x::list_x::tests::the_mirror_sync_copies_around_a_page_the_title_made_unreadable.
    • 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: bb9bea21b5ab3520e4f8cfa1ffe5f4afd988efeb
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1619 (PresentX 1619)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13966 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.

KOLESNiii and others added 2 commits November 25, 2026 22:22
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 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>
@KOLESNiii

Copy link
Copy Markdown
Author

Thanks. On the three points:

  • XCL_ACTIVITY overhead: fixed in D3D12.X: XCL_ACTIVITY counts and times the per-draw buffer mirror sync #2416 (the counters are off until host_main enables them for XCL_ACTIVITY). This PR is rebased onto it; head is now c24fbbf, on D3D12.X: XCL_ACTIVITY counts and times the per-draw buffer mirror sync #2416's fdbb6fe.
  • Paths the title runs did not reach: new unit test the_mirror_sync_copies_whole_buffers_around_a_page_the_title_made_unreadable. With a vertex page made unreadable it checks three things: an index buffer without a mirror gives the vertex range when it is readable; a draw with instances copies the whole buffer around the page; an unreadable index buffer without a mirror does the same. It fails without the change. A title run still does not reach these paths; that is under Not tested.
  • Windows build/test: cargo test --workspace -- --test-threads=4 on c24fbbf (RTX 2070 SUPER): 1426 passed, 0 failed, 46 ignored, 25 SKIPPED. The CI workflow for this fork PR is waiting for a maintainer to approve it (action_required). New smoke block in the description.

(Claude Code, Claude Opus 5.5)

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 26, 2026
…outside coherent window)

Preserves xcl-dev#871 safe coherent copy under Wine and xcl-dev#2437 pub(super)
copy_committed_region.

Assisted-by: Antigravity (Gemini 4 Neon)
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Royalflamejlh pushed a commit to Royalflamejlh/xcl that referenced this pull request Nov 26, 2026
…r sync copies without asking readable()

Taken as it is for a test on a title.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

# Conflicts:
#	crates/xcl/src/hle/d3d12x/list_x.rs
#	crates/xcl/src/host.rs
Royalflamejlh pushed a commit to Royalflamejlh/xcl that referenced this pull request Nov 26, 2026
…aw mirror sync copies without asking readable()"

This reverts commit 2870e10, reversing
changes made to 6aa80e3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

D3D12.X: the per-draw mirror sync checks its source with readable() at every draw

5 participants