From b3c83465b31fd644308277e9bae7dfa5d0a86a81 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Thu, 27 Mar 2025 22:35:47 -0700 Subject: [PATCH] Fix and improve tracy rendering spans (#18588) * `submit_graph_commands` was incorrectly timing the command buffer generation tasks as well, and not only the queue submission. Moved the span to fix that. * Added a new `command_buffer_generation_tasks` span as a parent for all the individual command buffer generation tasks that don't run as part of the Core3d span. ![image](https://github.com/user-attachments/assets/5a20c2f5-f1df-4c03-afbb-4865327aea33) --- crates/bevy_render/src/renderer/graph_runner.rs | 4 ++-- crates/bevy_render/src/renderer/mod.rs | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/renderer/graph_runner.rs b/crates/bevy_render/src/renderer/graph_runner.rs index cc03374ea4..64a7b885d5 100644 --- a/crates/bevy_render/src/renderer/graph_runner.rs +++ b/crates/bevy_render/src/renderer/graph_runner.rs @@ -87,10 +87,10 @@ impl RenderGraphRunner { finalizer(render_context.command_encoder()); let (render_device, mut diagnostics_recorder) = { + let (commands, render_device, diagnostics_recorder) = render_context.finish(); + #[cfg(feature = "trace")] let _span = info_span!("submit_graph_commands").entered(); - - let (commands, render_device, diagnostics_recorder) = render_context.finish(); queue.submit(commands); (render_device, diagnostics_recorder) diff --git a/crates/bevy_render/src/renderer/mod.rs b/crates/bevy_render/src/renderer/mod.rs index 32fe441f4d..81da7444dc 100644 --- a/crates/bevy_render/src/renderer/mod.rs +++ b/crates/bevy_render/src/renderer/mod.rs @@ -498,6 +498,10 @@ impl<'w> RenderContext<'w> { let mut command_buffers = Vec::with_capacity(self.command_buffer_queue.len()); + #[cfg(feature = "trace")] + let _command_buffer_generation_tasks_span = + info_span!("command_buffer_generation_tasks").entered(); + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] { let mut task_based_command_buffers = ComputeTaskPool::get().scope(|task_pool| { @@ -537,6 +541,9 @@ impl<'w> RenderContext<'w> { } } + #[cfg(feature = "trace")] + drop(_command_buffer_generation_tasks_span); + command_buffers.sort_unstable_by_key(|(i, _)| *i); let mut command_buffers = command_buffers