performance counters
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
use std::{sync::Arc, time::Instant};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use cgmath::{Matrix4, SquareMatrix};
|
||||
@@ -44,6 +44,8 @@ const VALIDATION_LAYERS: &[&str] = &[
|
||||
"VK_LAYER_KHRONOS_validation",
|
||||
];
|
||||
|
||||
pub const PERF_COUNTER_SIZE: usize = 1000;
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Vertex {
|
||||
pub position: [f32; 3],
|
||||
@@ -113,6 +115,11 @@ pub struct GameData {
|
||||
pub meshes: Vec<Mesh<Vertex>>,
|
||||
pub meshes_text: Vec<Mesh<TextVertex>>,
|
||||
pub textures: Vec<Texture>,
|
||||
pub update_perf_counters: [u128; PERF_COUNTER_SIZE],
|
||||
pub render_perf_counters: [u128; PERF_COUNTER_SIZE],
|
||||
pub other_perf_counters: [u128; PERF_COUNTER_SIZE],
|
||||
pub other_perf_instant: Instant,
|
||||
pub performance_counter_index: usize,
|
||||
}
|
||||
|
||||
pub(crate) type RendererDescriptorSets = dyn DescriptorSet + Send + Sync;
|
||||
@@ -151,6 +158,11 @@ impl VulkanRenderer {
|
||||
meshes: vec![],
|
||||
meshes_text: vec![],
|
||||
textures: vec![],
|
||||
update_perf_counters: [0; PERF_COUNTER_SIZE],
|
||||
render_perf_counters: [0; PERF_COUNTER_SIZE],
|
||||
other_perf_counters: [0; PERF_COUNTER_SIZE],
|
||||
performance_counter_index: 0,
|
||||
other_perf_instant: Instant::now(),
|
||||
};
|
||||
|
||||
// Create basic vulkan instance with layers and info
|
||||
@@ -333,6 +345,8 @@ impl VulkanRenderer {
|
||||
}
|
||||
|
||||
pub fn render_loop(self: &mut Self, new_ubo: vs::ty::ObjectUniformData, game_objects: &Vec<GameObject>) {
|
||||
let precise_start = Instant::now();
|
||||
|
||||
// cleanup previous frame
|
||||
self.previous_frame_end.as_mut().unwrap().cleanup_finished();
|
||||
|
||||
@@ -423,6 +437,8 @@ impl VulkanRenderer {
|
||||
self.previous_frame_end = Some(Box::new(sync::now(self.device.clone())) as Box<_>);
|
||||
}
|
||||
};
|
||||
|
||||
self.game_data.render_perf_counters[self.game_data.performance_counter_index] = precise_start.elapsed().as_micros();
|
||||
}
|
||||
|
||||
pub fn upload_mesh(self: &mut Self, mesh: CPUMesh, original_path: Option<String>) -> usize {
|
||||
@@ -671,6 +687,9 @@ pub fn start_event_loop(mut renderer: VulkanRenderer, mut game: Box<dyn Game>, e
|
||||
Event::RedrawEventsCleared => {
|
||||
let ubo = game.update(&mut renderer);
|
||||
renderer.render_loop(ubo, &game.get_game_objects());
|
||||
renderer.game_data.other_perf_counters[renderer.game_data.performance_counter_index] = renderer.game_data.other_perf_instant.elapsed().as_micros();
|
||||
renderer.game_data.other_perf_instant = Instant::now();
|
||||
renderer.game_data.performance_counter_index = (renderer.game_data.performance_counter_index + 1) % PERF_COUNTER_SIZE;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user