Add try_* to add_slot_edge, add_node_edge (#6720)
# Objective `add_node_edge` and `add_slot_edge` are fallible methods, but are always used with `.unwrap()`. `input_node` is often unwrapped as well. This points to having an infallible behaviour as default, with an alternative fallible variant if needed. Improves readability and ergonomics. ## Solution - Change `add_node_edge` and `add_slot_edge` to panic on error. - Change `input_node` to panic on `None`. - Add `try_add_node_edge` and `try_add_slot_edge` in case fallible methods are needed. - Add `get_input_node` to still be able to get an `Option`. --- ## Changelog ### Added - `try_add_node_edge` - `try_add_slot_edge` - `get_input_node` ### Changed - `add_node_edge` is now infallible (panics on error) - `add_slot_edge` is now infallible (panics on error) - `input_node` now panics on `None` ## Migration Guide Remove `.unwrap()` from `add_node_edge` and `add_slot_edge`. For cases where the error was handled, use `try_add_node_edge` and `try_add_slot_edge` instead. Remove `.unwrap()` from `input_node`. For cases where the option was handled, use `get_input_node` instead. Co-authored-by: Torstein Grindvik <52322338+torsteingrindvik@users.noreply.github.com>
This commit is contained in:
parent
e2d1d9dff8
commit
daa57fe489
@ -59,27 +59,21 @@ impl Plugin for BloomPlugin {
|
|||||||
.get_sub_graph_mut(crate::core_3d::graph::NAME)
|
.get_sub_graph_mut(crate::core_3d::graph::NAME)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
draw_3d_graph.add_node(core_3d::graph::node::BLOOM, bloom_node);
|
draw_3d_graph.add_node(core_3d::graph::node::BLOOM, bloom_node);
|
||||||
draw_3d_graph
|
draw_3d_graph.add_slot_edge(
|
||||||
.add_slot_edge(
|
draw_3d_graph.input_node().id,
|
||||||
draw_3d_graph.input_node().unwrap().id,
|
|
||||||
crate::core_3d::graph::input::VIEW_ENTITY,
|
crate::core_3d::graph::input::VIEW_ENTITY,
|
||||||
core_3d::graph::node::BLOOM,
|
core_3d::graph::node::BLOOM,
|
||||||
BloomNode::IN_VIEW,
|
BloomNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
// MAIN_PASS -> BLOOM -> TONEMAPPING
|
// MAIN_PASS -> BLOOM -> TONEMAPPING
|
||||||
draw_3d_graph
|
draw_3d_graph.add_node_edge(
|
||||||
.add_node_edge(
|
|
||||||
crate::core_3d::graph::node::MAIN_PASS,
|
crate::core_3d::graph::node::MAIN_PASS,
|
||||||
core_3d::graph::node::BLOOM,
|
core_3d::graph::node::BLOOM,
|
||||||
)
|
);
|
||||||
.unwrap();
|
draw_3d_graph.add_node_edge(
|
||||||
draw_3d_graph
|
|
||||||
.add_node_edge(
|
|
||||||
core_3d::graph::node::BLOOM,
|
core_3d::graph::node::BLOOM,
|
||||||
crate::core_3d::graph::node::TONEMAPPING,
|
crate::core_3d::graph::node::TONEMAPPING,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -89,27 +83,21 @@ impl Plugin for BloomPlugin {
|
|||||||
.get_sub_graph_mut(crate::core_2d::graph::NAME)
|
.get_sub_graph_mut(crate::core_2d::graph::NAME)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
draw_2d_graph.add_node(core_2d::graph::node::BLOOM, bloom_node);
|
draw_2d_graph.add_node(core_2d::graph::node::BLOOM, bloom_node);
|
||||||
draw_2d_graph
|
draw_2d_graph.add_slot_edge(
|
||||||
.add_slot_edge(
|
draw_2d_graph.input_node().id,
|
||||||
draw_2d_graph.input_node().unwrap().id,
|
|
||||||
crate::core_2d::graph::input::VIEW_ENTITY,
|
crate::core_2d::graph::input::VIEW_ENTITY,
|
||||||
core_2d::graph::node::BLOOM,
|
core_2d::graph::node::BLOOM,
|
||||||
BloomNode::IN_VIEW,
|
BloomNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
// MAIN_PASS -> BLOOM -> TONEMAPPING
|
// MAIN_PASS -> BLOOM -> TONEMAPPING
|
||||||
draw_2d_graph
|
draw_2d_graph.add_node_edge(
|
||||||
.add_node_edge(
|
|
||||||
crate::core_2d::graph::node::MAIN_PASS,
|
crate::core_2d::graph::node::MAIN_PASS,
|
||||||
core_2d::graph::node::BLOOM,
|
core_2d::graph::node::BLOOM,
|
||||||
)
|
);
|
||||||
.unwrap();
|
draw_2d_graph.add_node_edge(
|
||||||
draw_2d_graph
|
|
||||||
.add_node_edge(
|
|
||||||
core_2d::graph::node::BLOOM,
|
core_2d::graph::node::BLOOM,
|
||||||
crate::core_2d::graph::node::TONEMAPPING,
|
crate::core_2d::graph::node::TONEMAPPING,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,45 +72,33 @@ impl Plugin for Core2dPlugin {
|
|||||||
graph::input::VIEW_ENTITY,
|
graph::input::VIEW_ENTITY,
|
||||||
SlotType::Entity,
|
SlotType::Entity,
|
||||||
)]);
|
)]);
|
||||||
draw_2d_graph
|
draw_2d_graph.add_slot_edge(
|
||||||
.add_slot_edge(
|
|
||||||
input_node_id,
|
input_node_id,
|
||||||
graph::input::VIEW_ENTITY,
|
graph::input::VIEW_ENTITY,
|
||||||
graph::node::MAIN_PASS,
|
graph::node::MAIN_PASS,
|
||||||
MainPass2dNode::IN_VIEW,
|
MainPass2dNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
draw_2d_graph.add_slot_edge(
|
||||||
draw_2d_graph
|
|
||||||
.add_slot_edge(
|
|
||||||
input_node_id,
|
input_node_id,
|
||||||
graph::input::VIEW_ENTITY,
|
graph::input::VIEW_ENTITY,
|
||||||
graph::node::TONEMAPPING,
|
graph::node::TONEMAPPING,
|
||||||
TonemappingNode::IN_VIEW,
|
TonemappingNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
draw_2d_graph.add_slot_edge(
|
||||||
draw_2d_graph
|
|
||||||
.add_slot_edge(
|
|
||||||
input_node_id,
|
input_node_id,
|
||||||
graph::input::VIEW_ENTITY,
|
graph::input::VIEW_ENTITY,
|
||||||
graph::node::UPSCALING,
|
graph::node::UPSCALING,
|
||||||
UpscalingNode::IN_VIEW,
|
UpscalingNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
draw_2d_graph.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING);
|
||||||
draw_2d_graph
|
draw_2d_graph.add_node_edge(
|
||||||
.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING)
|
|
||||||
.unwrap();
|
|
||||||
draw_2d_graph
|
|
||||||
.add_node_edge(
|
|
||||||
graph::node::TONEMAPPING,
|
graph::node::TONEMAPPING,
|
||||||
graph::node::END_MAIN_PASS_POST_PROCESSING,
|
graph::node::END_MAIN_PASS_POST_PROCESSING,
|
||||||
)
|
);
|
||||||
.unwrap();
|
draw_2d_graph.add_node_edge(
|
||||||
draw_2d_graph
|
|
||||||
.add_node_edge(
|
|
||||||
graph::node::END_MAIN_PASS_POST_PROCESSING,
|
graph::node::END_MAIN_PASS_POST_PROCESSING,
|
||||||
graph::node::UPSCALING,
|
graph::node::UPSCALING,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
graph.add_sub_graph(graph::NAME, draw_2d_graph);
|
graph.add_sub_graph(graph::NAME, draw_2d_graph);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,45 +82,33 @@ impl Plugin for Core3dPlugin {
|
|||||||
graph::input::VIEW_ENTITY,
|
graph::input::VIEW_ENTITY,
|
||||||
SlotType::Entity,
|
SlotType::Entity,
|
||||||
)]);
|
)]);
|
||||||
draw_3d_graph
|
draw_3d_graph.add_slot_edge(
|
||||||
.add_slot_edge(
|
|
||||||
input_node_id,
|
input_node_id,
|
||||||
graph::input::VIEW_ENTITY,
|
graph::input::VIEW_ENTITY,
|
||||||
graph::node::MAIN_PASS,
|
graph::node::MAIN_PASS,
|
||||||
MainPass3dNode::IN_VIEW,
|
MainPass3dNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
draw_3d_graph.add_slot_edge(
|
||||||
draw_3d_graph
|
|
||||||
.add_slot_edge(
|
|
||||||
input_node_id,
|
input_node_id,
|
||||||
graph::input::VIEW_ENTITY,
|
graph::input::VIEW_ENTITY,
|
||||||
graph::node::TONEMAPPING,
|
graph::node::TONEMAPPING,
|
||||||
TonemappingNode::IN_VIEW,
|
TonemappingNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
draw_3d_graph.add_slot_edge(
|
||||||
draw_3d_graph
|
|
||||||
.add_slot_edge(
|
|
||||||
input_node_id,
|
input_node_id,
|
||||||
graph::input::VIEW_ENTITY,
|
graph::input::VIEW_ENTITY,
|
||||||
graph::node::UPSCALING,
|
graph::node::UPSCALING,
|
||||||
UpscalingNode::IN_VIEW,
|
UpscalingNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
draw_3d_graph.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING);
|
||||||
draw_3d_graph
|
draw_3d_graph.add_node_edge(
|
||||||
.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING)
|
|
||||||
.unwrap();
|
|
||||||
draw_3d_graph
|
|
||||||
.add_node_edge(
|
|
||||||
graph::node::TONEMAPPING,
|
graph::node::TONEMAPPING,
|
||||||
graph::node::END_MAIN_PASS_POST_PROCESSING,
|
graph::node::END_MAIN_PASS_POST_PROCESSING,
|
||||||
)
|
);
|
||||||
.unwrap();
|
draw_3d_graph.add_node_edge(
|
||||||
draw_3d_graph
|
|
||||||
.add_node_edge(
|
|
||||||
graph::node::END_MAIN_PASS_POST_PROCESSING,
|
graph::node::END_MAIN_PASS_POST_PROCESSING,
|
||||||
graph::node::UPSCALING,
|
graph::node::UPSCALING,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
graph.add_sub_graph(graph::NAME, draw_3d_graph);
|
graph.add_sub_graph(graph::NAME, draw_3d_graph);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,27 +103,21 @@ impl Plugin for FxaaPlugin {
|
|||||||
|
|
||||||
graph.add_node(core_3d::graph::node::FXAA, fxaa_node);
|
graph.add_node(core_3d::graph::node::FXAA, fxaa_node);
|
||||||
|
|
||||||
graph
|
graph.add_slot_edge(
|
||||||
.add_slot_edge(
|
graph.input_node().id,
|
||||||
graph.input_node().unwrap().id,
|
|
||||||
core_3d::graph::input::VIEW_ENTITY,
|
core_3d::graph::input::VIEW_ENTITY,
|
||||||
core_3d::graph::node::FXAA,
|
core_3d::graph::node::FXAA,
|
||||||
FxaaNode::IN_VIEW,
|
FxaaNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
graph
|
graph.add_node_edge(
|
||||||
.add_node_edge(
|
|
||||||
core_3d::graph::node::TONEMAPPING,
|
core_3d::graph::node::TONEMAPPING,
|
||||||
core_3d::graph::node::FXAA,
|
core_3d::graph::node::FXAA,
|
||||||
)
|
);
|
||||||
.unwrap();
|
graph.add_node_edge(
|
||||||
graph
|
|
||||||
.add_node_edge(
|
|
||||||
core_3d::graph::node::FXAA,
|
core_3d::graph::node::FXAA,
|
||||||
core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
|
core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let fxaa_node = FxaaNode::new(&mut render_app.world);
|
let fxaa_node = FxaaNode::new(&mut render_app.world);
|
||||||
@ -132,27 +126,21 @@ impl Plugin for FxaaPlugin {
|
|||||||
|
|
||||||
graph.add_node(core_2d::graph::node::FXAA, fxaa_node);
|
graph.add_node(core_2d::graph::node::FXAA, fxaa_node);
|
||||||
|
|
||||||
graph
|
graph.add_slot_edge(
|
||||||
.add_slot_edge(
|
graph.input_node().id,
|
||||||
graph.input_node().unwrap().id,
|
|
||||||
core_2d::graph::input::VIEW_ENTITY,
|
core_2d::graph::input::VIEW_ENTITY,
|
||||||
core_2d::graph::node::FXAA,
|
core_2d::graph::node::FXAA,
|
||||||
FxaaNode::IN_VIEW,
|
FxaaNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
graph
|
graph.add_node_edge(
|
||||||
.add_node_edge(
|
|
||||||
core_2d::graph::node::TONEMAPPING,
|
core_2d::graph::node::TONEMAPPING,
|
||||||
core_2d::graph::node::FXAA,
|
core_2d::graph::node::FXAA,
|
||||||
)
|
);
|
||||||
.unwrap();
|
graph.add_node_edge(
|
||||||
graph
|
|
||||||
.add_node_edge(
|
|
||||||
core_2d::graph::node::FXAA,
|
core_2d::graph::node::FXAA,
|
||||||
core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
|
core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,19 +256,15 @@ impl Plugin for PbrPlugin {
|
|||||||
.get_sub_graph_mut(bevy_core_pipeline::core_3d::graph::NAME)
|
.get_sub_graph_mut(bevy_core_pipeline::core_3d::graph::NAME)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
draw_3d_graph.add_node(draw_3d_graph::node::SHADOW_PASS, shadow_pass_node);
|
draw_3d_graph.add_node(draw_3d_graph::node::SHADOW_PASS, shadow_pass_node);
|
||||||
draw_3d_graph
|
draw_3d_graph.add_node_edge(
|
||||||
.add_node_edge(
|
|
||||||
draw_3d_graph::node::SHADOW_PASS,
|
draw_3d_graph::node::SHADOW_PASS,
|
||||||
bevy_core_pipeline::core_3d::graph::node::MAIN_PASS,
|
bevy_core_pipeline::core_3d::graph::node::MAIN_PASS,
|
||||||
)
|
);
|
||||||
.unwrap();
|
draw_3d_graph.add_slot_edge(
|
||||||
draw_3d_graph
|
draw_3d_graph.input_node().id,
|
||||||
.add_slot_edge(
|
|
||||||
draw_3d_graph.input_node().unwrap().id,
|
|
||||||
bevy_core_pipeline::core_3d::graph::input::VIEW_ENTITY,
|
bevy_core_pipeline::core_3d::graph::input::VIEW_ENTITY,
|
||||||
draw_3d_graph::node::SHADOW_PASS,
|
draw_3d_graph::node::SHADOW_PASS,
|
||||||
ShadowPassNode::IN_VIEW,
|
ShadowPassNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ impl<'a> RenderGraphContext<'a> {
|
|||||||
.graph
|
.graph
|
||||||
.get_sub_graph(&name)
|
.get_sub_graph(&name)
|
||||||
.ok_or_else(|| RunSubGraphError::MissingSubGraph(name.clone()))?;
|
.ok_or_else(|| RunSubGraphError::MissingSubGraph(name.clone()))?;
|
||||||
if let Some(input_node) = sub_graph.input_node() {
|
if let Some(input_node) = sub_graph.get_input_node() {
|
||||||
for (i, input_slot) in input_node.input_slots.iter().enumerate() {
|
for (i, input_slot) in input_node.input_slots.iter().enumerate() {
|
||||||
if let Some(input_value) = inputs.get(i) {
|
if let Some(input_value) = inputs.get(i) {
|
||||||
if input_slot.slot_type != input_value.slot_type() {
|
if input_slot.slot_type != input_value.slot_type() {
|
||||||
|
@ -46,7 +46,7 @@ use super::EdgeExistence;
|
|||||||
/// let mut graph = RenderGraph::default();
|
/// let mut graph = RenderGraph::default();
|
||||||
/// graph.add_node("input_node", MyNode);
|
/// graph.add_node("input_node", MyNode);
|
||||||
/// graph.add_node("output_node", MyNode);
|
/// graph.add_node("output_node", MyNode);
|
||||||
/// graph.add_node_edge("output_node", "input_node").unwrap();
|
/// graph.add_node_edge("output_node", "input_node");
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default)]
|
||||||
pub struct RenderGraph {
|
pub struct RenderGraph {
|
||||||
@ -80,12 +80,30 @@ impl RenderGraph {
|
|||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the [`NodeState`] of the input node of this graph..
|
/// Returns the [`NodeState`] of the input node of this graph.
|
||||||
|
///
|
||||||
|
/// # See also
|
||||||
|
///
|
||||||
|
/// - [`input_node`](Self::input_node) for an unchecked version.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn input_node(&self) -> Option<&NodeState> {
|
pub fn get_input_node(&self) -> Option<&NodeState> {
|
||||||
self.input_node.and_then(|id| self.get_node_state(id).ok())
|
self.input_node.and_then(|id| self.get_node_state(id).ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the [`NodeState`] of the input node of this graph.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if there is no input node set.
|
||||||
|
///
|
||||||
|
/// # See also
|
||||||
|
///
|
||||||
|
/// - [`get_input_node`](Self::get_input_node) for a version which returns an [`Option`] instead.
|
||||||
|
#[inline]
|
||||||
|
pub fn input_node(&self) -> &NodeState {
|
||||||
|
self.get_input_node().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
/// Adds the `node` with the `name` to the graph.
|
/// Adds the `node` with the `name` to the graph.
|
||||||
/// If the name is already present replaces it instead.
|
/// If the name is already present replaces it instead.
|
||||||
pub fn add_node<T>(&mut self, name: impl Into<Cow<'static, str>>, node: T) -> NodeId
|
pub fn add_node<T>(&mut self, name: impl Into<Cow<'static, str>>, node: T) -> NodeId
|
||||||
@ -209,7 +227,13 @@ impl RenderGraph {
|
|||||||
|
|
||||||
/// Adds the [`Edge::SlotEdge`] to the graph. This guarantees that the `output_node`
|
/// Adds the [`Edge::SlotEdge`] to the graph. This guarantees that the `output_node`
|
||||||
/// is run before the `input_node` and also connects the `output_slot` to the `input_slot`.
|
/// is run before the `input_node` and also connects the `output_slot` to the `input_slot`.
|
||||||
pub fn add_slot_edge(
|
///
|
||||||
|
/// Fails if any invalid [`NodeLabel`]s or [`SlotLabel`]s are given.
|
||||||
|
///
|
||||||
|
/// # See also
|
||||||
|
///
|
||||||
|
/// - [`add_slot_edge`](Self::add_slot_edge) for an infallible version.
|
||||||
|
pub fn try_add_slot_edge(
|
||||||
&mut self,
|
&mut self,
|
||||||
output_node: impl Into<NodeLabel>,
|
output_node: impl Into<NodeLabel>,
|
||||||
output_slot: impl Into<SlotLabel>,
|
output_slot: impl Into<SlotLabel>,
|
||||||
@ -251,6 +275,27 @@ impl RenderGraph {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds the [`Edge::SlotEdge`] to the graph. This guarantees that the `output_node`
|
||||||
|
/// is run before the `input_node` and also connects the `output_slot` to the `input_slot`.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Any invalid [`NodeLabel`]s or [`SlotLabel`]s are given.
|
||||||
|
///
|
||||||
|
/// # See also
|
||||||
|
///
|
||||||
|
/// - [`try_add_slot_edge`](Self::try_add_slot_edge) for a fallible version.
|
||||||
|
pub fn add_slot_edge(
|
||||||
|
&mut self,
|
||||||
|
output_node: impl Into<NodeLabel>,
|
||||||
|
output_slot: impl Into<SlotLabel>,
|
||||||
|
input_node: impl Into<NodeLabel>,
|
||||||
|
input_slot: impl Into<SlotLabel>,
|
||||||
|
) {
|
||||||
|
self.try_add_slot_edge(output_node, output_slot, input_node, input_slot)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
/// Removes the [`Edge::SlotEdge`] from the graph. If any nodes or slots do not exist then
|
/// Removes the [`Edge::SlotEdge`] from the graph. If any nodes or slots do not exist then
|
||||||
/// nothing happens.
|
/// nothing happens.
|
||||||
pub fn remove_slot_edge(
|
pub fn remove_slot_edge(
|
||||||
@ -297,7 +342,13 @@ impl RenderGraph {
|
|||||||
|
|
||||||
/// Adds the [`Edge::NodeEdge`] to the graph. This guarantees that the `output_node`
|
/// Adds the [`Edge::NodeEdge`] to the graph. This guarantees that the `output_node`
|
||||||
/// is run before the `input_node`.
|
/// is run before the `input_node`.
|
||||||
pub fn add_node_edge(
|
///
|
||||||
|
/// Fails if any invalid [`NodeLabel`] is given.
|
||||||
|
///
|
||||||
|
/// # See also
|
||||||
|
///
|
||||||
|
/// - [`add_node_edge`](Self::add_node_edge) for an infallible version.
|
||||||
|
pub fn try_add_node_edge(
|
||||||
&mut self,
|
&mut self,
|
||||||
output_node: impl Into<NodeLabel>,
|
output_node: impl Into<NodeLabel>,
|
||||||
input_node: impl Into<NodeLabel>,
|
input_node: impl Into<NodeLabel>,
|
||||||
@ -322,6 +373,24 @@ impl RenderGraph {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds the [`Edge::NodeEdge`] to the graph. This guarantees that the `output_node`
|
||||||
|
/// is run before the `input_node`.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if any invalid [`NodeLabel`] is given.
|
||||||
|
///
|
||||||
|
/// # See also
|
||||||
|
///
|
||||||
|
/// - [`try_add_node_edge`](Self::try_add_node_edge) for a fallible version.
|
||||||
|
pub fn add_node_edge(
|
||||||
|
&mut self,
|
||||||
|
output_node: impl Into<NodeLabel>,
|
||||||
|
input_node: impl Into<NodeLabel>,
|
||||||
|
) {
|
||||||
|
self.try_add_node_edge(output_node, input_node).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
/// Removes the [`Edge::NodeEdge`] from the graph. If either node does not exist then nothing
|
/// Removes the [`Edge::NodeEdge`] from the graph. If either node does not exist then nothing
|
||||||
/// happens.
|
/// happens.
|
||||||
pub fn remove_node_edge(
|
pub fn remove_node_edge(
|
||||||
@ -615,9 +684,9 @@ mod tests {
|
|||||||
let c_id = graph.add_node("C", TestNode::new(1, 1));
|
let c_id = graph.add_node("C", TestNode::new(1, 1));
|
||||||
let d_id = graph.add_node("D", TestNode::new(1, 0));
|
let d_id = graph.add_node("D", TestNode::new(1, 0));
|
||||||
|
|
||||||
graph.add_slot_edge("A", "out_0", "C", "in_0").unwrap();
|
graph.add_slot_edge("A", "out_0", "C", "in_0");
|
||||||
graph.add_node_edge("B", "C").unwrap();
|
graph.add_node_edge("B", "C");
|
||||||
graph.add_slot_edge("C", 0, "D", 0).unwrap();
|
graph.add_slot_edge("C", 0, "D", 0);
|
||||||
|
|
||||||
fn input_nodes(name: &'static str, graph: &RenderGraph) -> HashSet<NodeId> {
|
fn input_nodes(name: &'static str, graph: &RenderGraph) -> HashSet<NodeId> {
|
||||||
graph
|
graph
|
||||||
@ -703,9 +772,9 @@ mod tests {
|
|||||||
graph.add_node("B", TestNode::new(0, 1));
|
graph.add_node("B", TestNode::new(0, 1));
|
||||||
graph.add_node("C", TestNode::new(1, 1));
|
graph.add_node("C", TestNode::new(1, 1));
|
||||||
|
|
||||||
graph.add_slot_edge("A", 0, "C", 0).unwrap();
|
graph.add_slot_edge("A", 0, "C", 0);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
graph.add_slot_edge("B", 0, "C", 0),
|
graph.try_add_slot_edge("B", 0, "C", 0),
|
||||||
Err(RenderGraphError::NodeInputSlotAlreadyOccupied {
|
Err(RenderGraphError::NodeInputSlotAlreadyOccupied {
|
||||||
node: graph.get_node_id("C").unwrap(),
|
node: graph.get_node_id("C").unwrap(),
|
||||||
input_slot: 0,
|
input_slot: 0,
|
||||||
@ -722,9 +791,9 @@ mod tests {
|
|||||||
graph.add_node("A", TestNode::new(0, 1));
|
graph.add_node("A", TestNode::new(0, 1));
|
||||||
graph.add_node("B", TestNode::new(1, 0));
|
graph.add_node("B", TestNode::new(1, 0));
|
||||||
|
|
||||||
graph.add_slot_edge("A", 0, "B", 0).unwrap();
|
graph.add_slot_edge("A", 0, "B", 0);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
graph.add_slot_edge("A", 0, "B", 0),
|
graph.try_add_slot_edge("A", 0, "B", 0),
|
||||||
Err(RenderGraphError::EdgeAlreadyExists(Edge::SlotEdge {
|
Err(RenderGraphError::EdgeAlreadyExists(Edge::SlotEdge {
|
||||||
output_node: graph.get_node_id("A").unwrap(),
|
output_node: graph.get_node_id("A").unwrap(),
|
||||||
output_index: 0,
|
output_index: 0,
|
||||||
|
@ -98,7 +98,7 @@ impl RenderGraphRunner {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// pass inputs into the graph
|
// pass inputs into the graph
|
||||||
if let Some(input_node) = graph.input_node() {
|
if let Some(input_node) = graph.get_input_node() {
|
||||||
let mut input_values: SmallVec<[SlotValue; 4]> = SmallVec::new();
|
let mut input_values: SmallVec<[SlotValue; 4]> = SmallVec::new();
|
||||||
for (i, input_slot) in input_node.input_slots.iter().enumerate() {
|
for (i, input_slot) in input_node.input_slots.iter().enumerate() {
|
||||||
if let Some(input_value) = inputs.get(i) {
|
if let Some(input_value) = inputs.get(i) {
|
||||||
|
@ -102,32 +102,24 @@ pub fn build_ui_render(app: &mut App) {
|
|||||||
draw_ui_graph::node::UI_PASS,
|
draw_ui_graph::node::UI_PASS,
|
||||||
RunGraphOnViewNode::new(draw_ui_graph::NAME),
|
RunGraphOnViewNode::new(draw_ui_graph::NAME),
|
||||||
);
|
);
|
||||||
graph_2d
|
graph_2d.add_node_edge(
|
||||||
.add_node_edge(
|
|
||||||
bevy_core_pipeline::core_2d::graph::node::MAIN_PASS,
|
bevy_core_pipeline::core_2d::graph::node::MAIN_PASS,
|
||||||
draw_ui_graph::node::UI_PASS,
|
draw_ui_graph::node::UI_PASS,
|
||||||
)
|
);
|
||||||
.unwrap();
|
graph_2d.add_slot_edge(
|
||||||
graph_2d
|
graph_2d.input_node().id,
|
||||||
.add_slot_edge(
|
|
||||||
graph_2d.input_node().unwrap().id,
|
|
||||||
bevy_core_pipeline::core_2d::graph::input::VIEW_ENTITY,
|
bevy_core_pipeline::core_2d::graph::input::VIEW_ENTITY,
|
||||||
draw_ui_graph::node::UI_PASS,
|
draw_ui_graph::node::UI_PASS,
|
||||||
RunGraphOnViewNode::IN_VIEW,
|
RunGraphOnViewNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
graph_2d.add_node_edge(
|
||||||
graph_2d
|
|
||||||
.add_node_edge(
|
|
||||||
bevy_core_pipeline::core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
|
bevy_core_pipeline::core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
|
||||||
draw_ui_graph::node::UI_PASS,
|
draw_ui_graph::node::UI_PASS,
|
||||||
)
|
);
|
||||||
.unwrap();
|
graph_2d.add_node_edge(
|
||||||
graph_2d
|
|
||||||
.add_node_edge(
|
|
||||||
draw_ui_graph::node::UI_PASS,
|
draw_ui_graph::node::UI_PASS,
|
||||||
bevy_core_pipeline::core_2d::graph::node::UPSCALING,
|
bevy_core_pipeline::core_2d::graph::node::UPSCALING,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(graph_3d) = graph.get_sub_graph_mut(bevy_core_pipeline::core_3d::graph::NAME) {
|
if let Some(graph_3d) = graph.get_sub_graph_mut(bevy_core_pipeline::core_3d::graph::NAME) {
|
||||||
@ -136,32 +128,24 @@ pub fn build_ui_render(app: &mut App) {
|
|||||||
draw_ui_graph::node::UI_PASS,
|
draw_ui_graph::node::UI_PASS,
|
||||||
RunGraphOnViewNode::new(draw_ui_graph::NAME),
|
RunGraphOnViewNode::new(draw_ui_graph::NAME),
|
||||||
);
|
);
|
||||||
graph_3d
|
graph_3d.add_node_edge(
|
||||||
.add_node_edge(
|
|
||||||
bevy_core_pipeline::core_3d::graph::node::MAIN_PASS,
|
bevy_core_pipeline::core_3d::graph::node::MAIN_PASS,
|
||||||
draw_ui_graph::node::UI_PASS,
|
draw_ui_graph::node::UI_PASS,
|
||||||
)
|
);
|
||||||
.unwrap();
|
graph_3d.add_node_edge(
|
||||||
graph_3d
|
|
||||||
.add_node_edge(
|
|
||||||
bevy_core_pipeline::core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
|
bevy_core_pipeline::core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
|
||||||
draw_ui_graph::node::UI_PASS,
|
draw_ui_graph::node::UI_PASS,
|
||||||
)
|
);
|
||||||
.unwrap();
|
graph_3d.add_node_edge(
|
||||||
graph_3d
|
|
||||||
.add_node_edge(
|
|
||||||
draw_ui_graph::node::UI_PASS,
|
draw_ui_graph::node::UI_PASS,
|
||||||
bevy_core_pipeline::core_3d::graph::node::UPSCALING,
|
bevy_core_pipeline::core_3d::graph::node::UPSCALING,
|
||||||
)
|
);
|
||||||
.unwrap();
|
graph_3d.add_slot_edge(
|
||||||
graph_3d
|
graph_3d.input_node().id,
|
||||||
.add_slot_edge(
|
|
||||||
graph_3d.input_node().unwrap().id,
|
|
||||||
bevy_core_pipeline::core_3d::graph::input::VIEW_ENTITY,
|
bevy_core_pipeline::core_3d::graph::input::VIEW_ENTITY,
|
||||||
draw_ui_graph::node::UI_PASS,
|
draw_ui_graph::node::UI_PASS,
|
||||||
RunGraphOnViewNode::IN_VIEW,
|
RunGraphOnViewNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,14 +157,12 @@ fn get_ui_graph(render_app: &mut App) -> RenderGraph {
|
|||||||
draw_ui_graph::input::VIEW_ENTITY,
|
draw_ui_graph::input::VIEW_ENTITY,
|
||||||
SlotType::Entity,
|
SlotType::Entity,
|
||||||
)]);
|
)]);
|
||||||
ui_graph
|
ui_graph.add_slot_edge(
|
||||||
.add_slot_edge(
|
|
||||||
input_node_id,
|
input_node_id,
|
||||||
draw_ui_graph::input::VIEW_ENTITY,
|
draw_ui_graph::input::VIEW_ENTITY,
|
||||||
draw_ui_graph::node::UI_PASS,
|
draw_ui_graph::node::UI_PASS,
|
||||||
UiPassNode::IN_VIEW,
|
UiPassNode::IN_VIEW,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
ui_graph
|
ui_graph
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,12 +77,10 @@ impl Plugin for GameOfLifeComputePlugin {
|
|||||||
|
|
||||||
let mut render_graph = render_app.world.resource_mut::<RenderGraph>();
|
let mut render_graph = render_app.world.resource_mut::<RenderGraph>();
|
||||||
render_graph.add_node("game_of_life", GameOfLifeNode::default());
|
render_graph.add_node("game_of_life", GameOfLifeNode::default());
|
||||||
render_graph
|
render_graph.add_node_edge(
|
||||||
.add_node_edge(
|
|
||||||
"game_of_life",
|
"game_of_life",
|
||||||
bevy::render::main_graph::node::CAMERA_DRIVER,
|
bevy::render::main_graph::node::CAMERA_DRIVER,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user