From 45fd2a5347ee8c3c68550a371da05d0152353450 Mon Sep 17 00:00:00 2001 From: yoriswind <164435053+yoriswind@users.noreply.github.com> Date: Tue, 1 Dec 2026 01:59:09 -0800 Subject: [PATCH] Troubleshooting: report the active graphics driver (#10348) --- apps/vectorcraft/src/hang_watch.rs | 31 +++++++++++++++++++++--- apps/vectorcraft/src/hang_watch/tests.rs | 19 +++++++++++++++ apps/vectorcraft/src/main.rs | 22 +++++++++++------ 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/apps/vectorcraft/src/hang_watch.rs b/apps/vectorcraft/src/hang_watch.rs index 5714b8c548..5039c89bd1 100644 --- a/apps/vectorcraft/src/hang_watch.rs +++ b/apps/vectorcraft/src/hang_watch.rs @@ -3,8 +3,8 @@ //! mark for [`STALL`] while inside a stage of its frame, the thread writes what the app knows to the //! log (`logs/vectorcraft.log`) and to `logs/hang-report-.txt`: the stage, a clipboard //! call in progress, the last commands, the last frames' times, the platform, the window system, the -//! graphics processor and the present mode the app asked for, and how long the session has run with -//! how many documents open. The process holds a lock on the file until the interface thread answers +//! graphics processor, its driver when known, and the present mode the app asked for, and how long +//! the session has run with how many documents open. The process holds a lock on the file until the interface thread answers //! again; then the log says after how long and the file is removed. A file nobody holds at a later //! launch was left by a session that was closed while it did not answer, and a locked one belongs to //! another instance that is stalled now and is left alone. That launch writes the report to the log, @@ -113,6 +113,8 @@ pub struct Facts { pub flatpak: bool, /// The graphics processor the window draws with. pub graphics: Option, + /// The active graphics driver's identity, when the backend reports it. + graphics_driver: Option, /// The present mode and frame queue the app asked the window surface for. pub surface: String, } @@ -128,14 +130,29 @@ impl Facts { session_type: value("XDG_SESSION_TYPE"), flatpak: flatpak_info || env("FLATPAK_ID").is_some_and(|v| !v.is_empty()), graphics, + graphics_driver: None, surface, } } + #[cfg(any(feature = "wgpu", test))] + pub fn with_graphics_driver(mut self, driver: &str, info: &str) -> Facts { + // D3D12 reports 0.0.0.0 when the driver version could not be read. + let mut fields = [driver, info].map(clean).into_iter().filter(|value| !value.is_empty() && value != "0.0.0.0"); + self.graphics_driver = fields.next().map(|mut detail| { + if let Some(info) = fields.next().filter(|info| info != &detail) { + detail.push_str(" / "); + detail.push_str(&info); + } + detail + }); + self + } + /// The facts as report lines. pub fn lines(&self) -> String { let or_unknown = |v: &Option| v.clone().unwrap_or_else(|| "unknown".to_string()); - format!( + let mut lines = format!( "VectorCraft {} on {} {}\nWindow system: {}; desktop: {}; session type: {}; Flatpak: {}\nGraphics: {}; {}\n", vectorcraft_ui_egui::os_window::version(), std::env::consts::OS, @@ -146,7 +163,13 @@ impl Facts { if self.flatpak { "yes" } else { "no" }, or_unknown(&self.graphics), self.surface, - ) + ); + if let Some(driver) = &self.graphics_driver { + lines.push_str("Graphics driver: "); + lines.push_str(driver); + lines.push('\n'); + } + lines } } diff --git a/apps/vectorcraft/src/hang_watch/tests.rs b/apps/vectorcraft/src/hang_watch/tests.rs index 7452d41502..608d6e9b78 100644 --- a/apps/vectorcraft/src/hang_watch/tests.rs +++ b/apps/vectorcraft/src/hang_watch/tests.rs @@ -279,3 +279,22 @@ fn troubleshooting_info_holds_both_sessions_reports() { assert!(text.contains("(it was closed while it did not answer):\nVectorCraft hang report, last session\n")); assert!(text.contains("Recent commands, oldest first: none")); } + +#[test] +fn troubleshooting_info_distinguishes_drivers_on_the_same_adapter() { + let mut shared = shared(None); + let beacon = Beacon::new(); + for (driver, info, expected) in [ + (" 32.0.16.1088 ", "", Some("32.0.16.1088")), + ("32.0.16.2124", "", Some("32.0.16.2124")), + ("Mesa\nRADV", "Mesa 25.2", Some("MesaRADV / Mesa 25.2")), + ("Mesa", "Mesa", Some("Mesa")), + ("0.0.0.0", "", None), + ("", "", None), + ] { + shared.facts = facts().with_graphics_driver(driver, info); + let text = troubleshooting(&shared, &beacon, UNIX_EPOCH); + assert!(text.contains("Graphics: Test GPU"), "the adapter description is still in the report"); + assert_eq!(text.lines().find_map(|line| line.strip_prefix("Graphics driver: ")), expected); + } +} diff --git a/apps/vectorcraft/src/main.rs b/apps/vectorcraft/src/main.rs index b603ed7960..dc6e7fd7d6 100644 --- a/apps/vectorcraft/src/main.rs +++ b/apps/vectorcraft/src/main.rs @@ -981,14 +981,22 @@ fn main() -> std::process::ExitCode { .map(|_| (format!("{:?}", requested_surface.present_mode), requested_surface.desired_maximum_frame_latency)); #[cfg(not(feature = "wgpu"))] let surface = None; + let facts = hang_watch::Facts::new( + |name| std::env::var(name).ok(), + std::path::Path::new("/.flatpak-info").exists(), + hang_watch::window_system(winit_window.as_deref()), + app.graphics_adapter.clone(), + hang_watch::surface(surface), + ); + #[cfg(feature = "wgpu")] + let facts = if let Some(rs) = &cc.wgpu_render_state { + let info = rs.adapter.get_info(); + facts.with_graphics_driver(&info.driver, &info.driver_info) + } else { + facts + }; let hang = std::sync::Arc::new(hang_watch::Shared { - facts: hang_watch::Facts::new( - |name| std::env::var(name).ok(), - std::path::Path::new("/.flatpak-info").exists(), - hang_watch::window_system(winit_window.as_deref()), - app.graphics_adapter.clone(), - hang_watch::surface(surface), - ), + facts, started: std::time::Instant::now(), last: std::sync::Mutex::new(None), previous: previous_hang.clone(),