Skip to content

Commit ebd1078

Browse files
committed
Talk about conditional_render_set in migration guide.
1 parent cb6ecd5 commit ebd1078

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

release-content/migration-guides/render_startup.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,67 @@ 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(
176+
render_app,
177+
SomethingSystems,
178+
SomethingSupported,
179+
check_something_supported,
180+
);
181+
182+
// This system doesn't run unless check_something_supported returned true.
183+
render_app.add_systems(Render, prepare_something.in_set(SomethingSystems));
184+
}
185+
186+
// No more finish!
187+
}
188+
189+
#[derive(SystemSet, PartialEq, Eq, Hash, Debug, Clone)]
190+
struct SomethingSystems;
191+
192+
#[derive(SystemSet, PartialEq, Eq, Hash, Debug, Clone)]
193+
struct SomethingSupported;
194+
195+
fn check_something_supported(render_device: Res<RenderDevice>) -> bool {
196+
render_device.limits().max_storage_textures_per_shader_stage < 5
197+
}
198+
```
199+
200+
There are **many** ways to achieve this effect, so feel free to skip using `conditional_render_set`!
201+
This is just a convience for adding run conditions!

0 commit comments

Comments
 (0)