Skip to content

Commit

Permalink
Better profiling integration for the renderer, make hot reload optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Oct 30, 2023
1 parent 3de2a81 commit a7efd1b
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions blade-asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ base64 = { workspace = true }
bytemuck = { workspace = true }
choir = { workspace = true }
log = { workspace = true }
profiling = { workspace = true }
1 change: 1 addition & 0 deletions blade-asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ enum CookReason {
WrongDataOffset,
}

#[profiling::function]
#[allow(clippy::read_zero_byte_vec)] // bad warning?
fn check_target_relevancy(
target_path: &Path,
Expand Down
1 change: 1 addition & 0 deletions blade-egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ blade-graphics = { version = "0.2", path = "../blade-graphics"}
blade-macros = { version = "0.2", path = "../blade-macros"}
bytemuck = { workspace = true }
egui = { workspace = true, features = ["bytemuck"] }
profiling = { workspace = true }
5 changes: 5 additions & 0 deletions blade-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl GuiPainter {
///
/// It supports renderpasses with only a color attachment,
/// and this attachment format must be The `output_format`.
#[profiling::function]
pub fn new(
context: &blade_graphics::Context,
output_format: blade_graphics::TextureFormat,
Expand Down Expand Up @@ -167,6 +168,7 @@ impl GuiPainter {
}
}

#[profiling::function]
fn triage_deletions(&mut self, context: &blade_graphics::Context) {
let valid_pos = self
.textures_to_delete
Expand All @@ -182,6 +184,7 @@ impl GuiPainter {
/// Updates the texture used by egui for the fonts etc.
/// New textures should be added before the call to `execute()`,
/// and old textures should be removed after.
#[profiling::function]
pub fn update_textures(
&mut self,
command_encoder: &mut blade_graphics::CommandEncoder,
Expand Down Expand Up @@ -270,6 +273,7 @@ impl GuiPainter {

/// Render the set of clipped primitives into a render pass.
/// The `sd` must contain dimensions of the render target.
#[profiling::function]
pub fn paint(
&mut self,
pass: &mut blade_graphics::RenderCommandEncoder,
Expand Down Expand Up @@ -344,6 +348,7 @@ impl GuiPainter {
}

/// Call this after submitting work at the given `sync_point`.
#[profiling::function]
pub fn after_submit(&mut self, sync_point: blade_graphics::SyncPoint) {
self.textures_to_delete.extend(
self.textures_dropped
Expand Down
2 changes: 1 addition & 1 deletion blade-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ pub struct ShaderDataLayout {
}

impl ShaderDataLayout {
pub const EMPTY: &Self = &Self {
pub const EMPTY: &'static Self = &Self {
bindings: Vec::new(),
};
}
Expand Down
2 changes: 2 additions & 0 deletions blade-render/src/asset_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl AssetHub {
///
/// Populates the list of temporary buffers that can be freed when the
/// relevant submission is completely retired.
#[profiling::function]
pub fn flush(
&self,
command_encoder: &mut blade_graphics::CommandEncoder,
Expand Down Expand Up @@ -78,6 +79,7 @@ impl AssetHub {
}
}

#[profiling::function]
pub fn list_running_tasks(&self) -> Vec<choir::RunningTask> {
let mut list = Vec::new();
self.textures.list_running_tasks(&mut list);
Expand Down
9 changes: 9 additions & 0 deletions blade-render/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ impl Renderer {
///
/// Panics if the system is not compatible.
/// Records initialization routines into the given command encoder.
#[profiling::function]
pub fn new(
encoder: &mut blade_graphics::CommandEncoder,
gpu: &blade_graphics::Context,
Expand Down Expand Up @@ -876,6 +877,7 @@ impl Renderer {
self.is_tlas_dirty = true;
}

#[profiling::function]
pub fn hot_reload(
&mut self,
asset_hub: &crate::AssetHub,
Expand Down Expand Up @@ -964,6 +966,7 @@ impl Renderer {
self.env_map.weight_view
}

#[profiling::function]
pub fn resize_screen(
&mut self,
size: blade_graphics::Extent,
Expand Down Expand Up @@ -998,6 +1001,7 @@ impl Renderer {
}

/// Prepare to render a frame.
#[profiling::function]
#[allow(clippy::too_many_arguments)]
pub fn prepare(
&mut self,
Expand Down Expand Up @@ -1258,6 +1262,7 @@ impl Renderer {
/// Ray trace the scene.
///
/// The result is stored internally in an HDR render target.
#[profiling::function]
pub fn ray_trace(
&self,
command_encoder: &mut blade_graphics::CommandEncoder,
Expand Down Expand Up @@ -1335,6 +1340,8 @@ impl Renderer {
}
}

/// Perform noise reduction using SVGF.
#[profiling::function]
pub fn denoise(
&mut self, //TODO: borrow immutably
command_encoder: &mut blade_graphics::CommandEncoder,
Expand Down Expand Up @@ -1405,6 +1412,7 @@ impl Renderer {
}

/// Blit the rendering result into a specified render pass.
#[profiling::function]
pub fn post_proc(
&self,
pass: &mut blade_graphics::RenderCommandEncoder,
Expand Down Expand Up @@ -1469,6 +1477,7 @@ impl Renderer {
}
}

#[profiling::function]
pub fn read_debug_selection_info(&self) -> SelectionInfo {
let db_v = unsafe { &*(self.debug.variance_buffer.data() as *const DebugVariance) };
let db_e = unsafe { &*(self.debug.entry_buffer.data() as *const DebugEntry) };
Expand Down
22 changes: 16 additions & 6 deletions examples/scene/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct Example {
camera: blade_render::Camera,
fly_speed: f32,
debug: blade_render::DebugConfig,
track_hot_reloads: bool,
need_accumulation_reset: bool,
is_debug_drawing: bool,
last_render_time: time::Instant,
Expand Down Expand Up @@ -106,9 +107,9 @@ impl Example {
}
}

#[profiling::function]
fn new(window: &winit::window::Window, scene_path: &Path) -> Self {
log::info!("Initializing");
//let _ = profiling::tracy_client::Client::start();

let context = Arc::new(unsafe {
gpu::Context::init_windowed(
Expand Down Expand Up @@ -220,6 +221,7 @@ impl Example {
camera,
fly_speed: config_scene.camera.speed,
debug: blade_render::DebugConfig::default(),
track_hot_reloads: false,
need_accumulation_reset: true,
is_debug_drawing: false,
last_render_time: time::Instant::now(),
Expand Down Expand Up @@ -253,6 +255,7 @@ impl Example {
.destroy_command_encoder(self.command_encoder.take().unwrap());
}

#[profiling::function]
fn wait_for_previous_frame(&mut self) {
if let Some(sp) = self.prev_sync_point.take() {
self.context.wait_for(&sp, !0);
Expand All @@ -265,6 +268,7 @@ impl Example {
}
}

#[profiling::function]
fn render(
&mut self,
gui_primitives: &[egui::ClippedPrimitive],
Expand All @@ -280,11 +284,13 @@ impl Example {
}
}

self.need_accumulation_reset |= self.renderer.hot_reload(
&self.asset_hub,
&self.context,
self.prev_sync_point.as_ref().unwrap(),
);
if self.track_hot_reloads {
self.need_accumulation_reset |= self.renderer.hot_reload(
&self.asset_hub,
&self.context,
self.prev_sync_point.as_ref().unwrap(),
);
}

// Note: the resize is split in 2 parts because `wait_for_previous_frame`
// wants to borrow `self` mutably, and `command_encoder` blocks that.
Expand Down Expand Up @@ -374,6 +380,7 @@ impl Example {
.extend(temp_acceleration_structures);
}

#[profiling::function]
fn add_gui(&mut self, ui: &mut egui::Ui) {
use strum::IntoEnumIterator as _;

Expand Down Expand Up @@ -421,6 +428,7 @@ impl Example {
egui::CollapsingHeader::new("Debug")
.default_open(true)
.show(ui, |ui| {
ui.checkbox(&mut self.track_hot_reloads, "Hot reloading");
// debug mode
egui::ComboBox::from_label("View mode")
.selected_text(format!("{:?}", self.debug.view_mode))
Expand Down Expand Up @@ -667,6 +675,7 @@ impl Example {

fn main() {
env_logger::init();
//let _ = profiling::tracy_client::Client::start();

let event_loop = winit::event_loop::EventLoop::new();
let window = winit::window::WindowBuilder::new()
Expand Down Expand Up @@ -851,6 +860,7 @@ fn main() {
window.inner_size(),
egui_ctx.pixels_per_point(),
);
profiling::finish_frame!();
}
winit::event::Event::LoopDestroyed => {
example.destroy();
Expand Down

0 comments on commit a7efd1b

Please sign in to comment.