Allow calling add_render_graph_node on World. (#19912)

# Objective

- This unblocks some work I am doing for #19887.

## Solution

- Rename `RenderGraphApp` to `RenderGraphExt`.
- Implement `RenderGraphExt` for `World`.
- Change `SubApp` and `App` to call the `World` impl.
This commit is contained in:
andriyDev 2025-07-02 07:56:18 -07:00 committed by GitHub
parent c8cdb1197e
commit f95f42b44a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 83 additions and 41 deletions

View File

@ -11,7 +11,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin},
prelude::Camera,
render_graph::RenderGraphApp,
render_graph::RenderGraphExt,
render_resource::{
binding_types::{sampler, texture_2d, uniform_buffer},
*,

View File

@ -11,7 +11,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
prelude::Camera,
render_graph::{RenderGraphApp, ViewNodeRunner},
render_graph::{RenderGraphExt, ViewNodeRunner},
render_resource::{
binding_types::{sampler, texture_2d},
*,

View File

@ -58,7 +58,7 @@ use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
render_asset::RenderAssets,
render_graph::{
NodeRunError, RenderGraphApp as _, RenderGraphContext, ViewNode, ViewNodeRunner,
NodeRunError, RenderGraphContext, RenderGraphExt as _, ViewNode, ViewNodeRunner,
},
render_resource::{
binding_types::{sampler, texture_2d, uniform_buffer},

View File

@ -21,7 +21,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
camera::{ExtractedCamera, MipBias, TemporalJitter},
prelude::{Camera, Projection},
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_graph::{NodeRunError, RenderGraphContext, RenderGraphExt, ViewNode, ViewNodeRunner},
render_resource::{
binding_types::{sampler, texture_2d, texture_depth_2d},
BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries, CachedRenderPipelineId,

View File

@ -4,7 +4,7 @@ use bevy_ecs::prelude::*;
use bevy_render::{
extract_component::ExtractComponentPlugin,
render_asset::RenderAssetPlugin,
render_graph::RenderGraphApp,
render_graph::RenderGraphExt,
render_resource::{
Buffer, BufferDescriptor, BufferUsages, PipelineCache, SpecializedComputePipelines,
},

View File

@ -20,7 +20,7 @@ use bevy_render::{
extract_component::{
ComponentUniforms, DynamicUniformIndex, ExtractComponentPlugin, UniformComponentPlugin,
},
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_graph::{NodeRunError, RenderGraphContext, RenderGraphExt, ViewNode, ViewNodeRunner},
render_resource::*,
renderer::{RenderContext, RenderDevice},
texture::{CachedTexture, TextureCache},

View File

@ -52,7 +52,7 @@ use bevy_math::FloatOrd;
use bevy_render::{
camera::{Camera, ExtractedCamera},
extract_component::ExtractComponentPlugin,
render_graph::{EmptyNode, RenderGraphApp, ViewNodeRunner},
render_graph::{EmptyNode, RenderGraphExt, ViewNodeRunner},
render_phase::{
sort_phase_system, BinnedPhaseItem, CachedRenderPipelinePhaseItem, DrawFunctionId,
DrawFunctions, PhaseItem, PhaseItemExtraIndex, SortedPhaseItem, ViewBinnedRenderPhases,

View File

@ -92,7 +92,7 @@ use bevy_render::{
camera::{Camera, ExtractedCamera},
extract_component::ExtractComponentPlugin,
prelude::Msaa,
render_graph::{EmptyNode, RenderGraphApp, ViewNodeRunner},
render_graph::{EmptyNode, RenderGraphExt, ViewNodeRunner},
render_phase::{
sort_phase_system, BinnedPhaseItem, CachedRenderPipelinePhaseItem, DrawFunctionId,
DrawFunctions, PhaseItem, PhaseItemExtraIndex, SortedPhaseItem, ViewBinnedRenderPhases,

View File

@ -34,7 +34,7 @@ use bevy_render::{
camera::{PhysicalCameraParameters, Projection},
extract_component::{ComponentUniforms, DynamicUniformIndex, UniformComponentPlugin},
render_graph::{
NodeRunError, RenderGraphApp as _, RenderGraphContext, ViewNode, ViewNodeRunner,
NodeRunError, RenderGraphContext, RenderGraphExt as _, ViewNode, ViewNodeRunner,
},
render_resource::{
binding_types::{

View File

@ -30,7 +30,7 @@ use bevy_render::{
experimental::occlusion_culling::{
OcclusionCulling, OcclusionCullingSubview, OcclusionCullingSubviewEntities,
},
render_graph::{Node, NodeRunError, RenderGraphApp, RenderGraphContext},
render_graph::{Node, NodeRunError, RenderGraphContext, RenderGraphExt},
render_resource::{
binding_types::{sampler, texture_2d, texture_2d_multisampled, texture_storage_2d},
BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries,

View File

@ -18,7 +18,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
camera::Camera,
extract_component::{ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin},
render_graph::{RenderGraphApp, ViewNodeRunner},
render_graph::{RenderGraphExt, ViewNodeRunner},
render_resource::{ShaderType, SpecializedRenderPipelines},
Render, RenderApp, RenderSystems,
};

View File

@ -8,7 +8,7 @@ use bevy_color::LinearRgba;
use bevy_ecs::{prelude::*, query::QueryItem};
use bevy_render::{
camera::ExtractedCamera,
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_graph::{NodeRunError, RenderGraphContext, RenderGraphExt, ViewNode, ViewNodeRunner},
render_resource::*,
renderer::RenderContext,
view::{Msaa, ViewTarget},

View File

@ -10,7 +10,7 @@ use bevy_render::{
camera::{Camera, ExtractedCamera},
extract_component::{ExtractComponent, ExtractComponentPlugin},
load_shader_library,
render_graph::{RenderGraphApp, ViewNodeRunner},
render_graph::{RenderGraphExt, ViewNodeRunner},
render_resource::{BufferUsages, BufferVec, DynamicUniformBuffer, ShaderType, TextureUsages},
renderer::{RenderDevice, RenderQueue},
view::Msaa,

View File

@ -23,7 +23,7 @@ use bevy_render::{
load_shader_library,
render_asset::{RenderAssetUsages, RenderAssets},
render_graph::{
NodeRunError, RenderGraphApp as _, RenderGraphContext, ViewNode, ViewNodeRunner,
NodeRunError, RenderGraphContext, RenderGraphExt as _, ViewNode, ViewNodeRunner,
},
render_resource::{
binding_types::{sampler, texture_2d, uniform_buffer},

View File

@ -55,7 +55,7 @@ use bevy_render::{
};
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
render_graph::{RenderGraphApp, ViewNodeRunner},
render_graph::{RenderGraphExt, ViewNodeRunner},
render_resource::{TextureFormat, TextureUsages},
renderer::RenderAdapter,
Render, RenderApp, RenderSystems,

View File

@ -25,7 +25,7 @@ use bevy_render::{
extract_component::{
ComponentUniforms, ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin,
},
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_graph::{NodeRunError, RenderGraphContext, RenderGraphExt, ViewNode, ViewNodeRunner},
render_resource::{binding_types::uniform_buffer, *},
renderer::{RenderContext, RenderDevice},
view::{ExtractedView, ViewTarget, ViewUniformOffset},

View File

@ -75,7 +75,7 @@ use bevy_ecs::{
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
load_shader_library,
render_graph::{RenderGraphApp, ViewNodeRunner},
render_graph::{RenderGraphExt, ViewNodeRunner},
renderer::RenderDevice,
settings::WgpuFeatures,
view::{self, prepare_view_targets, Msaa, Visibility, VisibilityClass},

View File

@ -38,7 +38,7 @@ use bevy_render::{
UntypedPhaseBatchedInstanceBuffers,
},
experimental::occlusion_culling::OcclusionCulling,
render_graph::{Node, NodeRunError, RenderGraphApp, RenderGraphContext},
render_graph::{Node, NodeRunError, RenderGraphContext, RenderGraphExt},
render_resource::{
binding_types::{storage_buffer, storage_buffer_read_only, texture_2d, uniform_buffer},
BindGroup, BindGroupEntries, BindGroupLayout, BindingResource, Buffer, BufferBinding,

View File

@ -23,7 +23,7 @@ use bevy_render::{
globals::{GlobalsBuffer, GlobalsUniform},
load_shader_library,
prelude::Camera,
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_graph::{NodeRunError, RenderGraphContext, RenderGraphExt, ViewNode, ViewNodeRunner},
render_resource::{
binding_types::{
sampler, texture_2d, texture_depth_2d, texture_storage_2d, uniform_buffer,

View File

@ -25,7 +25,7 @@ use bevy_image::BevyDefault as _;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_graph::{NodeRunError, RenderGraphContext, RenderGraphExt, ViewNode, ViewNodeRunner},
render_resource::{
binding_types, AddressMode, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries,
CachedRenderPipelineId, ColorTargetState, ColorWrites, DynamicUniformBuffer, FilterMode,

View File

@ -47,7 +47,7 @@ use bevy_math::{
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
mesh::{Mesh, Meshable},
render_graph::{RenderGraphApp, ViewNodeRunner},
render_graph::{RenderGraphExt, ViewNodeRunner},
render_resource::SpecializedRenderPipelines,
sync_component::SyncComponentPlugin,
view::Visibility,

View File

@ -38,7 +38,7 @@ use bevy_render::{
render_asset::{
prepare_assets, PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets,
},
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_graph::{NodeRunError, RenderGraphContext, RenderGraphExt, ViewNode, ViewNodeRunner},
render_phase::{
AddRenderCommand, BinnedPhaseItem, BinnedRenderPhasePlugin, BinnedRenderPhaseType,
CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions, PhaseItem,

View File

@ -1,11 +1,11 @@
use bevy_app::{App, SubApp};
use bevy_ecs::world::FromWorld;
use bevy_ecs::world::{FromWorld, World};
use tracing::warn;
use super::{IntoRenderNodeArray, Node, RenderGraph, RenderLabel, RenderSubGraph};
/// Adds common [`RenderGraph`] operations to [`SubApp`] (and [`App`]).
pub trait RenderGraphApp {
pub trait RenderGraphExt {
// Add a sub graph to the [`RenderGraph`]
fn add_render_sub_graph(&mut self, sub_graph: impl RenderSubGraph) -> &mut Self;
/// Add a [`Node`] to the [`RenderGraph`]:
@ -32,15 +32,15 @@ pub trait RenderGraphApp {
) -> &mut Self;
}
impl RenderGraphApp for SubApp {
impl RenderGraphExt for World {
fn add_render_graph_node<T: Node + FromWorld>(
&mut self,
sub_graph: impl RenderSubGraph,
node_label: impl RenderLabel,
) -> &mut Self {
let sub_graph = sub_graph.intern();
let node = T::from_world(self.world_mut());
let mut render_graph = self.world_mut().get_resource_mut::<RenderGraph>().expect(
let node = T::from_world(self);
let mut render_graph = self.get_resource_mut::<RenderGraph>().expect(
"RenderGraph not found. Make sure you are using add_render_graph_node on the RenderApp",
);
if let Some(graph) = render_graph.get_sub_graph_mut(sub_graph) {
@ -59,7 +59,7 @@ impl RenderGraphApp for SubApp {
edges: impl IntoRenderNodeArray<N>,
) -> &mut Self {
let sub_graph = sub_graph.intern();
let mut render_graph = self.world_mut().get_resource_mut::<RenderGraph>().expect(
let mut render_graph = self.get_resource_mut::<RenderGraph>().expect(
"RenderGraph not found. Make sure you are using add_render_graph_edges on the RenderApp",
);
if let Some(graph) = render_graph.get_sub_graph_mut(sub_graph) {
@ -79,7 +79,7 @@ impl RenderGraphApp for SubApp {
input_node: impl RenderLabel,
) -> &mut Self {
let sub_graph = sub_graph.intern();
let mut render_graph = self.world_mut().get_resource_mut::<RenderGraph>().expect(
let mut render_graph = self.get_resource_mut::<RenderGraph>().expect(
"RenderGraph not found. Make sure you are using add_render_graph_edge on the RenderApp",
);
if let Some(graph) = render_graph.get_sub_graph_mut(sub_graph) {
@ -93,7 +93,7 @@ impl RenderGraphApp for SubApp {
}
fn add_render_sub_graph(&mut self, sub_graph: impl RenderSubGraph) -> &mut Self {
let mut render_graph = self.world_mut().get_resource_mut::<RenderGraph>().expect(
let mut render_graph = self.get_resource_mut::<RenderGraph>().expect(
"RenderGraph not found. Make sure you are using add_render_sub_graph on the RenderApp",
);
render_graph.add_sub_graph(sub_graph, RenderGraph::default());
@ -101,13 +101,13 @@ impl RenderGraphApp for SubApp {
}
}
impl RenderGraphApp for App {
impl RenderGraphExt for SubApp {
fn add_render_graph_node<T: Node + FromWorld>(
&mut self,
sub_graph: impl RenderSubGraph,
node_label: impl RenderLabel,
) -> &mut Self {
SubApp::add_render_graph_node::<T>(self.main_mut(), sub_graph, node_label);
World::add_render_graph_node::<T>(self.world_mut(), sub_graph, node_label);
self
}
@ -117,7 +117,7 @@ impl RenderGraphApp for App {
output_node: impl RenderLabel,
input_node: impl RenderLabel,
) -> &mut Self {
SubApp::add_render_graph_edge(self.main_mut(), sub_graph, output_node, input_node);
World::add_render_graph_edge(self.world_mut(), sub_graph, output_node, input_node);
self
}
@ -126,12 +126,47 @@ impl RenderGraphApp for App {
sub_graph: impl RenderSubGraph,
edges: impl IntoRenderNodeArray<N>,
) -> &mut Self {
SubApp::add_render_graph_edges(self.main_mut(), sub_graph, edges);
World::add_render_graph_edges(self.world_mut(), sub_graph, edges);
self
}
fn add_render_sub_graph(&mut self, sub_graph: impl RenderSubGraph) -> &mut Self {
SubApp::add_render_sub_graph(self.main_mut(), sub_graph);
World::add_render_sub_graph(self.world_mut(), sub_graph);
self
}
}
impl RenderGraphExt for App {
fn add_render_graph_node<T: Node + FromWorld>(
&mut self,
sub_graph: impl RenderSubGraph,
node_label: impl RenderLabel,
) -> &mut Self {
World::add_render_graph_node::<T>(self.world_mut(), sub_graph, node_label);
self
}
fn add_render_graph_edge(
&mut self,
sub_graph: impl RenderSubGraph,
output_node: impl RenderLabel,
input_node: impl RenderLabel,
) -> &mut Self {
World::add_render_graph_edge(self.world_mut(), sub_graph, output_node, input_node);
self
}
fn add_render_graph_edges<const N: usize>(
&mut self,
sub_graph: impl RenderSubGraph,
edges: impl IntoRenderNodeArray<N>,
) -> &mut Self {
World::add_render_graph_edges(self.world_mut(), sub_graph, edges);
self
}
fn add_render_sub_graph(&mut self, sub_graph: impl RenderSubGraph) -> &mut Self {
World::add_render_sub_graph(self.world_mut(), sub_graph);
self
}
}

View File

@ -9,7 +9,7 @@ use bevy_core_pipeline::core_3d::graph::{Core3d, Node3d};
use bevy_ecs::{component::Component, reflect::ReflectComponent, schedule::IntoScheduleConfigs};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
render_graph::{RenderGraphApp, ViewNodeRunner},
render_graph::{RenderGraphExt, ViewNodeRunner},
renderer::RenderDevice,
view::Hdr,
ExtractSchedule, Render, RenderApp, RenderSystems,

View File

@ -13,7 +13,7 @@ use bevy_ecs::{component::Component, reflect::ReflectComponent, schedule::IntoSc
use bevy_pbr::DefaultOpaqueRendererMethod;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
render_graph::{RenderGraphApp, ViewNodeRunner},
render_graph::{RenderGraphExt, ViewNodeRunner},
renderer::RenderDevice,
view::Hdr,
ExtractSchedule, Render, RenderApp, RenderSystems,

View File

@ -36,7 +36,7 @@ use bevy_render::{
render_asset::{
prepare_assets, PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets,
},
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_graph::{NodeRunError, RenderGraphContext, RenderGraphExt, ViewNode, ViewNodeRunner},
render_phase::{
AddRenderCommand, BinnedPhaseItem, BinnedRenderPhasePlugin, BinnedRenderPhaseType,
CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions, InputUniformIndex, PhaseItem,

View File

@ -30,7 +30,7 @@ use bevy::{
IndirectParametersIndexed,
},
experimental::occlusion_culling::OcclusionCulling,
render_graph::{self, NodeRunError, RenderGraphApp, RenderGraphContext, RenderLabel},
render_graph::{self, NodeRunError, RenderGraphContext, RenderGraphExt, RenderLabel},
render_resource::{Buffer, BufferDescriptor, BufferUsages, MapMode},
renderer::{RenderContext, RenderDevice},
settings::WgpuFeatures,

View File

@ -19,7 +19,7 @@ use bevy::{
UniformComponentPlugin,
},
render_graph::{
NodeRunError, RenderGraphApp, RenderGraphContext, RenderLabel, ViewNode, ViewNodeRunner,
NodeRunError, RenderGraphContext, RenderGraphExt, RenderLabel, ViewNode, ViewNodeRunner,
},
render_resource::{
binding_types::{sampler, texture_2d, uniform_buffer},

View File

@ -39,7 +39,7 @@ use bevy::{
mesh::{allocator::MeshAllocator, MeshVertexBufferLayoutRef, RenderMesh},
render_asset::RenderAssets,
render_graph::{
NodeRunError, RenderGraphApp, RenderGraphContext, RenderLabel, ViewNode, ViewNodeRunner,
NodeRunError, RenderGraphContext, RenderGraphExt, RenderLabel, ViewNode, ViewNodeRunner,
},
render_phase::{
sort_phase_system, AddRenderCommand, CachedRenderPipelinePhaseItem, DrawFunctionId,

View File

@ -0,0 +1,7 @@
---
title: `RenderGraphApp` renamed to `RenderGraphExt`.
pull_requests: [19912]
---
`RenderGraphApp` has been renamed to `RenderGraphExt`. Rename this for cases where you are
explicitly importing this trait.