diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 38387c1fe0d..88aaf899f7a 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -45,10 +45,7 @@ pub mod resource; mod track; mod validation; -pub use hal::api; -pub use hal::MAX_BIND_GROUPS; -pub use hal::MAX_COLOR_TARGETS; -pub use hal::MAX_VERTEX_BUFFERS; +pub use hal::{api, MAX_BIND_GROUPS, MAX_COLOR_TARGETS, MAX_VERTEX_BUFFERS}; use atomic::{AtomicUsize, Ordering}; diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index cd27dda1fdc..2d236548d35 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -184,7 +184,7 @@ impl super::Adapter { log::info!("Vendor: {}", vendor); log::info!("Renderer: {}", renderer); - log::info!("Version: {}", &version); + log::info!("Version: {}", version); log::debug!("Extensions: {:#?}", extensions); @@ -254,13 +254,9 @@ impl super::Adapter { wgt::DownlevelFlags::VERTEX_STORAGE, ver >= (3, 1) && max_storage_block_size != 0 - && (vertex_shader_storage_blocks != 0 || vertex_ssbo_false_zero) - && !cfg!(target_arch = "wasm32"), - ); - downlevel_flags.set( - wgt::DownlevelFlags::FRAGMENT_STORAGE, - ver >= (3, 1) && !cfg!(target_arch = "wasm32"), + && (vertex_shader_storage_blocks != 0 || vertex_ssbo_false_zero), ); + downlevel_flags.set(wgt::DownlevelFlags::FRAGMENT_STORAGE, ver >= (3, 1)); let mut features = wgt::Features::empty() | wgt::Features::TEXTURE_COMPRESSION_ETC2 @@ -294,6 +290,10 @@ impl super::Adapter { super::PrivateCapabilities::INDEX_BUFFER_ROLE_CHANGE, cfg!(not(target_arch = "wasm32")), ); + private_caps.set( + super::PrivateCapabilities::CAN_DISABLE_DRAW_BUFFER, + cfg!(not(target_arch = "wasm32")), + ); let max_texture_size = gl.get_parameter_i32(glow::MAX_TEXTURE_SIZE) as u32; let max_texture_3d_size = gl.get_parameter_i32(glow::MAX_3D_TEXTURE_SIZE) as u32; @@ -352,8 +352,10 @@ impl super::Adapter { let mut workarounds = super::Workarounds::empty(); - #[cfg(target_arch = "wasm32")] - workarounds.set(super::Workarounds::EMULATE_BUFFER_MAP, true); + workarounds.set( + super::Workarounds::EMULATE_BUFFER_MAP, + cfg!(target_arch = "wasm32"), + ); let r = renderer.to_lowercase(); // Check for Mesa sRGB clear bug. See @@ -373,7 +375,9 @@ impl super::Adapter { let downlevel_defaults = wgt::DownlevelLimits {}; // Drop the GL guard so we can move the context into AdapterShared - #[cfg(not(target_arch = "wasm32"))] + // ( on WASM the gl handle is just a ref so we tell clippy to allow + // dropping the ref ) + #[allow(clippy::drop_ref)] drop(gl); Some(crate::ExposedAdapter { diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index b38410566af..8b78c345c8e 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -130,6 +130,8 @@ bitflags::bitflags! { /// Indicates that buffers used as ELEMENT_ARRAY_BUFFER may be created / initialized / used /// as other targets, if not present they must not be mixed with other targets. const INDEX_BUFFER_ROLE_CHANGE = 1 << 4; + /// Indicates that the device supports disabling draw buffers + const CAN_DISABLE_DRAW_BUFFER = 1 << 5; } } diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index ed1d9a550da..57a4c6b59fa 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -645,9 +645,15 @@ impl super::Queue { .map(|i| glow::COLOR_ATTACHMENT0 + i) .collect::>(); gl.draw_buffers(&indices); - #[cfg(not(target_arch = "wasm32"))] - for draw_buffer in 0..count as u32 { - gl.disable_draw_buffer(glow::BLEND, draw_buffer); + + if self + .shared + .private_caps + .contains(super::PrivateCapabilities::CAN_DISABLE_DRAW_BUFFER) + { + for draw_buffer in 0..count as u32 { + gl.disable_draw_buffer(glow::BLEND, draw_buffer); + } } } C::ClearColorF { @@ -906,8 +912,11 @@ impl super::Queue { gl.blend_equation_draw_buffer(index, blend.color.equation); gl.blend_func_draw_buffer(index, blend.color.src, blend.color.dst); } - } else { - #[cfg(not(target_arch = "wasm32"))] + } else if self + .shared + .private_caps + .contains(super::PrivateCapabilities::CAN_DISABLE_DRAW_BUFFER) + { gl.disable_draw_buffer(index, glow::BLEND); } } else { diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 1a4b4ed0ec0..ace6032c3fe 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -691,21 +691,22 @@ 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")] + #[cfg(target_arch = "wasm32")] + let defaults = Self { 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 ..Self::downlevel_defaults() - } + }; + + #[cfg(not(target_arch = "wasm32"))] + let defaults = Self::downlevel_defaults(); + + defaults } /// Modify the current limits to use the resolution limits of the other. diff --git a/wgpu/examples/framework.rs b/wgpu/examples/framework.rs index 562b2d72044..24aecbc0183 100644 --- a/wgpu/examples/framework.rs +++ b/wgpu/examples/framework.rs @@ -419,10 +419,10 @@ pub fn run(title: &str) { /// Parse the query string as returned by `web_sys::window()?.location().search()?` and get a /// specific key out of it. pub fn parse_url_query_string<'a>(query: &'a str, search_key: &str) -> Option<&'a str> { - let query_string = query.strip_prefix("?")?; + let query_string = query.strip_prefix('?')?; - for pair in query_string.split("&") { - let mut pair = pair.split("="); + for pair in query_string.split('&') { + let mut pair = pair.split('='); let key = pair.next()?; let value = pair.next()?;