Skip to content

Commit 3a91f1a

Browse files
committed
Talk about conditional_render_set in migration guide.
1 parent 15090bd commit 3a91f1a

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

release-content/migration-guides/render_startup.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,59 @@ system uses `Res<UiPipeline>`, you will need to add an ordering like:
135135
```rust
136136
render_app.add_systems(RenderStartup, init_my_resource.after(init_ui_pipeline));
137137
```
138+
139+
In Bevy internal code prior to 0.17, we've had plugins that conditionally add systems if some
140+
feature is supported or not. To support this workflow, we've created
141+
`bevy_render::conditional_render_set` which streamlines the process of creating these conditional
142+
sets of systems. For example, if in Bevy 0.16, your code looked like:
143+
144+
```rust
145+
impl Plugin for MyRenderingPlugin {
146+
fn build(&self, app: &mut App) {
147+
// Some other stuff, or even nothing!
148+
}
149+
150+
fn finish(&self, app: &mut App) {
151+
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
152+
return;
153+
};
154+
155+
let render_device = render_app.world().resource::<RenderDevice>();
156+
if render_device.limits().max_storage_textures_per_shader_stage < 5 {
157+
return;
158+
}
159+
160+
// This system isn't added to the schedule at all if the feature isn't supported.
161+
render_app.add_systems(Render, prepare_something);
162+
}
163+
}
164+
```
165+
166+
In Bevy 0.17, it would look like this:
167+
168+
```rust
169+
impl Plugin for MyRenderingPlugin {
170+
fn build(&self, app: &mut App) {
171+
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
172+
return;
173+
};
174+
175+
conditional_render_set(render_app, SomethingSystems, check_something_supported);
176+
177+
// This system doesn't run unless check_something_supported returned true.
178+
render_app.add_systems(Render, prepare_something.in_set(SomethingSystems));
179+
}
180+
181+
// No more finish!
182+
}
183+
184+
#[derive(SystemSet, PartialEq, Eq, Hash, Debug, Clone)]
185+
struct SomethingSystems;
186+
187+
fn check_something_supported(render_device: Res<RenderDevice>) -> bool {
188+
render_device.limits().max_storage_textures_per_shader_stage < 5
189+
}
190+
```
191+
192+
There are **many** ways to achieve this effect, so feel free to skip using `conditional_render_set`!
193+
This is just a convenience for adding run conditions!

0 commit comments

Comments
 (0)