Skip to content

Commit

Permalink
default UI camera extraction fix (#17100)
Browse files Browse the repository at this point in the history
# 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"
```
<img width="631" alt="default-camera-extract"
src="https://github.com/user-attachments/assets/db712bce-6a0b-49a7-8e20-654baf588390"
/>

`extract_uinode_background_colors` yellow is this PR, red is main.
  • Loading branch information
ickshonpe authored Jan 6, 2025
1 parent 13deb3e commit b4b47d6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions crates/bevy_ui/src/render/box_shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,11 @@ pub fn extract_shadows(
>,
mapping: Extract<Query<RenderEntity>>,
) {
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;
};

Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_ui/src/render/debug_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ pub fn extract_uinode_background_colors(
>,
mapping: Extract<Query<RenderEntity>>,
) {
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;
};

Expand Down Expand Up @@ -330,9 +330,9 @@ pub fn extract_uinode_images(
>,
mapping: Extract<Query<RenderEntity>>,
) {
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;
};

Expand Down Expand Up @@ -423,7 +423,7 @@ pub fn extract_uinode_borders(
ui_children: UiChildren,
) {
let image = AssetId::<Image>::default();

let default_camera_entity = default_ui_camera.get();
for (
entity,
node,
Expand All @@ -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;
};
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,10 @@ pub fn extract_ui_texture_slices(
>,
mapping: Extract<Query<RenderEntity>>,
) {
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;
};

Expand Down

0 comments on commit b4b47d6

Please sign in to comment.