bevy/examples/shader
François 71842c5ac9
Webgpu support (#8336)
# Objective

- Support WebGPU
- alternative to #5027 that doesn't need any async / await
- fixes #8315 
- Surprise fix #7318

## Solution

### For async renderer initialisation 

- Update the plugin lifecycle:
  - app builds the plugin
    - calls `plugin.build`
    - registers the plugin
  - app starts the event loop
- event loop waits for `ready` of all registered plugins in the same
order
    - returns `true` by default
- then call all `finish` then all `cleanup` in the same order as
registered
  - then execute the schedule

In the case of the renderer, to avoid anything async:
- building the renderer plugin creates a detached task that will send
back the initialised renderer through a mutex in a resource
- `ready` will wait for the renderer to be present in the resource
- `finish` will take that renderer and place it in the expected
resources by other plugins
- other plugins (that expect the renderer to be available) `finish` are
called and they are able to set up their pipelines
- `cleanup` is called, only custom one is still for pipeline rendering

### For WebGPU support

- update the `build-wasm-example` script to support passing `--api
webgpu` that will build the example with WebGPU support
- feature for webgl2 was always enabled when building for wasm. it's now
in the default feature list and enabled on all platforms, so check for
this feature must also check that the target_arch is `wasm32`

---

## Migration Guide

- `Plugin::setup` has been renamed `Plugin::cleanup`
- `Plugin::finish` has been added, and plugins adding pipelines should
do it in this function instead of `Plugin::build`
```rust
// Before
impl Plugin for MyPlugin {
    fn build(&self, app: &mut App) {
        app.insert_resource::<MyResource>
            .add_systems(Update, my_system);

        let render_app = match app.get_sub_app_mut(RenderApp) {
            Ok(render_app) => render_app,
            Err(_) => return,
        };

        render_app
            .init_resource::<RenderResourceNeedingDevice>()
            .init_resource::<OtherRenderResource>();
    }
}

// After
impl Plugin for MyPlugin {
    fn build(&self, app: &mut App) {
        app.insert_resource::<MyResource>
            .add_systems(Update, my_system);
    
        let render_app = match app.get_sub_app_mut(RenderApp) {
            Ok(render_app) => render_app,
            Err(_) => return,
        };
    
        render_app
            .init_resource::<OtherRenderResource>();
    }

    fn finish(&self, app: &mut App) {
        let render_app = match app.get_sub_app_mut(RenderApp) {
            Ok(render_app) => render_app,
            Err(_) => return,
        };
    
        render_app
            .init_resource::<RenderResourceNeedingDevice>();
    }
}
```
2023-05-04 22:07:57 +00:00
..
animate_shader.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
array_texture.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
compute_shader_game_of_life.rs Webgpu support (#8336) 2023-05-04 22:07:57 +00:00
custom_vertex_attribute.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
post_processing.rs Remove old post_processing example (#8376) 2023-04-15 21:48:31 +00:00
shader_defs.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
shader_instancing.rs Webgpu support (#8336) 2023-05-04 22:07:57 +00:00
shader_material.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
shader_material_glsl.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
shader_material_screenspace_texture.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
shader_prepass.rs Handle vertex_uvs if they are present in default prepass fragment shader (#8330) 2023-04-23 08:07:15 +00:00
texture_binding_array.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00