From ebe223cb5d9dfdd20e0978969807d6944d670742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 6 Sep 2025 06:16:00 +0200 Subject: [PATCH] Relax `Send` and `Sync` bounds for `wgpu::Primitive` on Wasm --- wgpu/src/primitive.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/wgpu/src/primitive.rs b/wgpu/src/primitive.rs index c8bcb65d..dd877d4d 100644 --- a/wgpu/src/primitive.rs +++ b/wgpu/src/primitive.rs @@ -1,6 +1,7 @@ //! Draw custom primitives. use crate::core::{self, Rectangle}; use crate::graphics::Viewport; +use crate::graphics::futures::{MaybeSend, MaybeSync}; use rustc_hash::FxHashMap; use std::any::{Any, TypeId}; @@ -10,7 +11,7 @@ use std::fmt::Debug; pub type Batch = Vec; /// A set of methods which allows a [`Primitive`] to be rendered. -pub trait Primitive: Debug + Send + Sync + 'static { +pub trait Primitive: Debug + MaybeSend + MaybeSync + 'static { /// Processes the [`Primitive`], allowing for GPU buffer allocation. fn prepare( &self, @@ -59,9 +60,10 @@ pub trait Renderer: core::Renderer { } /// Stores custom, user-provided types. -#[derive(Default, Debug)] +#[derive(Default)] +#[allow(missing_debug_implementations)] pub struct Storage { - pipelines: FxHashMap>, + pipelines: FxHashMap>, } impl Storage { @@ -71,14 +73,14 @@ impl Storage { } /// Inserts the data `T` in to [`Storage`]. - pub fn store(&mut self, data: T) { + pub fn store(&mut self, data: T) { let _ = self.pipelines.insert(TypeId::of::(), Box::new(data)); } /// Returns a reference to the data with type `T` if it exists in [`Storage`]. pub fn get(&self) -> Option<&T> { self.pipelines.get(&TypeId::of::()).map(|pipeline| { - pipeline + (pipeline.as_ref() as &dyn Any) .downcast_ref::() .expect("Value with this type does not exist in Storage.") }) @@ -87,9 +89,13 @@ impl Storage { /// Returns a mutable reference to the data with type `T` if it exists in [`Storage`]. pub fn get_mut(&mut self) -> Option<&mut T> { self.pipelines.get_mut(&TypeId::of::()).map(|pipeline| { - pipeline + (pipeline.as_mut() as &mut dyn Any) .downcast_mut::() .expect("Value with this type does not exist in Storage.") }) } } + +trait AnyConcurrent: Any + MaybeSend + MaybeSync {} + +impl AnyConcurrent for T where T: Any + MaybeSend + MaybeSync {}