diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 325bfc6532..1a4b4ed0ec 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -692,10 +692,15 @@ impl Limits { /// These default limits are guarenteed to be compatible with GLES3, and D3D11, and WebGL2 pub fn downlevel_webgl2_defaults() -> Self { Self { + #[cfg(target_arch = "wasm32")] max_storage_buffers_per_shader_stage: 0, + #[cfg(target_arch = "wasm32")] max_storage_textures_per_shader_stage: 0, + #[cfg(target_arch = "wasm32")] max_dynamic_storage_buffers_per_pipeline_layout: 0, + #[cfg(target_arch = "wasm32")] max_storage_buffer_binding_size: 0, + #[cfg(target_arch = "wasm32")] max_vertex_buffer_array_stride: 255, // Most of the values should be the same as the downlevel defaults diff --git a/wgpu/examples/boids/main.rs b/wgpu/examples/boids/main.rs index 83442b25c8..54c1c47638 100644 --- a/wgpu/examples/boids/main.rs +++ b/wgpu/examples/boids/main.rs @@ -31,7 +31,7 @@ struct Example { } impl framework::Example for Example { - fn required_limits(_: &wgpu::Adapter) -> wgpu::Limits { + fn required_limits() -> wgpu::Limits { wgpu::Limits::downlevel_defaults() } diff --git a/wgpu/examples/framework.rs b/wgpu/examples/framework.rs index fb82952ffb..562b2d7204 100644 --- a/wgpu/examples/framework.rs +++ b/wgpu/examples/framework.rs @@ -47,8 +47,7 @@ pub trait Example: 'static + Sized { ..wgpu::DownlevelCapabilities::default() } } - fn required_limits(adapter: &wgpu::Adapter) -> wgpu::Limits { - let _ = adapter; + fn required_limits() -> wgpu::Limits { wgpu::Limits::downlevel_webgl2_defaults() // These downlevel limits will allow the code to run on all possible hardware } fn init( @@ -167,7 +166,7 @@ async fn setup(title: &str) -> Setup { ); // Make sure we use the texture resolution limits from the adapter, so we can support images the size of the surface. - let needed_limits = E::required_limits(&adapter).using_resolution(adapter.limits()); + let needed_limits = E::required_limits().using_resolution(adapter.limits()); let trace_dir = std::env::var("WGPU_TRACE"); let (device, queue) = adapter diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs index 2eedf62592..78b88854a8 100644 --- a/wgpu/examples/shadow/main.rs +++ b/wgpu/examples/shadow/main.rs @@ -213,25 +213,6 @@ impl framework::Example for Example { wgpu::Features::DEPTH_CLAMPING } - fn required_limits(adapter: &wgpu::Adapter) -> wgpu::Limits { - let downlevel_limits = wgpu::Limits::downlevel_defaults(); - let webgl_limits = wgpu::Limits::downlevel_webgl2_defaults(); - if adapter - .get_downlevel_properties() - .flags - .contains(wgpu::DownlevelFlags::VERTEX_STORAGE | wgpu::DownlevelFlags::FRAGMENT_STORAGE) - { - wgpu::Limits { - max_storage_buffers_per_shader_stage: downlevel_limits - .max_storage_buffers_per_shader_stage, - max_storage_buffer_binding_size: downlevel_limits.max_storage_buffer_binding_size, - ..webgl_limits - } - } else { - webgl_limits - } - } - fn init( sc_desc: &wgpu::SurfaceConfiguration, adapter: &wgpu::Adapter, @@ -241,7 +222,8 @@ impl framework::Example for Example { let supports_storage_resources = adapter .get_downlevel_properties() .flags - .contains(wgpu::DownlevelFlags::VERTEX_STORAGE); + .contains(wgpu::DownlevelFlags::VERTEX_STORAGE) + && device.limits().max_storage_buffers_per_shader_stage > 0; // Create the vertex and index buffers let vertex_size = mem::size_of::(); diff --git a/wgpu/examples/texture-arrays/main.rs b/wgpu/examples/texture-arrays/main.rs index ddd2a9631a..b126b7a8ad 100644 --- a/wgpu/examples/texture-arrays/main.rs +++ b/wgpu/examples/texture-arrays/main.rs @@ -78,7 +78,7 @@ impl framework::Example for Example { fn required_features() -> wgpu::Features { wgpu::Features::TEXTURE_BINDING_ARRAY | wgpu::Features::SPIRV_SHADER_PASSTHROUGH } - fn required_limits(_: &wgpu::Adapter) -> wgpu::Limits { + fn required_limits() -> wgpu::Limits { wgpu::Limits { max_push_constant_size: 4, ..wgpu::Limits::default()