Skip to content

Commit e2d96ac

Browse files
authored
Allow configuring fullscreen material system order (#23786)
# Objective Fixes #23781 When Hdr is on, the order of `tonemapping` and `fullscreen_material_system` is uncertain and the result of main pass can be cleared. `run_in` `run_before` `run_after` can only specify system set and can't specify a specific system and them hardcode `Core3dSystems`. ## Solution Replace `run_in` `run_before` `run_after` with `fn schedule_configs(system: ScheduleConfigs<BoxedSystem>) -> ScheduleConfigs<BoxedSystem>` ## Testing Run fullscreen_material example with Hdr
1 parent af04602 commit e2d96ac

3 files changed

Lines changed: 57 additions & 34 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: "`FullScreenMaterial` API changes"
3+
pull_requests: [23786]
4+
---
5+
6+
`FullScreenMaterial::run_in`, `FullScreenMaterial::run_after` and `FullScreenMaterial::run_before` are replaced
7+
by `FullScreenMaterial::schedule_configs` to configure the system order.
8+
9+
```rust
10+
// 0.18
11+
impl FullscreenMaterial for FullscreenEffect {
12+
fn fragment_shader() -> ShaderRef {
13+
"shaders/fullscreen_effect.wgsl".into()
14+
}
15+
fn run_in() -> impl SystemSet {
16+
Core3dSystems::PostProcess
17+
}
18+
fn run_after() -> Option<Core3dSystems> {
19+
None
20+
}
21+
fn run_before() -> Option<Core3dSystems> {
22+
None
23+
}
24+
}
25+
26+
// 0.19
27+
impl FullscreenMaterial for FullscreenEffect {
28+
fn fragment_shader() -> ShaderRef {
29+
"shaders/fullscreen_effect.wgsl".into()
30+
}
31+
fn schedule_configs(system: ScheduleConfigs<BoxedSystem>) -> ScheduleConfigs<BoxedSystem> {
32+
system
33+
.in_set(Core3dSystems::PostProcess)
34+
.before(tonemapping)
35+
}
36+
}
37+
```

crates/bevy_core_pipeline/src/fullscreen_material.rs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use core::any::type_name;
88
use core::marker::PhantomData;
99

10-
use crate::{schedule::Core3d, Core3dSystems, FullscreenShader};
10+
use crate::{schedule::Core3d, tonemapping::tonemapping, Core3dSystems, FullscreenShader};
1111
use bevy_app::{App, Plugin};
1212
use bevy_asset::AssetServer;
1313
use bevy_ecs::{
@@ -16,8 +16,8 @@ use bevy_ecs::{
1616
error::BevyError,
1717
query::With,
1818
resource::Resource,
19-
schedule::{IntoScheduleConfigs, ScheduleLabel, SystemSet},
20-
system::{Commands, Query, Res, ResMut},
19+
schedule::{IntoScheduleConfigs, ScheduleConfigs, ScheduleLabel},
20+
system::{BoxedSystem, Commands, Query, Res, ResMut},
2121
};
2222
use bevy_render::{
2323
camera::ExtractedCamera,
@@ -68,13 +68,7 @@ impl<T: FullscreenMaterial> Plugin for FullscreenMaterialPlugin<T> {
6868
),
6969
);
7070

71-
let mut system = fullscreen_material_system::<T>.in_set(T::run_in());
72-
if let Some(run_after) = T::run_after() {
73-
system = system.after(run_after);
74-
}
75-
if let Some(run_before) = T::run_before() {
76-
system = system.before(run_before);
77-
}
71+
let system = T::schedule_configs(fullscreen_material_system::<T>.into_configs());
7872
render_app.add_systems(T::schedule(), system);
7973
}
8074
}
@@ -93,30 +87,18 @@ pub trait FullscreenMaterial:
9387
Core3d
9488
}
9589

96-
/// The system set this effect belongs to.
97-
///
98-
/// Defaults to [`Core3dSystems::PostProcess`].
99-
fn run_in() -> impl SystemSet {
100-
Core3dSystems::PostProcess
101-
}
102-
103-
/// The system set this effect runs after.
104-
///
105-
/// Defaults to `None`.
106-
fn run_after() -> Option<Core3dSystems> {
107-
None
108-
}
109-
110-
/// The system set this effect runs before.
90+
/// Configures this effect's system set and system order.
11191
///
112-
/// Defaults to `None`.
113-
fn run_before() -> Option<Core3dSystems> {
114-
None
92+
/// By default it's in [`Core3dSystems::PostProcess`] and before [`tonemapping`].
93+
fn schedule_configs(system: ScheduleConfigs<BoxedSystem>) -> ScheduleConfigs<BoxedSystem> {
94+
system
95+
.in_set(Core3dSystems::PostProcess)
96+
.before(tonemapping)
11597
}
11698
}
11799

118100
#[derive(Resource)]
119-
struct FullscreenMaterialPipeline<T: FullscreenMaterial> {
101+
pub struct FullscreenMaterialPipeline<T: FullscreenMaterial> {
120102
layout: BindGroupLayoutDescriptor,
121103
sampler: Sampler,
122104
variants: Variants<RenderPipeline, FullscreenMaterialPipelineSpecializer>,
@@ -203,7 +185,7 @@ fn init_pipeline<T: FullscreenMaterial>(
203185
}
204186

205187
#[derive(Component)]
206-
struct FullscreenMaterialPipelineId(CachedRenderPipelineId);
188+
pub struct FullscreenMaterialPipelineId(pub CachedRenderPipelineId);
207189

208190
fn prepare_fullscreen_material_pipelines<T: FullscreenMaterial>(
209191
mut commands: Commands,
@@ -232,7 +214,7 @@ fn prepare_fullscreen_material_pipelines<T: FullscreenMaterial>(
232214
/// We can't know ahead of time which one is the source or destination so we create a bind group
233215
/// for both
234216
#[derive(Component)]
235-
struct FullscreenMaterialBindGroup<T: FullscreenMaterial> {
217+
pub struct FullscreenMaterialBindGroup<T: FullscreenMaterial> {
236218
a: (TextureViewId, BindGroup),
237219
b: (TextureViewId, BindGroup),
238220
// This is in case someone wants multiple `FullscreenMaterial` per camera
@@ -295,7 +277,7 @@ fn prepare_bind_groups<T: FullscreenMaterial>(
295277
}
296278
}
297279

298-
fn fullscreen_material_system<T: FullscreenMaterial>(
280+
pub fn fullscreen_material_system<T: FullscreenMaterial>(
299281
view: ViewQuery<(
300282
&ViewTarget,
301283
&DynamicUniformIndex<T>,

examples/shader_advanced/fullscreen_material.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ impl FullscreenMaterial for FullscreenEffect {
9191
// fn schedule() -> impl bevy::ecs::schedule::ScheduleLabel + Clone {
9292
// bevy::core_pipeline::Core2d
9393
// }
94-
// fn run_in() -> impl SystemSet {
95-
// bevy::core_pipeline::Core2dSystems::PostProcess
94+
// fn schedule_configs(
95+
// system: bevy::ecs::schedule::ScheduleConfigs<bevy::ecs::system::BoxedSystem>,
96+
// ) -> bevy::ecs::schedule::ScheduleConfigs<bevy::ecs::system::BoxedSystem> {
97+
// system
98+
// .in_set(bevy::core_pipeline::Core2dSystems::PostProcess)
99+
// .before(bevy::core_pipeline::tonemapping::tonemapping)
96100
// }
97101
}

0 commit comments

Comments
 (0)