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

Add RenderGraphApp to simplify adding render nodes #8007

Merged
merged 6 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
64 changes: 23 additions & 41 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bevy_render::{
ComponentUniforms, DynamicUniformIndex, ExtractComponentPlugin, UniformComponentPlugin,
},
prelude::Color,
render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext},
render_graph::{Node, NodeRunError, RenderGraphApp, RenderGraphContext},
render_resource::*,
renderer::{RenderContext, RenderDevice},
texture::{CachedTexture, TextureCache},
Expand Down Expand Up @@ -71,45 +71,27 @@ impl Plugin for BloomPlugin {
prepare_upsampling_pipeline.in_set(RenderSet::Prepare),
queue_bloom_bind_groups.in_set(RenderSet::Queue),
),
)
// Add bloom to the 3d render graph
.add_render_graph_node::<BloomNode>(core_3d::graph::NAME, core_3d::graph::node::BLOOM)
.add_render_graph_edges(
core_3d::graph::NAME,
&[
core_3d::graph::node::END_MAIN_PASS,
core_3d::graph::node::BLOOM,
core_3d::graph::node::TONEMAPPING,
],
)
// Add bloom to the 2d render graph
.add_render_graph_node::<BloomNode>(core_2d::graph::NAME, core_2d::graph::node::BLOOM)
.add_render_graph_edges(
core_2d::graph::NAME,
&[
core_2d::graph::node::MAIN_PASS,
core_2d::graph::node::BLOOM,
core_2d::graph::node::TONEMAPPING,
],
);

// Add bloom to the 3d render graph
{
let bloom_node = BloomNode::new(&mut render_app.world);
let mut graph = render_app.world.resource_mut::<RenderGraph>();
let draw_3d_graph = graph
.get_sub_graph_mut(crate::core_3d::graph::NAME)
.unwrap();
draw_3d_graph.add_node(core_3d::graph::node::BLOOM, bloom_node);
// MAIN_PASS -> BLOOM -> TONEMAPPING
draw_3d_graph.add_node_edge(
crate::core_3d::graph::node::END_MAIN_PASS,
core_3d::graph::node::BLOOM,
);
draw_3d_graph.add_node_edge(
core_3d::graph::node::BLOOM,
crate::core_3d::graph::node::TONEMAPPING,
);
}

// Add bloom to the 2d render graph
{
let bloom_node = BloomNode::new(&mut render_app.world);
let mut graph = render_app.world.resource_mut::<RenderGraph>();
let draw_2d_graph = graph
.get_sub_graph_mut(crate::core_2d::graph::NAME)
.unwrap();
draw_2d_graph.add_node(core_2d::graph::node::BLOOM, bloom_node);
// MAIN_PASS -> BLOOM -> TONEMAPPING
draw_2d_graph.add_node_edge(
crate::core_2d::graph::node::MAIN_PASS,
core_2d::graph::node::BLOOM,
);
draw_2d_graph.add_node_edge(
core_2d::graph::node::BLOOM,
crate::core_2d::graph::node::TONEMAPPING,
);
}
}
}

Expand All @@ -126,8 +108,8 @@ pub struct BloomNode {
)>,
}

impl BloomNode {
pub fn new(world: &mut World) -> Self {
impl FromWorld for BloomNode {
fn from_world(world: &mut World) -> Self {
Self {
view_query: QueryState::new(world),
}
Expand Down
58 changes: 29 additions & 29 deletions crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_reflect::{Reflect, TypeUuid};
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin},
prelude::Camera,
render_graph::RenderGraph,
render_graph::RenderGraphApp,
render_resource::*,
renderer::RenderDevice,
texture::BevyDefault,
Expand Down Expand Up @@ -114,47 +114,47 @@ impl Plugin for CASPlugin {
render_app
.init_resource::<CASPipeline>()
.init_resource::<SpecializedRenderPipelines<CASPipeline>>()
.add_systems(Render, prepare_cas_pipelines.in_set(RenderSet::Prepare));
{
let cas_node = CASNode::new(&mut render_app.world);
let mut binding = render_app.world.resource_mut::<RenderGraph>();
let graph = binding.get_sub_graph_mut(core_3d::graph::NAME).unwrap();

graph.add_node(core_3d::graph::node::CONTRAST_ADAPTIVE_SHARPENING, cas_node);

graph.add_node_edge(
.add_systems(Render, prepare_cas_pipelines.in_set(RenderSet::Prepare))
// 3d
.add_render_graph_node::<CASNode>(
core_3d::graph::NAME,
core_3d::graph::node::CONTRAST_ADAPTIVE_SHARPENING,
)
.add_render_graph_edge(
core_3d::graph::NAME,
core_3d::graph::node::TONEMAPPING,
core_3d::graph::node::CONTRAST_ADAPTIVE_SHARPENING,
);
graph.add_node_edge(
)
.add_render_graph_edge(
core_3d::graph::NAME,
core_3d::graph::node::FXAA,
core_3d::graph::node::CONTRAST_ADAPTIVE_SHARPENING,
);
graph.add_node_edge(
)
.add_render_graph_edge(
core_3d::graph::NAME,
core_3d::graph::node::CONTRAST_ADAPTIVE_SHARPENING,
core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
);
}
{
let cas_node = CASNode::new(&mut render_app.world);
let mut binding = render_app.world.resource_mut::<RenderGraph>();
let graph = binding.get_sub_graph_mut(core_2d::graph::NAME).unwrap();

graph.add_node(core_2d::graph::node::CONTRAST_ADAPTIVE_SHARPENING, cas_node);

graph.add_node_edge(
)
// 2d
.add_render_graph_node::<CASNode>(
core_2d::graph::NAME,
core_2d::graph::node::CONTRAST_ADAPTIVE_SHARPENING,
)
.add_render_graph_edge(
core_2d::graph::NAME,
core_2d::graph::node::TONEMAPPING,
core_2d::graph::node::CONTRAST_ADAPTIVE_SHARPENING,
);
graph.add_node_edge(
)
.add_render_graph_edge(
core_2d::graph::NAME,
core_2d::graph::node::FXAA,
core_2d::graph::node::CONTRAST_ADAPTIVE_SHARPENING,
);
graph.add_node_edge(
)
.add_render_graph_edge(
core_2d::graph::NAME,
core_2d::graph::node::CONTRAST_ADAPTIVE_SHARPENING,
core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub struct CASNode {
cached_bind_group: Mutex<Option<(BufferId, TextureViewId, BindGroup)>>,
}

impl CASNode {
pub fn new(world: &mut World) -> Self {
impl FromWorld for CASNode {
fn from_world(world: &mut World) -> Self {
Self {
query: QueryState::new(world),
cached_bind_group: Mutex::new(None),
Expand Down
11 changes: 5 additions & 6 deletions crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ impl Plugin for Core2dPlugin {
draw_2d_graph.add_node(graph::node::TONEMAPPING, tonemapping);
draw_2d_graph.add_node(graph::node::END_MAIN_PASS_POST_PROCESSING, EmptyNode);
draw_2d_graph.add_node(graph::node::UPSCALING, upscaling);
draw_2d_graph.add_node_edge(graph::node::MAIN_PASS, graph::node::TONEMAPPING);
draw_2d_graph.add_node_edge(

draw_2d_graph.add_node_edges(&[
graph::node::MAIN_PASS,
graph::node::TONEMAPPING,
graph::node::END_MAIN_PASS_POST_PROCESSING,
);
draw_2d_graph.add_node_edge(
graph::node::END_MAIN_PASS_POST_PROCESSING,
graph::node::UPSCALING,
);
]);

graph.add_sub_graph(graph::NAME, draw_2d_graph);
}
}
Expand Down
18 changes: 5 additions & 13 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,17 @@ impl Plugin for Core3dPlugin {
draw_3d_graph.add_node(graph::node::END_MAIN_PASS_POST_PROCESSING, EmptyNode);
draw_3d_graph.add_node(graph::node::UPSCALING, upscaling);

draw_3d_graph.add_node_edge(graph::node::PREPASS, graph::node::START_MAIN_PASS);
draw_3d_graph.add_node_edge(graph::node::START_MAIN_PASS, graph::node::MAIN_OPAQUE_PASS);
draw_3d_graph.add_node_edge(
draw_3d_graph.add_node_edges(&[
graph::node::PREPASS,
graph::node::START_MAIN_PASS,
graph::node::MAIN_OPAQUE_PASS,
graph::node::MAIN_TRANSPARENT_PASS,
);
draw_3d_graph.add_node_edge(
graph::node::MAIN_TRANSPARENT_PASS,
graph::node::END_MAIN_PASS,
);
draw_3d_graph.add_node_edge(graph::node::END_MAIN_PASS, graph::node::TONEMAPPING);
draw_3d_graph.add_node_edge(
graph::node::TONEMAPPING,
graph::node::END_MAIN_PASS_POST_PROCESSING,
);
draw_3d_graph.add_node_edge(
graph::node::END_MAIN_PASS_POST_PROCESSING,
graph::node::UPSCALING,
);
]);

graph.add_sub_graph(graph::NAME, draw_3d_graph);
}
}
Expand Down
53 changes: 19 additions & 34 deletions crates/bevy_core_pipeline/src/fxaa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy_reflect::{
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
prelude::Camera,
render_graph::RenderGraph,
render_graph::RenderGraphApp,
render_resource::*,
renderer::RenderDevice,
texture::BevyDefault,
Expand Down Expand Up @@ -90,40 +90,25 @@ impl Plugin for FxaaPlugin {
render_app
.init_resource::<FxaaPipeline>()
.init_resource::<SpecializedRenderPipelines<FxaaPipeline>>()
.add_systems(Render, prepare_fxaa_pipelines.in_set(RenderSet::Prepare));

{
let fxaa_node = FxaaNode::new(&mut render_app.world);
let mut binding = render_app.world.resource_mut::<RenderGraph>();
let graph = binding.get_sub_graph_mut(core_3d::graph::NAME).unwrap();

graph.add_node(core_3d::graph::node::FXAA, fxaa_node);

graph.add_node_edge(
core_3d::graph::node::TONEMAPPING,
core_3d::graph::node::FXAA,
);
graph.add_node_edge(
core_3d::graph::node::FXAA,
core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
);
}
{
let fxaa_node = FxaaNode::new(&mut render_app.world);
let mut binding = render_app.world.resource_mut::<RenderGraph>();
let graph = binding.get_sub_graph_mut(core_2d::graph::NAME).unwrap();

graph.add_node(core_2d::graph::node::FXAA, fxaa_node);

graph.add_node_edge(
core_2d::graph::node::TONEMAPPING,
core_2d::graph::node::FXAA,
);
graph.add_node_edge(
core_2d::graph::node::FXAA,
core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
.add_systems(Render, prepare_fxaa_pipelines.in_set(RenderSet::Prepare))
.add_render_graph_node::<FxaaNode>(core_3d::graph::NAME, core_3d::graph::node::FXAA)
.add_render_graph_edges(
core_3d::graph::NAME,
&[
core_3d::graph::node::TONEMAPPING,
core_3d::graph::node::FXAA,
core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
],
)
.add_render_graph_node::<FxaaNode>(core_2d::graph::NAME, core_2d::graph::node::FXAA)
.add_render_graph_edges(
core_2d::graph::NAME,
&[
core_2d::graph::node::TONEMAPPING,
core_2d::graph::node::FXAA,
core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
],
);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/fxaa/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub struct FxaaNode {
cached_texture_bind_group: Mutex<Option<(TextureViewId, BindGroup)>>,
}

impl FxaaNode {
pub fn new(world: &mut World) -> Self {
impl FromWorld for FxaaNode {
fn from_world(world: &mut World) -> Self {
Self {
query: QueryState::new(world),
cached_texture_bind_group: Mutex::new(None),
Expand Down
34 changes: 14 additions & 20 deletions crates/bevy_core_pipeline/src/taa/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
core_3d,
fullscreen_vertex_shader::fullscreen_shader_vertex_state,
prelude::Camera3d,
prepass::{DepthPrepass, MotionVectorPrepass, ViewPrepassTextures},
Expand All @@ -18,7 +19,7 @@ use bevy_reflect::{Reflect, TypeUuid};
use bevy_render::{
camera::{ExtractedCamera, TemporalJitter},
prelude::{Camera, Projection},
render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext},
render_graph::{Node, NodeRunError, RenderGraphApp, RenderGraphContext},
render_resource::{
BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor,
BindGroupLayoutEntry, BindingResource, BindingType, CachedRenderPipelineId,
Expand Down Expand Up @@ -71,24 +72,17 @@ impl Plugin for TemporalAntiAliasPlugin {
prepare_taa_history_textures.in_set(RenderSet::Prepare),
prepare_taa_pipelines.in_set(RenderSet::Prepare),
),
)
.add_render_graph_node::<TAANode>(core_3d::graph::NAME, draw_3d_graph::node::TAA)
.add_render_graph_edges(
core_3d::graph::NAME,
&[
core_3d::graph::node::END_MAIN_PASS,
draw_3d_graph::node::TAA,
core_3d::graph::node::BLOOM,
core_3d::graph::node::TONEMAPPING,
],
);

let taa_node = TAANode::new(&mut render_app.world);
let mut graph = render_app.world.resource_mut::<RenderGraph>();
let draw_3d_graph = graph
.get_sub_graph_mut(crate::core_3d::graph::NAME)
.unwrap();
draw_3d_graph.add_node(draw_3d_graph::node::TAA, taa_node);
// MAIN_PASS -> TAA -> BLOOM -> TONEMAPPING
draw_3d_graph.add_node_edge(
crate::core_3d::graph::node::END_MAIN_PASS,
draw_3d_graph::node::TAA,
);
draw_3d_graph.add_node_edge(draw_3d_graph::node::TAA, crate::core_3d::graph::node::BLOOM);
draw_3d_graph.add_node_edge(
draw_3d_graph::node::TAA,
crate::core_3d::graph::node::TONEMAPPING,
);
}
}

Expand Down Expand Up @@ -168,8 +162,8 @@ struct TAANode {
)>,
}

impl TAANode {
fn new(world: &mut World) -> Self {
impl FromWorld for TAANode {
fn from_world(world: &mut World) -> Self {
Self {
view_query: QueryState::new(world),
}
Expand Down
Loading