fyrox_impl/renderer/
stats.rs1use fyrox_core::instant;
22use fyrox_graphics::framebuffer::DrawCallStatistics;
23pub use fyrox_graphics::stats::*;
24use std::fmt::{Display, Formatter};
25use std::ops::AddAssign;
26
27#[derive(Debug, Copy, Clone, Default)]
29pub struct LightingStatistics {
30 pub point_lights_rendered: usize,
32 pub point_shadow_maps_rendered: usize,
34 pub csm_rendered: usize,
36 pub spot_lights_rendered: usize,
38 pub spot_shadow_maps_rendered: usize,
40 pub directional_lights_rendered: usize,
42}
43
44impl AddAssign for LightingStatistics {
45 fn add_assign(&mut self, rhs: Self) {
46 self.point_lights_rendered += rhs.point_lights_rendered;
47 self.point_shadow_maps_rendered += rhs.point_shadow_maps_rendered;
48 self.spot_lights_rendered += rhs.spot_lights_rendered;
49 self.spot_shadow_maps_rendered += rhs.spot_shadow_maps_rendered;
50 self.directional_lights_rendered += rhs.directional_lights_rendered;
51 self.csm_rendered += rhs.csm_rendered;
52 }
53}
54
55impl Display for LightingStatistics {
56 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
57 write!(
58 f,
59 "Lighting Statistics:\n\
60 \tPoint Lights: {}\n\
61 \tSpot Lights: {}\n\
62 \tDirectional Lights: {}\n\
63 \tPoint Shadow Maps: {}\n\
64 \tSpot Shadow Maps: {}\n\
65 \tSpot Shadow Maps: {}\n",
66 self.point_lights_rendered,
67 self.spot_lights_rendered,
68 self.directional_lights_rendered,
69 self.point_shadow_maps_rendered,
70 self.spot_shadow_maps_rendered,
71 self.csm_rendered
72 )
73 }
74}
75
76#[derive(Debug, Copy, Clone, Default)]
78pub struct SceneStatistics {
79 pub pipeline: PipelineStatistics,
81 pub lighting: LightingStatistics,
83 pub geometry: RenderPassStatistics,
85}
86
87impl Display for SceneStatistics {
88 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
89 write!(
90 f,
91 "{}\n\
92 {}\n\
93 {}\n",
94 self.geometry, self.lighting, self.pipeline
95 )
96 }
97}
98
99impl AddAssign<DrawCallStatistics> for SceneStatistics {
100 fn add_assign(&mut self, rhs: DrawCallStatistics) {
101 self.geometry += rhs;
102 }
103}
104
105impl AddAssign<PipelineStatistics> for SceneStatistics {
106 fn add_assign(&mut self, rhs: PipelineStatistics) {
107 self.pipeline += rhs;
108 }
109}
110
111impl AddAssign<RenderPassStatistics> for SceneStatistics {
112 fn add_assign(&mut self, rhs: RenderPassStatistics) {
113 self.geometry += rhs;
114 }
115}
116
117impl AddAssign<LightingStatistics> for SceneStatistics {
118 fn add_assign(&mut self, rhs: LightingStatistics) {
119 self.lighting += rhs;
120 }
121}
122
123#[derive(Debug, Copy, Clone)]
126pub struct Statistics {
127 pub pipeline: PipelineStatistics,
129 pub lighting: LightingStatistics,
131 pub geometry: RenderPassStatistics,
133 pub pure_frame_time: f32,
135 pub capped_frame_time: f32,
139 pub frames_per_second: usize,
141 pub texture_cache_size: usize,
143 pub geometry_cache_size: usize,
145 pub shader_cache_size: usize,
147 pub uniform_buffer_cache_size: usize,
149 pub(super) frame_counter: usize,
150 pub(super) frame_start_time: instant::Instant,
151 pub(super) last_fps_commit_time: instant::Instant,
152}
153
154impl std::ops::AddAssign<SceneStatistics> for Statistics {
155 fn add_assign(&mut self, rhs: SceneStatistics) {
156 self.pipeline += rhs.pipeline;
157 self.lighting += rhs.lighting;
158 self.geometry += rhs.geometry;
159 }
160}
161
162impl Display for Statistics {
163 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
164 let fps = self.frames_per_second;
165 let pure_frame_time = self.pure_frame_time * 1000.0;
166 let capped_frame_time = self.capped_frame_time * 1000.0;
167 let geometry_stats = &self.geometry;
168 let lighting_stats = &self.lighting;
169 let pipeline_stats = &self.pipeline;
170 let texture_cache_size = self.texture_cache_size;
171 let geometry_cache_size = self.geometry_cache_size;
172 let shader_cache_size = self.shader_cache_size;
173 let uniform_buffer_cache_size = self.uniform_buffer_cache_size;
174 write!(
175 f,
176 "FPS: {fps}\n\
177 Pure Frame Time: {pure_frame_time:.2} ms\n\
178 Capped Frame Time: {capped_frame_time:.2} ms\n\
179 {geometry_stats}\n\
180 {lighting_stats}\n\
181 {pipeline_stats}\n\
182 Texture Cache Size: {texture_cache_size}\n\
183 Geometry Cache Size: {geometry_cache_size}\n\
184 Shader Cache Size: {shader_cache_size}\n
185 Uniform Buffer Cache Size: {uniform_buffer_cache_size}\n",
186 )
187 }
188}
189
190impl std::ops::AddAssign<RenderPassStatistics> for Statistics {
191 fn add_assign(&mut self, rhs: RenderPassStatistics) {
192 self.geometry += rhs;
193 }
194}