From 0695de54b41acd9d453e0d99621aca0e1d3bdcdc Mon Sep 17 00:00:00 2001 From: Kal0s-design <356578040+Kal0s-design@users.noreply.github.com> Date: Mon, 30 Nov 2026 10:07:04 +0100 Subject: [PATCH 1/2] d3d12: say how many submissions were not yet seen finished when the device went The device-removed report (removal_context) said "(nothing of ours was running on the card)" for every phase of the submitting thread but "waiting for the card", also when submissions sent ahead were still not seen finished: the same line's "submissions started X finished Y" could say otherwise, and the report read as an idle card when it may not have been. The phase now carries the number of submissions of ours sent and not yet seen finished (STARTED less FINISHED), and says nothing of ours was running only when that number is 0. Nothing else in the report changes. Same change as TaynanGT/Vice-Tay#451 on the same code. Co-Authored-By: Claude Opus 5.5 --- d3d12/crates/leonida-gpu/src/host.rs | 44 ++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/host.rs b/d3d12/crates/leonida-gpu/src/host.rs index 536afe46ad..7bfdde5a19 100644 --- a/d3d12/crates/leonida-gpu/src/host.rs +++ b/d3d12/crates/leonida-gpu/src/host.rs @@ -836,21 +836,15 @@ pub(crate) fn removal_context() -> String { use std::fmt::Write; let now = now_us(); let ms = |at: u64| now.saturating_sub(at) as f64 / 1000.0; - let phase = match SUBMITTING[0].load(Ordering::Relaxed) { - 0 => "between submissions (nothing of ours was running on the card)", - 1 => "preparing a submission (nothing of ours was running on the card)", - 2 => "waiting for the card to run a submission", - _ => "copying back what a submission wrote (nothing of ours was running on the card)", - }; + let (started, finished) = (STARTED.load(Ordering::Relaxed), FINISHED.load(Ordering::Relaxed)); + let phase = submitting_phase(SUBMITTING[0].load(Ordering::Relaxed), started.saturating_sub(finished)); let mut text = format!( - "the submitting thread was {phase}, of {} lists, for {:.1} ms; {}; objects let go at once {} and after a running submission {}; submissions started {} finished {}", + "the submitting thread was {phase}, of {} lists, for {:.1} ms; {}; objects let go at once {} and after a running submission {}; submissions started {started} finished {finished}", SUBMITTING[1].load(Ordering::Relaxed), ms(SUBMITTING[2].load(Ordering::Relaxed)), crate::pipeline::library_removal_note(), RETIREMENTS[0].load(Ordering::Relaxed), RETIREMENTS[1].load(Ordering::Relaxed), - STARTED.load(Ordering::Relaxed), - FINISHED.load(Ordering::Relaxed), ); let trail = TRAIL.lock().unwrap_or_else(|e| e.into_inner()); let _ = write!(text, "; the last {} things done, newest last:", trail.len()); @@ -860,6 +854,25 @@ pub(crate) fn removal_context() -> String { text } +/// What the submitting thread was doing ([`SUBMITTING`]), and how many submissions of ours were sent +/// and not yet seen finished (`in_air`: [`STARTED`] less [`FINISHED`]). With submissions sent ahead the +/// submitting thread can be preparing the next one while earlier ones may still run, so a device lost +/// then is told as idle only when that number is 0. (A submission not yet seen finished may have +/// finished already: the count is of what was not observed complete.) +fn submitting_phase(phase: u64, in_air: u64) -> String { + let doing = match phase { + 0 => "between submissions", + 1 => "preparing a submission", + 2 => return "waiting for the card to run a submission".to_owned(), + _ => "copying back what a submission wrote", + }; + match in_air { + 0 => format!("{doing} (nothing of ours was running on the card)"), + 1 => format!("{doing} (1 submission of ours sent and not yet seen finished)"), + n => format!("{doing} ({n} submissions of ours sent and not yet seen finished)"), + } +} + /// Says [`removal_context`] in the log, once: called by whoever finds the /// host device removed. pub(crate) fn log_removal_context() { @@ -13818,6 +13831,19 @@ mod trail { assert!(text.contains(&format!("thing {} done", super::TRAIL_MOST + 4))); assert!(!text.contains("thing 4 done"), "the oldest entries are dropped"); } + + /// A device lost while the submitting thread is between submissions or preparing the next one is + /// told as idle only when none of ours was sent and not yet seen finished: with submissions sent + /// ahead some can still be on the card then. + #[test] + fn the_removal_phase_names_submissions_not_yet_seen_finished() { + use super::submitting_phase; + assert_eq!(submitting_phase(1, 0), "preparing a submission (nothing of ours was running on the card)"); + assert_eq!(submitting_phase(1, 1), "preparing a submission (1 submission of ours sent and not yet seen finished)"); + assert_eq!(submitting_phase(0, 3), "between submissions (3 submissions of ours sent and not yet seen finished)"); + assert_eq!(submitting_phase(2, 5), "waiting for the card to run a submission"); + assert_eq!(submitting_phase(3, 0), "copying back what a submission wrote (nothing of ours was running on the card)"); + } } #[cfg(test)] From d3590784531c456a8f9868b5e07125f35e954406 Mon Sep 17 00:00:00 2001 From: Kal0s-design <356578040+Kal0s-design@users.noreply.github.com> Date: Mon, 30 Nov 2026 10:39:50 +0100 Subject: [PATCH 2/2] d3d12: removal report says 'started', which is what STARTED counts STARTED is counted at the start of a submission's preparation, before its lists go to the queue, so while the submitting thread prepares one, that one is among STARTED less FINISHED. 'sent' claimed more than the counter holds; 'started and not yet seen finished' is what it counts (review by merzleckeier). Co-Authored-By: Claude Opus 5.5 --- d3d12/crates/leonida-gpu/src/host.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/host.rs b/d3d12/crates/leonida-gpu/src/host.rs index 7bfdde5a19..71886f7fc8 100644 --- a/d3d12/crates/leonida-gpu/src/host.rs +++ b/d3d12/crates/leonida-gpu/src/host.rs @@ -854,10 +854,11 @@ pub(crate) fn removal_context() -> String { text } -/// What the submitting thread was doing ([`SUBMITTING`]), and how many submissions of ours were sent +/// What the submitting thread was doing ([`SUBMITTING`]), and how many submissions of ours were started /// and not yet seen finished (`in_air`: [`STARTED`] less [`FINISHED`]). With submissions sent ahead the /// submitting thread can be preparing the next one while earlier ones may still run, so a device lost -/// then is told as idle only when that number is 0. (A submission not yet seen finished may have +/// then is told as idle only when that number is 0. (`STARTED` counts a submission from the start of +/// its preparation, so the one being prepared is among them; and one not yet seen finished may have /// finished already: the count is of what was not observed complete.) fn submitting_phase(phase: u64, in_air: u64) -> String { let doing = match phase { @@ -868,8 +869,8 @@ fn submitting_phase(phase: u64, in_air: u64) -> String { }; match in_air { 0 => format!("{doing} (nothing of ours was running on the card)"), - 1 => format!("{doing} (1 submission of ours sent and not yet seen finished)"), - n => format!("{doing} ({n} submissions of ours sent and not yet seen finished)"), + 1 => format!("{doing} (1 submission of ours started and not yet seen finished)"), + n => format!("{doing} ({n} submissions of ours started and not yet seen finished)"), } } @@ -13833,14 +13834,14 @@ mod trail { } /// A device lost while the submitting thread is between submissions or preparing the next one is - /// told as idle only when none of ours was sent and not yet seen finished: with submissions sent + /// told as idle only when none of ours was started and not yet seen finished: with submissions sent /// ahead some can still be on the card then. #[test] fn the_removal_phase_names_submissions_not_yet_seen_finished() { use super::submitting_phase; assert_eq!(submitting_phase(1, 0), "preparing a submission (nothing of ours was running on the card)"); - assert_eq!(submitting_phase(1, 1), "preparing a submission (1 submission of ours sent and not yet seen finished)"); - assert_eq!(submitting_phase(0, 3), "between submissions (3 submissions of ours sent and not yet seen finished)"); + assert_eq!(submitting_phase(1, 1), "preparing a submission (1 submission of ours started and not yet seen finished)"); + assert_eq!(submitting_phase(0, 3), "between submissions (3 submissions of ours started and not yet seen finished)"); assert_eq!(submitting_phase(2, 5), "waiting for the card to run a submission"); assert_eq!(submitting_phase(3, 0), "copying back what a submission wrote (nothing of ours was running on the card)"); }