From a3b36430390a72f0b933bb22fac1734d72c72864 Mon Sep 17 00:00:00 2001 From: bmjask <> Date: Thu, 26 Nov 2026 11:41:50 -0800 Subject: [PATCH] D3D12.X: measure pipeline queue admission Queue residence timings excluded producer contention on the shared scheduler state, leaving an unmeasured candidate for pipeline stalls. Attribute admission and promotion synchronization separately, hand off to residence without overlap, and wake accepted workers before publishing timing. Cross-checked debug tests and release all-target builds for x86_64-pc-windows-gnu; Windows runtime tests were not run here. Assisted-by: Codex (GPT-5.6-sol) --- crates/xcl/src/hle/d3d12x/build_queue.rs | 58 ++++++++++++++++++++---- crates/xcl/src/report.rs | 2 + crates/xcl/src/stall.rs | 4 +- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/build_queue.rs b/crates/xcl/src/hle/d3d12x/build_queue.rs index b1a3cad6d0..a0fdafbf37 100644 --- a/crates/xcl/src/hle/d3d12x/build_queue.rs +++ b/crates/xcl/src/hle/d3d12x/build_queue.rs @@ -251,16 +251,28 @@ impl Inner { } fn promote(&self, id: JobId, priority: Priority) -> bool { + // Stop admission at the authoritative transition, then wake the accepted work before + // publishing timing. Reporting must never delay a worker that can now take the job. + let admission = crate::stall::deferred_span(); let mut state = self.state.lock().unwrap_or_else(|e| e.into_inner()); - let Some(job) = state.jobs.get_mut(&id) else { return false }; + let Some(job) = state.jobs.get_mut(&id) else { + let admission = admission.map(crate::stall::DeferredSpan::stop); + drop(state); + if let Some(admission) = admission { + admission.finish(crate::stall::StallKind::PipelineQueueAdmission); + } + return false; + }; if priority <= job.priority { + let admission = admission.map(crate::stall::DeferredSpan::stop); + drop(state); + if let Some(admission) = admission { + admission.finish(crate::stall::StallKind::PipelineQueueAdmission); + } return true; } let ranked_preload = job.priority == Priority::Preload && job.preload_rank.is_some(); - if queue_stall_kind(job.priority) != queue_stall_kind(priority) { - job.previous_queue_wait = job.queue_wait.take().map(crate::stall::DeferredSpan::stop); - job.queue_wait = crate::stall::deferred_span(); - } + let cross_band = queue_stall_kind(job.priority) != queue_stall_kind(priority); job.priority = priority; job.generation += 1; let ticket = Ticket { id, generation: job.generation }; @@ -269,7 +281,21 @@ impl Inner { if ranked_preload { self.ranked_preloads.promoted.fetch_add(1, Ordering::Relaxed); } + if cross_band { + let job = state.jobs.get_mut(&id).unwrap(); + // Admission legitimately overlaps the old band's residence until this promotion is + // accepted. The new band's residence starts only after admission itself has stopped. + job.previous_queue_wait = job.queue_wait.take().map(crate::stall::DeferredSpan::stop); + } + let admission = admission.map(crate::stall::DeferredSpan::stop); + if cross_band { + state.jobs.get_mut(&id).unwrap().queue_wait = crate::stall::deferred_span(); + } + drop(state); self.wake(priority); + if let Some(admission) = admission { + admission.finish(crate::stall::StallKind::PipelineQueueAdmission); + } true } @@ -400,13 +426,22 @@ impl BuildQueue { /// Add work, optionally ordered by an earlier-run rank within the Preload band only. /// - /// Queue latency measures accepted priority-band residence: it starts at insertion after the - /// state mutex is acquired, so admission mutex wait is excluded. A cross-band promotion ends - /// the speculative interval when that promotion is accepted while holding the same mutex. + /// Queue latency measures accepted priority-band residence: it starts at the handoff after + /// queue insertion, immediately before the state mutex is released, so admission is excluded. + /// A cross-band promotion ends the old interval when that promotion is accepted while holding + /// the same mutex and starts the new interval after promotion admission stops. pub(super) fn submit_ranked(&self, priority: Priority, preload_rank: Option, work: Work) -> Option { let completion = Arc::new(Completion::new()); + // Accepted queue residence deliberately excludes admission synchronization. Stop that + // interval at the handoff, start residence, unlock, wake, then publish admission timing. + let admission = crate::stall::deferred_span(); let mut state = self.inner.state.lock().unwrap_or_else(|e| e.into_inner()); if state.stopped { + let admission = admission.map(crate::stall::DeferredSpan::stop); + drop(state); + if let Some(admission) = admission { + admission.finish(crate::stall::StallKind::PipelineQueueAdmission); + } return None; } state.next_id = state.next_id.checked_add(1).expect("build queue job ID overflow"); @@ -418,7 +453,7 @@ impl BuildQueue { preload_rank, generation, previous_queue_wait: None, - queue_wait: crate::stall::deferred_span(), + queue_wait: None, work, completion: completion.clone(), }); @@ -426,8 +461,13 @@ impl BuildQueue { if preload_rank.is_some() { self.inner.ranked_preloads.submissions.fetch_add(1, Ordering::Relaxed); } + let admission = admission.map(crate::stall::DeferredSpan::stop); + state.jobs.get_mut(&id).unwrap().queue_wait = crate::stall::deferred_span(); drop(state); self.inner.wake(priority); + if let Some(admission) = admission { + admission.finish(crate::stall::StallKind::PipelineQueueAdmission); + } Some(JobHandle { id, queue: Arc::downgrade(&self.inner), completion }) } diff --git a/crates/xcl/src/report.rs b/crates/xcl/src/report.rs index b0bcfa6b98..b9e1e1676f 100644 --- a/crates/xcl/src/report.rs +++ b/crates/xcl/src/report.rs @@ -87,6 +87,7 @@ fn stall_kind_name(kind: crate::stall::StallKind) -> &'static str { StallKind::ShaderTranslation => "shader_translation", StallKind::DxcQueue => "dxc_queue", StallKind::DxcCompile => "dxc_compile", + StallKind::PipelineQueueAdmission => "pipeline_queue_admission", StallKind::PipelineQueueSpeculative => "pipeline_queue_speculative", StallKind::PipelineQueueDemand => "pipeline_queue_demand", StallKind::PipelineWait => "pipeline_wait", @@ -422,6 +423,7 @@ mod tests { #[test] fn pipeline_queue_stall_names_are_stable() { + assert_eq!(stall_kind_name(crate::stall::StallKind::PipelineQueueAdmission), "pipeline_queue_admission"); assert_eq!(stall_kind_name(crate::stall::StallKind::PipelineQueueSpeculative), "pipeline_queue_speculative"); assert_eq!(stall_kind_name(crate::stall::StallKind::PipelineQueueDemand), "pipeline_queue_demand"); } diff --git a/crates/xcl/src/stall.rs b/crates/xcl/src/stall.rs index 9a8a397593..e457b9766f 100644 --- a/crates/xcl/src/stall.rs +++ b/crates/xcl/src/stall.rs @@ -19,6 +19,7 @@ pub enum StallKind { ShaderTranslation, DxcQueue, DxcCompile, + PipelineQueueAdmission, PipelineQueueSpeculative, PipelineQueueDemand, PipelineWait, @@ -42,10 +43,11 @@ pub enum StallKind { } impl StallKind { - pub const ALL: [Self; 23] = [ + pub const ALL: [Self; 24] = [ Self::ShaderTranslation, Self::DxcQueue, Self::DxcCompile, + Self::PipelineQueueAdmission, Self::PipelineQueueSpeculative, Self::PipelineQueueDemand, Self::PipelineWait,