From 30cebd45c7e470bb31f108e5645a435ba63bbabf Mon Sep 17 00:00:00 2001 From: Guus Waals <_@guusw.nl> Date: Fri, 22 Nov 2024 18:02:56 +0800 Subject: [PATCH] Add visionos support --- deno_webgpu/Cargo.toml | 2 +- naga/build.rs | 2 +- naga/fuzz/Cargo.toml | 4 ++-- naga/fuzz/fuzz_targets/glsl_parser.rs | 2 +- naga/fuzz/fuzz_targets/ir.rs | 2 +- naga/fuzz/fuzz_targets/spv_parser.rs | 2 +- naga/fuzz/fuzz_targets/wgsl_parser.rs | 2 +- naga/xtask/src/validate.rs | 2 +- wgpu-core/build.rs | 2 +- wgpu-core/src/lib.rs | 2 +- wgpu-hal/Cargo.toml | 4 ++-- wgpu-hal/build.rs | 2 +- wgpu-hal/examples/halmark/main.rs | 2 +- wgpu-hal/examples/raw-gles.rs | 6 +++--- wgpu-hal/examples/ray-traced-triangle/main.rs | 2 +- wgpu-hal/src/gles/egl.rs | 4 ++-- wgpu-hal/src/metal/adapter.rs | 2 +- wgpu-hal/src/metal/mod.rs | 2 +- wgpu-hal/src/metal/surface.rs | 2 +- wgpu-hal/src/vulkan/adapter.rs | 2 +- wgpu-hal/src/vulkan/instance.rs | 2 +- wgpu/Cargo.toml | 8 ++++---- wgpu/build.rs | 2 +- 23 files changed, 31 insertions(+), 31 deletions(-) diff --git a/deno_webgpu/Cargo.toml b/deno_webgpu/Cargo.toml index ba72507dd7d..83c1acd5ae0 100644 --- a/deno_webgpu/Cargo.toml +++ b/deno_webgpu/Cargo.toml @@ -35,7 +35,7 @@ features = [ ] # We want the wgpu-core Metal backend on macOS and iOS. -[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.wgpu-core] +[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos"))'.dependencies.wgpu-core] workspace = true features = ["metal"] diff --git a/naga/build.rs b/naga/build.rs index e263f626a90..b6367c8c6aa 100644 --- a/naga/build.rs +++ b/naga/build.rs @@ -3,7 +3,7 @@ fn main() { dot_out: { feature = "dot-out" }, glsl_out: { feature = "glsl-out" }, hlsl_out: { any(feature = "hlsl-out", all(target_os = "windows", feature = "hlsl-out-if-target-windows")) }, - msl_out: { any(feature = "msl-out", all(any(target_os = "ios", target_os = "macos"), feature = "msl-out-if-target-apple")) }, + msl_out: { any(feature = "msl-out", all(any(target_os = "ios", target_os = "visionos", target_os = "macos"), feature = "msl-out-if-target-apple")) }, spv_out: { feature = "spv-out" }, wgsl_out: { feature = "wgsl-out" }, } diff --git a/naga/fuzz/Cargo.toml b/naga/fuzz/Cargo.toml index f34a6f92e92..09d16615f27 100644 --- a/naga/fuzz/Cargo.toml +++ b/naga/fuzz/Cargo.toml @@ -9,11 +9,11 @@ license = "MIT OR Apache-2.0" [package.metadata] cargo-fuzz = true -[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios")))'.dependencies] +[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos")))'.dependencies] arbitrary = { version = "1.3.2", features = ["derive"] } libfuzzer-sys = "0.4" -[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios")))'.dependencies.naga] +[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos")))'.dependencies.naga] path = ".." version = "23.0.0" features = ["arbitrary", "spv-in", "wgsl-in", "glsl-in"] diff --git a/naga/fuzz/fuzz_targets/glsl_parser.rs b/naga/fuzz/fuzz_targets/glsl_parser.rs index aed7ba981b8..b4590915637 100644 --- a/naga/fuzz/fuzz_targets/glsl_parser.rs +++ b/naga/fuzz/fuzz_targets/glsl_parser.rs @@ -1,5 +1,5 @@ #![no_main] -#[cfg(not(any(target_arch = "wasm32", target_os = "ios")))] +#[cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos")))] mod fuzz { use arbitrary::Arbitrary; use libfuzzer_sys::fuzz_target; diff --git a/naga/fuzz/fuzz_targets/ir.rs b/naga/fuzz/fuzz_targets/ir.rs index 6768917c3b5..e473e751b17 100644 --- a/naga/fuzz/fuzz_targets/ir.rs +++ b/naga/fuzz/fuzz_targets/ir.rs @@ -1,5 +1,5 @@ #![no_main] -#[cfg(not(any(target_arch = "wasm32", target_os = "ios")))] +#[cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos")))] mod fuzz { use libfuzzer_sys::fuzz_target; diff --git a/naga/fuzz/fuzz_targets/spv_parser.rs b/naga/fuzz/fuzz_targets/spv_parser.rs index 2b0fae2960f..4d01fecac8f 100644 --- a/naga/fuzz/fuzz_targets/spv_parser.rs +++ b/naga/fuzz/fuzz_targets/spv_parser.rs @@ -1,5 +1,5 @@ #![no_main] -#[cfg(not(any(target_arch = "wasm32", target_os = "ios")))] +#[cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos")))] mod fuzz { use libfuzzer_sys::fuzz_target; use naga::front::spv::{Frontend, Options}; diff --git a/naga/fuzz/fuzz_targets/wgsl_parser.rs b/naga/fuzz/fuzz_targets/wgsl_parser.rs index 7513d63d1db..810cfb55492 100644 --- a/naga/fuzz/fuzz_targets/wgsl_parser.rs +++ b/naga/fuzz/fuzz_targets/wgsl_parser.rs @@ -1,5 +1,5 @@ #![no_main] -#[cfg(not(any(target_arch = "wasm32", target_os = "ios")))] +#[cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos")))] mod fuzz { use libfuzzer_sys::fuzz_target; use naga::front::wgsl::Frontend; diff --git a/naga/xtask/src/validate.rs b/naga/xtask/src/validate.rs index fa330f0a969..17d6b652fd8 100644 --- a/naga/xtask/src/validate.rs +++ b/naga/xtask/src/validate.rs @@ -150,7 +150,7 @@ fn collect_validation_jobs(jobs: &mut Vec, cmd: ValidateSubcommand) -> anyh | ValidateSubcommand::Spirv | ValidateSubcommand::Glsl | ValidateSubcommand::Dot => true, - ValidateSubcommand::Metal => cfg!(any(target_os = "macos", target_os = "ios")), + ValidateSubcommand::Metal => cfg!(any(target_os = "macos", target_os = "ios", target_os = "visionos")), // The FXC compiler is only available on Windows. // // The DXC compiler can be built and run on any platform, diff --git a/wgpu-core/build.rs b/wgpu-core/build.rs index 2f715fdb2a1..710383d54f7 100644 --- a/wgpu-core/build.rs +++ b/wgpu-core/build.rs @@ -7,7 +7,7 @@ fn main() { webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), gles) }, dx12: { all(target_os = "windows", feature = "dx12") }, gles: { all(feature = "gles") }, - metal: { all(any(target_os = "ios", target_os = "macos"), feature = "metal") }, + metal: { all(any(target_os = "ios", target_os = "visionos", target_os = "macos"), feature = "metal") }, vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") } } } diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 1edb27e7ab7..e96e942aff6 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -10,7 +10,7 @@ #![cfg_attr( all( not(all(feature = "vulkan", not(target_arch = "wasm32"))), - not(all(feature = "metal", any(target_os = "macos", target_os = "ios"))), + not(all(feature = "metal", any(target_os = "macos", target_os = "ios", target_os = "visionos"))), not(all(feature = "dx12", windows)), not(feature = "gles"), ), diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 35e85f45da7..cd77aec5ec1 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -164,7 +164,7 @@ windows-core = { workspace = true, optional = true } # backend: Gles glutin_wgl_sys = { workspace = true, optional = true } -[target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies] +[target.'cfg(any(target_os="macos", target_os="ios", target_os="visionos"))'.dependencies] # backend: Metal block = { workspace = true, optional = true } @@ -208,7 +208,7 @@ env_logger.workspace = true glam.workspace = true # for ray-traced-triangle example winit.workspace = true # for "halmark" example -[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios")))'.dev-dependencies] +[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos")))'.dev-dependencies] glutin-winit = { workspace = true, features = [ "egl", "wgl", diff --git a/wgpu-hal/build.rs b/wgpu-hal/build.rs index 7d17591605a..fa6054ca301 100644 --- a/wgpu-hal/build.rs +++ b/wgpu-hal/build.rs @@ -9,7 +9,7 @@ fn main() { Emscripten: { all(target_os = "emscripten", gles) }, dx12: { all(target_os = "windows", feature = "dx12") }, gles: { all(feature = "gles") }, - metal: { all(any(target_os = "ios", target_os = "macos"), feature = "metal") }, + metal: { all(any(target_os = "ios", target_os = "visionos", target_os = "macos"), feature = "metal") }, vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") } } } diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 020d362e8ba..c43b7618ebb 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -782,7 +782,7 @@ impl Example { cfg_if::cfg_if! { // Apple + Metal - if #[cfg(all(any(target_os = "macos", target_os = "ios"), feature = "metal"))] { + if #[cfg(all(any(target_os = "macos", target_os = "ios", target_os = "visionos"), feature = "metal"))] { type Api = hal::api::Metal; } // Wasm + Vulkan diff --git a/wgpu-hal/examples/raw-gles.rs b/wgpu-hal/examples/raw-gles.rs index 2743ce9b823..a316585c3f0 100644 --- a/wgpu-hal/examples/raw-gles.rs +++ b/wgpu-hal/examples/raw-gles.rs @@ -10,7 +10,7 @@ extern crate wgpu_hal as hal; -#[cfg(not(any(target_arch = "wasm32", target_os = "ios")))] +#[cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos")))] fn main() { use std::{ffi::CString, num::NonZeroU32}; @@ -256,7 +256,7 @@ fn main() { #[cfg(any( all(target_arch = "wasm32", not(target_os = "emscripten")), - target_os = "ios" + target_os = "ios", target_os = "visionos" ))] fn main() { eprintln!("This example is not supported on Windows and non-emscripten wasm32") @@ -264,7 +264,7 @@ fn main() { #[cfg(not(any( all(target_arch = "wasm32", not(target_os = "emscripten")), - target_os = "ios" + target_os = "ios", target_os = "visionos" )))] fn fill_screen(exposed: &hal::ExposedAdapter, width: u32, height: u32) { use hal::{Adapter as _, CommandEncoder as _, Device as _, Queue as _}; diff --git a/wgpu-hal/examples/ray-traced-triangle/main.rs b/wgpu-hal/examples/ray-traced-triangle/main.rs index 7212988f48f..e6c0867c568 100644 --- a/wgpu-hal/examples/ray-traced-triangle/main.rs +++ b/wgpu-hal/examples/ray-traced-triangle/main.rs @@ -1078,7 +1078,7 @@ impl Example { cfg_if::cfg_if! { // Apple + Metal - if #[cfg(all(any(target_os = "macos", target_os = "ios"), feature = "metal"))] { + if #[cfg(all(any(target_os = "macos", target_os = "ios", target_os = "visionos"), feature = "metal"))] { type Api = hal::api::Metal; } // Wasm + Vulkan diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 42aec2b253d..b550b6c0d90 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -785,7 +785,7 @@ impl crate::Instance for Instance { "libEGL.dll", ) } - } else if cfg!(any(target_os = "macos", target_os = "ios")) { + } else if cfg!(any(target_os = "macos", target_os = "ios", target_os = "visionos")) { unsafe { khronos_egl::DynamicInstance::::load_required_from_filename( "libEGL.dylib", @@ -1313,7 +1313,7 @@ impl crate::Surface for Surface { let window_ptr = handle.ns_view.as_ptr(); #[cfg(target_os = "macos")] let window_ptr = { - use objc::{msg_send, runtime::Object, sel, sel_impl}; + use objc::{msg_send, runtime::Object, sel}; // ns_view always have a layer and don't need to verify that it exists. let layer: *mut Object = msg_send![handle.ns_view.as_ptr().cast::(), layer]; diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index fa7622a372e..7be3c4eb7e0 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -1,5 +1,5 @@ use metal::{MTLFeatureSet, MTLGPUFamily, MTLLanguageVersion, MTLReadWriteTextureTier}; -use objc::{class, msg_send, sel, sel_impl}; +use objc::{class, msg_send, sel}; use parking_lot::Mutex; use wgt::{AstcBlock, AstcChannel}; diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index 1935e843ec6..aef28ef2954 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -120,7 +120,7 @@ impl crate::Instance for Instance { window_handle: raw_window_handle::RawWindowHandle, ) -> Result { match window_handle { - #[cfg(target_os = "ios")] + #[cfg(any(target_os = "ios", target_os = "visionos"))] raw_window_handle::RawWindowHandle::UiKit(handle) => { Ok(unsafe { Surface::from_view(handle.ui_view.cast()) }) } diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index b35c73c9102..17d4561cc7b 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -16,7 +16,7 @@ use objc::{ msg_send, rc::{autoreleasepool, StrongPtr}, runtime::{Class, Object, Sel, BOOL, NO, YES}, - sel, sel_impl, + sel }; use parking_lot::{Mutex, RwLock}; diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 6e88e03b8c2..962d99a53e7 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1005,7 +1005,7 @@ impl PhysicalDeviceProperties { } // Require `VK_KHR_portability_subset` on macOS/iOS - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos"))] extensions.push(khr::portability_subset::NAME); // Require `VK_EXT_texture_compression_astc_hdr` if the associated feature was requested diff --git a/wgpu-hal/src/vulkan/instance.rs b/wgpu-hal/src/vulkan/instance.rs index 6ec300ec77e..19b17d127f3 100644 --- a/wgpu-hal/src/vulkan/instance.rs +++ b/wgpu-hal/src/vulkan/instance.rs @@ -881,7 +881,7 @@ impl crate::Instance for super::Instance { { self.create_surface_from_view(handle.ns_view) } - #[cfg(all(target_os = "ios", feature = "metal"))] + #[cfg(all(any(target_os = "ios", target_os = "visionos"), feature = "metal"))] (Rwh::UiKit(handle), _) if self.shared.extensions.contains(&ext::metal_surface::NAME) => { diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index ed630133e23..abf736b1abe 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -138,7 +138,7 @@ features = ["indirect-validation"] # Enable `wgc` by default on macOS and iOS to allow the `metal` crate feature to # enable the Metal backend while being no-op on other targets. -[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.wgc] +[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos"))'.dependencies.wgc] workspace = true # We want the wgpu-core Direct3D backend and OpenGL (via WGL) on Windows. @@ -147,12 +147,12 @@ workspace = true features = ["gles"] # We want the wgpu-core Vulkan backend on Unix (but not emscripten, macOS, iOS) and Windows. -[target.'cfg(any(windows, all(unix, not(target_os = "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", target_os = "visionos"), not(target_os = "macos"))))'.dependencies.wgc] workspace = true features = ["vulkan"] # We want the wgpu-core GLES backend on Unix (but not macOS, iOS). -[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies.wgc] +[target.'cfg(all(unix, not(target_os = "ios", target_os = "visionos"), not(target_os = "macos")))'.dependencies.wgc] workspace = true features = ["gles"] @@ -163,7 +163,7 @@ workspace = true [target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies] hal = { workspace = true } -[target.'cfg(all(not(target_arch = "wasm32"), unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies] +[target.'cfg(all(not(target_arch = "wasm32"), unix, not(target_os = "ios", target_os = "visionos"), not(target_os = "macos")))'.dependencies] hal = { workspace = true, features = ["renderdoc"] } [target.'cfg(windows)'.dependencies] diff --git a/wgpu/build.rs b/wgpu/build.rs index 1f07f7ebba5..0354a9e08fe 100644 --- a/wgpu/build.rs +++ b/wgpu/build.rs @@ -10,7 +10,7 @@ fn main() { 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") }, + metal: { all(any(target_os = "ios", target_os = "visionos", target_os = "macos"), feature = "metal") }, // This alias is _only_ if _we_ need naga in the wrapper. wgpu-core provides // its own re-export of naga, which can be used in other situations naga: { any(feature = "naga-ir", feature = "spirv", feature = "glsl") },