From 25f96b349bf850a5db6dd165b9f35388f8043b9f Mon Sep 17 00:00:00 2001 From: Josh Groves Date: Sun, 30 Apr 2023 07:52:41 -0500 Subject: [PATCH 1/4] Pass correct surface for existing canvases (#3718) --- CHANGELOG.md | 6 ++++++ wgpu/src/backend/web.rs | 13 ------------- wgpu/src/context.rs | 2 +- wgpu/src/lib.rs | 8 ++++---- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49048f2f4c..36f2e4c5cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,12 @@ Bottom level categories: ## Unreleased +### Bug Fixes + +#### WebGPU + +* Fix crash when calling `create_surface_from_canvas`. By @grovesNL in [#3718](https://github.com/gfx-rs/wgpu/pull/3718) + ## v0.16.0 (2023-04-19) ### Major changes diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 8417dc39d5..299626eef1 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -63,19 +63,6 @@ impl From> for ObjectId { } } -#[allow(unused_variables)] -impl From<(Identified, Sendable)> for ObjectId { - fn from((id, _data): (Identified, Sendable)) -> Self { - Self::new( - // TODO: the ID isn't used, so we hardcode it to 1 for now until we rework this - // API. - core::num::NonZeroU64::new(1).unwrap(), - #[cfg(feature = "expose-ids")] - id.0, - ) - } -} - #[derive(Clone, Debug)] pub(crate) struct Sendable(T); unsafe impl Send for Sendable {} diff --git a/wgpu/src/context.rs b/wgpu/src/context.rs index 11a495aa7c..6633e61b61 100644 --- a/wgpu/src/context.rs +++ b/wgpu/src/context.rs @@ -1004,7 +1004,7 @@ pub struct ObjectId { } impl ObjectId { - const UNUSED: Self = ObjectId { + pub(crate) const UNUSED: Self = ObjectId { id: None, #[cfg(feature = "expose-ids")] global_id: None, diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index dbb8ac9100..3b98e1e1a6 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -1616,9 +1616,9 @@ impl Instance { #[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] data: Box::new(surface), #[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] - id: ObjectId::from(surface), + id: ObjectId::UNUSED, #[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] - data: Box::new(()), + data: Box::new(surface.1), config: Mutex::new(None), }) } @@ -1652,9 +1652,9 @@ impl Instance { #[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] data: Box::new(surface), #[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] - id: ObjectId::from(surface), + id: ObjectId::UNUSED, #[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] - data: Box::new(()), + data: Box::new(surface.1), config: Mutex::new(None), }) } From 979c80d5ff07a2c332ad851d824f164bc15a5501 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 3 May 2023 11:00:59 +0200 Subject: [PATCH 2/4] Fix crash on command buffer drop (#3726) --- CHANGELOG.md | 4 ++++ wgpu/src/lib.rs | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36f2e4c5cc..9a0287f43f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,10 @@ Bottom level categories: ### Bug Fixes +#### General + +- Fix crash on dropping `wgpu::CommandBuffer`. By @wumpf in [#3726](https://github.com/gfx-rs/wgpu/pull/3726). + #### WebGPU * Fix crash when calling `create_surface_from_canvas`. By @grovesNL in [#3718](https://github.com/gfx-rs/wgpu/pull/3718) diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 3b98e1e1a6..ea26098916 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -574,8 +574,9 @@ static_assertions::assert_impl_all!(CommandBuffer: Send, Sync); impl Drop for CommandBuffer { fn drop(&mut self) { if !thread::panicking() { - if let Some(ref id) = self.id { - self.context.command_buffer_drop(id, &self.data.take()); + if let Some(id) = self.id.take() { + self.context + .command_buffer_drop(&id, self.data.take().unwrap().as_ref()); } } } From acb7c4b685cdee28e05ea55508f95202c8b3613d Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Wed, 3 May 2023 20:56:54 -0400 Subject: [PATCH 3/4] fix(wgpu-core)!: use `u32` indices for bind group layouts everywhere (#3743) --- CHANGELOG.md | 1 + wgpu-core/src/binding_model.rs | 8 ++++---- wgpu-core/src/command/bundle.rs | 10 +++++----- wgpu-core/src/command/compute.rs | 10 +++++----- wgpu-core/src/command/draw.rs | 4 ++-- wgpu-core/src/command/render.rs | 6 +++--- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a0287f43f..8592bd1505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Bottom level categories: #### General - Fix crash on dropping `wgpu::CommandBuffer`. By @wumpf in [#3726](https://github.com/gfx-rs/wgpu/pull/3726). +- Use `u32`s internally for bind group indices, rather than `u8`. By @ErichDonGubler in [#3743](https://github.com/gfx-rs/wgpu/pull/3743). #### WebGPU diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 5c63ac43ff..97f56095f4 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -697,7 +697,7 @@ pub enum BindError { s1 = if *.actual >= 2 { "s" } else { "" }, )] MismatchedDynamicOffsetCount { - group: u8, + group: u32, actual: usize, expected: usize, }, @@ -706,7 +706,7 @@ pub enum BindError { )] UnalignedDynamicBinding { idx: usize, - group: u8, + group: u32, binding: u32, offset: u32, alignment: u32, @@ -718,7 +718,7 @@ pub enum BindError { )] DynamicBindingOutOfBounds { idx: usize, - group: u8, + group: u32, binding: u32, offset: u32, buffer_size: wgt::BufferAddress, @@ -780,7 +780,7 @@ pub struct BindGroup { impl BindGroup { pub(crate) fn validate_dynamic_bindings( &self, - bind_group_index: u8, + bind_group_index: u32, offsets: &[wgt::DynamicOffset], limits: &wgt::Limits, ) -> Result<(), BindError> { diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index fa95ff87fe..34d7e84cf4 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -302,7 +302,7 @@ impl RenderBundleEncoder { .map_pass_err(scope)?; let max_bind_groups = device.limits.max_bind_groups; - if (index as u32) >= max_bind_groups { + if index >= max_bind_groups { return Err(RenderCommandError::BindGroupIndexOutOfRange { index, max: max_bind_groups, @@ -784,7 +784,7 @@ impl RenderBundle { unsafe { raw.set_bind_group( &pipeline_layout_guard[pipeline_layout_id.unwrap()].raw, - index as u32, + index, &bind_group.raw, &offsets[..num_dynamic_offsets as usize], ) @@ -1222,7 +1222,7 @@ impl State { fn set_bind_group( &mut self, - slot: u8, + slot: u32, bind_group_id: id::BindGroupId, layout_id: id::Valid, dynamic_offsets: Range, @@ -1365,7 +1365,7 @@ impl State { contents.is_dirty = false; let offsets = &contents.dynamic_offsets; return Some(RenderCommand::SetBindGroup { - index: i as u8, + index: i.try_into().unwrap(), bind_group_id: contents.bind_group_id, num_dynamic_offsets: (offsets.end - offsets.start) as u8, }); @@ -1469,7 +1469,7 @@ pub mod bundle_ffi { } bundle.base.commands.push(RenderCommand::SetBindGroup { - index: index.try_into().unwrap(), + index, num_dynamic_offsets: offset_length.try_into().unwrap(), bind_group_id, }); diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index ce40b8b79f..d5b514f194 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -38,7 +38,7 @@ use std::{fmt, mem, str}; )] pub enum ComputeCommand { SetBindGroup { - index: u8, + index: u32, num_dynamic_offsets: u8, bind_group_id: id::BindGroupId, }, @@ -163,7 +163,7 @@ pub enum ComputePassErrorInner { #[error("Bind group {0:?} is invalid")] InvalidBindGroup(id::BindGroupId), #[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")] - BindGroupIndexOutOfRange { index: u8, max: u32 }, + BindGroupIndexOutOfRange { index: u32, max: u32 }, #[error("Compute pipeline {0:?} is invalid")] InvalidPipeline(id::ComputePipelineId), #[error("QuerySet {0:?} is invalid")] @@ -407,7 +407,7 @@ impl Global { let scope = PassErrorScope::SetBindGroup(bind_group_id); let max_bind_groups = cmd_buf.limits.max_bind_groups; - if (index as u32) >= max_bind_groups { + if index >= max_bind_groups { return Err(ComputePassErrorInner::BindGroupIndexOutOfRange { index, max: max_bind_groups, @@ -464,7 +464,7 @@ impl Global { unsafe { raw.set_bind_group( pipeline_layout, - index as u32 + i as u32, + index + i as u32, raw_bg, &e.dynamic_offsets, ); @@ -816,7 +816,7 @@ pub mod compute_ffi { } pass.base.commands.push(ComputeCommand::SetBindGroup { - index: index.try_into().unwrap(), + index, num_dynamic_offsets: offset_length.try_into().unwrap(), bind_group_id, }); diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index 26d2849e26..b629ffaba0 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -66,7 +66,7 @@ pub enum RenderCommandError { #[error("Render bundle {0:?} is invalid")] InvalidRenderBundle(id::RenderBundleId), #[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")] - BindGroupIndexOutOfRange { index: u8, max: u32 }, + BindGroupIndexOutOfRange { index: u32, max: u32 }, #[error("Dynamic buffer offset {0} does not respect device's requested `{1}` limit {2}")] UnalignedBufferOffset(u64, &'static str, u32), #[error("Number of buffer offsets ({actual}) does not match the number of dynamic bindings ({expected})")] @@ -148,7 +148,7 @@ pub struct Rect { )] pub enum RenderCommand { SetBindGroup { - index: u8, + index: u32, num_dynamic_offsets: u8, bind_group_id: id::BindGroupId, }, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 0570ae8a0a..b38e79c4b4 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1305,7 +1305,7 @@ impl Global { } => { let scope = PassErrorScope::SetBindGroup(bind_group_id); let max_bind_groups = device.limits.max_bind_groups; - if (index as u32) >= max_bind_groups { + if index >= max_bind_groups { return Err(RenderCommandError::BindGroupIndexOutOfRange { index, max: max_bind_groups, @@ -1372,7 +1372,7 @@ impl Global { unsafe { raw.set_bind_group( pipeline_layout, - index as u32 + i as u32, + index + i as u32, raw_bg, &e.dynamic_offsets, ); @@ -2225,7 +2225,7 @@ pub mod render_ffi { } pass.base.commands.push(RenderCommand::SetBindGroup { - index: index.try_into().unwrap(), + index, num_dynamic_offsets: offset_length.try_into().unwrap(), bind_group_id, }); From 6b2c114fc7f70a78ef91718f78ab9cefa6def0ee Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 19 May 2023 16:39:07 +0200 Subject: [PATCH 4/4] Fix missing 4X MSAA support on some OpenGL backends (#3780) * Always support 4x MSAA on GL * Update changelog --- CHANGELOG.md | 2 ++ wgpu-hal/src/gles/adapter.rs | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8592bd1505..fe486ffb2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,8 @@ Bottom level categories: ### Bug Fixes +- Fix missing 4X MSAA support on some OpenGL backends. By @emilk in [#3780](https://github.com/gfx-rs/wgpu/pull/3780) + #### General - Fix crash on dropping `wgpu::CommandBuffer`. By @wumpf in [#3726](https://github.com/gfx-rs/wgpu/pull/3726). diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 5ccae1154f..faea60e25c 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -713,10 +713,12 @@ impl crate::Adapter for super::Adapter { | Tfc::MULTISAMPLE_X16 } else if max_samples >= 8 { Tfc::MULTISAMPLE_X2 | Tfc::MULTISAMPLE_X4 | Tfc::MULTISAMPLE_X8 - } else if max_samples >= 4 { - Tfc::MULTISAMPLE_X2 | Tfc::MULTISAMPLE_X4 } else { - Tfc::MULTISAMPLE_X2 + // The lowest supported level in GLE3.0/WebGL2 is 4X + // (see GL_MAX_SAMPLES in https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glGet.xhtml). + // On some platforms, like iOS Safari, `get_parameter_i32(MAX_SAMPLES)` returns 0, + // so we always fall back to supporting 4x here. + Tfc::MULTISAMPLE_X2 | Tfc::MULTISAMPLE_X4 } };