From 6158a6bc53ed6b9bd0d05f096bbd4233eadf91fb Mon Sep 17 00:00:00 2001 From: mgt Date: Thu, 29 Feb 2024 11:56:15 +0800 Subject: [PATCH 1/3] Fix negative duration panic on macos --- examples/with_winit/src/stats.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with_winit/src/stats.rs b/examples/with_winit/src/stats.rs index 72b433cf8..49b45d5a3 100644 --- a/examples/with_winit/src/stats.rs +++ b/examples/with_winit/src/stats.rs @@ -386,7 +386,7 @@ pub fn draw_gpu_profiling( cur_text_y = text_y + text_height; let label = format!( "{:.2?} - {:.30}", - Duration::from_secs_f64(this_time), + Duration::from_secs_f64(this_time.max(0.0)), profile.label ); scene.fill( From 0490756804d4dab38d5d47b940b6764676d412ec Mon Sep 17 00:00:00 2001 From: mgt Date: Sun, 3 Mar 2024 00:31:37 +0800 Subject: [PATCH 2/3] apply suggestions from code review --- examples/with_winit/src/stats.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/with_winit/src/stats.rs b/examples/with_winit/src/stats.rs index 49b45d5a3..8926ba383 100644 --- a/examples/with_winit/src/stats.rs +++ b/examples/with_winit/src/stats.rs @@ -384,11 +384,21 @@ 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 = format!( - "{:.2?} - {:.30}", - Duration::from_secs_f64(this_time.max(0.0)), - profile.label - ); + let label = { + 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 + ) + } + }; scene.fill( Fill::NonZero, offset, From 7d266f8d9cad2accbea597b18803915e97b4c7cd Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Mon, 4 Mar 2024 08:39:27 +0000 Subject: [PATCH 3/3] Add a comment explaining condition --- examples/with_winit/src/stats.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/with_winit/src/stats.rs b/examples/with_winit/src/stats.rs index 8926ba383..2b788e3ce 100644 --- a/examples/with_winit/src/stats.rs +++ b/examples/with_winit/src/stats.rs @@ -385,6 +385,9 @@ pub fn draw_gpu_profiling( // 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}",