wgpu resource diagnostic plugin

This commit is contained in:
Carter Anderson 2020-05-04 12:36:18 -07:00
parent 6f32d18dc5
commit 0e63fd3838
5 changed files with 243 additions and 1 deletions

View file

@ -65,7 +65,7 @@ impl PrintDiagnosticsState {
fn print_diagnostic(diagnostic: &Diagnostic) {
if let Some(value) = diagnostic.value() {
print!("{:<10}: {:<9.6}", diagnostic.name, value);
print!("{:<20}: {:<19.6}", diagnostic.name, value);
if let Some(average) = diagnostic.average() {
print!(" (avg {:.6})", average);
}

View file

@ -12,6 +12,7 @@ default = ["bevy_winit"]
bevy_app = { path = "../bevy_app" }
bevy_asset = { path = "../bevy_asset" }
bevy_core = { path = "../bevy_core" }
bevy_diagnostic = { path = "../bevy_diagnostic" }
bevy_render = { path = "../bevy_render" }
bevy_window = { path = "../bevy_window" }
bevy_winit = { path = "../bevy_winit", optional = true }

View file

@ -0,0 +1,2 @@
mod wgpu_resource;
pub use wgpu_resource::WgpuResourceDiagnosticPlugin;

View file

@ -0,0 +1,238 @@
use crate::renderer::WgpuRenderResourceContext;
use bevy_app::{AppBuilder, AppPlugin};
use bevy_diagnostic::{Diagnostic, DiagnosticId, Diagnostics};
use bevy_render::renderer::GlobalRenderResourceContext;
use legion::prelude::{IntoSystem, Resource, ResourceMut};
#[derive(Default)]
pub struct WgpuResourceDiagnosticPlugin;
impl AppPlugin for WgpuResourceDiagnosticPlugin {
fn build(&self, app: &mut AppBuilder) {
app.add_startup_system(Self::setup_system.system())
.add_system(Self::diagnostic_system.system());
}
}
impl WgpuResourceDiagnosticPlugin {
pub const WINDOW_SURFACES: DiagnosticId =
DiagnosticId::from_u128(108237028251680341878766034324149135605);
pub const SWAP_CHAINS: DiagnosticId =
DiagnosticId::from_u128(199253035828743332241465305105689014605);
pub const SWAP_CHAIN_OUTPUTS: DiagnosticId =
DiagnosticId::from_u128(112048874168736161226721327099863374234);
pub const BUFFERS: DiagnosticId =
DiagnosticId::from_u128(133146619577893994787249934474491530491);
pub const TEXTURES: DiagnosticId =
DiagnosticId::from_u128(305955424195390184883220102469231911115);
pub const TEXTURE_VIEWS: DiagnosticId =
DiagnosticId::from_u128(257307432866562594739240898780307437578);
pub const SAMPLERS: DiagnosticId =
DiagnosticId::from_u128(305855369913076220671125671543184691267);
pub const BIND_GROUPS: DiagnosticId =
DiagnosticId::from_u128(283571569334075937453357861280307923122);
pub const BIND_GROUP_LAYOUTS: DiagnosticId =
DiagnosticId::from_u128(96406067032931216377076410852598331304);
pub const SHADER_MODULES: DiagnosticId =
DiagnosticId::from_u128(287681470908132753275843248383768232237);
pub const RENDER_PIPELINES: DiagnosticId =
DiagnosticId::from_u128(278527620040377353875091478462209885377);
pub fn setup_system(mut diagnostics: ResourceMut<Diagnostics>) {
diagnostics.add(Diagnostic::new(
Self::WINDOW_SURFACES,
"window_surfaces",
10,
));
diagnostics.add(Diagnostic::new(
Self::SWAP_CHAINS,
"swap_chains",
10,
));
diagnostics.add(Diagnostic::new(
Self::SWAP_CHAIN_OUTPUTS,
"swap_chain_outputs",
10,
));
diagnostics.add(Diagnostic::new(
Self::BUFFERS,
"buffers",
10,
));
diagnostics.add(Diagnostic::new(
Self::TEXTURES,
"textures",
10,
));
diagnostics.add(Diagnostic::new(
Self::TEXTURE_VIEWS,
"texture_views",
10,
));
diagnostics.add(Diagnostic::new(
Self::SAMPLERS,
"samplers",
10,
));
diagnostics.add(Diagnostic::new(
Self::BIND_GROUPS,
"bind_groups",
10,
));
diagnostics.add(Diagnostic::new(
Self::BIND_GROUP_LAYOUTS,
"bind_group_layouts",
10,
));
diagnostics.add(Diagnostic::new(
Self::SHADER_MODULES,
"shader_modules",
10,
));
diagnostics.add(Diagnostic::new(
Self::RENDER_PIPELINES,
"render_pipelines",
10,
));
}
pub fn diagnostic_system(
mut diagnostics: ResourceMut<Diagnostics>,
global_resource_context: Resource<GlobalRenderResourceContext>,
) {
let render_resource_context = global_resource_context
.context
.downcast_ref::<WgpuRenderResourceContext>()
.unwrap();
diagnostics.add_measurement(
Self::WINDOW_SURFACES,
render_resource_context
.wgpu_resources
.window_surfaces
.read()
.unwrap()
.len() as f64,
);
diagnostics.add_measurement(
Self::SWAP_CHAINS,
render_resource_context
.wgpu_resources
.window_swap_chains
.read()
.unwrap()
.len() as f64,
);
diagnostics.add_measurement(
Self::SWAP_CHAIN_OUTPUTS,
render_resource_context
.wgpu_resources
.swap_chain_outputs
.read()
.unwrap()
.len() as f64,
);
diagnostics.add_measurement(
Self::BUFFERS,
render_resource_context
.wgpu_resources
.buffers
.read()
.unwrap()
.len() as f64,
);
diagnostics.add_measurement(
Self::TEXTURES,
render_resource_context
.wgpu_resources
.textures
.read()
.unwrap()
.len() as f64,
);
diagnostics.add_measurement(
Self::TEXTURE_VIEWS,
render_resource_context
.wgpu_resources
.texture_views
.read()
.unwrap()
.len() as f64,
);
diagnostics.add_measurement(
Self::SAMPLERS,
render_resource_context
.wgpu_resources
.samplers
.read()
.unwrap()
.len() as f64,
);
diagnostics.add_measurement(
Self::BIND_GROUPS,
render_resource_context
.wgpu_resources
.bind_groups
.read()
.unwrap()
.len() as f64,
);
diagnostics.add_measurement(
Self::BIND_GROUP_LAYOUTS,
render_resource_context
.wgpu_resources
.bind_group_layouts
.read()
.unwrap()
.len() as f64,
);
diagnostics.add_measurement(
Self::SHADER_MODULES,
render_resource_context
.wgpu_resources
.shader_modules
.read()
.unwrap()
.len() as f64,
);
diagnostics.add_measurement(
Self::RENDER_PIPELINES,
render_resource_context
.wgpu_resources
.render_pipelines
.read()
.unwrap()
.len() as f64,
);
}
}

View file

@ -1,4 +1,5 @@
pub mod renderer;
pub mod diagnostic;
mod wgpu_render_pass;
mod wgpu_renderer;
mod wgpu_resources;