From b0d8178c2137577866779c02961e991cef5b5599 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:46:44 +0100 Subject: [PATCH 1/5] Upgrade wgpu-profiler --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 11b70341..0cc896f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2943,9 +2943,9 @@ dependencies = [ [[package]] name = "wgpu-profiler" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "111850b8b96db7f12f310e20d9f16ad2d18a0c8ac8493e434441d1dfb288c6bf" +checksum = "bb9c0c8c123e8772c9b44a1ca04a9549929654bb3f86a6f4b4ed2d5559f6027d" dependencies = [ "parking_lot", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 3626a800..d0007ed0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,5 +60,5 @@ clap = "4.5.4" anyhow = "1.0.86" pollster = "0.3.0" web-time = "1.1.0" -wgpu-profiler = "0.18.0" +wgpu-profiler = "0.18.1" scenes = { path = "examples/scenes" } From d32d986d242c43cdc70201edde985c312590d2a5 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:28:13 +0100 Subject: [PATCH 2/5] Upgrade wgpu-profiler --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0cc896f2..2e1e8565 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2943,9 +2943,9 @@ dependencies = [ [[package]] name = "wgpu-profiler" -version = "0.18.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb9c0c8c123e8772c9b44a1ca04a9549929654bb3f86a6f4b4ed2d5559f6027d" +checksum = "06b2cee91fdc885ff0d3d714c59810cc72c6d84b81b0eaa48bab8ff2ad54fb5b" dependencies = [ "parking_lot", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index d0007ed0..c5e5ad26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,5 +60,5 @@ clap = "4.5.4" anyhow = "1.0.86" pollster = "0.3.0" web-time = "1.1.0" -wgpu-profiler = "0.18.1" +wgpu-profiler = "0.18.2" scenes = { path = "examples/scenes" } From b9a90ffd90240a5c20ee2ddb7d2fbd65dcc71a63 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:14:35 +0100 Subject: [PATCH 3/5] Avoid panics in seconds formatting --- examples/with_winit/src/stats.rs | 48 +++++++++++++++++++------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/examples/with_winit/src/stats.rs b/examples/with_winit/src/stats.rs index 3b5339de..27a6d6d9 100644 --- a/examples/with_winit/src/stats.rs +++ b/examples/with_winit/src/stats.rs @@ -3,6 +3,7 @@ use scenes::SimpleText; use std::collections::VecDeque; +use std::fmt::{Debug, Display}; use vello::kurbo::{Affine, PathEl, Rect, Stroke}; use vello::peniko::{Brush, Color, Fill}; use vello::{AaConfig, BumpAllocators, Scene}; @@ -22,6 +23,28 @@ pub struct Snapshot { pub frame_time_max_ms: f64, } +/// Formats the given number of seconds as a Duration. +/// +/// This is necessary as sometimes, the duration from wgpu-profiler turns out to be negative. +/// We have not yet debugged this, but we choose to display the absolute +/// value in that case. +/// +/// See for context +struct PaniclessSecondsFormatter(f64); + +impl Display for PaniclessSecondsFormatter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if self.0 < 0. { + if let Ok(val) = Duration::try_from_secs_f64(-self.0) { + return write!(f, "-{val:.2?}(!)"); + } + } else if let Ok(val) = Duration::try_from_secs_f64(self.0) { + return write!(f, "{val:.2?}"); + } + write!(f, "{} seconds(!)", self.0) + } +} + impl Snapshot { #[allow(clippy::too_many_arguments)] pub fn draw_layer<'a, T>( @@ -313,7 +336,7 @@ pub fn draw_gpu_profiling( let total_time = max - min; { let labels = [ - format!("GPU Time: {:.2?}", Duration::from_secs_f64(total_time)), + format!("GPU Time: {}", PaniclessSecondsFormatter(total_time)), "Press P to save a trace".to_string(), ]; @@ -397,24 +420,11 @@ pub fn draw_gpu_profiling( let text_size = (text_height * 0.9) as f32; // Text is specified by the baseline, but the y positions all refer to the top of the text cur_text_y = text_y + text_height; - let label = { - // Sometimes, the duration turns out to be negative - // We have not yet debugged this, but display the absolute value in that case - // see https://github.com/linebender/vello/pull/475 for more - if this_time < 0.0 { - format!( - "-{:.2?}(!!) - {:.30}", - Duration::from_secs_f64(this_time.abs()), - profile.label - ) - } else { - format!( - "{:.2?} - {:.30}", - Duration::from_secs_f64(this_time), - profile.label - ) - } - }; + let label = format!( + "{} - {:.30}", + PaniclessSecondsFormatter(this_time), + profile.label + ); scene.fill( Fill::NonZero, offset, From 4e11b7ad79e19e1f88b1adcfb234d595d850e14d Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:17:47 +0100 Subject: [PATCH 4/5] Appease the great and might clippy --- examples/with_winit/src/stats.rs | 46 +++++++++++++++++--------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/examples/with_winit/src/stats.rs b/examples/with_winit/src/stats.rs index 27a6d6d9..dce2baf7 100644 --- a/examples/with_winit/src/stats.rs +++ b/examples/with_winit/src/stats.rs @@ -23,28 +23,6 @@ pub struct Snapshot { pub frame_time_max_ms: f64, } -/// Formats the given number of seconds as a Duration. -/// -/// This is necessary as sometimes, the duration from wgpu-profiler turns out to be negative. -/// We have not yet debugged this, but we choose to display the absolute -/// value in that case. -/// -/// See for context -struct PaniclessSecondsFormatter(f64); - -impl Display for PaniclessSecondsFormatter { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if self.0 < 0. { - if let Ok(val) = Duration::try_from_secs_f64(-self.0) { - return write!(f, "-{val:.2?}(!)"); - } - } else if let Ok(val) = Duration::try_from_secs_f64(self.0) { - return write!(f, "{val:.2?}"); - } - write!(f, "{} seconds(!)", self.0) - } -} - impl Snapshot { #[allow(clippy::too_many_arguments)] pub fn draw_layer<'a, T>( @@ -273,6 +251,30 @@ fn round_up(n: usize, f: usize) -> usize { #[cfg(feature = "wgpu-profiler")] use wgpu_profiler::GpuTimerQueryResult; +/// Formats the given number of seconds as a Duration. +/// +/// This is necessary as sometimes, the duration from wgpu-profiler turns out to be negative. +/// We have not yet debugged this, but we choose to display the absolute +/// value in that case. +/// +/// See for context +#[cfg(feature = "wgpu-profiler")] +struct PaniclessSecondsFormatter(f64); + +#[cfg(feature = "wgpu-profiler")] +impl Display for PaniclessSecondsFormatter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if self.0 < 0. { + if let Ok(val) = Duration::try_from_secs_f64(-self.0) { + return write!(f, "-{val:.2?}(!)"); + } + } else if let Ok(val) = Duration::try_from_secs_f64(self.0) { + return write!(f, "{val:.2?}"); + } + write!(f, "{} seconds(!)", self.0) + } +} + #[cfg(feature = "wgpu-profiler")] fn profiles_are_empty(profiles: &[GpuTimerQueryResult]) -> bool { profiles.iter().all(|p| p.time.is_none()) From 725d52e76558e9fc3fe446285d38e7a7cdf21c3f Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:25:04 +0100 Subject: [PATCH 5/5] Fix incorrect import --- examples/with_winit/src/stats.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/with_winit/src/stats.rs b/examples/with_winit/src/stats.rs index dce2baf7..9660f351 100644 --- a/examples/with_winit/src/stats.rs +++ b/examples/with_winit/src/stats.rs @@ -3,7 +3,6 @@ use scenes::SimpleText; use std::collections::VecDeque; -use std::fmt::{Debug, Display}; use vello::kurbo::{Affine, PathEl, Rect, Stroke}; use vello::peniko::{Brush, Color, Fill}; use vello::{AaConfig, BumpAllocators, Scene}; @@ -262,7 +261,7 @@ use wgpu_profiler::GpuTimerQueryResult; struct PaniclessSecondsFormatter(f64); #[cfg(feature = "wgpu-profiler")] -impl Display for PaniclessSecondsFormatter { +impl std::fmt::Display for PaniclessSecondsFormatter { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { if self.0 < 0. { if let Ok(val) = Duration::try_from_secs_f64(-self.0) {