Skip to content

Commit

Permalink
desktop: Send wgpu stats to tracy
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone committed Jul 19, 2023
1 parent 5597535 commit 2729da8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
9 changes: 3 additions & 6 deletions desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::custom_event::RuffleEvent;
use crate::gui::{GuiController, MENU_HEIGHT};
use crate::player::{PlayerController, PlayerOptions};
use crate::util::{
get_screen_size, parse_url, pick_file, winit_key_to_char, winit_to_ruffle_key_code,
winit_to_ruffle_text_control,
get_screen_size, parse_url, pick_file, plot_stats_in_tracy, winit_key_to_char,
winit_to_ruffle_key_code, winit_to_ruffle_text_control,
};
use anyhow::{Context, Error};
use ruffle_core::{PlayerEvent, StageDisplayState};
Expand Down Expand Up @@ -136,10 +136,7 @@ impl App {
} else {
self.gui.borrow_mut().render(None);
}
#[cfg(feature = "tracy")]
tracing_tracy::client::Client::running()
.expect("tracy client must be running")
.frame_mark();
plot_stats_in_tracy(&self.gui.borrow().descriptors().wgpu_instance);
}
}

Expand Down
39 changes: 39 additions & 0 deletions desktop/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,42 @@ pub fn pick_file(in_ui: bool, path: Option<PathBuf>) -> Option<PathBuf> {
pub fn pick_file(_in_ui: bool, path: Option<PathBuf>) -> Option<PathBuf> {
actually_pick_file(path)
}

#[cfg(not(feature = "tracy"))]
pub fn plot_stats_in_tracy(_instance: &wgpu::Instance) {}

#[cfg(feature = "tracy")]
pub fn plot_stats_in_tracy(instance: &wgpu::Instance) {
use tracing_tracy::client::*;
const BIND_GROUPS: PlotName = plot_name!("Bind Groups");
const BUFFERS: PlotName = plot_name!("Buffers");
const TEXTURES: PlotName = plot_name!("Textures");
const TEXTURE_VIEWS: PlotName = plot_name!("Texture Views");

let tracy = Client::running().expect("tracy client must be running");
let report = instance.generate_report();

#[allow(unused_mut)]
let mut backend = None;
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
{
backend = backend.or(report.vulkan).or(report.gl);
}
#[cfg(windows)]
{
backend = backend.or(report.dx12).or(report.dx11);
}
#[cfg(any(target_os = "macos", target_os = "ios"))]
{
backend = backend.or(report.metal);
}

if let Some(stats) = backend {
tracy.plot(BIND_GROUPS, stats.bind_groups.num_occupied as f64);
tracy.plot(BUFFERS, stats.buffers.num_occupied as f64);
tracy.plot(TEXTURES, stats.textures.num_occupied as f64);
tracy.plot(TEXTURE_VIEWS, stats.texture_views.num_occupied as f64);
}

tracy.frame_mark();
}

0 comments on commit 2729da8

Please sign in to comment.