From ecbb2254b6edd7103d87cb039cd0b816598dbc2f Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Fri, 10 Feb 2023 15:02:27 +0100 Subject: [PATCH 1/4] Remove `emscripten` crate features --- .github/workflows/ci.yml | 6 ++-- deno_webgpu/Cargo.toml | 2 +- player/Cargo.toml | 2 +- wgpu-core/Cargo.toml | 3 -- wgpu-core/src/conv.rs | 2 +- wgpu-core/src/device/queue.rs | 2 +- wgpu-hal/Cargo.toml | 1 - wgpu-hal/examples/raw-gles.rs | 6 ++-- wgpu-hal/src/empty.rs | 2 +- wgpu-hal/src/gles/command.rs | 2 +- wgpu-hal/src/gles/device.rs | 4 +-- wgpu-hal/src/gles/egl.rs | 31 +++++++++++---------- wgpu-hal/src/gles/mod.rs | 14 +++++----- wgpu-hal/src/gles/queue.rs | 6 ++-- wgpu-hal/src/lib.rs | 2 +- wgpu/Cargo.toml | 7 +---- wgpu/src/backend/direct.rs | 40 +++++++++++++++++---------- wgpu/src/backend/mod.rs | 22 ++++++++++++--- wgpu/src/backend/web.rs | 2 +- wgpu/src/context.rs | 6 ++-- wgpu/src/lib.rs | 50 ++++++++++++++++++++++------------ wgpu/tests/common/mod.rs | 32 +++++++++++++++++----- wgpu/tests/external_texture.rs | 2 +- 23 files changed, 150 insertions(+), 96 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00c0858978..c95c31ad90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -139,13 +139,13 @@ jobs: set -e # build for Emscripten/WebGL - cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-hal --no-default-features --features webgl,emscripten + cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-hal --no-default-features # build cube example - cargo clippy --target ${{ matrix.target }} --example cube --features webgl,emscripten + cargo clippy --target ${{ matrix.target }} --example cube # build raw-gles example - cargo clippy --target ${{ matrix.target }} --example raw-gles --features webgl,emscripten + cargo clippy --target ${{ matrix.target }} --example raw-gles - name: check native if: matrix.kind == 'native' diff --git a/deno_webgpu/Cargo.toml b/deno_webgpu/Cargo.toml index eeb012f41e..67b76d5ae3 100644 --- a/deno_webgpu/Cargo.toml +++ b/deno_webgpu/Cargo.toml @@ -35,6 +35,6 @@ workspace = true features = ["dx11", "dx12"] # We want the wgpu-core Vulkan backend on Unix (but not Emscripten) and Windows. -[target.'cfg(any(windows, all(unix, not(target_arch = "emscripten"))))'.dependencies.wgpu-core] +[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"))))'.dependencies.wgpu-core] workspace = true features = ["vulkan"] diff --git a/player/Cargo.toml b/player/Cargo.toml index 0946dad9dd..01aaf02db4 100644 --- a/player/Cargo.toml +++ b/player/Cargo.toml @@ -37,7 +37,7 @@ features = ["metal"] workspace = true features = ["dx11", "dx12"] -[target.'cfg(any(windows, all(unix, not(target_arch = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc] +[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc] workspace = true features = ["vulkan"] diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 8f0c00babc..95a8133d11 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -35,9 +35,6 @@ dx12 = ["hal/dx12"] # https://renderdoc.org/ renderdoc = ["hal/renderdoc"] -# Compile for the Emscripten POSIX-in-a-web-page emulation environment. -emscripten = ["hal/emscripten"] - # Apply run-time checks, even in release builds. These are in addition # to the validation carried out at public APIs in all builds. strict_asserts = ["wgt/strict_asserts"] diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index 52daa335a6..43986c946e 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -34,7 +34,7 @@ pub fn is_valid_copy_dst_texture_format( } #[cfg_attr( - any(not(target_arch = "wasm32"), feature = "emscripten"), + any(not(target_arch = "wasm32"), target_os = "emscripten"), allow(unused) )] pub fn is_valid_external_image_copy_dst_texture_format(format: wgt::TextureFormat) -> bool { diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index e0cc9bf656..37b9104723 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -814,7 +814,7 @@ impl Global { Ok(()) } - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] pub fn queue_copy_external_image_to_texture( &self, queue_id: id::QueueId, diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 983031c2b4..e198ab7e8f 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -43,7 +43,6 @@ dx12 = ["naga/hlsl-out", "native", "bit-set", "range-alloc", "winapi/std", "wina windows_rs = ["gpu-allocator"] dxc_shader_compiler = ["hassle-rs"] renderdoc = ["libloading", "renderdoc-sys"] -emscripten = ["gles"] [[example]] name = "halmark" diff --git a/wgpu-hal/examples/raw-gles.rs b/wgpu-hal/examples/raw-gles.rs index 4c793bba68..02857b9693 100644 --- a/wgpu-hal/examples/raw-gles.rs +++ b/wgpu-hal/examples/raw-gles.rs @@ -4,7 +4,7 @@ //! Emscripten build: //! 1. install emsdk //! 2. build this example with cargo: -//! EMCC_CFLAGS="-g -s ERROR_ON_UNDEFINED_SYMBOLS=0 --no-entry -s FULL_ES3=1" cargo build --example raw-gles --target wasm32-unknown-emscripten --features emscripten,webgl +//! EMCC_CFLAGS="-g -s ERROR_ON_UNDEFINED_SYMBOLS=0 --no-entry -s FULL_ES3=1" cargo build --example raw-gles --target wasm32-unknown-emscripten //! 3. copy raw-gles.em.html into target directory and open it in browser: //! cp wgpu-hal/examples/raw-gles.em.html target/wasm32-unknown-emscripten/debug/examples @@ -66,7 +66,7 @@ fn main() { }); } -#[cfg(feature = "emscripten")] +#[cfg(target_os = "emscripten")] fn main() { env_logger::init(); @@ -116,7 +116,7 @@ fn main() { fill_screen(&exposed, 640, 400); } -#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] fn main() {} fn fill_screen(exposed: &hal::ExposedAdapter, width: u32, height: u32) { diff --git a/wgpu-hal/src/empty.rs b/wgpu-hal/src/empty.rs index 5e112b126b..1497acad91 100644 --- a/wgpu-hal/src/empty.rs +++ b/wgpu-hal/src/empty.rs @@ -264,7 +264,7 @@ impl crate::CommandEncoder for Encoder { unsafe fn copy_buffer_to_buffer(&mut self, src: &Resource, dst: &Resource, regions: T) {} - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] unsafe fn copy_external_image_to_texture( &mut self, src: &wgt::ImageCopyExternalImage, diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index 8076a13aeb..50e9f9fad3 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -309,7 +309,7 @@ impl crate::CommandEncoder for super::CommandEncoder { } } - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] unsafe fn copy_external_image_to_texture( &mut self, src: &wgt::ImageCopyExternalImage, diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index f6921d2b69..19bf7843da 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -94,7 +94,7 @@ impl super::Device { /// - If `drop_guard` is [`None`], wgpu-hal will take ownership of the texture. If `drop_guard` is /// [`Some`], the texture must be valid until the drop implementation /// of the drop guard is called. - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn texture_from_raw( &self, name: std::num::NonZeroU32, @@ -125,7 +125,7 @@ impl super::Device { /// - If `drop_guard` is [`None`], wgpu-hal will take ownership of the renderbuffer. If `drop_guard` is /// [`Some`], the renderbuffer must be valid until the drop implementation /// of the drop guard is called. - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn texture_from_raw_renderbuffer( &self, name: std::num::NonZeroU32, diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index b9eac71193..146eebdd7a 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -26,10 +26,10 @@ type WlDisplayConnectFun = type WlDisplayDisconnectFun = unsafe extern "system" fn(display: *const raw::c_void); -#[cfg(not(feature = "emscripten"))] +#[cfg(not(target_os = "emscripten"))] type EglInstance = egl::DynamicInstance; -#[cfg(feature = "emscripten")] +#[cfg(target_os = "emscripten")] type EglInstance = egl::Instance; type WlEglWindowCreateFun = unsafe extern "system" fn( @@ -423,7 +423,7 @@ struct Inner { version: (i32, i32), supports_native_window: bool, config: egl::Config, - #[cfg_attr(feature = "emscripten", allow(dead_code))] + #[cfg_attr(target_os = "emscripten", allow(dead_code))] wl_display: Option<*mut raw::c_void>, /// Method by which the framebuffer should support srgb srgb_kind: SrgbFrameBufferKind, @@ -535,7 +535,7 @@ impl Inner { // and creating dummy pbuffer surface if not. let pbuffer = if version >= (1, 5) || display_extensions.contains("EGL_KHR_surfaceless_context") - || cfg!(feature = "emscripten") + || cfg!(target_os = "emscripten") { log::info!("\tEGL context: +surfaceless"); None @@ -624,10 +624,10 @@ unsafe impl Sync for Instance {} impl crate::Instance for Instance { unsafe fn init(desc: &crate::InstanceDescriptor) -> Result { - #[cfg(feature = "emscripten")] + #[cfg(target_os = "emscripten")] let egl_result: Result = Ok(egl::Instance::new(egl::Static)); - #[cfg(not(feature = "emscripten"))] + #[cfg(not(target_os = "emscripten"))] let egl_result = if cfg!(windows) { unsafe { egl::DynamicInstance::::load_required_from_filename("libEGL.dll") @@ -674,10 +674,10 @@ impl crate::Instance for Instance { None }; - #[cfg(not(feature = "emscripten"))] + #[cfg(not(target_os = "emscripten"))] let egl1_5 = egl.upcast::(); - #[cfg(feature = "emscripten")] + #[cfg(target_os = "emscripten")] let egl1_5: Option<&Arc> = Some(&egl); let (display, wsi_library, wsi_kind) = if let (Some(library), Some(egl)) = @@ -776,7 +776,10 @@ impl crate::Instance for Instance { ) -> Result { use raw_window_handle::RawWindowHandle as Rwh; - #[cfg_attr(any(target_os = "android", feature = "emscripten"), allow(unused_mut))] + #[cfg_attr( + any(target_os = "android", target_os = "emscripten"), + allow(unused_mut) + )] let mut inner = self.inner.lock(); match (window_handle, display_handle) { @@ -801,7 +804,7 @@ impl crate::Instance for Instance { return Err(crate::InstanceError); } } - #[cfg(not(feature = "emscripten"))] + #[cfg(not(target_os = "emscripten"))] (Rwh::Wayland(_), raw_window_handle::RawDisplayHandle::Wayland(display_handle)) => { if inner .wl_display @@ -841,7 +844,7 @@ impl crate::Instance for Instance { drop(old_inner); } } - #[cfg(feature = "emscripten")] + #[cfg(target_os = "emscripten")] (Rwh::Web(_), _) => {} other => { log::error!("Unsupported window: {:?}", other); @@ -1087,7 +1090,7 @@ impl crate::Surface for Surface { wl_window = Some(window); window } - #[cfg(feature = "emscripten")] + #[cfg(target_os = "emscripten")] (WindowKind::Unknown, Rwh::Web(handle)) => handle.id as *mut std::ffi::c_void, (WindowKind::Unknown, Rwh::Win32(handle)) => handle.hwnd, (WindowKind::Unknown, Rwh::AppKit(handle)) => { @@ -1140,10 +1143,10 @@ impl crate::Surface for Surface { } attributes.push(egl::ATTRIB_NONE as i32); - #[cfg(not(feature = "emscripten"))] + #[cfg(not(target_os = "emscripten"))] let egl1_5 = self.egl.instance.upcast::(); - #[cfg(feature = "emscripten")] + #[cfg(target_os = "emscripten")] let egl1_5: Option<&Arc> = Some(&self.egl.instance); // Careful, we can still be in 1.4 version even if `upcast` succeeds diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 31fde089d9..2af4066419 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -57,9 +57,9 @@ To address this, we invalidate the vertex buffers based on: */ ///cbindgen:ignore -#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] +#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] mod egl; -#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] mod web; mod adapter; @@ -70,14 +70,14 @@ mod queue; use crate::{CopyExtent, TextureDescriptor}; -#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] +#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub use self::egl::{AdapterContext, AdapterContextLock}; -#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] +#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] use self::egl::{Instance, Surface}; -#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] pub use self::web::AdapterContext; -#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] use self::web::{Instance, Surface}; use arrayvec::ArrayVec; @@ -680,7 +680,7 @@ enum Command { dst_target: BindTarget, copy: crate::BufferCopy, }, - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] CopyExternalImageToTexture { src: wgt::ImageCopyExternalImage, dst: glow::Texture, diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index add1daeb74..9b0d2d2c74 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -379,7 +379,7 @@ impl super::Queue { unsafe { gl.bind_buffer(copy_dst_target, None) }; } } - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] C::CopyExternalImageToTexture { ref src, dst, @@ -1509,10 +1509,10 @@ impl crate::Queue for super::Queue { surface: &mut super::Surface, texture: super::Texture, ) -> Result<(), crate::SurfaceError> { - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] let gl = unsafe { &self.shared.context.get_without_egl_lock() }; - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] let gl = &self.shared.context.glow_context; unsafe { surface.present(texture, gl) } diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 3178e255af..58c70e3ac1 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -407,7 +407,7 @@ pub trait CommandEncoder: Send + Sync + fmt::Debug { /// Works with a single array layer. /// Note: `dst` current usage has to be `TextureUses::COPY_DST`. /// Note: the copy extent is in physical size (rounded to the block size) - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] unsafe fn copy_external_image_to_texture( &mut self, src: &wgt::ImageCopyExternalImage, diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index cf377227ea..69cdbe5a8d 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -97,7 +97,6 @@ trace = ["serde", "wgc/trace"] replay = ["serde", "wgc/replay"] angle = ["wgc/angle"] webgl = ["hal", "wgc"] -emscripten = ["webgl"] vulkan-portability = ["wgc/vulkan"] expose-ids = [] @@ -128,14 +127,10 @@ workspace = true features = ["dx11", "dx12"] # We want the wgpu-core Vulkan backend on Unix (but not Emscripten) and Windows. -[target.'cfg(any(windows, all(unix, not(target_arch = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc] +[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc] workspace = true features = ["vulkan"] -[target.'cfg(target_os = "emscripten")'.dependencies.wgc] -workspace = true -features = ["emscripten"] - [dependencies.wgt] workspace = true diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 844c827091..c4cc638f2d 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -41,7 +41,7 @@ impl fmt::Debug for Context { } impl Context { - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn from_hal_instance(hal_instance: A::Instance) -> Self { Self(unsafe { wgc::hub::Global::from_hal_instance::( @@ -69,13 +69,13 @@ impl Context { &self.0 } - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub fn enumerate_adapters(&self, backends: wgt::Backends) -> Vec { self.0 .enumerate_adapters(wgc::instance::AdapterInputs::Mask(backends, |_| ())) } - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn create_adapter_from_hal( &self, hal_adapter: hal::ExposedAdapter, @@ -94,7 +94,7 @@ impl Context { } } - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn create_device_from_hal( &self, adapter: &wgc::id::AdapterId, @@ -128,7 +128,11 @@ impl Context { Ok((device, queue)) } - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten", feature = "webgl"))] + #[cfg(any( + not(target_arch = "wasm32"), + target_os = "emscripten", + feature = "webgl" + ))] pub unsafe fn create_texture_from_hal( &self, hal_texture: A::Texture, @@ -154,7 +158,7 @@ impl Context { } } - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn device_as_hal) -> R, R>( &self, device: &Device, @@ -166,7 +170,7 @@ impl Context { } } - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn surface_as_hal_mut< A: wgc::hub::HalApi, F: FnOnce(Option<&mut A::Surface>) -> R, @@ -182,7 +186,7 @@ impl Context { } } - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn texture_as_hal)>( &self, texture: &Texture, @@ -194,7 +198,7 @@ impl Context { } } - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub fn generate_report(&self) -> wgc::hub::GlobalReport { self.0.generate_report() } @@ -211,7 +215,11 @@ impl Context { } } - #[cfg(all(target_arch = "wasm32", feature = "webgl", not(feature = "emscripten")))] + #[cfg(all( + target_arch = "wasm32", + feature = "webgl", + not(target_os = "emscripten") + ))] pub fn instance_create_surface_from_canvas( &self, canvas: &web_sys::HtmlCanvasElement, @@ -226,7 +234,11 @@ impl Context { }) } - #[cfg(all(target_arch = "wasm32", feature = "webgl", not(feature = "emscripten")))] + #[cfg(all( + target_arch = "wasm32", + feature = "webgl", + not(target_os = "emscripten") + ))] pub fn instance_create_surface_from_offscreen_canvas( &self, canvas: &web_sys::OffscreenCanvas, @@ -353,7 +365,7 @@ fn map_texture_copy_view(view: crate::ImageCopyTexture) -> wgc::command::ImageCo } #[cfg_attr( - any(not(target_arch = "wasm32"), feature = "emscripten"), + any(not(target_arch = "wasm32"), target_os = "emscripten"), allow(unused) )] fn map_texture_tagged_copy_view( @@ -1408,7 +1420,7 @@ impl crate::Context for Context { fn device_drop(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) { let global = &self.0; - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] { match wgc::gfx_select!(device => global.device_poll(*device, wgt::Maintain::Wait)) { Ok(_) => (), @@ -2219,7 +2231,7 @@ impl crate::Context for Context { } } - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] fn queue_copy_external_image_to_texture( &self, queue: &Self::QueueId, diff --git a/wgpu/src/backend/mod.rs b/wgpu/src/backend/mod.rs index d28cc0c102..5680b6c5a6 100644 --- a/wgpu/src/backend/mod.rs +++ b/wgpu/src/backend/mod.rs @@ -1,9 +1,23 @@ -#[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] +#[cfg(all( + target_arch = "wasm32", + not(any(target_os = "emscripten", feature = "webgl")) +))] mod web; -#[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] +#[cfg(all( + target_arch = "wasm32", + not(any(target_os = "emscripten", feature = "webgl")) +))] pub(crate) use web::Context; -#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] +#[cfg(any( + not(target_arch = "wasm32"), + target_os = "emscripten", + feature = "webgl" +))] mod direct; -#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] +#[cfg(any( + not(target_arch = "wasm32"), + target_os = "emscripten", + feature = "webgl" +))] pub(crate) use direct::Context; diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index f3b9383610..1b87355eaf 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -2394,7 +2394,7 @@ impl crate::context::Context for Context { ); } - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] fn queue_copy_external_image_to_texture( &self, queue: &Self::QueueId, diff --git a/wgpu/src/context.rs b/wgpu/src/context.rs index 3fe71a122e..92b85a9a04 100644 --- a/wgpu/src/context.rs +++ b/wgpu/src/context.rs @@ -561,7 +561,7 @@ pub trait Context: Debug + Send + Sized + Sync { data_layout: ImageDataLayout, size: Extent3d, ); - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] fn queue_copy_external_image_to_texture( &self, queue: &Self::QueueId, @@ -1488,7 +1488,7 @@ pub(crate) trait DynContext: Debug + Send + Sync { data_layout: ImageDataLayout, size: Extent3d, ); - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] fn queue_copy_external_image_to_texture( &self, queue: &ObjectId, @@ -2884,7 +2884,7 @@ where Context::queue_write_texture(self, &queue, queue_data, texture, data, data_layout, size) } - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] fn queue_copy_external_image_to_texture( &self, queue: &ObjectId, diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 9fd36fa2c7..7414c0e637 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -49,9 +49,9 @@ pub use wgt::{ // 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(feature = "emscripten")))] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] pub use wgt::{ExternalImageSource, ImageCopyExternalImage}; -#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] static_assertions::assert_impl_all!(ExternalImageSource: Send, Sync); /// Filter for error scopes. @@ -1341,7 +1341,7 @@ impl Instance { /// # Safety /// /// Refer to the creation of wgpu-hal Instance for every backend. - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn from_hal(hal_instance: A::Instance) -> Self { Self { context: Arc::new(unsafe { @@ -1360,7 +1360,11 @@ impl Instance { /// - The raw instance handle returned must not be manually destroyed. /// /// [`Instance`]: hal::Api::Instance - #[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] + #[cfg(any( + not(target_arch = "wasm32"), + target_os = "emscripten", + feature = "webgl" + ))] pub unsafe fn as_hal(&self) -> Option<&A::Instance> { unsafe { self.context @@ -1380,7 +1384,11 @@ impl Instance { /// # Safety /// /// Refer to the creation of wgpu-core Instance. - #[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] + #[cfg(any( + not(target_arch = "wasm32"), + target_os = "emscripten", + feature = "webgl" + ))] pub unsafe fn from_core(core_instance: wgc::instance::Instance) -> Self { Self { context: Arc::new(unsafe { @@ -1394,7 +1402,7 @@ impl Instance { /// # Arguments /// /// - `backends` - Backends from which to enumerate adapters. - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub fn enumerate_adapters(&self, backends: Backends) -> impl Iterator { let context = Arc::clone(&self.context); self.context @@ -1433,7 +1441,7 @@ impl Instance { /// # Safety /// /// `hal_adapter` must be created from this instance internal handle. - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn create_adapter_from_hal( &self, hal_adapter: hal::ExposedAdapter, @@ -1575,7 +1583,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(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] pub fn create_surface_from_canvas( &self, canvas: &web_sys::HtmlCanvasElement, @@ -1611,7 +1619,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(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] pub fn create_surface_from_offscreen_canvas( &self, canvas: &web_sys::OffscreenCanvas, @@ -1659,7 +1667,7 @@ impl Instance { } /// Generates memory report. - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub fn generate_report(&self) -> wgc::hub::GlobalReport { self.context .as_any() @@ -1730,7 +1738,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"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn create_device_from_hal( &self, hal_device: hal::OpenDevice, @@ -1780,7 +1788,11 @@ 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"), feature = "webgl"))] + #[cfg(any( + not(target_arch = "wasm32"), + target_os = "emscripten", + feature = "webgl" + ))] pub unsafe fn as_hal) -> R, R>( &self, hal_adapter_callback: F, @@ -2125,7 +2137,11 @@ 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"), feature = "emscripten", feature = "webgl"))] + #[cfg(any( + not(target_arch = "wasm32"), + target_os = "emscripten", + feature = "webgl" + ))] pub unsafe fn create_texture_from_hal( &self, hal_texture: A::Texture, @@ -2226,7 +2242,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"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn as_hal) -> R, R>( &self, hal_device_callback: F, @@ -2564,7 +2580,7 @@ impl Texture { /// # Safety /// /// - The raw handle obtained from the hal Texture must not be manually destroyed - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn as_hal)>( &self, hal_texture_callback: F, @@ -3973,7 +3989,7 @@ impl Queue { } /// Schedule a copy of data from `image` into `texture`. - #[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] pub fn copy_external_image_to_texture( &self, source: &wgt::ImageCopyExternalImage, @@ -4185,7 +4201,7 @@ impl Surface { /// # Safety /// /// - The raw handle obtained from the hal Surface must not be manually destroyed - #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] + #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] pub unsafe fn as_hal_mut) -> R, R>( &mut self, hal_surface_callback: F, diff --git a/wgpu/tests/common/mod.rs b/wgpu/tests/common/mod.rs index d12ba5f3f9..319f60f7d4 100644 --- a/wgpu/tests/common/mod.rs +++ b/wgpu/tests/common/mod.rs @@ -340,12 +340,18 @@ fn initialize_adapter() -> (Adapter, SurfaceGuard) { let surface_guard; let compatible_surface; - #[cfg(not(all(target_arch = "wasm32", feature = "webgl")))] + #[cfg(not(all( + target_arch = "wasm32", + any(target_os = "emscripten", feature = "webgl") + )))] { surface_guard = SurfaceGuard {}; compatible_surface = None; } - #[cfg(all(target_arch = "wasm32", feature = "webgl"))] + #[cfg(all( + target_arch = "wasm32", + any(target_os = "emscripten", feature = "webgl") + ))] { // On wasm, append a canvas to the document body for initializing the adapter let canvas = create_html_canvas(); @@ -371,14 +377,17 @@ fn initialize_adapter() -> (Adapter, SurfaceGuard) { } struct SurfaceGuard { - #[cfg(all(target_arch = "wasm32", feature = "webgl"))] + #[cfg(all( + target_arch = "wasm32", + any(target_os = "emscripten", feature = "webgl") + ))] canvas: web_sys::HtmlCanvasElement, } impl SurfaceGuard { fn check_for_unreported_errors(&self) -> bool { cfg_if::cfg_if! { - if #[cfg(all(target_arch = "wasm32", feature = "webgl"))] { + if #[cfg(all(target_arch = "wasm32", any(target_os = "emscripten", feature = "webgl")))] { use wasm_bindgen::JsCast; self.canvas @@ -396,14 +405,20 @@ impl SurfaceGuard { } } -#[cfg(all(target_arch = "wasm32", feature = "webgl"))] +#[cfg(all( + target_arch = "wasm32", + any(target_os = "emscripten", feature = "webgl") +))] impl Drop for SurfaceGuard { fn drop(&mut self) { delete_html_canvas(); } } -#[cfg(all(target_arch = "wasm32", feature = "webgl"))] +#[cfg(all( + target_arch = "wasm32", + any(target_os = "emscripten", feature = "webgl") +))] fn create_html_canvas() -> web_sys::HtmlCanvasElement { use wasm_bindgen::JsCast; @@ -419,7 +434,10 @@ fn create_html_canvas() -> web_sys::HtmlCanvasElement { .expect("couldn't append canvas to document body") } -#[cfg(all(target_arch = "wasm32", feature = "webgl"))] +#[cfg(all( + target_arch = "wasm32", + any(target_os = "emscripten", feature = "webgl") +))] fn delete_html_canvas() { if let Some(document) = web_sys::window().and_then(|win| win.document()) { if let Some(element) = document.get_element_by_id(CANVAS_ID) { diff --git a/wgpu/tests/external_texture.rs b/wgpu/tests/external_texture.rs index 49640a5174..2bb2ec21bb 100644 --- a/wgpu/tests/external_texture.rs +++ b/wgpu/tests/external_texture.rs @@ -1,4 +1,4 @@ -#![cfg(all(target_arch = "wasm32", not(features = "emscripten")))] +#![cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] use std::num::NonZeroU32; From b918551c6f12694d0dc8e1db4dbf5171cca8cde3 Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Wed, 15 Feb 2023 12:24:03 +0100 Subject: [PATCH 2/4] Address review --- wgpu/src/backend/direct.rs | 5 ----- wgpu/src/backend/web.rs | 1 - 2 files changed, 6 deletions(-) diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index c4cc638f2d..b8d496d53f 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -128,11 +128,6 @@ impl Context { Ok((device, queue)) } - #[cfg(any( - not(target_arch = "wasm32"), - target_os = "emscripten", - feature = "webgl" - ))] pub unsafe fn create_texture_from_hal( &self, hal_texture: A::Texture, diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 1b87355eaf..5017ddbcd0 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -2394,7 +2394,6 @@ impl crate::context::Context for Context { ); } - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] fn queue_copy_external_image_to_texture( &self, queue: &Self::QueueId, From 054822e2ef7d857e3c28bda54d1bc842e8e6159f Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Fri, 10 Feb 2023 12:05:21 +0100 Subject: [PATCH 3/4] Make crate features no-op on incompatible targets --- wgpu-core/src/device/mod.rs | 8 ++-- wgpu-core/src/hub.rs | 48 ++++++++++----------- wgpu-core/src/instance.rs | 84 ++++++++++++++++++------------------- wgpu-core/src/lib.rs | 16 +++---- wgpu-hal/Cargo.toml | 32 +++++++------- wgpu-hal/src/auxil/mod.rs | 2 +- wgpu-hal/src/lib.rs | 26 +++--------- 7 files changed, 101 insertions(+), 115 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 49e158c664..17c0ef88cf 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -5530,22 +5530,22 @@ impl Global { let mut closures = UserClosures::default(); let mut all_queue_empty = true; - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] { all_queue_empty = self.poll_devices::(force_wait, &mut closures)? && all_queue_empty; } - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] { all_queue_empty = self.poll_devices::(force_wait, &mut closures)? && all_queue_empty; } - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] { all_queue_empty = self.poll_devices::(force_wait, &mut closures)? && all_queue_empty; } - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] { all_queue_empty = self.poll_devices::(force_wait, &mut closures)? && all_queue_empty; diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index e1b2f2557e..655a47ad18 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -1057,13 +1057,13 @@ impl Hub { } pub struct Hubs { - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] vulkan: Hub, - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] metal: Hub, - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] dx12: Hub, - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] dx11: Hub, #[cfg(feature = "gles")] gl: Hub, @@ -1072,13 +1072,13 @@ pub struct Hubs { impl Hubs { fn new(factory: &F) -> Self { Self { - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] vulkan: Hub::new(factory), - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] metal: Hub::new(factory), - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] dx12: Hub::new(factory), - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] dx11: Hub::new(factory), #[cfg(feature = "gles")] gl: Hub::new(factory), @@ -1089,13 +1089,13 @@ impl Hubs { #[derive(Debug)] pub struct GlobalReport { pub surfaces: StorageReport, - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] pub vulkan: Option, - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] pub metal: Option, - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] pub dx12: Option, - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] pub dx11: Option, #[cfg(feature = "gles")] pub gl: Option, @@ -1162,25 +1162,25 @@ impl Global { pub fn generate_report(&self) -> GlobalReport { GlobalReport { surfaces: self.surfaces.data.read().generate_report(), - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] vulkan: if self.instance.vulkan.is_some() { Some(self.hubs.vulkan.generate_report()) } else { None }, - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] metal: if self.instance.metal.is_some() { Some(self.hubs.metal.generate_report()) } else { None }, - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] dx12: if self.instance.dx12.is_some() { Some(self.hubs.dx12.generate_report()) } else { None }, - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] dx11: if self.instance.dx11.is_some() { Some(self.hubs.dx11.generate_report()) } else { @@ -1203,19 +1203,19 @@ impl Drop for Global { let mut surface_guard = self.surfaces.data.write(); // destroy hubs before the instance gets dropped - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] { self.hubs.vulkan.clear(&mut surface_guard, true); } - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] { self.hubs.metal.clear(&mut surface_guard, true); } - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] { self.hubs.dx12.clear(&mut surface_guard, true); } - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] { self.hubs.dx11.clear(&mut surface_guard, true); } @@ -1261,7 +1261,7 @@ impl HalApi for hal::api::Empty { } } -#[cfg(feature = "vulkan")] +#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] impl HalApi for hal::api::Vulkan { const VARIANT: Backend = Backend::Vulkan; fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance { @@ -1285,7 +1285,7 @@ impl HalApi for hal::api::Vulkan { } } -#[cfg(feature = "metal")] +#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] impl HalApi for hal::api::Metal { const VARIANT: Backend = Backend::Metal; fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance { @@ -1309,7 +1309,7 @@ impl HalApi for hal::api::Metal { } } -#[cfg(feature = "dx12")] +#[cfg(all(feature = "dx12", windows))] impl HalApi for hal::api::Dx12 { const VARIANT: Backend = Backend::Dx12; fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance { @@ -1333,7 +1333,7 @@ impl HalApi for hal::api::Dx12 { } } -#[cfg(feature = "dx11")] +#[cfg(all(feature = "dx11", windows))] impl HalApi for hal::api::Dx11 { const VARIANT: Backend = Backend::Dx11; fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance { diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 02e4b51885..5562312927 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -54,13 +54,13 @@ fn downlevel_default_limits_less_than_default_limits() { pub struct Instance { #[allow(dead_code)] pub name: String, - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] pub vulkan: Option>, - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] pub metal: Option>, - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] pub dx12: Option>, - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] pub dx11: Option>, #[cfg(feature = "gles")] pub gl: Option>, @@ -88,13 +88,13 @@ impl Instance { Self { name: name.to_string(), - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] vulkan: init(hal::api::Vulkan, &instance_desc), - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] metal: init(hal::api::Metal, &instance_desc), - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] dx12: init(hal::api::Dx12, &instance_desc), - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] dx11: init(hal::api::Dx11, &instance_desc), #[cfg(feature = "gles")] gl: init(hal::api::Gles, &instance_desc), @@ -113,13 +113,13 @@ impl Instance { } } } - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] destroy(hal::api::Vulkan, &self.vulkan, surface.vulkan); - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] destroy(hal::api::Metal, &self.metal, surface.metal); - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] destroy(hal::api::Dx12, &self.dx12, surface.dx12); - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] destroy(hal::api::Dx11, &self.dx11, surface.dx11); #[cfg(feature = "gles")] destroy(hal::api::Gles, &self.gl, surface.gl); @@ -128,13 +128,13 @@ impl Instance { pub struct Surface { pub(crate) presentation: Option, - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] pub vulkan: Option>, - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] pub metal: Option>, - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] pub dx12: Option>, - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] pub dx11: Option>, #[cfg(feature = "gles")] pub gl: Option>, @@ -468,13 +468,13 @@ impl Global { let surface = Surface { presentation: None, - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] vulkan: init::(&self.instance.vulkan, display_handle, window_handle), - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] metal: init::(&self.instance.metal, display_handle, window_handle), - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] dx12: init::(&self.instance.dx12, display_handle, window_handle), - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] dx11: init::(&self.instance.dx11, display_handle, window_handle), #[cfg(feature = "gles")] gl: init::(&self.instance.gl, display_handle, window_handle), @@ -485,7 +485,7 @@ impl Global { id.0 } - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] pub fn instance_create_surface_metal( &self, layer: *mut std::ffi::c_void, @@ -503,7 +503,7 @@ impl Global { }, //acquired_texture: None, }), - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] vulkan: None, #[cfg(feature = "gles")] gl: None, @@ -568,7 +568,7 @@ impl Global { Ok(id.0) } - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] /// # Safety /// /// The visual must be valid and able to be used to make a swapchain with. @@ -581,7 +581,7 @@ impl Global { let surface = Surface { presentation: None, - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] vulkan: None, dx12: self.instance.dx12.as_ref().map(|inst| HalSurface { raw: unsafe { inst.create_surface_from_visual(visual as _) }, @@ -596,7 +596,7 @@ impl Global { id.0 } - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] /// # Safety /// /// The surface_handle must be valid and able to be used to make a swapchain with. @@ -609,7 +609,7 @@ impl Global { let surface = Surface { presentation: None, - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] vulkan: None, dx12: self.instance.dx12.as_ref().map(|inst| HalSurface { raw: unsafe { inst.create_surface_from_surface_handle(surface_handle) }, @@ -668,23 +668,23 @@ impl Global { let mut adapters = Vec::new(); - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] self.enumerate( hal::api::Vulkan, &self.instance.vulkan, &inputs, &mut adapters, ); - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] self.enumerate( hal::api::Metal, &self.instance.metal, &inputs, &mut adapters, ); - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] self.enumerate(hal::api::Dx12, &self.instance.dx12, &inputs, &mut adapters); - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] self.enumerate(hal::api::Dx11, &self.instance.dx11, &inputs, &mut adapters); #[cfg(feature = "gles")] self.enumerate(hal::api::Gles, &self.instance.gl, &inputs, &mut adapters); @@ -769,7 +769,7 @@ impl Global { .transpose()?; let mut device_types = Vec::new(); - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] let (id_vulkan, adapters_vk) = gather( hal::api::Vulkan, self.instance.vulkan.as_ref(), @@ -778,7 +778,7 @@ impl Global { desc.force_fallback_adapter, &mut device_types, ); - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] let (id_metal, adapters_metal) = gather( hal::api::Metal, self.instance.metal.as_ref(), @@ -787,7 +787,7 @@ impl Global { desc.force_fallback_adapter, &mut device_types, ); - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] let (id_dx12, adapters_dx12) = gather( hal::api::Dx12, self.instance.dx12.as_ref(), @@ -796,7 +796,7 @@ impl Global { desc.force_fallback_adapter, &mut device_types, ); - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] let (id_dx11, adapters_dx11) = gather( hal::api::Dx11, self.instance.dx11.as_ref(), @@ -858,19 +858,19 @@ impl Global { }; let mut selected = preferred_gpu.unwrap_or(0); - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] if let Some(id) = self.select(&mut selected, id_vulkan, adapters_vk) { return Ok(id); } - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] if let Some(id) = self.select(&mut selected, id_metal, adapters_metal) { return Ok(id); } - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] if let Some(id) = self.select(&mut selected, id_dx12, adapters_dx12) { return Ok(id); } - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] if let Some(id) = self.select(&mut selected, id_dx11, adapters_dx11) { return Ok(id); } @@ -898,13 +898,13 @@ impl Global { let fid = A::hub(self).adapters.prepare(input); match A::VARIANT { - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] Backend::Vulkan => fid.assign(Adapter::new(hal_adapter), &mut token).0, - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] Backend::Metal => fid.assign(Adapter::new(hal_adapter), &mut token).0, - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] Backend::Dx12 => fid.assign(Adapter::new(hal_adapter), &mut token).0, - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] Backend::Dx11 => fid.assign(Adapter::new(hal_adapter), &mut token).0, #[cfg(feature = "gles")] Backend::Gl => fid.assign(Adapter::new(hal_adapter), &mut token).0, diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 041cb2ef0b..dcd283e268 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -295,14 +295,14 @@ platform supports."; /// private name, which is never used outside this macro. For details: /// macro_rules! define_backend_caller { - { $public:ident, $private:ident if $feature:literal } => { - #[cfg(feature = $feature )] + { $public:ident, $private:ident, $feature:literal if $cfg:meta } => { + #[cfg($cfg)] #[macro_export] macro_rules! $private { ( $call:expr ) => ( $call ) } - #[cfg(not(feature = $feature ))] + #[cfg(not($cfg))] #[macro_export] macro_rules! $private { ( $call:expr ) => ( @@ -321,11 +321,11 @@ macro_rules! define_backend_caller { // // expands to `expr` if the `"vulkan"` feature is enabled, or to a panic // otherwise. -define_backend_caller! { gfx_if_vulkan, gfx_if_vulkan_hidden if "vulkan" } -define_backend_caller! { gfx_if_metal, gfx_if_metal_hidden if "metal" } -define_backend_caller! { gfx_if_dx12, gfx_if_dx12_hidden if "dx12" } -define_backend_caller! { gfx_if_dx11, gfx_if_dx11_hidden if "dx11" } -define_backend_caller! { gfx_if_gles, gfx_if_gles_hidden if "gles" } +define_backend_caller! { gfx_if_vulkan, gfx_if_vulkan_hidden, "vulkan" if all(feature = "vulkan", not(target_arch = "wasm32")) } +define_backend_caller! { gfx_if_metal, gfx_if_metal_hidden, "metal" if all(feature = "metal", any(target_os = "macos", target_os = "ios")) } +define_backend_caller! { gfx_if_dx12, gfx_if_dx12_hidden, "dx12" if all(feature = "dx12", windows) } +define_backend_caller! { gfx_if_dx11, gfx_if_dx11_hidden, "dx11" if all(feature = "dx11", windows) } +define_backend_caller! { gfx_if_gles, gfx_if_gles_hidden, "gles" if feature = "gles" } /// Dispatch on an [`Id`]'s backend to a backend-generic method. /// diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index e198ab7e8f..faa17a4aa1 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -64,31 +64,21 @@ fxhash = "0.2.1" log = "0.4" renderdoc-sys = { version = "0.7.1", optional = true } -# backend: Metal -block = { version = "0.1", optional = true } -foreign-types = { version = "0.3", optional = true } - -# backend: Vulkan -ash = { version = "0.37.2", optional = true } -gpu-alloc = { version = "0.5", optional = true } -gpu-descriptor = { version = "0.2", optional = true } -smallvec = { version = "1", optional = true, features = ["union"] } - # backend: Gles glow = { version = "0.12.0", optional = true } -# backend: Dx12 -bit-set = { version = "0.5", optional = true } -range-alloc = { version = "0.1", optional = true } -gpu-allocator = { version = "0.22", default_features = false, features = ["d3d12", "windows", "public-winapi"], optional = true } -hassle-rs = { version = "0.10", optional = true } - [dependencies.wgt] package = "wgpu-types" path = "../wgpu-types" version = "0.15" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] +# backend: Vulkan +ash = { version = "0.37.2", optional = true } +gpu-alloc = { version = "0.5", optional = true } +gpu-descriptor = { version = "0.2", optional = true } +smallvec = { version = "1", optional = true, features = ["union"] } + egl = { package = "khronos-egl", version = "4.1", features = ["dynamic"], optional = true } libloading = { version = "0.7", optional = true } @@ -98,10 +88,20 @@ egl = { package = "khronos-egl", version = "4.1", features = ["static", "no-pkg- libloading = { version = "0.7", optional = true } [target.'cfg(windows)'.dependencies] +# backend: Dx12 +bit-set = { version = "0.5", optional = true } +range-alloc = { version = "0.1", optional = true } +gpu-allocator = { version = "0.22", default_features = false, features = ["d3d12", "windows", "public-winapi"], optional = true } +hassle-rs = { version = "0.10", optional = true } + winapi = { version = "0.3", features = ["profileapi", "libloaderapi", "windef", "winuser", "dcomp"] } native = { package = "d3d12", version = "0.6.0", git = "https://github.com/gfx-rs/d3d12-rs", rev = "b940b1d71", features = ["libloading"], optional = true } [target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies] +# backend: Metal +block = { version = "0.1", optional = true } +foreign-types = { version = "0.3", optional = true } + mtl = { package = "metal", version = "0.24.0" } objc = "0.2.5" core-graphics-types = "0.1" diff --git a/wgpu-hal/src/auxil/mod.rs b/wgpu-hal/src/auxil/mod.rs index b496692bea..da7dbac668 100644 --- a/wgpu-hal/src/auxil/mod.rs +++ b/wgpu-hal/src/auxil/mod.rs @@ -1,4 +1,4 @@ -#[cfg(any(feature = "dx11", feature = "dx12"))] +#[cfg(all(any(feature = "dx11", feature = "dx12"), windows))] pub(super) mod dxgi; #[cfg(feature = "renderdoc")] diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 58c70e3ac1..a1484970db 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -51,20 +51,6 @@ clippy::pattern_type_mismatch, )] -#[cfg(not(any( - feature = "dx11", - feature = "dx12", - feature = "gles", - feature = "metal", - feature = "vulkan" -)))] -compile_error!("No back ends enabled in `wgpu-hal`. Enable at least one backend feature."); - -#[cfg(all(feature = "metal", not(any(target_os = "macos", target_os = "ios"))))] -compile_error!("Metal API enabled on non-Apple OS. If your project is not using resolver=\"2\" in Cargo.toml, it should."); -#[cfg(all(feature = "dx12", not(windows)))] -compile_error!("DX12 API enabled on non-Windows OS. If your project is not using resolver=\"2\" in Cargo.toml, it should."); - /// DirectX11 API internals. #[cfg(all(feature = "dx11", windows))] pub mod dx11; @@ -77,24 +63,24 @@ pub mod empty; #[cfg(all(feature = "gles"))] pub mod gles; /// Metal API internals. -#[cfg(all(feature = "metal"))] +#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] pub mod metal; /// Vulkan API internals. -#[cfg(feature = "vulkan")] +#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] pub mod vulkan; pub mod auxil; pub mod api { - #[cfg(feature = "dx11")] + #[cfg(all(feature = "dx11", windows))] pub use super::dx11::Api as Dx11; - #[cfg(feature = "dx12")] + #[cfg(all(feature = "dx12", windows))] pub use super::dx12::Api as Dx12; pub use super::empty::Api as Empty; #[cfg(feature = "gles")] pub use super::gles::Api as Gles; - #[cfg(feature = "metal")] + #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] pub use super::metal::Api as Metal; - #[cfg(feature = "vulkan")] + #[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] pub use super::vulkan::Api as Vulkan; } From 03f303b391ffe59a3299687766caed2da62102a4 Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Wed, 15 Feb 2023 12:02:48 +0100 Subject: [PATCH 4/4] Remove `portable_features` --- .github/workflows/ci.yml | 4 ++-- wgpu-core/Cargo.toml | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c95c31ad90..0ebe40fb7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -160,13 +160,13 @@ jobs: # (But watch out for backend-selection features in wgpu-core; some of # those only build on the right platforms.) cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-info -p player --tests --all-features - cargo clippy --target ${{ matrix.target }} -p wgpu-core --tests --features="portable_features" + cargo clippy --target ${{ matrix.target }} -p wgpu-core --tests --all-features # build docs # (Watch out for backend-selection features in wgpu-core; some of # those only build on the right platforms.) cargo doc --target ${{ matrix.target }} -p wgpu -p wgpu-info -p player --all-features --no-deps - cargo doc --target ${{ matrix.target }} -p wgpu-core --no-deps --features="portable_features" + cargo doc --target ${{ matrix.target }} -p wgpu-core --no-deps --all-features wasm-test: name: Test WebAssembly diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 95a8133d11..b45f40c856 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -49,9 +49,6 @@ id32 = [] # Enable `ShaderModuleSource::Wgsl` wgsl = ["naga/wgsl-in"] -# Features that are intended to work on all platforms. -portable_features = ["gles", "strict_asserts", "trace", "replay", "serial-pass", "id32", "wgsl"] - [dependencies] arrayvec = "0.7" bitflags = "1"