From d3d1a42bc3a20d8a9a24cc9a10e92668cf83cba9 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Wed, 27 Dec 2023 00:33:08 +0100 Subject: [PATCH 1/2] Add `cfg_aliases` to `wgpu` --- Cargo.lock | 1 + wgpu/Cargo.toml | 3 + wgpu/build.rs | 14 + wgpu/src/backend/direct.rs | 36 +-- wgpu/src/backend/mod.rs | 22 +- wgpu/src/backend/web.rs | 45 +-- wgpu/src/context.rs | 125 ++------ wgpu/src/lib.rs | 617 ++++++------------------------------- wgpu/src/util/init.rs | 8 +- 9 files changed, 164 insertions(+), 707 deletions(-) create mode 100644 wgpu/build.rs diff --git a/Cargo.lock b/Cargo.lock index 737dd49e12..cc102d9fe3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3994,6 +3994,7 @@ version = "0.18.0" dependencies = [ "arrayvec 0.7.4", "cfg-if", + "cfg_aliases", "js-sys", "log", "naga", diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 5418879df0..2a83aa364c 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -168,6 +168,9 @@ workspace = true features = ["clone"] optional = true +[build-dependencies] +cfg_aliases.workspace = true + # used to test all the example shaders [dev-dependencies.naga] workspace = true diff --git a/wgpu/build.rs b/wgpu/build.rs new file mode 100644 index 0000000000..b419deee24 --- /dev/null +++ b/wgpu/build.rs @@ -0,0 +1,14 @@ +fn main() { + cfg_aliases::cfg_aliases! { + native: { not(target_arch = "wasm32") }, + webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgl") }, + webgpu: { all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "webgl")) }, + emscripten: { all(target_arch = "wasm32", target_os = "emscripten") }, + send_sync: { any( + not(target_arch = "wasm32"), + all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics")) + ) }, + dx12: { all(target_os = "windows", feature = "dx12") }, + metal: { all(any(target_os = "ios", target_os = "macos"), feature = "metal") } + } +} diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 5dede69f3f..c2dde8838e 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -1,3 +1,5 @@ +#![allow(clippy::mismatched_target_os)] + use crate::{ context::{ObjectId, Unused}, AdapterInfo, BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource, BufferBinding, @@ -229,7 +231,7 @@ impl Context { self.0.generate_report() } - #[cfg(all(any(target_os = "ios", target_os = "macos"), feature = "metal"))] + #[cfg(metal)] pub unsafe fn create_surface_from_core_animation_layer( &self, layer: *mut std::ffi::c_void, @@ -241,7 +243,7 @@ impl Context { } } - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(any(webgpu, webgl))] pub fn instance_create_surface_from_canvas( &self, canvas: web_sys::HtmlCanvasElement, @@ -253,7 +255,7 @@ impl Context { }) } - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(any(webgpu, webgl))] pub fn instance_create_surface_from_offscreen_canvas( &self, canvas: web_sys::OffscreenCanvas, @@ -265,7 +267,7 @@ impl Context { }) } - #[cfg(all(target_os = "windows", feature = "dx12"))] + #[cfg(dx12)] pub unsafe fn create_surface_from_visual(&self, visual: *mut std::ffi::c_void) -> Surface { let id = unsafe { self.0.instance_create_surface_from_visual(visual, ()) }; Surface { @@ -274,7 +276,7 @@ impl Context { } } - #[cfg(all(target_os = "windows", feature = "dx12"))] + #[cfg(dx12)] pub unsafe fn create_surface_from_surface_handle( &self, surface_handle: *mut std::ffi::c_void, @@ -289,7 +291,7 @@ impl Context { } } - #[cfg(all(target_os = "windows", feature = "dx12"))] + #[cfg(dx12)] pub unsafe fn create_surface_from_swap_chain_panel( &self, swap_chain_panel: *mut std::ffi::c_void, @@ -1444,9 +1446,9 @@ impl crate::Context for Context { Err(e) => panic!("Error in Device::create_render_bundle_encoder: {e}"), } } - #[cfg_attr(target_arch = "wasm32", allow(unused))] + #[cfg_attr(not(any(native, emscripten)), allow(unused))] fn device_drop(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) { - #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] + #[cfg(any(native, emscripten))] { let global = &self.0; match wgc::gfx_select!(device => global.device_poll(*device, wgt::Maintain::Wait)) { @@ -2310,7 +2312,7 @@ impl crate::Context for Context { } } - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(any(webgpu, webgl))] fn queue_copy_external_image_to_texture( &self, queue: &Self::QueueId, @@ -3167,21 +3169,9 @@ pub struct BufferMappedRange { size: usize, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] unsafe impl Send for BufferMappedRange {} -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] unsafe impl Sync for BufferMappedRange {} impl crate::context::BufferMappedRange for BufferMappedRange { diff --git a/wgpu/src/backend/mod.rs b/wgpu/src/backend/mod.rs index 5680b6c5a6..9b8157e3ba 100644 --- a/wgpu/src/backend/mod.rs +++ b/wgpu/src/backend/mod.rs @@ -1,23 +1,9 @@ -#[cfg(all( - target_arch = "wasm32", - not(any(target_os = "emscripten", feature = "webgl")) -))] +#[cfg(webgpu)] mod web; -#[cfg(all( - target_arch = "wasm32", - not(any(target_os = "emscripten", feature = "webgl")) -))] +#[cfg(webgpu)] pub(crate) use web::Context; -#[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" -))] +#[cfg(not(webgpu))] mod direct; -#[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" -))] +#[cfg(not(webgpu))] pub(crate) use direct::Context; diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 04069f224b..4db98c76f9 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -57,50 +57,26 @@ impl From> for ObjectId { #[derive(Clone, Debug)] pub(crate) struct Sendable(T); -#[cfg(all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") -))] +#[cfg(send_sync)] unsafe impl Send for Sendable {} -#[cfg(all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") -))] +#[cfg(send_sync)] unsafe impl Sync for Sendable {} #[derive(Clone, Debug)] pub(crate) struct Identified(std::num::NonZeroU64, PhantomData); -#[cfg(all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") -))] +#[cfg(send_sync)] unsafe impl Send for Identified {} -#[cfg(all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") -))] +#[cfg(send_sync)] unsafe impl Sync for Identified {} pub(crate) struct Context(web_sys::Gpu); -#[cfg(all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") -))] +#[cfg(send_sync)] unsafe impl Send for Context {} -#[cfg(all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") -))] +#[cfg(send_sync)] unsafe impl Sync for Context {} -#[cfg(all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") -))] +#[cfg(send_sync)] unsafe impl Send for BufferMappedRange {} -#[cfg(all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") -))] +#[cfg(send_sync)] unsafe impl Sync for BufferMappedRange {} impl fmt::Debug for Context { @@ -157,10 +133,7 @@ impl MakeSendFuture { } } -#[cfg(all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") -))] +#[cfg(send_sync)] unsafe impl Send for MakeSendFuture {} fn map_texture_format(texture_format: wgt::TextureFormat) -> web_sys::GpuTextureFormat { diff --git a/wgpu/src/context.rs b/wgpu/src/context.rs index 45f27dce19..7494fa5fd5 100644 --- a/wgpu/src/context.rs +++ b/wgpu/src/context.rs @@ -321,10 +321,7 @@ pub trait Context: Debug + WasmNotSendSync + Sized { buffer_data: &Self::BufferData, sub_range: Range, ) -> Box; - #[cfg(all( - target_arch = "wasm32", - not(any(target_os = "emscripten", feature = "webgl")) - ))] + #[cfg(webgpu)] fn buffer_get_mapped_range_as_array_buffer( &self, buffer: &Self::BufferId, @@ -585,7 +582,7 @@ pub trait Context: Debug + WasmNotSendSync + Sized { data_layout: ImageDataLayout, size: Extent3d, ); - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(any(webgl, webgpu))] fn queue_copy_external_image_to_texture( &self, queue: &Self::QueueId, @@ -1068,13 +1065,7 @@ impl ObjectId { } } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(ObjectId: Send, Sync); pub(crate) fn downcast_ref(data: &crate::Data) -> &T { @@ -1115,109 +1106,37 @@ pub(crate) struct DeviceRequest { pub queue_data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] pub type BufferMapCallback = Box) + Send + 'static>; -#[cfg(not(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -)))] +#[cfg(not(send_sync))] pub type BufferMapCallback = Box) + 'static>; -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] pub(crate) type AdapterRequestDeviceFuture = Box> + Send>; -#[cfg(not(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -)))] +#[cfg(not(send_sync))] pub(crate) type AdapterRequestDeviceFuture = Box>>; -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] pub type InstanceRequestAdapterFuture = Box)>> + Send>; -#[cfg(not(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -)))] +#[cfg(not(send_sync))] pub type InstanceRequestAdapterFuture = Box)>>>; -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] pub type DevicePopErrorFuture = Box> + Send>; -#[cfg(not(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -)))] +#[cfg(not(send_sync))] pub type DevicePopErrorFuture = Box>>; -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] pub type SubmittedWorkDoneCallback = Box; -#[cfg(not(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -)))] +#[cfg(not(send_sync))] pub type SubmittedWorkDoneCallback = Box; -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] pub type DeviceLostCallback = Box; -#[cfg(not(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -)))] +#[cfg(not(send_sync))] pub type DeviceLostCallback = Box; /// An object safe variant of [`Context`] implemented by all types that implement [`Context`]. @@ -1427,10 +1346,7 @@ pub(crate) trait DynContext: Debug + WasmNotSendSync { buffer_data: &crate::Data, sub_range: Range, ) -> Box; - #[cfg(all( - target_arch = "wasm32", - not(any(target_os = "emscripten", feature = "webgl")) - ))] + #[cfg(webgpu)] fn buffer_get_mapped_range_as_array_buffer( &self, buffer: &ObjectId, @@ -1651,7 +1567,7 @@ pub(crate) trait DynContext: Debug + WasmNotSendSync { data_layout: ImageDataLayout, size: Extent3d, ); - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(any(webgpu, webgl))] fn queue_copy_external_image_to_texture( &self, queue: &ObjectId, @@ -2551,10 +2467,7 @@ where Context::buffer_get_mapped_range(self, &buffer, buffer_data, sub_range) } - #[cfg(all( - target_arch = "wasm32", - not(any(target_os = "emscripten", feature = "webgl")) - ))] + #[cfg(webgpu)] fn buffer_get_mapped_range_as_array_buffer( &self, buffer: &ObjectId, @@ -3098,7 +3011,7 @@ where Context::queue_write_texture(self, &queue, queue_data, texture, data, data_layout, size) } - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(any(webgpu, webgl))] fn queue_copy_external_image_to_texture( &self, queue: &ObjectId, diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index c7266d9bfb..5d316a4aee 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -97,26 +97,18 @@ pub use wgt::{ QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT, }; -#[cfg(any( - not(target_arch = "wasm32"), - feature = "webgl", - target_os = "emscripten" -))] +#[cfg(not(webgpu))] #[doc(hidden)] pub use ::hal; #[cfg(feature = "naga")] pub use ::naga; -#[cfg(any( - not(target_arch = "wasm32"), - feature = "webgl", - target_os = "emscripten" -))] +#[cfg(not(webgpu))] #[doc(hidden)] pub use ::wgc as core; // wasm-only types, we try to keep as many types non-platform // specific, but these need to depend on web-sys. -#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] +#[cfg(any(webgpu, webgl))] pub use wgt::{ExternalImageSource, ImageCopyExternalImage}; /// Filter for error scopes. @@ -130,21 +122,9 @@ pub enum ErrorFilter { static_assertions::assert_impl_all!(ErrorFilter: Send, Sync); type C = dyn DynContext; -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] type Data = dyn Any + Send + Sync; -#[cfg(not(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -)))] +#[cfg(not(send_sync))] type Data = dyn Any; /// Context for all other wgpu objects. Instance of wgpu. @@ -159,13 +139,7 @@ type Data = dyn Any; pub struct Instance { context: Arc, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(Instance: Send, Sync); /// Handle to a physical graphics and/or compute device. @@ -182,13 +156,7 @@ pub struct Adapter { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(Adapter: Send, Sync); impl Drop for Adapter { @@ -213,13 +181,7 @@ pub struct Device { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(Device: Send, Sync); /// Identifier for a particular call to [`Queue::submit`]. Can be used @@ -230,13 +192,7 @@ static_assertions::assert_impl_all!(Device: Send, Sync); /// There is no analogue in the WebGPU specification. #[derive(Debug, Clone)] pub struct SubmissionIndex(ObjectId, Arc); -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(SubmissionIndex: Send, Sync); /// The main purpose of this struct is to resolve mapped ranges (convert sizes @@ -313,13 +269,7 @@ pub struct Buffer { usage: BufferUsages, // Todo: missing map_state https://www.w3.org/TR/webgpu/#dom-gpubuffer-mapstate } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(Buffer: Send, Sync); /// Slice into a [`Buffer`]. @@ -336,13 +286,7 @@ pub struct BufferSlice<'a> { offset: BufferAddress, size: Option, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(BufferSlice<'_>: Send, Sync); /// Handle to a texture on the GPU. @@ -358,13 +302,7 @@ pub struct Texture { owned: bool, descriptor: TextureDescriptor<'static>, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(Texture: Send, Sync); /// Handle to a texture view. @@ -379,13 +317,7 @@ pub struct TextureView { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(TextureView: Send, Sync); /// Handle to a sampler. @@ -403,13 +335,7 @@ pub struct Sampler { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(Sampler: Send, Sync); impl Drop for Sampler { @@ -472,13 +398,7 @@ impl<'window> fmt::Debug for Surface<'window> { } } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(Surface<'_>: Send, Sync); impl Drop for Surface<'_> { @@ -506,13 +426,7 @@ pub struct BindGroupLayout { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(BindGroupLayout: Send, Sync); impl Drop for BindGroupLayout { @@ -538,13 +452,7 @@ pub struct BindGroup { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(BindGroup: Send, Sync); impl Drop for BindGroup { @@ -569,13 +477,7 @@ pub struct ShaderModule { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(ShaderModule: Send, Sync); impl Drop for ShaderModule { @@ -669,13 +571,7 @@ pub struct PipelineLayout { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(PipelineLayout: Send, Sync); impl Drop for PipelineLayout { @@ -699,13 +595,7 @@ pub struct RenderPipeline { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(RenderPipeline: Send, Sync); impl Drop for RenderPipeline { @@ -740,13 +630,7 @@ pub struct ComputePipeline { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(ComputePipeline: Send, Sync); impl Drop for ComputePipeline { @@ -784,13 +668,7 @@ pub struct CommandBuffer { id: Option, data: Option>, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(CommandBuffer: Send, Sync); impl Drop for CommandBuffer { @@ -819,13 +697,7 @@ pub struct CommandEncoder { id: Option, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(CommandEncoder: Send, Sync); impl Drop for CommandEncoder { @@ -914,13 +786,7 @@ pub struct RenderBundle { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(RenderBundle: Send, Sync); impl Drop for RenderBundle { @@ -943,20 +809,8 @@ pub struct QuerySet { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] +#[cfg(send_sync)] static_assertions::assert_impl_all!(QuerySet: Send, Sync); impl Drop for QuerySet { @@ -980,13 +834,7 @@ pub struct Queue { id: ObjectId, data: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(Queue: Send, Sync); impl Drop for Queue { @@ -1040,13 +888,7 @@ pub enum BindingResource<'a> { /// [`BindGroupLayoutEntry::count`] set to Some. TextureViewArray(&'a [&'a TextureView]), } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(BindingResource<'_>: Send, Sync); /// Describes the segment of a buffer to bind. @@ -1078,13 +920,7 @@ pub struct BufferBinding<'a> { /// Size of the binding in bytes, or `None` for using the rest of the buffer. pub size: Option, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(BufferBinding<'_>: Send, Sync); /// Operation to perform to the output attachment at the start of a render pass. @@ -1181,13 +1017,7 @@ pub struct RenderPassTimestampWrites<'a> { /// The index of the query set at which an end timestamp of this pass is written, if any. pub end_of_pass_write_index: Option, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(RenderPassTimestampWrites<'_>: Send, Sync); /// Describes a color attachment to a [`RenderPass`]. @@ -1207,13 +1037,7 @@ pub struct RenderPassColorAttachment<'tex> { /// What operations will be performed on this color attachment. pub ops: Operations, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(RenderPassColorAttachment<'_>: Send, Sync); /// Describes a depth/stencil attachment to a [`RenderPass`]. @@ -1231,13 +1055,7 @@ pub struct RenderPassDepthStencilAttachment<'tex> { /// What operations will be performed on the stencil part of the attachment. pub stencil_ops: Option>, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(RenderPassDepthStencilAttachment<'_>: Send, Sync); // The underlying types are also exported so that documentation shows up for them @@ -1252,13 +1070,7 @@ pub use wgt::RequestAdapterOptions as RequestAdapterOptionsBase; /// Corresponds to [WebGPU `GPURequestAdapterOptions`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpurequestadapteroptions). pub type RequestAdapterOptions<'a, 'b> = RequestAdapterOptionsBase<&'a Surface<'b>>; -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(RequestAdapterOptions<'_, '_>: Send, Sync); /// Describes a [`Device`]. /// @@ -1311,13 +1123,7 @@ static_assertions::assert_impl_all!(QuerySetDescriptor<'_>: Send, Sync); pub use wgt::Maintain as MaintainBase; /// Passed to [`Device::poll`] to control how and if it should block. pub type Maintain = wgt::Maintain; -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(Maintain: Send, Sync); /// Describes a [`TextureView`]. @@ -1373,13 +1179,7 @@ pub struct PipelineLayoutDescriptor<'a> { /// If this array is non-empty, the [`Features::PUSH_CONSTANTS`] must be enabled. pub push_constant_ranges: &'a [PushConstantRange], } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(PipelineLayoutDescriptor<'_>: Send, Sync); /// Describes a [`Sampler`]. @@ -1449,13 +1249,7 @@ pub struct BindGroupEntry<'a> { /// Resource to attach to the binding pub resource: BindingResource<'a>, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(BindGroupEntry<'_>: Send, Sync); /// Describes a group of bindings and the resources to be bound. @@ -1473,13 +1267,7 @@ pub struct BindGroupDescriptor<'a> { /// The resources to bind to this bind group. pub entries: &'a [BindGroupEntry<'a>], } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(BindGroupDescriptor<'_>: Send, Sync); /// Describes the attachments of a render pass. @@ -1506,13 +1294,7 @@ pub struct RenderPassDescriptor<'tex, 'desc> { /// Defines where the occlusion query results will be stored for this pass. pub occlusion_query_set: Option<&'tex QuerySet>, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(RenderPassDescriptor<'_, '_>: Send, Sync); /// Describes how the vertex buffer is interpreted. @@ -1548,13 +1330,7 @@ pub struct VertexState<'a> { /// The format of any vertex buffers used with this pipeline. pub buffers: &'a [VertexBufferLayout<'a>], } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(VertexState<'_>: Send, Sync); /// Describes the fragment processing in a render pipeline. @@ -1573,13 +1349,7 @@ pub struct FragmentState<'a> { /// The color state of the render targets. pub targets: &'a [Option], } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(FragmentState<'_>: Send, Sync); /// Describes a render (graphics) pipeline. @@ -1608,13 +1378,7 @@ pub struct RenderPipelineDescriptor<'a> { /// layers the attachments will have. pub multiview: Option, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(RenderPipelineDescriptor<'_>: Send, Sync); /// Describes the timestamp writes of a compute pass. @@ -1633,13 +1397,7 @@ pub struct ComputePassTimestampWrites<'a> { /// The index of the query set at which an end timestamp of this pass is written, if any. pub end_of_pass_write_index: Option, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(ComputePassTimestampWrites<'_>: Send, Sync); /// Describes the attachments of a compute pass. @@ -1657,13 +1415,7 @@ pub struct ComputePassDescriptor<'a> { /// Requires [`Features::TIMESTAMP_QUERY`] to be enabled. pub timestamp_writes: Option>, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(ComputePassDescriptor<'_>: Send, Sync); /// Describes a compute pipeline. @@ -1684,13 +1436,7 @@ pub struct ComputePipelineDescriptor<'a> { /// and no return value in the shader. pub entry_point: &'a str, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(ComputePipelineDescriptor<'_>: Send, Sync); pub use wgt::ImageCopyBuffer as ImageCopyBufferBase; @@ -1699,13 +1445,7 @@ pub use wgt::ImageCopyBuffer as ImageCopyBufferBase; /// Corresponds to [WebGPU `GPUImageCopyBuffer`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpuimagecopybuffer). pub type ImageCopyBuffer<'a> = ImageCopyBufferBase<&'a Buffer>; -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(ImageCopyBuffer<'_>: Send, Sync); pub use wgt::ImageCopyTexture as ImageCopyTextureBase; @@ -1714,13 +1454,7 @@ pub use wgt::ImageCopyTexture as ImageCopyTextureBase; /// Corresponds to [WebGPU `GPUImageCopyTexture`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpuimagecopytexture). pub type ImageCopyTexture<'a> = ImageCopyTextureBase<&'a Texture>; -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(ImageCopyTexture<'_>: Send, Sync); pub use wgt::ImageCopyTextureTagged as ImageCopyTextureTaggedBase; @@ -1730,13 +1464,7 @@ pub use wgt::ImageCopyTextureTagged as ImageCopyTextureTaggedBase; /// Corresponds to [WebGPU `GPUImageCopyTextureTagged`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpuimagecopytexturetagged). pub type ImageCopyTextureTagged<'a> = ImageCopyTextureTaggedBase<&'a Texture>; -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(ImageCopyTexture<'_>: Send, Sync); /// Describes a [`BindGroupLayout`]. @@ -1795,13 +1523,7 @@ pub struct SurfaceTexture { presented: bool, detail: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(SurfaceTexture: Send, Sync); /// Result of an unsuccessful call to [`Surface::get_current_texture`]. @@ -1905,11 +1627,7 @@ impl Instance { /// # Safety /// /// Refer to the creation of wgpu-hal Instance for every backend. - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub unsafe fn from_hal(hal_instance: A::Instance) -> Self { Self { context: Arc::new(unsafe { @@ -1928,11 +1646,7 @@ impl Instance { /// - The raw instance handle returned must not be manually destroyed. /// /// [`Instance`]: hal::Api::Instance - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub unsafe fn as_hal(&self) -> Option<&A::Instance> { unsafe { self.context @@ -1952,11 +1666,7 @@ impl Instance { /// # Safety /// /// Refer to the creation of wgpu-core Instance. - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub unsafe fn from_core(core_instance: wgc::instance::Instance) -> Self { Self { context: Arc::new(unsafe { @@ -1970,11 +1680,7 @@ impl Instance { /// # Arguments /// /// - `backends` - Backends from which to enumerate adapters. - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub fn enumerate_adapters(&self, backends: Backends) -> impl ExactSizeIterator { let context = Arc::clone(&self.context); self.context @@ -2013,11 +1719,7 @@ impl Instance { /// # Safety /// /// `hal_adapter` must be created from this instance internal handle. - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub unsafe fn create_adapter_from_hal( &self, hal_adapter: hal::ExposedAdapter, @@ -2121,7 +1823,7 @@ impl Instance { /// # Safety /// /// - layer must be a valid object to create a surface upon. - #[cfg(all(any(target_os = "ios", target_os = "macos"), feature = "metal"))] + #[cfg(metal)] pub unsafe fn create_surface_from_core_animation_layer( &self, layer: *mut std::ffi::c_void, @@ -2147,7 +1849,7 @@ impl Instance { /// # Safety /// /// - visual must be a valid IDCompositionVisual to create a surface upon. - #[cfg(all(target_os = "windows", feature = "dx12"))] + #[cfg(dx12)] pub unsafe fn create_surface_from_visual( &self, visual: *mut std::ffi::c_void, @@ -2173,7 +1875,7 @@ impl Instance { /// # Safety /// /// - surface_handle must be a valid SurfaceHandle to create a surface upon. - #[cfg(all(target_os = "windows", feature = "dx12"))] + #[cfg(dx12)] pub unsafe fn create_surface_from_surface_handle( &self, surface_handle: *mut std::ffi::c_void, @@ -2199,7 +1901,7 @@ impl Instance { /// # Safety /// /// - visual must be a valid SwapChainPanel to create a surface upon. - #[cfg(all(target_os = "windows", feature = "dx12"))] + #[cfg(dx12)] pub unsafe fn create_surface_from_swap_chain_panel( &self, swap_chain_panel: *mut std::ffi::c_void, @@ -2229,7 +1931,7 @@ impl Instance { /// /// - On WebGL2: Will return an error if the browser does not support WebGL2, /// or declines to provide GPU access (such as due to a resource shortage). - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(any(webgpu, webgl))] pub fn create_surface_from_canvas( &self, canvas: web_sys::HtmlCanvasElement, @@ -2245,13 +1947,13 @@ impl Instance { Ok(Surface { context: Arc::clone(&self.context), _surface: None, - #[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] + #[cfg(webgl)] id: ObjectId::from(surface.id()), - #[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] + #[cfg(webgl)] data: Box::new(surface), - #[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] + #[cfg(webgpu)] id: ObjectId::UNUSED, - #[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] + #[cfg(webgpu)] data: Box::new(surface.1), config: Mutex::new(None), }) @@ -2266,7 +1968,7 @@ impl Instance { /// /// - On WebGL2: Will return an error if the browser does not support WebGL2, /// or declines to provide GPU access (such as due to a resource shortage). - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(any(webgpu, webgl))] pub fn create_surface_from_offscreen_canvas( &self, canvas: web_sys::OffscreenCanvas, @@ -2282,13 +1984,13 @@ impl Instance { Ok(Surface { context: Arc::clone(&self.context), _surface: None, - #[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] + #[cfg(webgl)] id: ObjectId::from(surface.id()), - #[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] + #[cfg(webgl)] data: Box::new(surface), - #[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] + #[cfg(webgpu)] id: ObjectId::UNUSED, - #[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] + #[cfg(webgpu)] data: Box::new(surface.1), config: Mutex::new(None), }) @@ -2315,11 +2017,7 @@ impl Instance { } /// Generates memory report. - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub fn generate_report(&self) -> wgc::global::GlobalReport { self.context .as_any() @@ -2390,11 +2088,7 @@ impl Adapter { /// /// - `hal_device` must be created from this adapter internal handle. /// - `desc.features` must be a subset of `hal_device` features. - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub unsafe fn create_device_from_hal( &self, hal_device: hal::OpenDevice, @@ -2444,11 +2138,7 @@ impl Adapter { /// - The raw handle passed to the callback must not be manually destroyed. /// /// [`A::Adapter`]: hal::Api::Adapter - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub unsafe fn as_hal) -> R, R>( &self, hal_adapter_callback: F, @@ -2790,11 +2480,7 @@ impl Device { /// - `hal_texture` must be created from this device internal handle /// - `hal_texture` must be created respecting `desc` /// - `hal_texture` must be initialized - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub unsafe fn create_texture_from_hal( &self, hal_texture: A::Texture, @@ -2831,11 +2517,7 @@ impl Device { /// - `hal_buffer` must be created from this device internal handle /// - `hal_buffer` must be created respecting `desc` /// - `hal_buffer` must be initialized - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub unsafe fn create_buffer_from_hal( &self, hal_buffer: A::Buffer, @@ -2939,11 +2621,7 @@ impl Device { /// - The raw handle passed to the callback must not be manually destroyed. /// /// [`A::Device`]: hal::Api::Device - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub unsafe fn as_hal) -> R, R>( &self, hal_device_callback: F, @@ -2996,56 +2674,30 @@ pub struct RequestDeviceError { enum RequestDeviceErrorKind { /// Error from [`wgpu_core`]. // must match dependency cfg - #[cfg(any( - not(target_arch = "wasm32"), - feature = "webgl", - target_os = "emscripten" - ))] + #[cfg(not(webgpu))] Core(core::instance::RequestDeviceError), /// Error from web API that was called by `wgpu` to request a device. /// /// (This is currently never used by the webgl backend, but it could be.) - #[cfg(all( - target_arch = "wasm32", - not(any(target_os = "emscripten", feature = "webgl")) - ))] + #[cfg(webgpu)] Web(wasm_bindgen::JsValue), } -#[cfg(all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") -))] +#[cfg(send_sync)] unsafe impl Send for RequestDeviceErrorKind {} -#[cfg(all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") -))] +#[cfg(send_sync)] unsafe impl Sync for RequestDeviceErrorKind {} -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(RequestDeviceError: Send, Sync); impl fmt::Display for RequestDeviceError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self.inner { - #[cfg(any( - not(target_arch = "wasm32"), - feature = "webgl", - target_os = "emscripten" - ))] + #[cfg(not(webgpu))] RequestDeviceErrorKind::Core(error) => error.fmt(f), - #[cfg(all( - target_arch = "wasm32", - not(any(target_os = "emscripten", feature = "webgl")) - ))] + #[cfg(webgpu)] RequestDeviceErrorKind::Web(error_js_value) => { // wasm-bindgen provides a reasonable error stringification via `Debug` impl write!(f, "{error_js_value:?}") @@ -3057,26 +2709,15 @@ impl fmt::Display for RequestDeviceError { impl error::Error for RequestDeviceError { fn source(&self) -> Option<&(dyn error::Error + 'static)> { match &self.inner { - #[cfg(any( - not(target_arch = "wasm32"), - feature = "webgl", - target_os = "emscripten" - ))] + #[cfg(not(webgpu))] RequestDeviceErrorKind::Core(error) => error.source(), - #[cfg(all( - target_arch = "wasm32", - not(any(target_os = "emscripten", feature = "webgl")) - ))] + #[cfg(webgpu)] RequestDeviceErrorKind::Web(_) => None, } } } -#[cfg(any( - not(target_arch = "wasm32"), - feature = "webgl", - target_os = "emscripten" -))] +#[cfg(not(webgpu))] impl From for RequestDeviceError { fn from(error: core::instance::RequestDeviceError) -> Self { Self { @@ -3094,12 +2735,7 @@ pub struct CreateSurfaceError { #[derive(Clone, Debug)] enum CreateSurfaceErrorKind { /// Error from [`wgpu_hal`]. - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] - // must match dependency cfg + #[cfg(not(webgpu))] Hal(hal::InstanceError), /// Error from WebGPU surface creation. @@ -3115,11 +2751,7 @@ static_assertions::assert_impl_all!(CreateSurfaceError: Send, Sync); impl fmt::Display for CreateSurfaceError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self.inner { - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] CreateSurfaceErrorKind::Hal(e) => e.fmt(f), CreateSurfaceErrorKind::Web(e) => e.fmt(f), CreateSurfaceErrorKind::RawHandle(e) => e.fmt(f), @@ -3130,11 +2762,7 @@ impl fmt::Display for CreateSurfaceError { impl error::Error for CreateSurfaceError { fn source(&self) -> Option<&(dyn error::Error + 'static)> { match &self.inner { - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] CreateSurfaceErrorKind::Hal(e) => e.source(), CreateSurfaceErrorKind::Web(_) => None, CreateSurfaceErrorKind::RawHandle(e) => e.source(), @@ -3142,11 +2770,7 @@ impl error::Error for CreateSurfaceError { } } -#[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" -))] +#[cfg(not(webgpu))] impl From for CreateSurfaceError { fn from(e: hal::InstanceError) -> Self { Self { @@ -3384,10 +3008,7 @@ impl<'a> BufferSlice<'a> { /// This is useful in wasm builds when you want to pass mapped data directly to js. Unlike `get_mapped_range` /// which unconditionally copies mapped data into the wasm heap, this function directly hands you the /// ArrayBuffer that we mapped the data into in js. - #[cfg(all( - target_arch = "wasm32", - not(any(target_os = "emscripten", feature = "webgl")) - ))] + #[cfg(webgpu)] pub fn get_mapped_range_as_array_buffer(&self) -> js_sys::ArrayBuffer { let end = self.buffer.map_context.lock().add(self.offset, self.size); DynContext::buffer_get_mapped_range_as_array_buffer( @@ -3431,11 +3052,7 @@ impl Texture { /// # Safety /// /// - The raw handle obtained from the hal Texture must not be manually destroyed - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub unsafe fn as_hal)>( &self, hal_texture_callback: F, @@ -4835,13 +4452,7 @@ pub struct QueueWriteBufferView<'a> { offset: BufferAddress, inner: Box, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(QueueWriteBufferView<'_>: Send, Sync); impl Deref for QueueWriteBufferView<'_> { @@ -4976,7 +4587,7 @@ impl Queue { } /// Schedule a copy of data from `image` into `texture`. - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(any(webgpu, webgl))] pub fn copy_external_image_to_texture( &self, source: &wgt::ImageCopyExternalImage, @@ -5192,11 +4803,7 @@ impl Surface<'_> { /// # Safety /// /// - The raw handle obtained from the hal Surface must not be manually destroyed - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] + #[cfg(not(webgpu))] pub unsafe fn as_hal) -> R, R>( &mut self, hal_surface_callback: F, @@ -5428,55 +5035,25 @@ pub enum Error { /// Out of memory error OutOfMemory { /// Lower level source of the error. - #[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) - ))] + #[cfg(send_sync)] source: Box, /// Lower level source of the error. - #[cfg(not(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) - )))] + #[cfg(not(send_sync))] source: Box, }, /// Validation error, signifying a bug in code or data Validation { /// Lower level source of the error. - #[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) - ))] + #[cfg(send_sync)] source: Box, /// Lower level source of the error. - #[cfg(not(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) - )))] + #[cfg(not(send_sync))] source: Box, /// Description of the validation error. description: String, }, } -#[cfg(any( - not(target_arch = "wasm32"), - all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") - ) -))] +#[cfg(send_sync)] static_assertions::assert_impl_all!(Error: Send); impl error::Error for Error { diff --git a/wgpu/src/util/init.rs b/wgpu/src/util/init.rs index 9c06095c28..112500ee88 100644 --- a/wgpu/src/util/init.rs +++ b/wgpu/src/util/init.rs @@ -2,10 +2,10 @@ use wgt::{Backends, PowerPreference, RequestAdapterOptions}; use crate::{Adapter, Instance, Surface}; -#[cfg(any(not(target_arch = "wasm32"), feature = "wgc"))] +#[cfg(not(webgpu))] pub use wgc::instance::parse_backends_from_comma_list; /// Always returns WEBGPU on wasm over webgpu. -#[cfg(all(target_arch = "wasm32", not(feature = "wgc")))] +#[cfg(webgpu)] pub fn parse_backends_from_comma_list(_string: &str) -> Backends { Backends::BROWSER_WEBGPU } @@ -37,7 +37,7 @@ pub fn power_preference_from_env() -> Option { } /// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable. -#[cfg(not(target_arch = "wasm32"))] +#[cfg(native)] pub fn initialize_adapter_from_env( instance: &Instance, compatible_surface: Option<&Surface<'_>>, @@ -69,7 +69,7 @@ pub fn initialize_adapter_from_env( } /// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable. -#[cfg(target_arch = "wasm32")] +#[cfg(not(native))] pub fn initialize_adapter_from_env( _instance: &Instance, _compatible_surface: Option<&Surface<'_>>, From 7471b1ad4537e9a5853da44d461d5f39da9fdc3a Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sat, 30 Dec 2023 09:54:05 +0100 Subject: [PATCH 2/2] Remove unnecessary `cfg` documentation --- wgpu/src/lib.rs | 4 ++++ wgpu/src/util/init.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 5d316a4aee..fab63abe3d 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -5036,18 +5036,22 @@ pub enum Error { OutOfMemory { /// Lower level source of the error. #[cfg(send_sync)] + #[cfg_attr(docsrs, doc(cfg(all())))] source: Box, /// Lower level source of the error. #[cfg(not(send_sync))] + #[cfg_attr(docsrs, doc(cfg(all())))] source: Box, }, /// Validation error, signifying a bug in code or data Validation { /// Lower level source of the error. #[cfg(send_sync)] + #[cfg_attr(docsrs, doc(cfg(all())))] source: Box, /// Lower level source of the error. #[cfg(not(send_sync))] + #[cfg_attr(docsrs, doc(cfg(all())))] source: Box, /// Description of the validation error. description: String, diff --git a/wgpu/src/util/init.rs b/wgpu/src/util/init.rs index 112500ee88..016ce5f7f9 100644 --- a/wgpu/src/util/init.rs +++ b/wgpu/src/util/init.rs @@ -3,6 +3,7 @@ use wgt::{Backends, PowerPreference, RequestAdapterOptions}; use crate::{Adapter, Instance, Surface}; #[cfg(not(webgpu))] +#[cfg_attr(docsrs, doc(cfg(all())))] pub use wgc::instance::parse_backends_from_comma_list; /// Always returns WEBGPU on wasm over webgpu. #[cfg(webgpu)]