From 5cb6f7ffd23ae845c029fcc57b18b1f3e8af1062 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Mon, 2 May 2022 20:22:30 +0000 Subject: [PATCH] Do not create nor execute render passes which have no phase items to draw (#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 --- crates/bevy_core_pipeline/src/main_pass_2d.rs | 4 ++++ crates/bevy_core_pipeline/src/main_pass_3d.rs | 6 +++--- crates/bevy_pbr/src/render/light.rs | 5 +++++ crates/bevy_ui/src/render/render_pass.rs | 5 +++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/bevy_core_pipeline/src/main_pass_2d.rs b/crates/bevy_core_pipeline/src/main_pass_2d.rs index 0207863cd98f5..563edd3a9f527 100644 --- a/crates/bevy_core_pipeline/src/main_pass_2d.rs +++ b/crates/bevy_core_pipeline/src/main_pass_2d.rs @@ -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 { diff --git a/crates/bevy_core_pipeline/src/main_pass_3d.rs b/crates/bevy_core_pipeline/src/main_pass_3d.rs index 28841e8acbfd4..bd2ab599c4998 100644 --- a/crates/bevy_core_pipeline/src/main_pass_3d.rs +++ b/crates/bevy_core_pipeline/src/main_pass_3d.rs @@ -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")] @@ -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")] @@ -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")] diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index d3fafd0e018d1..9fc57c640d4f9 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -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: &[], diff --git a/crates/bevy_ui/src/render/render_pass.rs b/crates/bevy_ui/src/render/render_pass.rs index dd7c8fd31a60e..ccaa880e14a7e 100644 --- a/crates/bevy_ui/src/render/render_pass.rs +++ b/crates/bevy_ui/src/render/render_pass.rs @@ -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 {