Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially fix panics when setting WGPU_SETTINGS_PRIO=webgl2 #18113

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions crates/bevy_core_pipeline/src/experimental/mip_generation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ pub struct DownsampleDepthPipelines {
sampler: Sampler,
}

fn supports_compute_shaders(device: &RenderDevice, adapter: &RenderAdapter) -> bool {
adapter
.get_downlevel_capabilities()
.flags
.contains(DownlevelFlags::COMPUTE_SHADERS)
// Even if the adapter supports compute, we might be simulating a lack of
// compute via device limits (see `WgpuSettingsPriority::WebGL2` and
// `wgpu::Limits::downlevel_webgl2_defaults()`). This will have set all the
// `max_compute_*` limits to zero, so we arbitrarily pick one as a canary.
&& (device.limits().max_compute_workgroup_storage_size != 0)
}

/// Creates the [`DownsampleDepthPipelines`] if downsampling is supported on the
/// current platform.
fn create_downsample_depth_pipelines(
Expand All @@ -346,11 +358,7 @@ fn create_downsample_depth_pipelines(

// If we don't have compute shaders, we can't invoke the downsample depth
// compute shader.
if !render_adapter
.get_downlevel_capabilities()
.flags
.contains(DownlevelFlags::COMPUTE_SHADERS)
{
if !supports_compute_shaders(&render_device, &render_adapter) {
return;
}

Expand Down
14 changes: 14 additions & 0 deletions crates/bevy_core_pipeline/src/oit/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub const OIT_RESOLVE_SHADER_HANDLE: Handle<Shader> =
/// Contains the render node used to run the resolve pass.
pub mod node;

/// Minimum required value of `wgpu::Limits::max_storage_buffers_per_shader_stage`.
pub const OIT_REQUIRED_STORAGE_BUFFERS: u32 = 2;

/// Plugin needed to resolve the Order Independent Transparency (OIT) buffer to the screen.
pub struct OitResolvePlugin;
impl Plugin for OitResolvePlugin {
Expand Down Expand Up @@ -61,6 +64,17 @@ impl Plugin for OitResolvePlugin {
return;
}

if render_app
.world()
.resource::<RenderDevice>()
.limits()
.max_storage_buffers_per_shader_stage
< OIT_REQUIRED_STORAGE_BUFFERS
{
warn!("OrderIndependentTransparencyPlugin not loaded. RenderDevice lacks support: max_storage_buffers_per_shader_stage < OIT_REQUIRED_STORAGE_BUFFERS.");
return;
}

render_app
.add_systems(
Render,
Expand Down
6 changes: 5 additions & 1 deletion crates/bevy_pbr/src/render/mesh_view_bindings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use alloc::sync::Arc;
use bevy_core_pipeline::{
core_3d::ViewTransmissionTexture,
oit::{OitBuffers, OrderIndependentTransparencySettings},
oit::{
resolve::OIT_REQUIRED_STORAGE_BUFFERS, OitBuffers, OrderIndependentTransparencySettings,
},
prepass::ViewPrepassTextures,
tonemapping::{
get_lut_bind_group_layout_entries, get_lut_bindings, Tonemapping, TonemappingLuts,
Expand Down Expand Up @@ -388,6 +390,8 @@ fn layout_entries(
.get_downlevel_capabilities()
.flags
.contains(DownlevelFlags::FRAGMENT_WRITABLE_STORAGE)
&& (render_device.limits().max_storage_buffers_per_shader_stage
>= OIT_REQUIRED_STORAGE_BUFFERS)
{
entries = entries.extend_with_indices((
// oit_layers
Expand Down