Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade wgpu-profiler #687

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.2"
scenes = { path = "examples/scenes" }
49 changes: 30 additions & 19 deletions examples/with_winit/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,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 <https://github.com/linebender/vello/pull/475> for context
#[cfg(feature = "wgpu-profiler")]
struct PaniclessSecondsFormatter(f64);

#[cfg(feature = "wgpu-profiler")]
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) {
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())
Expand Down Expand Up @@ -313,7 +337,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(),
];

Expand Down Expand Up @@ -397,24 +421,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,
Expand Down