Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing profiling scopes in re_renderer #1567

Merged
merged 1 commit into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/re_renderer/src/allocator/cpu_write_gpu_read_belt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ impl CpuWriteGpuReadBelt {
buffer_pool: &GpuBufferPool,
num_elements: usize,
) -> CpuWriteGpuReadBuffer<T> {
crate::profile_function!();

// Potentially overestimate alignment with Self::MIN_ALIGNMENT, see Self::MIN_ALIGNMENT doc string.
let alignment = (std::mem::align_of::<T>() as wgpu::BufferAddress).max(Self::MIN_ALIGNMENT);
// Pad out the size of the used buffer to a multiple of Self::MIN_ALIGNMENT.
Expand Down Expand Up @@ -377,6 +379,8 @@ impl CpuWriteGpuReadBelt {
/// further writes) until after [`CpuWriteGpuReadBelt::after_queue_submit`] is called *and* the GPU is done
/// copying the data from them.
pub fn before_queue_submit(&mut self) {
crate::profile_function!();

// This would be a great usecase for persistent memory mapping, i.e. mapping without the need to unmap
// https://github.com/gfx-rs/wgpu/issues/1468
// However, WebGPU does not support this!
Expand All @@ -393,6 +397,7 @@ impl CpuWriteGpuReadBelt {
/// copy operations are submitted. Additional calls are harmless.
/// Not calling this as soon as possible may result in increased buffer memory usage.
pub fn after_queue_submit(&mut self) {
crate::profile_function!();
self.receive_chunks();

let sender = &self.sender;
Expand Down
3 changes: 3 additions & 0 deletions crates/re_renderer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ impl RenderContext {
queue: Arc<wgpu::Queue>,
config: RenderContextConfig,
) -> Self {
crate::profile_function!();

let mut gpu_resources = WgpuResourcePools::default();
let global_bindings = GlobalBindings::new(&mut gpu_resources, &device);

Expand Down Expand Up @@ -310,6 +312,7 @@ impl RenderContext {
self.cpu_write_gpu_read_belt.lock().before_queue_submit();

if let Some(command_encoder) = self.active_frame.encoder.lock().0.take() {
crate::profile_scope!("finish & submit frame-global encoder");
let command_buffer = command_encoder.finish();

// TODO(andreas): For better performance, we should try to bundle this with the single submit call that is currently happening in eframe.
Expand Down
2 changes: 2 additions & 0 deletions crates/re_renderer/src/view_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ impl ViewBuilder {
phase: DrawPhase,
pass: &mut wgpu::RenderPass<'a>,
) {
crate::profile_function!();

for queued_draw in &self.queued_draws {
if queued_draw.participated_phases.contains(&phase) {
let res = (queued_draw.draw_func)(ctx, phase, pass, queued_draw.draw_data.as_ref())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ where
desc: &Desc,
creation_func: F,
) -> Arc<DynamicResource<Handle, Desc, Res>> {
crate::profile_function!();
let mut state = self.state.write();

// First check if we can reclaim a resource we have around from a previous frame.
Expand Down Expand Up @@ -143,6 +144,7 @@ where
}

pub fn begin_frame(&mut self, frame_index: u64, mut on_destroy_resource: impl FnMut(&Res)) {
crate::profile_function!();
self.current_frame_index = frame_index;
let state = self.state.get_mut();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl GpuRenderPipelinePool {
shader_modules: &mut GpuShaderModulePool,
pipeline_layouts: &mut GpuPipelineLayoutPool,
) {
crate::profile_function!();
self.pool.current_frame_index = frame_index;

// Recompile render pipelines referencing shader modules that have been recompiled this frame.
Expand Down
3 changes: 3 additions & 0 deletions crates/re_renderer/src/wgpu_resources/static_resource_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ where
creation_func: F,
) -> Handle {
*self.lookup.entry(desc.clone()).or_insert_with(|| {
crate::profile_scope!("Creating new static resource", std::any::type_name::<Res>());
re_log::debug!(?desc, "Created new resource");
let resource = creation_func(desc);
self.resources.insert(StoredResource {
Expand All @@ -64,6 +65,8 @@ where
}

pub fn recreate_resources<F: FnMut(&Desc) -> Option<Res>>(&mut self, mut recreation_func: F) {
crate::profile_function!();

for (desc, handle) in &self.lookup {
if let Some(new_resource) = recreation_func(desc) {
let resource = self.resources.get_mut(*handle).unwrap();
Expand Down