From b4b47d695b301b14f60919d4d9ddb5b64deeb901 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Mon, 6 Jan 2025 18:49:18 +0000 Subject: [PATCH] default UI camera extraction fix (#17100) # Objective In UI extraction the default UI camera is queried for every UI node. It only needs to be retrieved once. ## Solution Query for the default UI camera once before iterating the UI nodes. ``` cargo run --example many_buttons --release --features "trace_tracy" ``` default-camera-extract `extract_uinode_background_colors` yellow is this PR, red is main. --- crates/bevy_ui/src/render/box_shadow.rs | 5 +++-- crates/bevy_ui/src/render/debug_overlay.rs | 5 +++-- crates/bevy_ui/src/render/mod.rs | 12 ++++++------ .../bevy_ui/src/render/ui_texture_slice_pipeline.rs | 5 +++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/crates/bevy_ui/src/render/box_shadow.rs b/crates/bevy_ui/src/render/box_shadow.rs index 4521f1854677a..515e06101581b 100644 --- a/crates/bevy_ui/src/render/box_shadow.rs +++ b/crates/bevy_ui/src/render/box_shadow.rs @@ -251,10 +251,11 @@ pub fn extract_shadows( >, mapping: Extract>, ) { + let default_camera_entity = default_ui_camera.get(); + for (entity, uinode, transform, view_visibility, box_shadow, clip, camera) in &box_shadow_query { - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_ui_camera.get()) - else { + let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) else { continue; }; diff --git a/crates/bevy_ui/src/render/debug_overlay.rs b/crates/bevy_ui/src/render/debug_overlay.rs index 6ee7f14732141..662d0d8d0e376 100644 --- a/crates/bevy_ui/src/render/debug_overlay.rs +++ b/crates/bevy_ui/src/render/debug_overlay.rs @@ -76,13 +76,14 @@ pub fn extract_debug_overlay( return; } + let default_camera_entity = default_ui_camera.get(); + for (entity, uinode, visibility, maybe_clip, transform, camera) in &uinode_query { if !debug_options.show_hidden && !visibility.get() { continue; } - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_ui_camera.get()) - else { + let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) else { continue; }; diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index e1528b02d23f0..b69d241dd9b82 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -267,11 +267,11 @@ pub fn extract_uinode_background_colors( >, mapping: Extract>, ) { + let default_camera_entity = default_ui_camera.get(); for (entity, uinode, transform, view_visibility, clip, camera, background_color) in &uinode_query { - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_ui_camera.get()) - else { + let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) else { continue; }; @@ -330,9 +330,9 @@ pub fn extract_uinode_images( >, mapping: Extract>, ) { + let default_camera_entity = default_ui_camera.get(); for (entity, uinode, transform, view_visibility, clip, camera, image) in &uinode_query { - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_ui_camera.get()) - else { + let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) else { continue; }; @@ -423,7 +423,7 @@ pub fn extract_uinode_borders( ui_children: UiChildren, ) { let image = AssetId::::default(); - + let default_camera_entity = default_ui_camera.get(); for ( entity, node, @@ -437,7 +437,7 @@ pub fn extract_uinode_borders( { let Some(camera_entity) = maybe_camera .map(TargetCamera::entity) - .or(default_ui_camera.get()) + .or(default_camera_entity) else { continue; }; diff --git a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs index f4fc6d77e9a0b..29c10dec09afb 100644 --- a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs @@ -264,9 +264,10 @@ pub fn extract_ui_texture_slices( >, mapping: Extract>, ) { + let default_camera_entity = default_ui_camera.get(); + for (entity, uinode, transform, view_visibility, clip, camera, image) in &slicers_query { - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_ui_camera.get()) - else { + let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) else { continue; };