#[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))]
macro_rules! wgpu_wrapper {
($( $(#[$($attrs:tt)*])* $vis:vis struct $name:ident ($wgputy:ty) );+ $(;)?) => {
$(
$( #[$($attrs)*] )*
$vis struct $name ($wgputy);
impl $name {
pub fn new(t: $wgputy) -> Self {
Self(t)
}
#[allow(clippy::allow_attributes, unused, reason = "This is not used on all wrappers.")]
pub fn into_inner(self) -> $wgputy {
self.0
}
}
impl ::core::ops::Deref for $name {
type Target = $wgputy;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl ::core::ops::DerefMut for $name {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
const _: () = {
const fn assert_sync_send<T: Sync + Send>() {}
assert_sync_send::<$wgputy>()
};
#[expect(unsafe_code, reason = "Blanket-impl Send requires unsafe.")]
unsafe impl Send for $name {}
#[expect(unsafe_code, reason = "Blanket-impl Send requires unsafe.")]
unsafe impl Sync for $name {}
)+
};
}
#[cfg(all(target_arch = "wasm32", target_feature = "atomics"))]
macro_rules! wgpu_wrapper {
($( $(#[$($attrs:tt)*])* $vis:vis struct $name:ident ($wgputy:ty) );+ $(;)?) => {
$(
// On web + atomics we use SendWrapper to make the type unconditionally Send + Sync,
// but the value can only be accessed on the `wgpu` thread or it will panic.
// We don't need short circuits here since `SendWrapper` does it for us.
$( #[$($attrs)*] )*
$vis struct $name (send_wrapper::SendWrapper<$wgputy>);
impl $name {
pub fn new(t: $wgputy) -> Self {
Self(send_wrapper::SendWrapper::new(t))
}
#[allow(clippy::allow_attributes, unused, reason = "This is not used on all wrappers.")]
pub fn into_inner(self) -> $wgputy {
self.0.take()
}
}
impl ::core::ops::Deref for $name {
type Target = $wgputy;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl ::core::ops::DerefMut for $name {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
)+
};
}
pub(crate) use wgpu_wrapper;