Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't ignore draw errors #13240

Merged
merged 10 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/src/core_2d/main_pass_2d_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Node for MainPass2dNode {
render_pass.set_camera_viewport(viewport);
}

transparent_phase.render(&mut render_pass, world, view_entity);
transparent_phase.render(&mut render_pass, world, view_entity)?;

pass_span.end(&mut render_pass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ impl ViewNode for MainOpaquePass3dNode {
if !opaque_phase.is_empty() {
#[cfg(feature = "trace")]
let _opaque_main_pass_3d_span = info_span!("opaque_main_pass_3d").entered();
opaque_phase.render(&mut render_pass, world, view_entity);
opaque_phase
.render(&mut render_pass, world, view_entity)
.expect("Error encountered while rendering the opaque phase");
}

// Alpha draws
if !alpha_mask_phase.is_empty() {
#[cfg(feature = "trace")]
let _alpha_mask_main_pass_3d_span = info_span!("alpha_mask_main_pass_3d").entered();
alpha_mask_phase.render(&mut render_pass, world, view_entity);
alpha_mask_phase
.render(&mut render_pass, world, view_entity)
.expect("Error encountered while rendering the alpha mask phase");
}

// Skybox draw using a fullscreen triangle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ impl ViewNode for MainTransmissivePass3dNode {
}

// render items in range
transmissive_phase.render_range(&mut render_pass, world, view_entity, range);
transmissive_phase
.render_range(&mut render_pass, world, view_entity, range)
.expect("Error encountered while rendering the transmissive phase");
}
} else {
let mut render_pass =
Expand All @@ -101,7 +103,9 @@ impl ViewNode for MainTransmissivePass3dNode {
render_pass.set_camera_viewport(viewport);
}

transmissive_phase.render(&mut render_pass, world, view_entity);
transmissive_phase
.render(&mut render_pass, world, view_entity)
.expect("Error encountered while rendering the transmissive phase");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ impl ViewNode for MainTransparentPass3dNode {
render_pass.set_camera_viewport(viewport);
}

transparent_phase.render(&mut render_pass, world, view_entity);
transparent_phase
.render(&mut render_pass, world, view_entity)
.expect("Error encountered while rendering the transparent phase");

pass_span.end(&mut render_pass);
}
Expand Down
8 changes: 6 additions & 2 deletions crates/bevy_core_pipeline/src/deferred/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,18 @@ impl ViewNode for DeferredGBufferPrepassNode {
{
#[cfg(feature = "trace")]
let _opaque_prepass_span = info_span!("opaque_deferred").entered();
opaque_deferred_phase.render(&mut render_pass, world, view_entity);
opaque_deferred_phase
.render(&mut render_pass, world, view_entity)
.expect("Error encountered while rendering the opaque deferred phase");
}

// Alpha masked draws
if !alpha_mask_deferred_phase.is_empty() {
#[cfg(feature = "trace")]
let _alpha_mask_deferred_span = info_span!("alpha_mask_deferred").entered();
alpha_mask_deferred_phase.render(&mut render_pass, world, view_entity);
alpha_mask_deferred_phase
.render(&mut render_pass, world, view_entity)
.expect("Error encountered while rendering the alpha mask deferred phase");
}

drop(render_pass);
Expand Down
8 changes: 6 additions & 2 deletions crates/bevy_core_pipeline/src/prepass/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,18 @@ impl ViewNode for PrepassNode {
{
#[cfg(feature = "trace")]
let _opaque_prepass_span = info_span!("opaque_prepass").entered();
opaque_prepass_phase.render(&mut render_pass, world, view_entity);
opaque_prepass_phase
.render(&mut render_pass, world, view_entity)
.expect("Error encountered while rendering the opaque prepass phase");
}

// Alpha masked draws
if !alpha_mask_prepass_phase.is_empty() {
#[cfg(feature = "trace")]
let _alpha_mask_prepass_span = info_span!("alpha_mask_prepass").entered();
alpha_mask_prepass_phase.render(&mut render_pass, world, view_entity);
alpha_mask_prepass_phase
.render(&mut render_pass, world, view_entity)
.expect("Error encountered while rendering the alpha mask prepass phase");
}

pass_span.end(&mut render_pass);
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,9 @@ impl Node for ShadowPassNode {
let pass_span =
diagnostics.pass_span(&mut render_pass, view_light.pass_name.clone());

shadow_phase.render(&mut render_pass, world, view_light_entity);
shadow_phase
.render(&mut render_pass, world, view_light_entity)
.expect("Error encountered while rendering the shadow phase");

pass_span.end(&mut render_pass);
drop(render_pass);
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_render/src/render_graph/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
Edge, InputSlotError, OutputSlotError, RenderGraphContext, RenderGraphError,
RunSubGraphError, SlotInfo, SlotInfos,
},
render_phase::DrawError,
renderer::RenderContext,
};
pub use bevy_ecs::label::DynEq;
Expand Down Expand Up @@ -97,6 +98,8 @@ pub enum NodeRunError {
OutputSlotError(#[from] OutputSlotError),
#[error("encountered an error when running a sub-graph")]
RunSubGraphError(#[from] RunSubGraphError),
#[error("encountered an error when executing draw command")]
DrawError(#[from] DrawError),
}

/// A collection of input and output [`Edges`](Edge) for a [`Node`].
Expand Down
34 changes: 28 additions & 6 deletions crates/bevy_render/src/render_phase/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::render_phase::{PhaseItem, TrackedRenderPass};
use bevy_app::{App, SubApp};
use bevy_ecs::{
entity::Entity,
query::{QueryState, ROQueryItem, ReadOnlyQueryData},
query::{QueryEntityError, QueryState, ROQueryItem, ReadOnlyQueryData},
system::{ReadOnlySystemParam, Resource, SystemParam, SystemParamItem, SystemState},
world::World,
};
Expand All @@ -13,6 +13,7 @@ use std::{
hash::Hash,
sync::{PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard},
};
use thiserror::Error;

/// A draw function used to draw [`PhaseItem`]s.
///
Expand All @@ -34,7 +35,17 @@ pub trait Draw<P: PhaseItem>: Send + Sync + 'static {
pass: &mut TrackedRenderPass<'w>,
view: Entity,
item: &P,
);
) -> Result<(), DrawError>;
}

#[derive(Error, Debug, PartialEq, Eq)]
pub enum DrawError {
#[error("Failed to execute render command")]
RenderCommandFailure,
#[error("Failed to get execute view query")]
InvalidViewQuery,
#[error("View entity not found")]
ViewEntityNotFound,
}

// TODO: make this generic?
Expand Down Expand Up @@ -290,12 +301,23 @@ where
pass: &mut TrackedRenderPass<'w>,
view: Entity,
item: &P,
) {
) -> Result<(), DrawError> {
let param = self.state.get_manual(world);
let view = self.view.get_manual(world, view).unwrap();
let view = match self.view.get_manual(world, view) {
Ok(view) => view,
Err(err) => match err {
QueryEntityError::NoSuchEntity(_) => return Err(DrawError::ViewEntityNotFound),
QueryEntityError::QueryDoesNotMatch(_) | QueryEntityError::AliasedMutability(_) => {
return Err(DrawError::InvalidViewQuery)
}
},
};

let entity = self.entity.get_manual(world, item.entity()).ok();
// TODO: handle/log `RenderCommand` failure
C::render(item, view, entity, param, pass);
match C::render(item, view, entity, param, pass) {
RenderCommandResult::Success => Ok(()),
RenderCommandResult::Failure => Err(DrawError::RenderCommandFailure),
}
}
}

Expand Down
16 changes: 9 additions & 7 deletions crates/bevy_render/src/render_phase/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ where
render_pass: &mut TrackedRenderPass<'w>,
world: &'w World,
view: Entity,
) {
) -> Result<(), DrawError> {
let draw_functions = world.resource::<DrawFunctions<BPI>>();
let mut draw_functions = draw_functions.write();
draw_functions.prepare(world);
Expand All @@ -259,7 +259,7 @@ where
continue;
};

draw_function.draw(world, render_pass, view, &binned_phase_item);
draw_function.draw(world, render_pass, view, &binned_phase_item)?;
}
}

Expand Down Expand Up @@ -307,9 +307,10 @@ where
continue;
};

draw_function.draw(world, render_pass, view, &binned_phase_item);
draw_function.draw(world, render_pass, view, &binned_phase_item)?;
}
}
Ok(())
}

pub fn is_empty(&self) -> bool {
Expand Down Expand Up @@ -583,8 +584,8 @@ where
render_pass: &mut TrackedRenderPass<'w>,
world: &'w World,
view: Entity,
) {
self.render_range(render_pass, world, view, ..);
) -> Result<(), DrawError> {
self.render_range(render_pass, world, view, ..)
}

/// Renders all [`PhaseItem`]s in the provided `range` (based on their index in `self.items`) using their corresponding draw functions.
Expand All @@ -594,7 +595,7 @@ where
world: &'w World,
view: Entity,
range: impl SliceIndex<[I], Output = [I]>,
) {
) -> Result<(), DrawError> {
let items = self
.items
.get(range)
Expand All @@ -612,10 +613,11 @@ where
index += 1;
} else {
let draw_function = draw_functions.get_mut(item.draw_function()).unwrap();
draw_function.draw(world, render_pass, view, item);
draw_function.draw(world, render_pass, view, item)?;
index += batch_range.len();
}
}
Ok(())
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_ui/src/render/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ impl Node for UiPassNode {
if let Some(viewport) = camera.viewport.as_ref() {
render_pass.set_camera_viewport(viewport);
}
transparent_phase.render(&mut render_pass, world, view_entity);
transparent_phase
.render(&mut render_pass, world, view_entity)
.expect("Error encountered while rendering the ui phase");

Ok(())
}
Expand Down
Loading