Repository navigation
Conversation
Only a 64-bit, GREATER_EQUAL, full-mask wait on an address a list wrote with Write64BitValue becomes a GPU queue.Wait; every other wait the memory does not yet hold blocks the submitting thread (up to XCL_WAIT_TIMEOUT_MS). Which kinds a title makes, and how long they hold the submit threads, decides which ones are worth moving to the GPU, and nothing measured it: XCL_STALL_TRACE lumps these waits together with the CPU-write waits. Each CPU wait is now counted by the first reason try_gpu_wait refuses it (32-bit, not >=, masked, >= 0, untracked address, non-monotonic, not recorded yet, other) with its time, and at most every 10 s, only after a CPU wait, one info line gives the counts, the times and the waits that went to the GPU. The cost is two clock reads and a sync-graph lookup on a path that then blocks anyway. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaZV7vMq866ni7pGnJC2Ew
|
Exercised the production reporting interval at
I released the respective gate after a deliberate 100 ms observation. Both CPU reads got 91, and repeating each already-satisfied wait added no counter. The actual log line was: The line measures which wait forms fell back and their accumulated polling time. Here its one bucket combined an already-complete producer with a genuinely pending one. Likewise, "on the GPU: 0" counted zero waits routed to queue.Wait; it cannot establish that both GPU producers were ready. For a world trace, correlating wait entry with a known producer's queue/fence completion and subsequent CPU-cell publication would distinguish the two costs. The measured duration is synthetic and excludes setup before The fixture used native queues, production deferred writes, and AI disclosure: OpenAI Codex built and ran the fixture and drafted this report. |
|
Ran the CPU-wait accounting tests at System
Results
What this adds Not tested AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used. |
|
I tried a narrow opt-in follow-up on On RTX 5070 / 616.92 and Ryzen 7 5700X3D, the production report showed one pending fence and one complete fence, matching an independent native marker. Both waits returned The new line reports state samples, not an elapsed-time breakdown or proof of the sole producer. Wider writes, multiple overlaps, publication already in progress and registry overflow all fall back to unknown. The registry is capped at 64 jobs with at most 64 write records per job. The fixtures used synthetic writes and native queues. Retail timing, overhead under sustained capture, and address aliases are unmeasured. Two-file prototype (apply-checked on 60ee4e9)--- a/crates/xcl/src/hle/d3d12x/cpu_writes.rs
+++ b/crates/xcl/src/hle/d3d12x/cpu_writes.rs
@@ -35,6 +35,7 @@
value: u64,
writes: Vec<Write>,
done: Option<mpsc::Sender<()>>,
+ probe: Option<ProbeTicket>,
}
// SAFETY: the fence is a free-threaded COM object; the writes are plain data
@@ -49,6 +50,125 @@
unsafe impl Send for QueueFence {}
static FENCES: Mutex<Option<HashMap<usize, QueueFence>>> = Mutex::new(None);
+
+// Optional diagnostics. Keep snapshots bounded and treat overflow as unknown. A matching job
+// describes what XCL queued; guest CPU stores and writes through aliases may exist as well.
+const PROBE_LIMIT: usize = 64;
+static PROBE_ENABLED: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| {
+ std::env::var("XCL_WAIT_PRODUCER_STATS").is_ok_and(|v| v.trim() == "1")
+});
+static PROBES: Mutex<Option<Probes>> = Mutex::new(None);
+
+#[derive(Default)]
+struct Probes {
+ jobs: HashMap<u64, ProbeJob>,
+ next: u64,
+ omitted: usize,
+}
+
+struct ProbeJob {
+ fence: ID3D12Fence,
+ value: u64,
+ publishing: bool,
+ writes: Vec<ProbeWrite>,
+}
+
+// SAFETY: ID3D12Fence is free-threaded. The rest of the probe contains only owned data.
+unsafe impl Send for ProbeJob {}
+
+struct ProbeWrite {
+ start: usize,
+ end: usize,
+ word: Option<u32>,
+}
+
+struct ProbeTicket(Option<u64>);
+
+impl ProbeTicket {
+ fn register(job: &Job) -> Option<Self> {
+ if !*PROBE_ENABLED {
+ return None;
+ }
+ let mut guard = PROBES.lock().unwrap();
+ let probes = guard.get_or_insert_with(Probes::default);
+ if probes.jobs.len() >= PROBE_LIMIT || job.writes.len() > PROBE_LIMIT {
+ probes.omitted += 1;
+ return Some(Self(None));
+ }
+ let writes = job.writes.iter().filter_map(|w| {
+ let (start, bytes, word) = match w {
+ Write::Immediate(start, words) => (*start, words.len().saturating_mul(4),
+ if words.len() == 1 { words.first().copied() } else { None }),
+ Write::ReadbackU64 { va, .. } => (*va, 8, None),
+ };
+ (bytes != 0).then_some(ProbeWrite { start, end: start.saturating_add(bytes), word })
+ }).collect();
+ let id = probes.next;
+ probes.next += 1;
+ probes.jobs.insert(id, ProbeJob { fence: job.fence.clone(), value: job.value, publishing: false, writes });
+ Some(Self(Some(id)))
+ }
+
+ fn mark_publishing(&self) {
+ if let Some(id) = self.0 {
+ if let Some(job) = PROBES.lock().unwrap().as_mut().and_then(|p| p.jobs.get_mut(&id)) {
+ job.publishing = true;
+ }
+ }
+ }
+}
+
+impl Drop for ProbeTicket {
+ fn drop(&mut self) {
+ let mut guard = PROBES.lock().unwrap();
+ let probes = guard.as_mut().unwrap();
+ if let Some(id) = self.0 {
+ let job = probes.jobs.remove(&id);
+ drop(guard);
+ drop(job);
+ } else {
+ probes.omitted -= 1;
+ }
+ }
+}
+
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub(super) enum WaitProbe {
+ Unknown,
+ FencePending,
+ FenceComplete,
+}
+
+/// Classify one DWORD wait using an exact overlapping XCL store that would satisfy it. Unknown
+/// includes multiple writers, wider writes, GPU-resolved values, and publication in progress.
+pub(super) fn probe_wait32(va: usize, accepts: impl FnOnce(u32) -> bool) -> Option<WaitProbe> {
+ if !*PROBE_ENABLED {
+ return None;
+ }
+ Some(probe_wait32_enabled(va, accepts).unwrap_or(WaitProbe::Unknown))
+}
+
+fn probe_wait32_enabled(va: usize, accepts: impl FnOnce(u32) -> bool) -> Option<WaitProbe> {
+ let end = va.checked_add(4)?;
+ let guard = PROBES.lock().unwrap();
+ let probes = guard.as_ref()?;
+ if probes.omitted != 0 {
+ return None;
+ }
+ let mut overlapping = probes.jobs.values().flat_map(|job| {
+ job.writes.iter().filter(move |w| w.start < end && va < w.end).map(move |w| (job, w))
+ });
+ let (job, write) = overlapping.next()?;
+ if overlapping.next().is_some() || job.publishing || write.start != va || !accepts(write.word?) {
+ return None;
+ }
+ let completed = unsafe { super::real::fence_completed(&job.fence) };
+ match completed {
+ u64::MAX => None,
+ value if value >= job.value => Some(WaitProbe::FenceComplete),
+ _ => Some(WaitProbe::FencePending),
+ }
+}
/// Forget a retired queue's cached fence before its address can be reused. Submitted jobs own
/// fence clones, so extracting this entry cannot let their writes run early.
@@ -81,6 +201,9 @@
}
}
}
+ if let Some(probe) = &job.probe {
+ probe.mark_publishing();
+ }
for w in &job.writes {
match w {
Write::Immediate(va, words) => write_now(*va, words),
@@ -90,6 +213,7 @@
}
}
}
+ drop(job.probe);
if let Some(done) = job.done {
let _ = done.send(());
}
@@ -251,7 +375,7 @@
} else {
(None, None)
};
- let job = {
+ let mut job = {
let mut g = FENCES.lock().unwrap();
let m = g.get_or_insert_with(HashMap::new);
let entry = match m.entry(queue as usize) {
@@ -270,8 +394,9 @@
if super::real::native_queue_signal(q, &entry.fence, entry.value).is_err() {
return None;
}
- Job { fence: entry.fence.clone(), value: entry.value, writes, done }
+ Job { fence: entry.fence.clone(), value: entry.value, writes, done, probe: None }
};
+ job.probe = ProbeTicket::register(&job);
static FIRST: std::sync::Once = std::sync::Once::new();
FIRST.call_once(|| crate::xlog_info!("D3D12.X: bottom-of-pipe writes outside unified memory are done by the CPU after the GPU ({} in the first submission)", job.writes.len()));
worker().lock().unwrap().send(job).ok()?;
--- a/crates/xcl/src/hle/d3d12x/list_x.rs
+++ b/crates/xcl/src/hle/d3d12x/list_x.rs
@@ -3395,6 +3395,8 @@
static CPU_WAITS: [(AtomicU64, AtomicU64); 8] = [const { (AtomicU64::new(0), AtomicU64::new(0)) }; 8];
/// waits the memory did not hold that went to the GPU since the last report
static GPU_WAITS: AtomicU64 = AtomicU64::new(0);
+/// Opt-in counts of fence states sampled at the start of DWORD CPU waits.
+static CPU_WAIT_PROBES: [AtomicU64; 3] = [const { AtomicU64::new(0) }; 3];
/// when the last report was made, in milliseconds since `CPU_WAIT_EPOCH`
static CPU_WAIT_REPORTED_MS: AtomicU64 = AtomicU64::new(0);
static CPU_WAIT_EPOCH: OnceLock<Instant> = OnceLock::new();
@@ -3419,6 +3421,13 @@
let gpu = GPU_WAITS.swap(0, Ordering::Relaxed);
if let Some(line) = cpu_wait_report(&counts, gpu, Duration::from_millis(now - last)) {
crate::xlog_info!("{line}");
+ }
+ let [unknown, pending, complete] = CPU_WAIT_PROBES.each_ref().map(|n| n.swap(0, Ordering::Relaxed));
+ if unknown != 0 || pending != 0 || complete != 0 {
+ crate::xlog_info!(
+ "D3D12.X: DWORD CPU wait entry samples: deferred write fence pending {pending}, \
+ deferred write fence complete {complete}, unknown or ambiguous {unknown}"
+ );
}
}
@@ -3627,6 +3636,13 @@
let g = SYNC_GRAPH.lock().unwrap();
g.as_ref().and_then(|gr| gr.cells.get(&w.va)).map(|c| (c.non_monotonic, c.recorded_max))
});
+ if w.width == 4 {
+ if let Some(probe) = super::cpu_writes::probe_wait32(w.va as usize, |word| {
+ compare_u64(w.comparison, u64::from(word) & w.mask, w.value) == Some(true)
+ }) {
+ CPU_WAIT_PROBES[probe as usize].fetch_add(1, Ordering::Relaxed);
+ }
+ }
let memory_stall = crate::stall::span(crate::stall::StallKind::MemorySynchronization);
let started = Instant::now();
let satisfied = w.wait_until_satisfied(timeout);
AI disclosure: OpenAI Codex (GPT-6.2 Sol) implemented and tested the optional probe using the saved Codex/Astra fixtures and drafted this report. |
KOLESNiii
left a comment
There was a problem hiding this comment.
Static review of 60ee4e99 for the stack in the #3041 comparison.
The new counters can misclassify waits. GpuWaitOutcome::Handled also covers waits released on the CPU and waits satisfied by a fence recheck. Both increment the GPU-wait counter. The CPU refusal reason is inferred from a second sync-graph lookup, so a concurrent producer can change the state used to label the refusal. Carrying the outcome and refusal reason from the original attempt would make the counts match the decisions. Counter and classification
Review assisted by Codex (GPT-6, exact variant unavailable). No new build or GPU run for this review.
bmjask
left a comment
There was a problem hiding this comment.
Critical review of current head 60ee4e99. The new telemetry can misattribute waits. GpuWaitOutcome::Handled includes cases resolved on the CPU or by a fence recheck, yet increments GPU_WAITS; the CPU refusal reason is reconstructed from a later sync-graph read and can change under concurrent writes. That makes the displayed GPU/CPU split unsuitable for deciding which waits to move. Return the actual route/reason from try_gpu_wait and count that immutable outcome, with a test for CPU-resolved Handled and a concurrent producer. See the earlier source review. No local Windows run.
|
merge-check
|
|
Test report for #3323 at Tested
Not tested
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report. |
|
merge-check claim |
|
merge-check AI-written and posted by Foniass without a human check of each point. |
|
merge-check claim withdrawn AI use: an agent posted this withdrawal. |
Requested by Prime
Only a 64-bit,
GREATER_EQUAL, full-mask wait on an address a list wrote withWrite64BitValuebecomes a GPUqueue.Wait; every otherWait32/64BitValueXthe memory does not yet hold blocks the submitting thread (up toXCL_WAIT_TIMEOUT_MS). Which kinds a title makes, and how long they hold the submit threads, decides which ones are worth moving to the GPU, and nothing measured it:XCL_STALL_TRACElumps these waits together with the CPU-write waits.Each CPU wait is now counted by the first reason
try_gpu_waitrefuses it (32-bit, not>=, masked,>= 0, untracked address, not monotonic, not recorded yet, other) with its time. At most every 10 s, and only after a CPU wait, one info line gives the counts, the times and the waits that went to the GPU. The cost is two clock reads and a sync-graph lookup on a path that then blocks anyway.What is in it
crates/xcl/src/hle/d3d12x/list_x.rs:CpuWaitWhy,cpu_wait_why, the counters andnote_cpu_wait/cpu_wait_report(theD3D12.X: memory waits on the CPU in the last N sline), called fromwait_all_on_noting_cpu; testsa_cpu_wait_is_counted_by_why_the_gpu_did_not_take_itandthe_cpu_wait_report_names_only_the_kinds_that_happenedTested
cargo test --workspace --no-fail-fast -- --test-threads=4with the threeuma_drivertests below skipped, on 60ee4e9: 2607 passed, 0 failed, 49 ignored (SKIPPED GPU tests: 28 lines: 21no wave64(this card runs wave32), 3 a wave32 per-lane form refused by the translator (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426), 2no heap windows(opt-inXCL_HEAP_WINDOWS=1), 1no dxc.exe, 1cannot disable the driver cache(needs Windows Developer Mode))cargo test -p xcl --lib -- --test-threads=1 uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom uma_driver::tests::mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment uma_driver::tests::failed_restore_stops_before_importing_an_unbacked_window): 3 passed, 0 failed. They are left out of the whole run because on this PC's driver they can end the library test process (exit 0x7c10003, "coherent window could not be restored"), onmaintoocargo test -p xcl --lib -- --test-threads=4, same skips): 2468 passed, 0 failed; 2468 passed, 0 failedmainfa20459: 2605 passed, 0 failed, 49 ignored, 28SKIPPEDlines (own-prs-20261129 run, same command)scripts/smoke.ps1, no input, copied profile and shader cache): blocks belowRegression run
Not tested
AI use
Optional temporary Discord for coordinating contributor work, testing and comparing results.
🤖 Generated with Claude Code