diff --git a/crates/bevy_render/src/diagnostic/mesh_allocator_diagnostic_plugin.rs b/crates/bevy_render/src/diagnostic/mesh_allocator_diagnostic_plugin.rs index f8ebae1414..cd0b70dbc5 100644 --- a/crates/bevy_render/src/diagnostic/mesh_allocator_diagnostic_plugin.rs +++ b/crates/bevy_render/src/diagnostic/mesh_allocator_diagnostic_plugin.rs @@ -6,25 +6,46 @@ use bevy_platform::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; use crate::{mesh::allocator::MeshAllocator, Extract, ExtractSchedule, RenderApp}; /// Number of meshes allocated by the allocator -const MESH_ALLOCATOR_SLABS: DiagnosticPath = DiagnosticPath::const_new("mesh_allocator_slabs"); +static MESH_ALLOCATOR_SLABS: DiagnosticPath = DiagnosticPath::const_new("mesh_allocator_slabs"); /// Total size of all slabs -const MESH_ALLOCATOR_SLABS_SIZE: DiagnosticPath = +static MESH_ALLOCATOR_SLABS_SIZE: DiagnosticPath = DiagnosticPath::const_new("mesh_allocator_slabs_size"); /// Number of meshes allocated into slabs -const MESH_ALLOCATOR_ALLOCATIONS: DiagnosticPath = +static MESH_ALLOCATOR_ALLOCATIONS: DiagnosticPath = DiagnosticPath::const_new("mesh_allocator_allocations"); pub struct MeshAllocatorDiagnosticPlugin; +impl MeshAllocatorDiagnosticPlugin { + /// Get the [`DiagnosticPath`] for slab count + pub fn slabs_diagnostic_path() -> &'static DiagnosticPath { + &MESH_ALLOCATOR_SLABS + } + /// Get the [`DiagnosticPath`] for total slabs size + pub fn slabs_size_diagnostic_path() -> &'static DiagnosticPath { + &MESH_ALLOCATOR_SLABS_SIZE + } + /// Get the [`DiagnosticPath`] for mesh allocations + pub fn allocations_diagnostic_path() -> &'static DiagnosticPath { + &MESH_ALLOCATOR_ALLOCATIONS + } +} + impl Plugin for MeshAllocatorDiagnosticPlugin { fn build(&self, app: &mut bevy_app::App) { - app.register_diagnostic(Diagnostic::new(MESH_ALLOCATOR_SLABS).with_suffix(" slabs")) - .register_diagnostic(Diagnostic::new(MESH_ALLOCATOR_SLABS_SIZE).with_suffix(" bytes")) - .register_diagnostic(Diagnostic::new(MESH_ALLOCATOR_ALLOCATIONS).with_suffix(" meshes")) - .init_resource::() - .add_systems(PreUpdate, add_mesh_allocator_measurement); + app.register_diagnostic( + Diagnostic::new(MESH_ALLOCATOR_SLABS.clone()).with_suffix(" slabs"), + ) + .register_diagnostic( + Diagnostic::new(MESH_ALLOCATOR_SLABS_SIZE.clone()).with_suffix(" bytes"), + ) + .register_diagnostic( + Diagnostic::new(MESH_ALLOCATOR_ALLOCATIONS.clone()).with_suffix(" meshes"), + ) + .init_resource::() + .add_systems(PreUpdate, add_mesh_allocator_measurement); if let Some(render_app) = app.get_sub_app_mut(RenderApp) { render_app.add_systems(ExtractSchedule, measure_allocator); diff --git a/crates/bevy_render/src/diagnostic/render_asset_diagnostic_plugin.rs b/crates/bevy_render/src/diagnostic/render_asset_diagnostic_plugin.rs index 48c4655859..347bae7338 100644 --- a/crates/bevy_render/src/diagnostic/render_asset_diagnostic_plugin.rs +++ b/crates/bevy_render/src/diagnostic/render_asset_diagnostic_plugin.rs @@ -12,7 +12,6 @@ use crate::{ pub struct RenderAssetDiagnosticPlugin { suffix: &'static str, - path: DiagnosticPath, _phantom: PhantomData, } @@ -20,17 +19,22 @@ impl RenderAssetDiagnosticPlugin { pub fn new(suffix: &'static str) -> Self { Self { suffix, - path: DiagnosticPath::from_components(["render_asset", type_name::()]), _phantom: PhantomData, } } + + pub fn render_asset_diagnostic_path() -> DiagnosticPath { + DiagnosticPath::from_components(["render_asset", type_name::()]) + } } impl Plugin for RenderAssetDiagnosticPlugin { fn build(&self, app: &mut bevy_app::App) { - app.register_diagnostic(Diagnostic::new(self.path.clone()).with_suffix(self.suffix)) - .init_resource::>() - .add_systems(PreUpdate, add_render_asset_measurement::); + app.register_diagnostic( + Diagnostic::new(Self::render_asset_diagnostic_path()).with_suffix(self.suffix), + ) + .init_resource::>() + .add_systems(PreUpdate, add_render_asset_measurement::); if let Some(render_app) = app.get_sub_app_mut(RenderApp) { render_app.add_systems(ExtractSchedule, measure_render_asset::); @@ -58,7 +62,7 @@ fn add_render_asset_measurement( measurements: Res>, ) { diagnostics.add_measurement( - &DiagnosticPath::from_components(["render_asset", type_name::()]), + &RenderAssetDiagnosticPlugin::::render_asset_diagnostic_path(), || measurements.assets.load(Ordering::Relaxed) as f64, ); }