Skip to content

Commit ebdd7d9

Browse files
authored
Fix(bg motion vectors): gate BackgroundMotionVectorsPlugin pipelines to DownlevelFlags(INDEPENDENT_BLEND) (#24067)
# Objective - Help out with #23975 - Fixes an issue on WebGL2 as a result of #23629 - Supporting #23975 on WebGL2 necessitates fixing the “Forward + Prepass” option on the `deferred_rendering` example. The WebGPU focused solution to #23629 requires this PR to also allow the “Forward + Prepass” option to work. ## Solution - @beicause mentioned gating the whole pipeline of `background_motion_vectors.rs` to `DownlevelFlags(INDEPENDENT_BLEND)` as implied in the error message in [this issue comment](#23975 (comment)). It works! ## Testing - Included the change from this PR on top of #24065, and it fixes the `deferred_rendering` example on WebGL2.
1 parent 2730c6e commit ebdd7d9

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

crates/bevy_core_pipeline/src/prepass/background_motion_vectors.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ use bevy_ecs::{
1818
schedule::IntoScheduleConfigs,
1919
system::{lifetimeless::Read, Commands, Query, Res, ResMut},
2020
};
21+
use bevy_log::warn;
2122
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
2223
use bevy_render::{
2324
extract_component::{ExtractComponent, ExtractComponentPlugin},
2425
render_resource::{
2526
binding_types::uniform_buffer, BindGroup, BindGroupEntries, BindGroupLayoutDescriptor,
2627
BindGroupLayoutEntries, CachedRenderPipelineId, CompareFunction, DepthStencilState,
27-
FragmentState, MultisampleState, PipelineCache, RenderPipelineDescriptor, ShaderStages,
28-
SpecializedRenderPipeline, SpecializedRenderPipelines,
28+
DownlevelFlags, FragmentState, MultisampleState, PipelineCache, RenderPipelineDescriptor,
29+
ShaderStages, SpecializedRenderPipeline, SpecializedRenderPipelines,
2930
},
30-
renderer::RenderDevice,
31+
renderer::{RenderAdapter, RenderDevice},
3132
sync_component::SyncComponent,
3233
view::{Msaa, ViewUniform, ViewUniforms},
3334
GpuResourceAppExt, Render, RenderApp, RenderStartup, RenderSystems,
@@ -84,19 +85,42 @@ pub struct BackgroundMotionVectorsBindGroup(pub BindGroup);
8485
#[derive(Default)]
8586
pub struct BackgroundMotionVectorsPlugin;
8687

88+
impl BackgroundMotionVectorsPlugin {
89+
/// [`DownlevelFlags`] required for this plugin to function.
90+
pub fn required_downlevel_flags() -> DownlevelFlags {
91+
DownlevelFlags::INDEPENDENT_BLEND
92+
}
93+
}
94+
8795
impl Plugin for BackgroundMotionVectorsPlugin {
8896
fn build(&self, app: &mut App) {
8997
embedded_asset!(app, "background_motion_vectors.wgsl");
90-
9198
app.register_type::<NoBackgroundMotionVectors>()
9299
.add_plugins(ExtractComponentPlugin::<NoBackgroundMotionVectors>::default());
93100

94101
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
95102
return;
96103
};
104+
render_app.init_gpu_resource::<PreviousViewUniforms>();
105+
}
106+
107+
fn finish(&self, app: &mut App) {
108+
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
109+
return;
110+
};
111+
112+
let render_adapter = render_app.world().resource::<RenderAdapter>();
113+
let downlevel_flags = render_adapter.get_downlevel_capabilities().flags;
114+
if !downlevel_flags.contains(BackgroundMotionVectorsPlugin::required_downlevel_flags()) {
115+
warn!(
116+
"BackgroundMotionVectorsPlugin not loaded. GPU lacks support for required downlevel capability flags: {:?}.",
117+
BackgroundMotionVectorsPlugin::required_downlevel_flags().difference(downlevel_flags)
118+
);
119+
return;
120+
}
121+
97122
render_app
98123
.init_gpu_resource::<SpecializedRenderPipelines<BackgroundMotionVectorsPipeline>>()
99-
.init_gpu_resource::<PreviousViewUniforms>()
100124
.add_systems(RenderStartup, init_background_motion_vectors_pipeline)
101125
.add_systems(
102126
Render,

0 commit comments

Comments
 (0)