diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index ab4c23b1c3bb5..e1c3f569fe0b2 100644 --- a/crates/bevy_core_pipeline/src/taa/mod.rs +++ b/crates/bevy_core_pipeline/src/taa/mod.rs @@ -60,7 +60,6 @@ impl Plugin for TemporalAntiAliasPlugin { let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return }; render_app - .init_resource::() .init_resource::>() .add_systems(ExtractSchedule, extract_taa_settings) .add_systems( @@ -84,6 +83,12 @@ impl Plugin for TemporalAntiAliasPlugin { ], ); } + + fn finish(&self, app: &mut App) { + let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return }; + + render_app.init_resource::(); + } } /// Bundle to apply temporal anti-aliasing. diff --git a/examples/2d/mesh2d_manual.rs b/examples/2d/mesh2d_manual.rs index 4e761edbfe4bb..0ad142a561ef5 100644 --- a/examples/2d/mesh2d_manual.rs +++ b/examples/2d/mesh2d_manual.rs @@ -277,15 +277,21 @@ impl Plugin for ColoredMesh2dPlugin { Shader::from_wgsl(COLORED_MESH2D_SHADER), ); - // Register our custom draw function and pipeline, and add our render systems + // Register our custom draw function, and add our render systems app.get_sub_app_mut(RenderApp) .unwrap() .add_render_command::() - .init_resource::() .init_resource::>() .add_systems(ExtractSchedule, extract_colored_mesh2d) .add_systems(Render, queue_colored_mesh2d.in_set(RenderSet::Queue)); } + + fn finish(&self, app: &mut App) { + // Register our custom pipeline + app.get_sub_app_mut(RenderApp) + .unwrap() + .init_resource::(); + } } /// Extract the [`ColoredMesh2d`] marker component into the render app diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 54f45e646bde6..2dc8c7a13c428 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -68,8 +68,6 @@ impl Plugin for PostProcessPlugin { }; render_app - // Initialize the pipeline - .init_resource::() // Bevy's renderer uses a render graph which is a collection of nodes in a directed acyclic graph. // It currently runs on each view/camera and executes each node in the specified order. // It will make sure that any node that needs a dependency from another node @@ -97,6 +95,17 @@ impl Plugin for PostProcessPlugin { ], ); } + + fn finish(&self, app: &mut App) { + // We need to get the render app from the main app + let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { + return; + }; + + render_app + // Initialize the pipeline + .init_resource::(); + } } /// The post process node used for the render graph diff --git a/examples/shader/texture_binding_array.rs b/examples/shader/texture_binding_array.rs index 0a88718ca7a36..22d4075a5e1d7 100644 --- a/examples/shader/texture_binding_array.rs +++ b/examples/shader/texture_binding_array.rs @@ -9,30 +9,17 @@ use bevy::{ render_resource::{AsBindGroupError, PreparedBindGroup, *}, renderer::RenderDevice, texture::FallbackImage, + RenderApp, }, }; -use std::num::NonZeroU32; +use std::{num::NonZeroU32, process::exit}; fn main() { let mut app = App::new(); app.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())); - let render_device = app.world.resource::(); - - // check if the device support the required feature - if !render_device - .features() - .contains(WgpuFeatures::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING) - { - error!( - "Render device doesn't support feature \ - SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, \ - which is required for texture binding arrays" - ); - return; - } - - app.add_plugin(MaterialPlugin::::default()) + app.add_plugin(GpuFeatureSupportChecker) + .add_plugin(MaterialPlugin::::default()) .add_systems(Startup, setup) .run(); } @@ -42,6 +29,34 @@ const TILE_ID: [usize; 16] = [ 19, 23, 4, 33, 12, 69, 30, 48, 10, 65, 40, 47, 57, 41, 44, 46, ]; +struct GpuFeatureSupportChecker; + +impl Plugin for GpuFeatureSupportChecker { + fn build(&self, _app: &mut App) {} + + fn finish(&self, app: &mut App) { + let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { + return + }; + + let render_device = render_app.world.resource::(); + + // Check if the device support the required feature. If not, exit the example. + // In a real application, you should setup a fallback for the missing feature + if !render_device + .features() + .contains(WgpuFeatures::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING) + { + error!( + "Render device doesn't support feature \ +SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, \ +which is required for texture binding arrays" + ); + exit(1); + } + } +} + fn setup( mut commands: Commands, mut meshes: ResMut>,