diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index 34f4f3a97..086374e77 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -1128,8 +1128,8 @@ pub struct Sampler { impl crate::DynSampler for Sampler {} -unsafe impl Send for Sampler {} -unsafe impl Sync for Sampler {} +#[cfg(send_sync)] +static_assertions::assert_impl_all!(Sampler: Send, Sync); #[derive(Debug)] pub struct QuerySet { diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 632331651..3d6f050e2 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -344,6 +344,11 @@ struct Inner { srgb_kind: SrgbFrameBufferKind, } +#[cfg(send_sync)] +unsafe impl Send for Inner {} +#[cfg(send_sync)] +unsafe impl Sync for Inner {} + // Different calls to `eglGetPlatformDisplay` may return the same `Display`, making it a global // state of all our `EglContext`s. This forces us to track the number of such context to prevent // terminating the display if it's currently used by another `EglContext`. @@ -707,8 +712,8 @@ impl Instance { } } -unsafe impl Send for Instance {} -unsafe impl Sync for Instance {} +#[cfg(send_sync)] +static_assertions::assert_impl_all!(Instance: Send, Sync); impl crate::Instance for Instance { type A = super::Api; diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 9fee614a0..87c8be619 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -692,6 +692,11 @@ struct PipelineInner { clip_distance_count: u32, } +#[cfg(send_sync)] +unsafe impl Sync for PipelineInner {} +#[cfg(send_sync)] +unsafe impl Send for PipelineInner {} + #[derive(Clone, Debug)] struct DepthState { function: u32, @@ -750,9 +755,7 @@ pub struct RenderPipeline { impl crate::DynRenderPipeline for RenderPipeline {} #[cfg(send_sync)] -unsafe impl Sync for RenderPipeline {} -#[cfg(send_sync)] -unsafe impl Send for RenderPipeline {} +static_assertions::assert_impl_all!(RenderPipeline: Send, Sync); #[derive(Debug)] pub struct ComputePipeline { @@ -762,9 +765,7 @@ pub struct ComputePipeline { impl crate::DynComputePipeline for ComputePipeline {} #[cfg(send_sync)] -unsafe impl Sync for ComputePipeline {} -#[cfg(send_sync)] -unsafe impl Send for ComputePipeline {} +static_assertions::assert_impl_all!(ComputePipeline: Send, Sync); #[derive(Debug)] pub struct QuerySet { diff --git a/wgpu-hal/src/gles/web.rs b/wgpu-hal/src/gles/web.rs index c9c65a04b..b0e595345 100644 --- a/wgpu-hal/src/gles/web.rs +++ b/wgpu-hal/src/gles/web.rs @@ -107,9 +107,7 @@ impl Instance { } #[cfg(send_sync)] -unsafe impl Sync for Instance {} -#[cfg(send_sync)] -unsafe impl Send for Instance {} +static_assertions::assert_impl_all!(Instance: Send, Sync); impl crate::Instance for Instance { type A = super::Api; diff --git a/wgpu-hal/src/gles/wgl.rs b/wgpu-hal/src/gles/wgl.rs index dba309e50..6d3fac22f 100644 --- a/wgpu-hal/src/gles/wgl.rs +++ b/wgpu-hal/src/gles/wgl.rs @@ -41,8 +41,8 @@ pub struct AdapterContext { inner: Arc>, } -unsafe impl Sync for AdapterContext {} -unsafe impl Send for AdapterContext {} +#[cfg(send_sync)] +static_assertions::assert_impl_all!(AdapterContext: Send, Sync); impl AdapterContext { pub fn is_owned(&self) -> bool { @@ -182,8 +182,8 @@ pub struct Instance { inner: Arc>, } -unsafe impl Send for Instance {} -unsafe impl Sync for Instance {} +#[cfg(send_sync)] +static_assertions::assert_impl_all!(Instance: Send, Sync); fn load_gl_func(name: &str, module: Option) -> *const c_void { let addr = CString::new(name.as_bytes()).unwrap(); diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index ce2313c1a..1ef3c062a 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -219,8 +219,6 @@ clippy::single_match, // Push commands are more regular than macros. clippy::vec_init_then_push, - // We unsafe impl `Send` for a reason. - clippy::non_send_fields_in_send_ty, // TODO! clippy::missing_safety_doc, // It gets in the way a lot and does not prevent bugs in practice. diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 4874179d7..ef4ddcdd2 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -62,9 +62,6 @@ const MAX_ACCELERATION_STRUCTURES_PER_SHADER_STAGE: u32 = 1; // Use the end of the range for vertex buffers. pub const VERTEX_BUFFER_SLOT_START: u32 = 31 - 8; -unsafe impl Send for super::Adapter {} -unsafe impl Sync for super::Adapter {} - impl super::Adapter { pub(super) fn new(shared: Arc) -> Self { Self { shared } diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index d6a15119d..1b55f9820 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -392,8 +392,8 @@ struct AdapterShared { presentation_timer: time::PresentationTimer, } -unsafe impl Send for AdapterShared {} -unsafe impl Sync for AdapterShared {} +#[cfg(send_sync)] +static_assertions::assert_impl_all!(AdapterShared: Send, Sync); impl AdapterShared { fn new( @@ -446,13 +446,16 @@ pub struct Adapter { shared: Arc, } +#[cfg(send_sync)] +static_assertions::assert_impl_all!(Adapter: Send, Sync); + pub struct Queue { shared: Arc, timestamp_period: f32, } -unsafe impl Send for Queue {} -unsafe impl Sync for Queue {} +#[cfg(send_sync)] +static_assertions::assert_impl_all!(Queue: Send, Sync); impl Queue { pub unsafe fn queue_from_raw( @@ -703,8 +706,8 @@ pub struct Sampler { impl crate::DynSampler for Sampler {} -unsafe impl Send for Sampler {} -unsafe impl Sync for Sampler {} +#[cfg(send_sync)] +static_assertions::assert_impl_all!(Sampler: Send, Sync); impl Sampler { fn as_raw(&self) -> NonNull> { @@ -887,8 +890,8 @@ pub struct PassthroughShader { pub num_workgroups: HashMap, } -unsafe impl Send for PassthroughShader {} -unsafe impl Sync for PassthroughShader {} +#[cfg(send_sync)] +static_assertions::assert_impl_all!(PassthroughShader: Send, Sync); #[derive(Debug)] pub struct ShaderModule { @@ -993,8 +996,8 @@ pub struct RenderPipeline { )>, } -unsafe impl Send for RenderPipeline {} -unsafe impl Sync for RenderPipeline {} +#[cfg(send_sync)] +static_assertions::assert_impl_all!(RenderPipeline: Send, Sync); impl crate::DynRenderPipeline for RenderPipeline {} @@ -1004,8 +1007,8 @@ pub struct ComputePipeline { cs_info: PipelineStageInfo, } -unsafe impl Send for ComputePipeline {} -unsafe impl Sync for ComputePipeline {} +#[cfg(send_sync)] +static_assertions::assert_impl_all!(ComputePipeline: Send, Sync); impl crate::DynComputePipeline for ComputePipeline {}