Skip to content

D3D12.X: XCL_ACTIVITY logs the CPU time of the looks before each submit - #1832

Open
marquezinii wants to merge 1 commit into
xcl-dev:mainfrom
marquezinii:activity-watch-time
Open

marquezinii wants to merge 1 commit into
xcl-dev:mainfrom
marquezinii:activity-watch-time

Conversation

@marquezinii

@marquezinii marquezinii commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Before every title submit, XCL looks for the CPU's writes. It runs GetWriteWatch over the watched ranges, copies what changed into sparse video memory, and uploads title textures again, all on the title's own submitting thread. On slower CPUs that look is most of the frame: @AlexLopezDevelop's i9-9900K sits at 2–6 fps with it in #582. The only record of it today is the sparse windows timing line, cumulative since the start and logged at power-of-two submit counts. From that line, a report at a few fps cannot tell how much of each second went to the look, or whether pipeline waits or the GPU are to blame instead.

With XCL_ACTIVITY=1, every 2 s now also logs one line about the looks of the last 2 s:

looks before submits (2 s): 13 looks took 29 ms (1.5 % of the time): write-watch 1 ms (5.2 MB watched a look, 26 pages written), copies into sparse video memory 27 ms, the rest 0 ms

The line gives:

  • the number of looks and their whole time, as a share of the 2 s (over 100 % when several threads submit);
  • the write-watch scan, with the MB it watched a look and the pages it found written;
  • the copies into sparse video memory (sparse::before_execute: lock wait, chunk scan, upload);
  • the rest: the look's lock, the title textures uploaded again, vram::before_execute.

This is meant to settle, from a tester's log, which of #582 / #1034 (the look), #1269 (pipeline compiles) or the GPU holds a slow run. The MB-per-look figure is the one #1034's description and ivall's request on #582 ask for ("ms per look, bytes per look"). Without XCL_ACTIVITY nothing is logged. The look itself gains two Instant::now() calls and a sum over the cached ranges (69 ranges a look in #582's numbers).

Related and different: #1065 (XCL_GPU_TIMING) times the whole ExecuteCommandLists call, #899 counts pipeline waits at a bind, and #1766 (XCL_GPU_PROFILE) times console programs on the GPU. None of them splits the look.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs: note_watch also counts looks and the bytes watched, plus note_look for a whole look; look_counters(), and look_line() for the log line; a unit test for the line.
  • crates/xcl/src/hle/d3d12x/title_textures.rs: refresh times the whole look, and refresh_once passes the bytes of the ranges it watched.
  • crates/xcl/src/host.rs: the XCL_ACTIVITY thread logs the line every 2 s.
  • HANDOFF.md: the line, next to what XCL_ACTIVITY already logs.

Tested

  • NVIDIA GeForce RTX 5070 12 GB, driver 621.40; Ryzen 5 5600X; Windows 11 Pro 26300; Rust 1.99.1 MSVC; DXC 1.9.2602.17; debug.
  • cargo test --workspace -- --test-threads=4 on 284a948: 960 passed, 0 failed, 43 ignored. SKIPPED: the wave64 cases of lower / lower_dxil and gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), the f16 and conversion forms lower_dxil refuses in wave32, heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache).
  • The project's test title through xcl run with XCL_ACTIVITY=1: the line above, logged at 4 s, next to its activity (2 s) line. The first 2 s logged 0 looks.

Regression run
Run by @kanade333 on an NVIDIA GeForce RTX 5080, 60 s each, release, retail title on its start screen, copied from their comment as posted. scripts/smoke.ps1 sets XCL_ACTIVITY=1 itself, so these runs also exercise the new line.

main:

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: NVIDIA GeForce RTX 5080
title: 1e8f5e55
seconds: 60
exit: 0x0
frames shown: 1615 (PresentX 1615)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16053 MB

PR:

xcl-smoke v1
commit: 284a948c83b9af874cd05d5f054e7af927de5789
gpu: NVIDIA GeForce RTX 5080
title: 1e8f5e55
seconds: 60
exit: 0x0
frames shown: 1649 (PresentX 1649)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15257 MB

What the line said in that run, at the start screen (last of 30):

looks before submits (2 s): 240 looks took 246 ms (12.3 % of the time): write-watch 238 ms (2173.3 MB watched a look, 810 pages written), copies into sparse video memory 4 ms, the rest 3 ms

That is about 1 ms a look, nearly all of it the write-watch over 2.2 GB, which agrees with #582's 0.83 ms on the first menus.

Not tested

  • The world: @kanade333's runs stay on the start screen, where the look matters least.
  • A title with XCL_ACTIVITY unset (smoke.ps1 sets it); the line is only logged with it set.
  • AMD, Intel and Wine.

AI use

  • Claude Code (Claude Opus 5.5): wrote the change, the test and this description, and ran the tests and the test-title run on the hardware above.

Before every title submit XCL looks for the CPU's writes (write-watch
over the watched ranges), copies them into sparse video memory and
uploads changed title textures, on the title's own thread. On slower
CPUs that look is most of the frame (2-6 fps on an i9-9900K in xcl-dev#582),
but the only record of it is the cumulative timing line logged at
power-of-two submit counts, so a report at a few fps cannot say how
much of each second went there.

With XCL_ACTIVITY=1 every 2 s now also logs the looks of the last 2 s:
how many, their whole time and its share of the 2 s, the write-watch
scan with the megabytes it watched a look and the pages it found, the
copies into sparse video memory, and the rest. Without XCL_ACTIVITY
only counters are added: two Instant::now() calls per look and a sum
over the cached ranges.
@kanade333

Copy link
Copy Markdown

Regression pair on a retail title for this head (284a948), and what the new line says on its start screen. Both runs pass the same way: no device removal, no crash, 1 649 frames against 1 615 on main.

Tested

  • NVIDIA GeForce RTX 5080 16 GB (driver 610.88, 32-lane waves), AMD Ryzen 9 9950X, 32 GB RAM, Windows 11 Pro 26200, rustc 1.100.0, DXC 1.9.2602.17, release.
  • Two clean worktrees, each built in its own target directory: main 20cf130 and this PR's head 284a948.
  • scripts\smoke.ps1 -Game <retail title 1.0.2.1> -Seconds 60 -Xcl <that build's xcl.exe>, each from its own worktree, main first and this head right after it. No input, so the title stays on its start screen. The blocks below are the script's output, not edited.

Regression run

main:

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: NVIDIA GeForce RTX 5080
title: 1e8f5e55
seconds: 60
exit: 0x0
frames shown: 1615 (PresentX 1615)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16053 MB

this PR's head:

xcl-smoke v1
commit: 284a948c83b9af874cd05d5f054e7af927de5789
gpu: NVIDIA GeForce RTX 5080
title: 1e8f5e55
seconds: 60
exit: 0x0
frames shown: 1649 (PresentX 1649)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15257 MB

The new line. The script sets XCL_ACTIVITY=1 itself, so the head's run printed it 30 times. Its last three:

looks before submits (2 s): 240 looks took 240 ms (12.0 % of the time): write-watch 232 ms (2173.3 MB watched a look, 810 pages written), copies into sparse video memory 4 ms, the rest 3 ms
looks before submits (2 s): 240 looks took 246 ms (12.3 % of the time): write-watch 238 ms (2173.3 MB watched a look, 810 pages written), copies into sparse video memory 4 ms, the rest 3 ms
looks before submits (2 s): 240 looks took 246 ms (12.3 % of the time): write-watch 238 ms (2173.3 MB watched a look, 810 pages written), copies into sparse video memory 4 ms, the rest 3 ms

So on this machine, at the start screen, a look takes about 1 ms and nearly all of it is the write watch, which agrees with #582's 0.83 ms.

Not tested

AI use: Claude Code (Claude Fable 5.2) built both trees, ran the script and wrote this report. I read it before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@marquezinii
marquezinii marked this pull request as ready for review November 25, 2026 04:32
@marquezinii

Copy link
Copy Markdown
Contributor Author

@kanade333 thank you, that's the smoke pair this needed, plus the first look at the line on a title. I've copied both blocks into Regression run as posted, with credit, and quoted one of the lines. The PR is out of draft now.

Your reading matches mine: about 1 ms a look at the start screen, nearly all of it write-watch over 2.2 GB. Six of eight thread dumps in title_textures::refresh in the world (your #505 comment) is exactly where I'd like to see what the line says, if you get a world run with it.

AI use: Claude Code (Claude Opus 5.5) drafted this reply.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
ozimchuk added a commit to ozimchuk/xcl-contrib that referenced this pull request Nov 25, 2026
The `looks before submits` line (xcl-dev#1832) leaves "the rest" of a look as one number. Its parts
are timed now: the view-source recheck, the VRAM pages' sync, the recheck of streamed textures
outside the write-watch, choosing the textures to upload, and the uploads (MB; the content hash
with its read, the detile, the submit with its wait), with what is left as "other". The line
also gives the longest look of the period: one slow look is a stall an average hides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

AMD RX 7800 XT test report

Tested locally by merging PR head 284a948c83b9af874cd05d5f054e7af927de5789 onto base main 3f2777019544c0ada2cd294aa792d3c378ff0df8 (no push). The base is an ancestor of current main and both trees merge cleanly.

Hardware and tools: AMD Radeon RX 7800 XT, driver 32.0.31035.1003; Windows 10 Pro; Rust 1.100.0 / Cargo 1.100.0; DXC 1.8.2502.11 (DXIL 1.8.2502.11). Debug test build.

cargo test --workspace --no-fail-fast -- --test-threads=4: 1,356 passed, 2 failed, 46 ignored. There were 7 SKIPPED reports: six GPU cases (wave32/wave64 variants for three unsupported instruction forms) and one heap-window case. The two failures and all 7 SKIPPED reports match the baseline (1,355 passed, 2 failed, 46 ignored).

Not tested

  • Smoke run or retail titles
  • Release build
  • Other GPUs

AI use
Codex (gpt-6-luna) ran Phase 2 tests and wrote this report (Phase 1 pre-compile / initial baseline run used Claude Code (Claude Sonnet 5.5)).

@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: diagnostics work runs unconditionally. refresh adds Instant timing/range sums and sparse note_look atomics on every non-BUSY submit; refresh_once/note_watch add more atomics, while XCL_ACTIVITY only gates logging. Users with it unset still pay hot-path timing/atomic overhead. Gate collection behind an activity-enabled fast path, or explicitly measure/document overhead-off. No line-arithmetic correctness defect found.

@thehollowedone

Copy link
Copy Markdown
Contributor

Follow-up to bmjask's hot-path review on current head 284a948c: I confirmed the new whole-look clock and note_look, watched-range byte sum, and WATCH[2..3] atomics run on each non-BUSY submit even with XCL_ACTIVITY unset. The older WATCH[0..1] timing and dirty-page counters also feed the existing sparse timing line, so they need to stay active.

The local candidate below caches the process-stable activity switch, times and sums only when it is on, and keeps the older counters in both modes. It adds a regression with private counters so it is safe in the parallel suite. #2144 is stacked on this PR and already has its own cached timed() flag for additional phases; it can reuse the same flag when rebased.

On Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, rustc 1.99.1 MSVC, DXC 1.8.2502.11, with this local diff on 284a948c:

  • cargo build --offline --locked --workspace: passed.
  • cargo test --offline --locked -p xcl --lib hle::d3d12x::title_textures::tests -- --test-threads=4 --nocapture: 13 passed, 0 failed, 0 ignored.
  • cargo test --offline --locked -p xcl --lib hle::d3d12x::sparse::tests -- --test-threads=4 --nocapture: 16 passed, 0 failed, 1 ignored, including the new counter regression.
  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --nocapture with XCL_ACTIVITY unset: 961 passed, 0 failed, 43 ignored across 20 targets, with 22 explicit GPU skip notices. A separate synthetic test_title_runs_and_game_folder_is_untouched e2e run passed 1/0/0 with activity unset and again with XCL_ACTIVITY=1; this short title exits before the 2 s activity line, so those runs do not validate its printed values.

I did not measure disabled-path frame-time overhead, run a retail title, or produce the required post-push smoke pair. This is a candidate for the author to consider, not a merge-readiness claim.

Candidate diff and regression
diff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs
index 877fc63e..f462c7ee 100644
--- a/crates/xcl/src/hle/d3d12x/sparse.rs
+++ b/crates/xcl/src/hle/d3d12x/sparse.rs
@@ -1446,21 +1446,38 @@ pub fn mapped_ranges() -> Vec<(usize, usize)> {
 /// time spent and pages found by the write-watch scans (`refresh_once`), for the timing line;
 /// then the looks, the bytes they watched and the µs of the whole looks (`XCL_ACTIVITY`)
 static WATCH: [AtomicU64; 5] = [const { AtomicU64::new(0) }; 5];
+/// The activity switch is set before title work starts and remains fixed for this process.
+pub fn activity_enabled() -> bool {
+    static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
+    *ON.get_or_init(|| std::env::var_os("XCL_ACTIVITY").is_some())
+}
 /// [lock wait, chunk scan, upload] in µs, runs uploaded
 static PHASES: [AtomicU64; 4] = [const { AtomicU64::new(0) }; 4];
 
 /// A look's write-watch scan: `t` long, `pages` found written in `watched` bytes.
-pub fn note_watch(t: std::time::Duration, pages: usize, watched: usize) {
-    WATCH[0].fetch_add(t.as_micros() as u64, Ordering::Relaxed);
-    WATCH[1].fetch_add(pages as u64, Ordering::Relaxed);
-    WATCH[2].fetch_add(1, Ordering::Relaxed);
-    WATCH[3].fetch_add(watched as u64, Ordering::Relaxed);
+pub fn note_watch(t: std::time::Duration, pages: usize, watched: Option<usize>) {
+    record_watch(&WATCH, t, pages, watched);
+}
+
+#[inline]
+fn record_watch(counters: &[AtomicU64; 5], t: std::time::Duration, pages: usize, watched: Option<usize>) {
+    counters[0].fetch_add(t.as_micros() as u64, Ordering::Relaxed);
+    counters[1].fetch_add(pages as u64, Ordering::Relaxed);
+    if let Some(watched) = watched {
+        counters[2].fetch_add(1, Ordering::Relaxed);
+        counters[3].fetch_add(watched as u64, Ordering::Relaxed);
+    }
 }
 
 /// A whole look before a title's submit (`title_textures::refresh`: the scan, the copies of
 /// CPU writes, the textures uploaded again), `t` long.
 pub fn note_look(t: std::time::Duration) {
-    WATCH[4].fetch_add(t.as_micros() as u64, Ordering::Relaxed);
+    record_look(&WATCH, t);
+}
+
+#[inline]
+fn record_look(counters: &[AtomicU64; 5], t: std::time::Duration) {
+    counters[4].fetch_add(t.as_micros() as u64, Ordering::Relaxed);
 }
 
 /// What the looks before the title's submits cost so far: [whole looks µs, write-watch µs,
@@ -1650,6 +1667,18 @@ mod tests {
         assert!(idle.contains("0 looks took 0 ms (0.0 % of the time)") && idle.contains("0.0 MB watched a look"), "{idle}");
     }
 
+    #[test]
+    fn activity_counters_do_not_replace_legacy_watch_timing() {
+        let counters = [const { AtomicU64::new(0) }; 5];
+        let values = || std::array::from_fn::<_, 5, _>(|i| counters[i].load(Ordering::Relaxed));
+        record_watch(&counters, std::time::Duration::from_micros(7), 3, None);
+        assert_eq!(values(), [7, 3, 0, 0, 0]); // legacy timing and pages, no activity counters
+
+        record_watch(&counters, std::time::Duration::from_micros(5), 2, Some(8192));
+        record_look(&counters, std::time::Duration::from_micros(11));
+        assert_eq!(values(), [12, 5, 1, 8192, 11]);
+    }
+
     /// `queue()` answers while the state's lock is held: a resource's last `Release` asks for
     /// it (`late_release::drain_known`) from inside a D3D12 call that the lock's holder can be
     /// waiting for (a list's `Reset` against an upload's allocator `Reset`, with `XCL_DRED=1`).
diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs
index 325f0ac6..615f12d1 100644
--- a/crates/xcl/src/hle/d3d12x/title_textures.rs
+++ b/crates/xcl/src/hle/d3d12x/title_textures.rs
@@ -659,10 +659,13 @@ pub(super) unsafe fn refresh(queue: *mut c_void) {
     if BUSY.with(|b| b.get()) {
         return;
     }
-    let t0 = std::time::Instant::now();
+    let measured = super::sparse::activity_enabled();
+    let t0 = measured.then(std::time::Instant::now);
     let _refresh = REFRESH.lock().unwrap();
-    own_work(|| refresh_once(queue));
-    super::sparse::note_look(t0.elapsed());
+    own_work(|| refresh_once(queue, measured));
+    if let Some(t0) = t0 {
+        super::sparse::note_look(t0.elapsed());
+    }
 }
 
 /// The pages of `[base, base + size)` written since the last look, added to `dirty` and reset
@@ -685,7 +688,7 @@ unsafe fn take_written(base: usize, size: usize, buf: &mut [*mut c_void], dirty:
     }
 }
 
-unsafe fn refresh_once(queue: *mut c_void) {
+unsafe fn refresh_once(queue: *mut c_void, measured: bool) {
     let Some(u) = crate::gpu::uma::get() else { return };
     let sparse = u.has_sparse();
     if !sparse && TEXTURES_LEN.load(Ordering::Relaxed) == 0 {
@@ -710,7 +713,8 @@ unsafe fn refresh_once(queue: *mut c_void) {
         dirty.sort_unstable();
         dirty.len()
     });
-    super::sparse::note_watch(watch_t0.elapsed(), dirty_len, ranges.iter().map(|r| r.1).sum());
+    let watched = measured.then(|| ranges.iter().map(|r| r.1).sum());
+    super::sparse::note_watch(watch_t0.elapsed(), dirty_len, watched);
     if super::present::trace_frame() {
         // every 600th look: what the CPU's view of a few textures holds now (does the title's
         // data reach the address at all, and is the texture still kept in step?)

AI use: Codex (GPT-6.2 Sol) traced the current call paths, wrote and tested the local candidate, and drafted this reply. I checked the reviewer point, diff, and test outputs before posting.

@thiagocalile

Copy link
Copy Markdown

Independent test and smoke report for head 284a948c83b9af874cd05d5f054e7af927de5789 on an AMD Radeon RX 6600 (8 GB VRAM, RDNA2, native wave64).

Tested

  • Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, RDNA2, native wave64 + mesh shaders, driver 32.0.21045.29003, XCL_ADAPTER=radeon), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (10.0.26200.0), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.8.2502.11.
  • XCL_ADAPTER=radeon cargo test --no-fail-fast -p xcl --lib -- sparse --test-threads=4: 18 passed, 0 failed, 1 ignored (0 skipped).

Not tested: full workspace suite, 60 s smoke run on this head, NVIDIA/Intel GPUs, or Linux/Wine.

AI use: Antigravity (Gemini 4 Neon) ran the builds, tests, and smoke runs and drafted this report; the account owner reviewed and approved posting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants