Skip to content

Commit

Permalink
fix missed examples in WebGPU update (#8553)
Browse files Browse the repository at this point in the history
# Objective

- I missed a few examples in #8336 
- fixes #8556 
- fixes #8620

## Solution

- Update them
  • Loading branch information
mockersf authored May 16, 2023
1 parent 56686a8 commit e0b1809
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 22 deletions.
7 changes: 6 additions & 1 deletion crates/bevy_core_pipeline/src/taa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ impl Plugin for TemporalAntiAliasPlugin {
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return };

render_app
.init_resource::<TAAPipeline>()
.init_resource::<SpecializedRenderPipelines<TAAPipeline>>()
.add_systems(ExtractSchedule, extract_taa_settings)
.add_systems(
Expand All @@ -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::<TAAPipeline>();
}
}

/// Bundle to apply temporal anti-aliasing.
Expand Down
10 changes: 8 additions & 2 deletions examples/2d/mesh2d_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Transparent2d, DrawColoredMesh2d>()
.init_resource::<ColoredMesh2dPipeline>()
.init_resource::<SpecializedRenderPipelines<ColoredMesh2dPipeline>>()
.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::<ColoredMesh2dPipeline>();
}
}

/// Extract the [`ColoredMesh2d`] marker component into the render app
Expand Down
13 changes: 11 additions & 2 deletions examples/shader/post_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ impl Plugin for PostProcessPlugin {
};

render_app
// Initialize the pipeline
.init_resource::<PostProcessPipeline>()
// 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
Expand Down Expand Up @@ -99,6 +97,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::<PostProcessPipeline>();
}
}

/// The post process node used for the render graph
Expand Down
49 changes: 32 additions & 17 deletions examples/shader/texture_binding_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<RenderDevice>();

// 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::<BindlessMaterial>::default())
app.add_plugin(GpuFeatureSupportChecker)
.add_plugin(MaterialPlugin::<BindlessMaterial>::default())
.add_systems(Startup, setup)
.run();
}
Expand All @@ -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::<RenderDevice>();

// 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<Assets<Mesh>>,
Expand Down

0 comments on commit e0b1809

Please sign in to comment.