Skip to content

Commit

Permalink
Do not create nor execute render passes which have no phase items to …
Browse files Browse the repository at this point in the history
…draw (bevyengine#4643)

# Objective

- Creating and executing render passes has GPU overhead. If there are no phase items in the render phase to draw, then this overhead should not be incurred as it has no benefit.

## Solution

- Check if there are no phase items to draw, and if not, do not construct not execute the render pass

---

## Changelog

- Changed: Do not create nor execute empty render passes
  • Loading branch information
superdump authored and ItsDoot committed Feb 1, 2023
1 parent 8327d53 commit 103e65b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions crates/bevy_core_pipeline/src/main_pass_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ impl Node for MainPass2dNode {
.get_manual(world, view_entity)
.expect("view entity should exist");

if transparent_phase.items.is_empty() {
return Ok(());
}

let pass_descriptor = RenderPassDescriptor {
label: Some("main_pass_2d"),
color_attachments: &[target.get_color_attachment(Operations {
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_core_pipeline/src/main_pass_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Node for MainPass3dNode {
Err(_) => return Ok(()), // No window
};

{
if !opaque_phase.items.is_empty() {
// Run the opaque pass, sorted front-to-back
// NOTE: Scoped to drop the mutable borrow of render_context
#[cfg(feature = "trace")]
Expand Down Expand Up @@ -92,7 +92,7 @@ impl Node for MainPass3dNode {
}
}

{
if !alpha_mask_phase.items.is_empty() {
// Run the alpha mask pass, sorted front-to-back
// NOTE: Scoped to drop the mutable borrow of render_context
#[cfg(feature = "trace")]
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Node for MainPass3dNode {
}
}

{
if !transparent_phase.items.is_empty() {
// Run the transparent pass, sorted back-to-front
// NOTE: Scoped to drop the mutable borrow of render_context
#[cfg(feature = "trace")]
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,11 @@ impl Node for ShadowPassNode {
.view_light_query
.get_manual(world, view_light_entity)
.unwrap();

if shadow_phase.items.is_empty() {
continue;
}

let pass_descriptor = RenderPassDescriptor {
label: Some(&view_light.pass_name),
color_attachments: &[],
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ui/src/render/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ impl Node for UiPassNode {
.query
.get_manual(world, view_entity)
.expect("view entity should exist");

if transparent_phase.items.is_empty() {
return Ok(());
}

let pass_descriptor = RenderPassDescriptor {
label: Some("ui_pass"),
color_attachments: &[RenderPassColorAttachment {
Expand Down

0 comments on commit 103e65b

Please sign in to comment.