Skip to content

Commit

Permalink
use better set inheritance in render systems (#7524)
Browse files Browse the repository at this point in the history
# Objective
Some render systems that have system set used as a label so that they can be referenced from somewhere else.
The 1:1 translation from `add_system_to_stage(Prepare, prepare_lights.label(PrepareLights))` is `add_system(prepare_lights.in_set(Prepare).in_set(PrepareLights)`, but configuring the `PrepareLights` set to be in `Prepare` would match the intention better (there are no systems in `PrepareLights` outside of `Prepare`) and it is easier for visualization tools to deal with.

# Solution

- replace
```rust
prepare_lights in PrepareLights
prepare_lights in Prepare
```
with
```rs
prepare_lights in PrepareLights
PrepareLights in Prepare
```

**Before**
![before](https://user-images.githubusercontent.com/22177966/216961792-a0f5eba7-f161-4994-b5a4-33e98763a3b0.svg)

**After**
![after](https://user-images.githubusercontent.com/22177966/216961790-857d0062-7943-49ef-8927-e602dfbab714.svg)
  • Loading branch information
jakobhellermann committed Feb 6, 2023
1 parent d26b63a commit 2e20d04
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 37 deletions.
15 changes: 6 additions & 9 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ impl Plugin for PbrPlugin {

// Extract the required data from the main world
render_app
.configure_set(RenderLightSystems::PrepareLights.in_set(RenderSet::Prepare))
.configure_set(RenderLightSystems::PrepareClusters.in_set(RenderSet::Prepare))
.configure_set(RenderLightSystems::QueueShadows.in_set(RenderSet::Queue))
.add_systems_to_schedule(
ExtractSchedule,
(
Expand All @@ -264,8 +267,7 @@ impl Plugin for PbrPlugin {
.add_system(
render::prepare_lights
.before(ViewSet::PrepareUniforms)
.in_set(RenderLightSystems::PrepareLights)
.in_set(RenderSet::Prepare),
.in_set(RenderLightSystems::PrepareLights),
)
// A sync is needed after prepare_lights, before prepare_view_uniforms,
// because prepare_lights creates new views for shadow mapping
Expand All @@ -277,14 +279,9 @@ impl Plugin for PbrPlugin {
.add_system(
render::prepare_clusters
.after(render::prepare_lights)
.in_set(RenderLightSystems::PrepareClusters)
.in_set(RenderSet::Prepare),
)
.add_system(
render::queue_shadows
.in_set(RenderLightSystems::QueueShadows)
.in_set(RenderSet::Queue),
.in_set(RenderLightSystems::PrepareClusters),
)
.add_system(render::queue_shadows.in_set(RenderLightSystems::QueueShadows))
.add_system(render::queue_shadow_view_bind_group.in_set(RenderSet::Queue))
.add_system(sort_phase_system::<Shadow>.in_set(RenderSet::PhaseSort))
.init_resource::<ShadowPipeline>()
Expand Down
6 changes: 1 addition & 5 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,7 @@ where
.init_resource::<RenderMaterials<M>>()
.init_resource::<SpecializedMeshPipelines<MaterialPipeline<M>>>()
.add_system_to_schedule(ExtractSchedule, extract_materials::<M>)
.add_system(
prepare_materials::<M>
.after(PrepareAssetLabel::PreAssetPrepare)
.in_set(RenderSet::Prepare),
)
.add_system(prepare_materials::<M>.after(PrepareAssetLabel::PreAssetPrepare))
.add_system(queue_material_meshes::<M>.in_set(RenderSet::Queue));
}

Expand Down
23 changes: 10 additions & 13 deletions crates/bevy_render/src/render_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,21 @@ impl<A: RenderAsset> Default for RenderAssetPlugin<A> {
impl<A: RenderAsset> Plugin for RenderAssetPlugin<A> {
fn build(&self, app: &mut App) {
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
let prepare_asset_system = prepare_assets::<A>.in_set(self.prepare_asset_label.clone());

let prepare_asset_system = match self.prepare_asset_label {
PrepareAssetLabel::PreAssetPrepare => prepare_asset_system,
PrepareAssetLabel::AssetPrepare => {
prepare_asset_system.after(PrepareAssetLabel::PreAssetPrepare)
}
PrepareAssetLabel::PostAssetPrepare => {
prepare_asset_system.after(PrepareAssetLabel::AssetPrepare)
}
};

render_app
.configure_sets(
(
PrepareAssetLabel::PreAssetPrepare,
PrepareAssetLabel::AssetPrepare,
PrepareAssetLabel::PostAssetPrepare,
)
.chain()
.in_set(RenderSet::Prepare),
)
.init_resource::<ExtractedAssets<A>>()
.init_resource::<RenderAssets<A>>()
.init_resource::<PrepareNextFrameAssets<A>>()
.add_system_to_schedule(ExtractSchedule, extract_render_asset::<A>)
.add_system(prepare_asset_system.in_set(RenderSet::Prepare));
.add_system(prepare_assets::<A>.in_set(self.prepare_asset_label.clone()));
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ impl Plugin for ViewPlugin {
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
render_app
.init_resource::<ViewUniforms>()
.add_system(
prepare_view_uniforms
.in_set(RenderSet::Prepare)
.in_set(ViewSet::PrepareUniforms),
)
.configure_set(ViewSet::PrepareUniforms.in_set(RenderSet::Prepare))
.add_system(prepare_view_uniforms.in_set(ViewSet::PrepareUniforms))
.add_system(
prepare_view_targets
.after(WindowSystem::Prepare)
Expand Down
7 changes: 2 additions & 5 deletions crates/bevy_render/src/view/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ impl Plugin for WindowRenderPlugin {
.init_resource::<WindowSurfaces>()
.init_non_send_resource::<NonSendMarker>()
.add_system_to_schedule(ExtractSchedule, extract_windows)
.add_system(
prepare_windows
.in_set(WindowSystem::Prepare)
.in_set(RenderSet::Prepare),
);
.configure_set(WindowSystem::Prepare.in_set(RenderSet::Prepare))
.add_system(prepare_windows.in_set(WindowSystem::Prepare));
}
}
}
Expand Down

0 comments on commit 2e20d04

Please sign in to comment.