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

Open
github-bot wants to merge 2 commits from github-bot/gh-2437 into main AGit
Owner

@⁠KOLESNiii on GitHub · 2026-11-25 18:54 UTC · original
KOLESNiii:d3d12x-mirror-sync-no-readable → main · +254 −8 · 3 files · 2 commits · open

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

  • 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.

  • cargo test --workspace -- --test-threads=4 on e426972 (rebased onto #2416's review fix): 1427 passed, 0 failed, 46 ignored; 25 SKIPPED (21 no wave64, 3 refused #1426 forms, 1 no heap windows, as on main).

  • Both new tests fail without the change ("the first page is copied", "the whole buffer is copied") and pass with it.

  • Retail game, menus, 120 s (on the earlier head bb9bea2) with its learned coherent window removed so mirrors are made (a 384 KiB index buffer and a 1.1 MiB vertex buffer at 32.5 s), XCL_ACTIVITY counters from #2416, 43 two-second windows each, mean per 2 s:

    #2416 (bb01e85) this PR
    draws synced / copies / KB copied 775 / 1,192 / 10,716 778 / 1,197 / 10,766
    readable() calls, time 1,788, 1.30 ms 0
    slowest readable() 0.15 ms –
    time in the sync: median, max 4.74 ms, 5.09 ms 4.74 ms, 4.97 ms

    The time readable() took went to the copy instead: no change on average. The slow readable() calls of #2389 (1–9 ms) did not occur in the bb01e85 run, so this run does not show the stall going away; what the change removes is the code path that made it.

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

**@⁠KOLESNiii** on GitHub · 2026-11-25 18:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/2437) `KOLESNiii:d3d12x-mirror-sync-no-readable` → `main` · +254 −8 · 3 files · 2 commits · open 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** - 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. - `cargo test --workspace -- --test-threads=4` on `e426972` (rebased onto #2416's review fix): 1427 passed, 0 failed, 46 ignored; 25 SKIPPED (21 `no wave64`, 3 refused #1426 forms, 1 `no heap windows`, as on `main`). - Both new tests fail without the change ("the first page is copied", "the whole buffer is copied") and pass with it. - Retail game, menus, 120 s (on the earlier head `bb9bea2`) with its learned coherent window removed so mirrors are made (a 384 KiB index buffer and a 1.1 MiB vertex buffer at 32.5 s), `XCL_ACTIVITY` counters from #2416, 43 two-second windows each, mean per 2 s: | | #2416 (`bb01e85`) | this PR | |---|---|---| | draws synced / copies / KB copied | 775 / 1,192 / 10,716 | 778 / 1,197 / 10,766 | | `readable()` calls, time | 1,788, 1.30 ms | 0 | | slowest `readable()` | 0.15 ms | – | | time in the sync: median, max | 4.74 ms, 5.09 ms | 4.74 ms, 4.97 ms | The time `readable()` took went to the copy instead: no change on average. The slow `readable()` calls of #2389 (1–9 ms) did not occur in the `bb01e85` run, so this run does not show the stall going away; what the change removes is the code path that made it. **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: e4269721c2795213b996c09ce0b90daf4c461287 gpu: NVIDIA GeForce RTX 2070 SUPER title: retail game seconds: 60 exit: 0x0 frames shown: 1478 (PresentX 1478) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16287 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](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]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:30:53 +00:00
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 19:46 UTC · original

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.

**@⁠SlopTart** on GitHub · 2026-11-25 19:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/2437#issuecomment-7172746857) `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](https://git.gtahub.st/github/xcl-dev--xcl/pulls/2280)), unrelated to this PR. Targeted run of `the_mirror_sync_copies_around_a_page_the_title_made_unreadable`: passed.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 19:54 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!

**@⁠DavidM1911** on GitHub · 2026-11-25 19:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/2437#issuecomment-7172931779) 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!
Author
Owner

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

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.
**@⁠emirduran707** on GitHub · 2026-11-25 20:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/2437#issuecomment-7174253523) 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.
Author
Owner

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

Thanks. On the three points:

  • XCL_ACTIVITY overhead: fixed in #2416 (the counters are off until host_main enables them for XCL_ACTIVITY). This PR is rebased onto it; head is now c24fbbf, on #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)

**@⁠KOLESNiii** on GitHub · 2026-11-25 22:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/2437#issuecomment-7176633978) Thanks. On the three points: - **`XCL_ACTIVITY` overhead:** fixed in #2416 (the counters are off until `host_main` enables them for `XCL_ACTIVITY`). This PR is rebased onto it; head is now c24fbbf, on #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)
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 02:12 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 02:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/2437#issuecomment-7180566196) 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
github-bot force-pushed github-bot/gh-2437 from c24fbbff5e to e4269721c2 2026-11-26 11:35:07 +00:00 Compare
Author
Owner

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

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.

**@⁠bmjask** on GitHub · 2026-11-25 20:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/2437#pullrequestreview-6064791295) · **reviewed** 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.
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/2437/head:github-bot/gh-2437'
git switch 'github-bot/gh-2437'

Merge

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