Skip to content

D3D12.X: XCL_ACTIVITY counts and times the per-draw buffer mirror sync - #2416

Open
KOLESNiii wants to merge 1 commit into
xcl-dev:mainfrom
KOLESNiii:d3d12x-mirror-sync-activity
Open

KOLESNiii wants to merge 1 commit into
xcl-dev:mainfrom
KOLESNiii:d3d12x-mirror-sync-activity

Conversation

@KOLESNiii

@KOLESNiii KOLESNiii commented Nov 25, 2026 •

Copy link
Copy Markdown

Once any buffer mirror exists, list_x::sync_title_buffers runs on every draw, and nothing reported what it costs. With XCL_ACTIVITY=1 it now logs one line every 2 s in which it ran. This is diagnostics only, with no change in behaviour, and without XCL_ACTIVITY the sync takes no time stamps and touches no counter, so the other parts of #2389 have before and after numbers.

Fixes #2391. Part of #2389.

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs: counters for draws synced and those with a mirror, copies (whole buffers), bytes copied, indices scanned, readable() calls (those over 16 pages), the time in readable() and its slowest call, and the time in the function. The old body is now sync_mirrors, unchanged apart from the counters. sync_title_buffers still returns first when no mirror exists.
  • The counters are off unless XCL_ACTIVITY is set: host_main calls enable_sync_activity() before it starts the activity thread; until then sync_title_buffers, sync_readable() and sync_count() only check one relaxed AtomicBool (no Instant::now(), no shared atomics).
  • crates/xcl/src/host.rs: the buffer mirrors (2 s): … line in the XCL_ACTIVITY thread, printed whenever any of its counters moved (list_x::sync_row_due), 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.
  • One addition to the list in D3D12.X: XCL_ACTIVITY counts and times the per-draw buffer mirror sync #2391: the slowest readable() call. The measurement on D3D12.X: every draw re-syncs buffer mirrors on the CPU (VirtualQuery, whole-buffer copies, index scan) #2389 found single calls of 16 pages or fewer taking 1–9 ms, which the totals average away.

Tested

  • NVIDIA RTX 2070 SUPER (driver 32.0.16.2140), AMD Ryzen 5 3600XT, Windows 11 build 26300, Rust 1.100.0, debug.
  • Rebased onto main ae5ae5a8 on 2026-11-28 (it also merges cleanly into 753e8b1a, which was not tested). cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 on 953d3754: 1508 passed, 0 failed, 47 ignored; 25 SKIPPED (21 no wave64, 3 refused gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 forms, 1 no heap windows). The results below are from before the rebase.
  • cargo test --workspace -- --test-threads=4 on 49f0474: 1425 passed, 0 failed, 46 ignored; 25 SKIPPED (21 no wave64, 3 refused gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 forms, 1 no heap windows, as on main).
  • New test list_x::tests::the_mirror_sync_counts_only_once_xcl_activity_enables_it: with the counters off, sync_readable() / sync_count() leave every counter and the slowest time at their values; after enable_sync_activity() they count.
  • New test list_x::tests::a_mirror_sync_row_with_no_finished_draw_is_still_logged: a row with readable() work or a slowest time but no draw synced is due, as is one with only a draw.

Regression run
After the rebase onto main ae5ae5a8: RTX 2070 SUPER, the retail game, 60 s, XCL_PRESS_AT=25:A. One batch of seven runs (main, then #2416, #2437, #2533, #2478, #2500, #2940); the DXIL cache carries over from run to run, starting from a snapshot of the live cache with its driver blobs.

xcl-smoke v1
commit: ae5ae5a8cfaa82404f2a7370dc178c7345f28b4e
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1426 (PresentX 1426)
presents per 2 s (last 3): 60 56 48
device removals: 0
crashes: 0
peak commit: 16202 MB
xcl-smoke v1
commit: 953d37545a2018a112e5170dcf388b2d9c90f825
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1511 (PresentX 1511)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16350 MB

Not tested

  • The new line itself: this smoke run made no mirrors (the title's learned coherent window was in place), so the code under the counters did not run. Its numbers on D3D12.X: every draw re-syncs buffer mirrors on the CPU (VirtualQuery, whole-buffer copies, index scan) #2389 come from an earlier local version of the same counters, not from this commit.
  • The cost of the off path was not measured separately: it is one relaxed load of a bool that is written once at start-up, and the smoke run did not reach the mirror sync anyway.
  • AMD and Intel GPUs, wave64.

AI use

  • Claude Code with Claude Opus 5.5: wrote the code, the commit message and this description, and ran the tests and the smoke runs.

🤖 Generated with Claude Code

@KOLESNiii
KOLESNiii force-pushed the d3d12x-mirror-sync-activity branch from 89e4d54 to bb01e85 Compare November 25, 2026 18:13
@KOLESNiii
KOLESNiii marked this pull request as ready for review November 25, 2026 18:15
@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head b52e97f619cce2afbe09ad9715490dcee30e4e1c (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: 1273 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 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: b52e97f619cce2afbe09ad9715490dcee30e4e1c
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1564 (PresentX 1564)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13930 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • XCL_ACTIVITY=1 log output; D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows/NVIDIA test on #2416 head b52e97f (clean detached worktree): cargo build --offline --locked --workspace, then cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 passed: 1,275 passed, 0 failed, 46 ignored across 23 test binaries. The log also had 26 explicit SKIPPED notices: 21 no wave64, three unsupported per-lane #1426 forms, one driver-cache-disable test needing Windows Developer Mode/SDK support, and one no heap windows. GPU tests that did not skip ran on the RTX 3080 Ti.

Setup: Windows 11 build 26300; RTX 3080 Ti 12 GB, driver 621.35; Ryzen 7 9800X3D, 32 GB RAM; Rust 1.99.1; DXC 1.8.2502.11 from Windows SDK 10.0.26100.0. XCL_NETWORK=0, XCL_ADAPTER=RTX 3080 Ti, and XCL_DXC_DIR pointed to that SDK's x64 bin directory. The first cargo test invocation had two launcher e2e failures because it preceded cargo build --workspace and the standalone test-title binaries were absent; the complete rerun after the build passed.

Not tested: the new XCL_ACTIVITY=1 buffer-mirror log line (the suite did not establish that a draw created a mirror), retail smoke, or an AMD GPU. This is an independent suite check, not a claim that the new counters were exercised.

AI-assisted: Codex (GPT-6, exact variant unavailable) inspected the diff, ran the build and tests, checked the counts, and drafted this report.

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

P2: instrumentation is active regardless of XCL_ACTIVITY. sync_title_buffers always creates an Instant and updates atomics once mirrors exist; sync_readable always times/updates several atomics and each copy adds more. XCL_ACTIVITY only gates the logging thread, so normal users pay timing and shared-atomic contention on the per-draw mirror path despite the diagnostics-only/no-behavior-change claim. Gate all accounting behind an enabled fast path, then measure/test overhead-off. Current head also has no visible Windows Build/test and the smoke did not execute these counters.

@KOLESNiii

Copy link
Copy Markdown
Author

Thanks, agreed: XCL_ACTIVITY only gated the logging thread. Fixed in 15f4019 (squashed into the PR's commit):

  • host_main calls list_x::enable_sync_activity() before it starts the activity thread. Until then sync_title_buffers, sync_readable() and sync_count() check one relaxed AtomicBool and go straight to the untimed path: no Instant::now(), no shared atomics.
  • New test the_mirror_sync_counts_only_once_xcl_activity_enables_it: with the counters off, sync_readable() / sync_count() leave every counter and the slowest time unchanged. After enable_sync_activity() they count.
  • cargo test --workspace -- --test-threads=4 on 15f4019 (RTX 2070 SUPER): 1276 passed, 0 failed, 46 ignored, 25 SKIPPED. New smoke block in the description.

As you said, the retail smoke run makes no mirrors, so it does not reach these counters (this is under Not tested). I did not measure the off path separately.

(Claude Code, Claude Opus 5.5)

@KOLESNiii
KOLESNiii force-pushed the d3d12x-mirror-sync-activity branch from 15f4019 to fdbb6fe Compare November 25, 2026 22:25
@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

@luckyteagirl luckyteagirl 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.

At head fdbb6fe7ec0027a5b0274364475f0204684a8c5e, a mirror sync can cross the 2-second reporting boundary after a readable() call finishes but before the draw finishes. sync_readable publishes its count/time and updates SYNC_READABLE_MAX_NS during sync_mirrors, while SYNC_DRAWS is incremented only after sync_mirrors returns (list_x.rs:3774-3795). If the host samples in that gap, s[0] == 0, so host.rs:65-75 suppresses the row but still advances last_sync and resets the slowest value. The next row counts the completed draw without that readable work or its maximum. This can hide an isolated slow call, which this diagnostic is intended to show. Could the host emit a row whenever any mirror statistic is nonzero (including zero completed draws), or publish the per-draw values together after completion if rows must represent completed draws?

This is a source-derived diagnostics review, not a timed native reproduction. AI use: OpenAI Codex (GPT-6.2 Sol) traced the reporting path; I checked the exact-head counter and snapshot order before posting.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
@KOLESNiii
KOLESNiii force-pushed the d3d12x-mirror-sync-activity branch from fdbb6fe to 49f0474 Compare November 26, 2026 11:20
@KOLESNiii

Copy link
Copy Markdown
Author

Thanks, confirmed: with no draw's sync finished in a window, the row was skipped while take_sync_slowest() had already reset the slowest readable(), so a stalled sync lost exactly the number this is for.

Fixed in 49f0474 (amended into the commit) the first way you suggested: host.rs logs the row whenever any mirror counter or the slowest time moved (list_x::sync_row_due), including with 0 draws synced, which then reads as a sync still running at the sample or stalled. I kept the counters published as they happen rather than at the end of the draw, so a sync that never returns still shows up. New test: a_mirror_sync_row_with_no_finished_draw_is_still_logged. The full suite and the smoke run were redone on 49f0474 (counts and block in the description).

AI use: Claude Code (Claude Opus 5.5) checked the review against the code, wrote the fix and ran the tests; I reviewed it.

Osanchez pushed a commit to Osanchez/xcl that referenced this pull request Nov 26, 2026
Commit:   fdbb6fe

Conflicts resolved in: crates/xcl/src/host.rs - kept both sides of both regions (HEAD first)
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 <[email protected]>
@KOLESNiii
KOLESNiii force-pushed the d3d12x-mirror-sync-activity branch from 49f0474 to 953d375 Compare November 28, 2026 02:04
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: XCL_ACTIVITY counts and times the per-draw buffer mirror sync

6 participants