add (profiler)
This commit is contained in:
parent
ab8e78e1b1
commit
a19661daa0
5 changed files with 179 additions and 8 deletions
|
|
@ -16,8 +16,10 @@ egui-ash = { version = "0.4.0", features = ["gpu-allocator"] }
|
|||
tobj = "4.0.2"
|
||||
egui = "0.25.0"
|
||||
ash-window = "0.12.0"
|
||||
|
||||
shaders-shared = { path = "../shaders-shared" }
|
||||
puffin = { git = "https://github.com/EmbarkStudios/puffin", rev = "5ac4e54164ee89bd68c29f288c2b5613afc2c929" }
|
||||
puffin_egui = { git = "https://github.com/EmbarkStudios/puffin", rev = "5ac4e54164ee89bd68c29f288c2b5613afc2c929" }
|
||||
gpu-profiler = { path = "../../../gpu-profiler", features = ["use-ash"] }
|
||||
|
||||
[build-dependencies]
|
||||
spirv-builder.workspace = true
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -51,10 +51,13 @@ struct Game {
|
|||
last_fps_update: std::time::Instant,
|
||||
frame_count_since_last_update: i32,
|
||||
current_fps: f32,
|
||||
|
||||
show_profiler: bool,
|
||||
}
|
||||
|
||||
impl App for Game {
|
||||
fn ui(&mut self, ctx: &egui::Context) {
|
||||
puffin::GlobalProfiler::lock().new_frame();
|
||||
let now = std::time::Instant::now();
|
||||
self.frame_count_since_last_update += 1;
|
||||
|
||||
|
|
@ -65,6 +68,10 @@ impl App for Game {
|
|||
self.last_fps_update = now;
|
||||
}
|
||||
|
||||
if self.show_profiler {
|
||||
puffin_egui::profiler_window(ctx);
|
||||
}
|
||||
|
||||
egui::SidePanel::left("my_side_panel").show(ctx, |ui| {
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
|
|
@ -97,6 +104,10 @@ impl App for Game {
|
|||
ui.label("Z:");
|
||||
ui.add(egui::DragValue::new(&mut self.camera_position.z).speed(0.1));
|
||||
});
|
||||
ui.separator();
|
||||
if ui.button("Show Profiler").clicked() {
|
||||
self.show_profiler = !self.show_profiler;
|
||||
}
|
||||
ui.label(format!("FPS: {:.1}", self.current_fps));
|
||||
});
|
||||
|
||||
|
|
@ -168,6 +179,7 @@ impl App for Game {
|
|||
}
|
||||
|
||||
fn request_redraw(&mut self, _viewport_id: egui::ViewportId) -> HandleRedraw {
|
||||
puffin::profile_function!();
|
||||
HandleRedraw::Handle(Box::new({
|
||||
let renderer = self.renderer.clone();
|
||||
let rotate_y = self.rotate_y;
|
||||
|
|
@ -333,10 +345,15 @@ impl MyAppCreator {
|
|||
surface_loader: &Surface,
|
||||
surface: vk::SurfaceKHR,
|
||||
required_device_extensions: &[CString],
|
||||
) -> (vk::PhysicalDevice, vk::PhysicalDeviceMemoryProperties, u32) {
|
||||
) -> (
|
||||
vk::PhysicalDevice,
|
||||
vk::PhysicalDeviceProperties,
|
||||
vk::PhysicalDeviceMemoryProperties,
|
||||
u32,
|
||||
) {
|
||||
let mut queue_family_index: Option<usize> = None;
|
||||
|
||||
let (physical_device, physical_device_memory_properties) = {
|
||||
let (physical_device, phsyical_device_properties, physical_device_memory_properties) = {
|
||||
let physical_devices = unsafe {
|
||||
instance
|
||||
.enumerate_physical_devices()
|
||||
|
|
@ -414,11 +431,19 @@ impl MyAppCreator {
|
|||
let physical_device_memory_properties =
|
||||
unsafe { instance.get_physical_device_memory_properties(physical_device) };
|
||||
|
||||
(physical_device, physical_device_memory_properties)
|
||||
let physical_device_properties =
|
||||
unsafe { instance.get_physical_device_properties(physical_device) };
|
||||
|
||||
(
|
||||
physical_device,
|
||||
physical_device_properties,
|
||||
physical_device_memory_properties,
|
||||
)
|
||||
};
|
||||
|
||||
(
|
||||
physical_device,
|
||||
phsyical_device_properties,
|
||||
physical_device_memory_properties,
|
||||
queue_family_index.unwrap() as u32,
|
||||
)
|
||||
|
|
@ -494,8 +519,12 @@ impl AppCreator<Arc<Mutex<Allocator>>> for MyAppCreator {
|
|||
for ext in &cc.required_device_extensions {
|
||||
req_ext.push(ext.to_owned());
|
||||
}
|
||||
let (physical_device, _physical_device_memory_properties, queue_family_index) =
|
||||
Self::create_physical_device(&instance, &surface_loader, surface, &req_ext);
|
||||
let (
|
||||
physical_device,
|
||||
physical_device_properties,
|
||||
_physical_device_memory_properties,
|
||||
queue_family_index,
|
||||
) = Self::create_physical_device(&instance, &surface_loader, surface, &req_ext);
|
||||
let (device, queue) = Self::create_device(
|
||||
&instance,
|
||||
physical_device,
|
||||
|
|
@ -536,6 +565,8 @@ impl AppCreator<Arc<Mutex<Allocator>>> for MyAppCreator {
|
|||
command_pool,
|
||||
allocator: ManuallyDrop::new(allocator.clone()),
|
||||
|
||||
show_profiler: false,
|
||||
|
||||
renderer: Renderer::new(
|
||||
physical_device,
|
||||
device,
|
||||
|
|
@ -584,6 +615,8 @@ impl AppCreator<Arc<Mutex<Allocator>>> for MyAppCreator {
|
|||
}
|
||||
|
||||
fn main() -> std::process::ExitCode {
|
||||
puffin::set_scopes_on(true);
|
||||
|
||||
egui_ash::run(
|
||||
"vulkan",
|
||||
MyAppCreator,
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ impl RendererInner {
|
|||
.queue_family_indices(&queue_family_indices)
|
||||
.pre_transform(surface_capabilities.current_transform)
|
||||
.composite_alpha(vk::CompositeAlphaFlagsKHR::OPAQUE)
|
||||
.present_mode(vk::PresentModeKHR::FIFO)
|
||||
.present_mode(vk::PresentModeKHR::MAILBOX)
|
||||
.clipped(true);
|
||||
|
||||
let swapchain = unsafe {
|
||||
|
|
@ -607,7 +607,7 @@ impl RendererInner {
|
|||
let mut allocator = allocator.lock().unwrap();
|
||||
let vertices = {
|
||||
let model_obj = tobj::load_obj(
|
||||
"./crates/vk-rs/assets/suzanne.obj",
|
||||
"./assets/suzanne.obj",
|
||||
&tobj::LoadOptions {
|
||||
single_index: true,
|
||||
triangulate: true,
|
||||
|
|
@ -1099,6 +1099,7 @@ impl RendererInner {
|
|||
}
|
||||
|
||||
pub fn render(&mut self, width: u32, height: u32, mut egui_cmd: EguiCommand, rotate_y: f32) {
|
||||
puffin::profile_function!();
|
||||
if width == 0 || height == 0 {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1113,10 +1114,12 @@ impl RendererInner {
|
|||
|| height != self.height
|
||||
|| egui_cmd.swapchain_recreate_required()
|
||||
{
|
||||
puffin::profile_scope!("recreate_swapchain");
|
||||
self.recreate_swapchain(width, height, &mut egui_cmd);
|
||||
}
|
||||
|
||||
let result = unsafe {
|
||||
puffin::profile_scope!("acquire_next_image");
|
||||
self.swapchain_loader.acquire_next_image(
|
||||
self.swapchain,
|
||||
u64::MAX,
|
||||
|
|
@ -1134,6 +1137,7 @@ impl RendererInner {
|
|||
};
|
||||
|
||||
unsafe {
|
||||
puffin::profile_scope!("wait_for_fences");
|
||||
self.device.wait_for_fences(
|
||||
std::slice::from_ref(&self.in_flight_fences[self.current_frame]),
|
||||
true,
|
||||
|
|
@ -1150,6 +1154,7 @@ impl RendererInner {
|
|||
.expect("Failed to reset fences");
|
||||
|
||||
let view = {
|
||||
puffin::profile_scope!("calculate_view");
|
||||
let (sin_pitch, cos_pitch) = self.camera_pitch.sin_cos();
|
||||
let (sin_yaw, cos_yaw) = self.camera_yaw.sin_cos();
|
||||
|
||||
|
|
@ -1185,6 +1190,7 @@ impl RendererInner {
|
|||
let command_buffer_begin_info = vk::CommandBufferBeginInfo::builder()
|
||||
.flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT);
|
||||
unsafe {
|
||||
puffin::profile_scope!("render");
|
||||
self.device
|
||||
.begin_command_buffer(
|
||||
self.command_buffers[self.current_frame],
|
||||
|
|
@ -1287,6 +1293,7 @@ impl RendererInner {
|
|||
&self.render_finished_semaphores[self.current_frame],
|
||||
));
|
||||
unsafe {
|
||||
puffin::profile_scope!("queue_submit");
|
||||
self.device
|
||||
.queue_submit(
|
||||
self.queue,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue