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

Refactor render_system into multiple systems #11233

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ use crate::{
mesh::{morph::MorphPlugin, Mesh, MeshPlugin},
render_asset::prepare_assets,
render_resource::{PipelineCache, Shader, ShaderLoader},
renderer::{render_system, RenderInstance},
renderer::{
finalize_render_system, present_system, render_graph_system, send_time_system,
RenderInstance,
},
settings::RenderCreation,
view::{ViewPlugin, WindowRenderPlugin},
};
Expand Down Expand Up @@ -424,9 +427,13 @@ unsafe fn initialize_render_app(app: &mut App) {
// is running in parallel with the main app.
apply_extract_commands.in_set(RenderSet::ExtractCommands),
(
PipelineCache::process_pipeline_queue_system.before(render_system),
render_system,
PipelineCache::process_pipeline_queue_system,
render_graph_system,
present_system,
finalize_render_system,
send_time_system,
)
.chain()
.in_set(RenderSet::Render),
World::clear_entities.in_set(RenderSet::Cleanup),
),
Expand Down
59 changes: 33 additions & 26 deletions crates/bevy_render/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use wgpu::{
};

/// Updates the [`RenderGraph`] with all of its nodes and then runs it to render the entire frame.
pub fn render_system(world: &mut World) {
pub fn render_graph_system(world: &mut World) {
world.resource_scope(|world, mut graph: Mut<RenderGraph>| {
graph.update(world);
});
Expand Down Expand Up @@ -53,40 +53,47 @@ pub fn render_system(world: &mut World) {

panic!("Error running render graph: {e}");
}
}

{
let _span = info_span!("present_frames").entered();
/// Presents the frame in all extracted windows.
pub fn present_system(world: &mut World) {
let _span = info_span!("present_frames").entered();

// Remove ViewTarget components to ensure swap chain TextureViews are dropped.
// If all TextureViews aren't dropped before present, acquiring the next swap chain texture will fail.
let view_entities = world
.query_filtered::<Entity, With<ViewTarget>>()
.iter(world)
.collect::<Vec<_>>();
for view_entity in view_entities {
world.entity_mut(view_entity).remove::<ViewTarget>();
}
// Remove ViewTarget components to ensure swap chain TextureViews are dropped.
// If all TextureViews aren't dropped before present, acquiring the next swap chain texture will fail.
let view_entities = world
.query_filtered::<Entity, With<ViewTarget>>()
.iter(world)
.collect::<Vec<_>>();
for view_entity in view_entities {
world.entity_mut(view_entity).remove::<ViewTarget>();
}

let mut windows = world.resource_mut::<ExtractedWindows>();
for window in windows.values_mut() {
if let Some(wrapped_texture) = window.swap_chain_texture.take() {
if let Some(surface_texture) = wrapped_texture.try_unwrap() {
surface_texture.present();
}
let mut windows = world.resource_mut::<ExtractedWindows>();
for window in windows.values_mut() {
if let Some(wrapped_texture) = window.swap_chain_texture.take() {
if let Some(surface_texture) = wrapped_texture.try_unwrap() {
surface_texture.present();
}
}

#[cfg(feature = "tracing-tracy")]
bevy_utils::tracing::event!(
bevy_utils::tracing::Level::INFO,
message = "finished frame",
tracy.frame_mark = true
);
}

#[cfg(feature = "tracing-tracy")]
bevy_utils::tracing::event!(
bevy_utils::tracing::Level::INFO,
message = "finished frame",
tracy.frame_mark = true
);
}

/// Finalizes any post-rendering rendering tasks.
/// - Collects screenshots.
pub fn finalize_render_system(world: &mut World) {
crate::view::screenshot::collect_screenshots(world);
}

// update the time and send it to the app world
/// Updates the time and sends it to the app world.
pub fn send_time_system(world: &mut World) {
let time_sender = world.resource::<TimeSender>();
if let Err(error) = time_sender.0.try_send(Instant::now()) {
match error {
Expand Down