-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Replace RenderGraph with systems
#22144
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
Open
tychedelia
wants to merge
51
commits into
bevyengine:main
Choose a base branch
from
tychedelia:render-graph-as-systems
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+6,435
−10,584
Open
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
fa703f0
Rewrite RenderGraph to use Schedule.
tychedelia 7ac2277
Merge branch 'main' into render-graph-as-systems
tychedelia 2e0c5a6
Fmt.
tychedelia 8ea6a02
Ci.
tychedelia e5ca7e2
Insert apply deferred automatically.
tychedelia 63388ed
Try pushing command encoders.
tychedelia c6a6706
Tracing.
tychedelia 57d84be
Don't parallelize.
tychedelia f5c54e0
Fix shadow ordering.
tychedelia 8c01b32
ci
atlv24 ff8f43f
examples
atlv24 6342c31
example imports
atlv24 b83663b
fix
atlv24 790a86d
fix guides
atlv24 1958963
tweaks
atlv24 1a7a9f4
Merge pull request #4 from atlv24/ad/render-graph-systems
tychedelia bad4c5e
Merge branch 'main' into render-graph-as-systems
tychedelia 6651227
Re-move for diff.
tychedelia ea05761
Ci.
tychedelia ca6343d
Fix occlusion culling.
tychedelia f715177
Ci.
tychedelia 3a9a97f
Merge remote-tracking branch 'origin/main' into render-graph-as-systems
tychedelia 8d5dc16
Ci.
tychedelia cd7baed
Oops.
tychedelia 6766122
Fix game of life.
tychedelia 9c80e00
Wasm atomics.
tychedelia eaa90bb
Docs.
tychedelia b1da2ce
Ci.
tychedelia 23803dd
Docs.
tychedelia e99c18a
More wasm atomics.
tychedelia 55a9596
Fix custom_render_phase.
tychedelia 4189f4f
Merge branch 'main' into render-graph-as-systems
tychedelia e1ecbf7
More constraints
tychedelia 3cc28a4
Respond to feedback.
tychedelia ac21b06
Respond to feedback.
tychedelia 6d4a4b6
Merge remote-tracking branch 'origin/main' into render-graph-as-systems
tychedelia b07aed1
Fix compute mesh example.
tychedelia 415f636
Restore missing solari code.
tychedelia 092a5e0
Merge remote-tracking branch 'origin/main' into render-graph-as-systems
tychedelia f786942
Solari fixes.
tychedelia 72fb694
Use chaining
tychedelia 7c8c843
Restore comments.
tychedelia 8e4b968
Fix render system ordering.
tychedelia c41b2e1
Add AntiAliasing system set.
tychedelia a012cad
Add AntiAliasing system set.
tychedelia 32a6f25
Use single system sets rather than begin/end system sets.
tychedelia c8a7ab9
Merge remote-tracking branch 'origin/main' into render-graph-as-systems
tychedelia bd962c2
Try fixing solari again.
tychedelia e29562b
Correctly submit only once.
tychedelia 9238715
Merge remote-tracking branch 'origin/main' into render-graph-as-systems
tychedelia 17c70cb
Ci.
tychedelia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,16 @@ | ||
| use crate::{fxaa::fxaa, AntiAliasing}; | ||
| use bevy_app::prelude::*; | ||
| use bevy_asset::{embedded_asset, load_embedded_asset, AssetServer}; | ||
| use bevy_camera::Camera; | ||
| use bevy_core_pipeline::{ | ||
| core_2d::graph::{Core2d, Node2d}, | ||
| core_3d::graph::{Core3d, Node3d}, | ||
| schedule::{Core2d, Core2dSystems, Core3d, Core3dSystems}, | ||
| FullscreenShader, | ||
| }; | ||
| use bevy_ecs::{prelude::*, query::QueryItem}; | ||
| use bevy_image::BevyDefault as _; | ||
| use bevy_reflect::{std_traits::ReflectDefault, Reflect}; | ||
| use bevy_render::{ | ||
| extract_component::{ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin}, | ||
| render_graph::RenderGraphExt, | ||
| render_resource::{ | ||
| binding_types::{sampler, texture_2d, uniform_buffer}, | ||
| *, | ||
|
|
@@ -23,7 +22,7 @@ use bevy_render::{ | |
|
|
||
| mod node; | ||
|
|
||
| pub use node::CasNode; | ||
| pub(crate) use node::cas; | ||
|
|
||
| /// Applies a contrast adaptive sharpening (CAS) filter to the camera. | ||
| /// | ||
|
|
@@ -113,42 +112,19 @@ impl Plugin for CasPlugin { | |
| }; | ||
| render_app | ||
| .add_systems(RenderStartup, init_cas_pipeline) | ||
| .add_systems(Render, prepare_cas_pipelines.in_set(RenderSystems::Prepare)); | ||
|
|
||
| { | ||
| render_app | ||
| .add_render_graph_node::<CasNode>(Core3d, Node3d::ContrastAdaptiveSharpening) | ||
| .add_render_graph_edge( | ||
| Core3d, | ||
| Node3d::Tonemapping, | ||
| Node3d::ContrastAdaptiveSharpening, | ||
| ) | ||
| .add_render_graph_edges( | ||
| Core3d, | ||
| ( | ||
| Node3d::Fxaa, | ||
| Node3d::ContrastAdaptiveSharpening, | ||
| Node3d::EndMainPassPostProcessing, | ||
| ), | ||
| ); | ||
| } | ||
| { | ||
| render_app | ||
| .add_render_graph_node::<CasNode>(Core2d, Node2d::ContrastAdaptiveSharpening) | ||
| .add_render_graph_edge( | ||
| Core2d, | ||
| Node2d::Tonemapping, | ||
| Node2d::ContrastAdaptiveSharpening, | ||
| ) | ||
| .add_render_graph_edges( | ||
| Core2d, | ||
| ( | ||
| Node2d::Fxaa, | ||
| Node2d::ContrastAdaptiveSharpening, | ||
| Node2d::EndMainPassPostProcessing, | ||
| ), | ||
| ); | ||
| } | ||
| .add_systems(Render, prepare_cas_pipelines.in_set(RenderSystems::Prepare)) | ||
| .add_systems( | ||
| Core3d, | ||
| cas.after(fxaa) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reviewer note: fxaa is ordered after tonemapping, so the .after tonemapping here is redundant thus removed
tychedelia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .in_set(Core3dSystems::PostProcess) | ||
| .in_set(AntiAliasing), | ||
| ) | ||
| .add_systems( | ||
| Core2d, | ||
| cas.after(fxaa) | ||
| .in_set(Core2dSystems::PostProcess) | ||
| .in_set(AntiAliasing), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
167 changes: 69 additions & 98 deletions
167
crates/bevy_anti_alias/src/contrast_adaptive_sharpening/node.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,126 +1,97 @@ | ||
| use std::sync::Mutex; | ||
|
|
||
| use crate::contrast_adaptive_sharpening::ViewCasPipeline; | ||
| use bevy_ecs::prelude::*; | ||
| use bevy_render::{ | ||
| diagnostic::RecordDiagnostics, | ||
| extract_component::{ComponentUniforms, DynamicUniformIndex}, | ||
| render_graph::{Node, NodeRunError, RenderGraphContext}, | ||
| render_resource::{ | ||
| BindGroup, BindGroupEntries, BufferId, Operations, PipelineCache, | ||
| RenderPassColorAttachment, RenderPassDescriptor, TextureViewId, | ||
| }, | ||
| renderer::RenderContext, | ||
| renderer::{RenderContext, ViewQuery}, | ||
| view::{ExtractedView, ViewTarget}, | ||
| }; | ||
|
|
||
| use super::{CasPipeline, CasUniform}; | ||
|
|
||
| pub struct CasNode { | ||
| query: QueryState< | ||
| pub(crate) fn cas( | ||
| view: ViewQuery< | ||
| ( | ||
| &'static ViewTarget, | ||
| &'static ViewCasPipeline, | ||
| &'static DynamicUniformIndex<CasUniform>, | ||
| &ViewTarget, | ||
| &ViewCasPipeline, | ||
| &DynamicUniformIndex<CasUniform>, | ||
| ), | ||
| With<ExtractedView>, | ||
| >, | ||
| cached_bind_group: Mutex<Option<(BufferId, TextureViewId, BindGroup)>>, | ||
| } | ||
|
|
||
| impl FromWorld for CasNode { | ||
| fn from_world(world: &mut World) -> Self { | ||
| Self { | ||
| query: QueryState::new(world), | ||
| cached_bind_group: Mutex::new(None), | ||
| sharpening_pipeline: Res<CasPipeline>, | ||
| pipeline_cache: Res<PipelineCache>, | ||
| uniforms: Res<ComponentUniforms<CasUniform>>, | ||
| mut ctx: RenderContext, | ||
| mut cached_bind_group: Local<Option<(BufferId, TextureViewId, BindGroup)>>, | ||
| ) { | ||
| let (target, pipeline, uniform_index) = view.into_inner(); | ||
|
|
||
| let uniforms_id = uniforms.buffer().unwrap().id(); | ||
| let Some(uniforms_binding) = uniforms.binding() else { | ||
| return; | ||
| }; | ||
|
|
||
| let Some(pipeline) = pipeline_cache.get_render_pipeline(pipeline.0) else { | ||
| return; | ||
| }; | ||
|
|
||
| let view_target = target.post_process_write(); | ||
| let source = view_target.source; | ||
| let destination = view_target.destination; | ||
|
|
||
| let bind_group = match &mut *cached_bind_group { | ||
| Some((buffer_id, texture_id, bind_group)) | ||
| if source.id() == *texture_id && uniforms_id == *buffer_id => | ||
| { | ||
| bind_group | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Node for CasNode { | ||
| fn update(&mut self, world: &mut World) { | ||
| self.query.update_archetypes(world); | ||
| } | ||
|
|
||
| fn run( | ||
| &self, | ||
| graph: &mut RenderGraphContext, | ||
| render_context: &mut RenderContext, | ||
| world: &World, | ||
| ) -> Result<(), NodeRunError> { | ||
| let view_entity = graph.view_entity(); | ||
| let pipeline_cache = world.resource::<PipelineCache>(); | ||
| let sharpening_pipeline = world.resource::<CasPipeline>(); | ||
| let uniforms = world.resource::<ComponentUniforms<CasUniform>>(); | ||
|
|
||
| let Ok((target, pipeline, uniform_index)) = self.query.get_manual(world, view_entity) | ||
| else { | ||
| return Ok(()); | ||
| }; | ||
|
|
||
| let uniforms_id = uniforms.buffer().unwrap().id(); | ||
| let Some(uniforms) = uniforms.binding() else { | ||
| return Ok(()); | ||
| }; | ||
|
|
||
| let Some(pipeline) = pipeline_cache.get_render_pipeline(pipeline.0) else { | ||
| return Ok(()); | ||
| }; | ||
|
|
||
| let diagnostics = render_context.diagnostic_recorder(); | ||
|
|
||
| let view_target = target.post_process_write(); | ||
| let source = view_target.source; | ||
| let destination = view_target.destination; | ||
|
|
||
| let mut cached_bind_group = self.cached_bind_group.lock().unwrap(); | ||
| let bind_group = match &mut *cached_bind_group { | ||
| Some((buffer_id, texture_id, bind_group)) | ||
| if source.id() == *texture_id && uniforms_id == *buffer_id => | ||
| { | ||
| bind_group | ||
| } | ||
| cached_bind_group => { | ||
| let bind_group = render_context.render_device().create_bind_group( | ||
| "cas_bind_group", | ||
| &pipeline_cache.get_bind_group_layout(&sharpening_pipeline.layout), | ||
| &BindGroupEntries::sequential(( | ||
| view_target.source, | ||
| &sharpening_pipeline.sampler, | ||
| uniforms, | ||
| )), | ||
| ); | ||
|
|
||
| let (_, _, bind_group) = | ||
| cached_bind_group.insert((uniforms_id, source.id(), bind_group)); | ||
| bind_group | ||
| } | ||
| }; | ||
|
|
||
| let pass_descriptor = RenderPassDescriptor { | ||
| label: Some("contrast_adaptive_sharpening"), | ||
| color_attachments: &[Some(RenderPassColorAttachment { | ||
| view: destination, | ||
| depth_slice: None, | ||
| resolve_target: None, | ||
| ops: Operations::default(), | ||
| })], | ||
| depth_stencil_attachment: None, | ||
| timestamp_writes: None, | ||
| occlusion_query_set: None, | ||
| }; | ||
|
|
||
| let mut render_pass = render_context | ||
| .command_encoder() | ||
| .begin_render_pass(&pass_descriptor); | ||
| cached => { | ||
| let bind_group = ctx.render_device().create_bind_group( | ||
| "cas_bind_group", | ||
| &pipeline_cache.get_bind_group_layout(&sharpening_pipeline.layout), | ||
| &BindGroupEntries::sequential(( | ||
| view_target.source, | ||
| &sharpening_pipeline.sampler, | ||
| uniforms_binding, | ||
| )), | ||
| ); | ||
|
|
||
| let (_, _, bind_group) = cached.insert((uniforms_id, source.id(), bind_group)); | ||
| bind_group | ||
| } | ||
| }; | ||
|
|
||
| let pass_descriptor = RenderPassDescriptor { | ||
| label: Some("contrast_adaptive_sharpening"), | ||
| color_attachments: &[Some(RenderPassColorAttachment { | ||
| view: destination, | ||
| depth_slice: None, | ||
| resolve_target: None, | ||
| ops: Operations::default(), | ||
| })], | ||
| depth_stencil_attachment: None, | ||
| timestamp_writes: None, | ||
| occlusion_query_set: None, | ||
| }; | ||
|
|
||
| let diagnostics = ctx.diagnostic_recorder(); | ||
| let diagnostics = diagnostics.as_deref(); | ||
| let time_span = diagnostics.time_span(ctx.command_encoder(), "contrast_adaptive_sharpening"); | ||
|
|
||
| { | ||
| let mut render_pass = ctx.command_encoder().begin_render_pass(&pass_descriptor); | ||
| let pass_span = diagnostics.pass_span(&mut render_pass, "contrast_adaptive_sharpening"); | ||
|
|
||
| render_pass.set_pipeline(pipeline); | ||
| render_pass.set_bind_group(0, bind_group, &[uniform_index.index()]); | ||
| render_pass.draw(0..3, 0..1); | ||
|
|
||
| pass_span.end(&mut render_pass); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| time_span.end(ctx.command_encoder()); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes clean compile a bit worse cus linearizes compilation of these two crates, but its probably fine. could use system sets to avoid it though