bevy/crates/bevy_core_pipeline/src
IceSentry 2c21d423fd
Make render graph slots optional for most cases (#8109)
# Objective

- Currently, the render graph slots are only used to pass the
view_entity around. This introduces significant boilerplate for very
little value. Instead of using slots for this, make the view_entity part
of the `RenderGraphContext`. This also means we won't need to have
`IN_VIEW` on every node and and we'll be able to use the default impl of
`Node::input()`.

## Solution

- Add `view_entity: Option<Entity>` to the `RenderGraphContext`
- Update all nodes to use this instead of entity slot input

---

## Changelog

- Add optional `view_entity` to `RenderGraphContext`

## Migration Guide

You can now get the view_entity directly from the `RenderGraphContext`. 

When implementing the Node:

```rust
// 0.10
struct FooNode;
impl FooNode {
    const IN_VIEW: &'static str = "view";
}
impl Node for FooNode {
    fn input(&self) -> Vec<SlotInfo> {
        vec![SlotInfo::new(Self::IN_VIEW, SlotType::Entity)]
    }
    fn run(
        &self,
        graph: &mut RenderGraphContext,
        // ... 
    ) -> Result<(), NodeRunError> {
        let view_entity = graph.get_input_entity(Self::IN_VIEW)?;
        // ...
        Ok(())
    }
}

// 0.11
struct FooNode;
impl Node for FooNode {
    fn run(
        &self,
        graph: &mut RenderGraphContext,
        // ... 
    ) -> Result<(), NodeRunError> {
        let view_entity = graph.view_entity();
        // ...
        Ok(())
    }
}
```

When adding the node to the graph, you don't need to specify a slot_edge
for the view_entity.

```rust
// 0.10
let mut graph = RenderGraph::default();
graph.add_node(FooNode::NAME, node);
let input_node_id = draw_2d_graph.set_input(vec![SlotInfo::new(
    graph::input::VIEW_ENTITY,
    SlotType::Entity,
)]);
graph.add_slot_edge(
    input_node_id,
    graph::input::VIEW_ENTITY,
    FooNode::NAME,
    FooNode::IN_VIEW,
);
// add_node_edge ...

// 0.11
let mut graph = RenderGraph::default();
graph.add_node(FooNode::NAME, node);
// add_node_edge ...
```

## Notes

This PR paired with #8007 will help reduce a lot of annoying boilerplate
with the render nodes. Depending on which one gets merged first. It will
require a bit of clean up work to make both compatible.

I tagged this as a breaking change, because using the old system to get
the view_entity will break things because it's not a node input slot
anymore.

## Notes for reviewers

A lot of the diffs are just removing the slots in every nodes and graph
creation. The important part is mostly in the
graph_runner/CameraDriverNode.
2023-03-21 20:11:13 +00:00
..
blit Camera Output Modes, MSAA Writeback, and BlitPipeline (#7671) 2023-03-01 20:35:13 +00:00
bloom Make render graph slots optional for most cases (#8109) 2023-03-21 20:11:13 +00:00
core_2d Make render graph slots optional for most cases (#8109) 2023-03-21 20:11:13 +00:00
core_3d Make render graph slots optional for most cases (#8109) 2023-03-21 20:11:13 +00:00
fullscreen_vertex_shader separate tonemapping and upscaling passes (#3425) 2022-10-26 20:13:59 +00:00
fxaa Make render graph slots optional for most cases (#8109) 2023-03-21 20:11:13 +00:00
prepass Make render graph slots optional for most cases (#8109) 2023-03-21 20:11:13 +00:00
tonemapping Make render graph slots optional for most cases (#8109) 2023-03-21 20:11:13 +00:00
upscaling Make render graph slots optional for most cases (#8109) 2023-03-21 20:11:13 +00:00
clear_color.rs Make Resource trait opt-in, requiring #[derive(Resource)] V2 (#5577) 2022-08-08 21:36:35 +00:00
lib.rs Camera Output Modes, MSAA Writeback, and BlitPipeline (#7671) 2023-03-01 20:35:13 +00:00
msaa_writeback.rs Make render graph slots optional for most cases (#8109) 2023-03-21 20:11:13 +00:00