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

Backport bugfixes to v0.16 #3774

Merged
merged 4 commits into from
May 25, 2023
Merged
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ Bottom level categories:

## Unreleased

### 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).
- Use `u32`s internally for bind group indices, rather than `u8`. By @ErichDonGubler in [#3743](https://github.com/gfx-rs/wgpu/pull/3743).

#### 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
Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ pub enum BindError {
s1 = if *.actual >= 2 { "s" } else { "" },
)]
MismatchedDynamicOffsetCount {
group: u8,
group: u32,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oi, this is, technically, a semver breaking change.

I think we could validly argue that while it is breaking, no one is going to be looking at it, only calling Display::fmt.

Let's go ahead with it.

actual: usize,
expected: usize,
},
Expand All @@ -706,7 +706,7 @@ pub enum BindError {
)]
UnalignedDynamicBinding {
idx: usize,
group: u8,
group: u32,
binding: u32,
offset: u32,
alignment: u32,
Expand All @@ -718,7 +718,7 @@ pub enum BindError {
)]
DynamicBindingOutOfBounds {
idx: usize,
group: u8,
group: u32,
binding: u32,
offset: u32,
buffer_size: wgt::BufferAddress,
Expand Down Expand Up @@ -780,7 +780,7 @@ pub struct BindGroup<A: HalApi> {
impl<A: HalApi> BindGroup<A> {
pub(crate) fn validate_dynamic_bindings(
&self,
bind_group_index: u8,
bind_group_index: u32,
offsets: &[wgt::DynamicOffset],
limits: &wgt::Limits,
) -> Result<(), BindError> {
Expand Down
10 changes: 5 additions & 5 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -784,7 +784,7 @@ impl<A: HalApi> RenderBundle<A> {
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],
)
Expand Down Expand Up @@ -1222,7 +1222,7 @@ impl<A: HalApi> State<A> {

fn set_bind_group(
&mut self,
slot: u8,
slot: u32,
bind_group_id: id::BindGroupId,
layout_id: id::Valid<id::BindGroupLayoutId>,
dynamic_offsets: Range<usize>,
Expand Down Expand Up @@ -1365,7 +1365,7 @@ impl<A: HalApi> State<A> {
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,
});
Expand Down Expand Up @@ -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,
});
Expand Down
10 changes: 5 additions & 5 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -407,7 +407,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
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,
Expand Down Expand Up @@ -464,7 +464,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
unsafe {
raw.set_bind_group(
pipeline_layout,
index as u32 + i as u32,
index + i as u32,
raw_bg,
&e.dynamic_offsets,
);
Expand Down Expand Up @@ -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,
});
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/command/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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})")]
Expand Down Expand Up @@ -148,7 +148,7 @@ pub struct Rect<T> {
)]
pub enum RenderCommand {
SetBindGroup {
index: u8,
index: u32,
num_dynamic_offsets: u8,
bind_group_id: id::BindGroupId,
},
Expand Down
6 changes: 3 additions & 3 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
} => {
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,
Expand Down Expand Up @@ -1372,7 +1372,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
unsafe {
raw.set_bind_group(
pipeline_layout,
index as u32 + i as u32,
index + i as u32,
raw_bg,
&e.dynamic_offsets,
);
Expand Down Expand Up @@ -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,
});
Expand Down
8 changes: 5 additions & 3 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,12 @@ impl crate::Adapter<super::Api> 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
}
};

Expand Down
13 changes: 0 additions & 13 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@ impl<T> From<Identified<T>> for ObjectId {
}
}

#[allow(unused_variables)]
impl<T> From<(Identified<T>, Sendable<T>)> for ObjectId {
fn from((id, _data): (Identified<T>, Sendable<T>)) -> 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>(T);
unsafe impl<T> Send for Sendable<T> {}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down Expand Up @@ -1616,9 +1617,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),
})
}
Expand Down Expand Up @@ -1652,9 +1653,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),
})
}
Expand Down