diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a5934c0e6b..4778b433629 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ env: # We sometimes need nightly to use special things in CI. # # In order to prevent CI regressions, we pin the nightly version. - NIGHTLY_VERSION: "nightly-2024-10-10" + NIGHTLY_VERSION: "nightly-2024-10-17" # This is the MSRV used by `wgpu` itself and all surrounding infrastructure. REPO_MSRV: "1.83" # This is the MSRV used by the `wgpu-core`, `wgpu-hal`, and `wgpu-types` crates, @@ -111,6 +111,14 @@ jobs: target: aarch64-apple-ios kind: native + # VisionOS + - name: VisionOS aarch64 + os: macos-14 + target: aarch64-apple-visionos + kind: wgpu-only + toolchain: nightly + extra-flags: -Zbuild-std + # Linux - name: Linux x86_64 os: ubuntu-22.04 @@ -137,7 +145,7 @@ jobs: - name: Emscripten os: ubuntu-22.04 target: wasm32-unknown-emscripten - kind: em + kind: wgpu-only name: Clippy ${{ matrix.name }} runs-on: ${{ matrix.os }} @@ -146,12 +154,31 @@ jobs: - name: checkout repo uses: actions/checkout@v4 - - name: Install Repo MSRV toolchain + - name: Install Toolchain (Repo MSRV) + if: matrix.toolchain != 'nightly' run: | - rustup toolchain install ${{ env.REPO_MSRV }} --no-self-update --profile=minimal --component clippy --target ${{ matrix.target }} + rustup toolchain install ${{ env.REPO_MSRV }} --no-self-update --profile=minimal --component clippy + rustup target add ${{ matrix.target }} --toolchain ${{ env.REPO_MSRV }} rustup override set ${{ env.REPO_MSRV }} cargo -V + # In order to build on platforms that require a nightly toolchain, we install stable as expected, + # add the rust-src component, then tell stable to consider itself nightly by setting RUSTC_BOOTSTRAP=1. + # + # This is not formally "correct" thing to do, but it saves significant maintainer burden. If we were to + # use a proper nightly toolchain we would have to manually find a date that works. Even with a date that is + # carefully coordinated with the version of stable we are using, there are often mismatches of clippy lints + # between nightly and stable. This is a real mess. By using RUSTC_BOOTSTRAP=1, we get access to all the nice + # nightly features without needing to go through the hassle of maintaining a nightly toolchain. + # + # RUSTC_BOOTSTRAP=1 is how the rust project builds itself when bootstrapping the compiler, so while not "stable" + # it has been around for many years and don't anticipate it going away any time soon. + - name: Install Toolchain (Repo MSRV - Pseudo Nightly) + if: matrix.toolchain == 'nightly' + run: | + rustup toolchain install ${{ env.REPO_MSRV }} --no-self-update --profile=minimal --component clippy,rust-src + echo "RUSTC_BOOTSTRAP=1" >> "$GITHUB_ENV" + - name: disable debug shell: bash run: | @@ -183,6 +210,7 @@ jobs: # the android sdk doesn't use the conventional name for ar, so explicitly set it. echo "AR_aarch64_linux_android=llvm-ar" >> "$GITHUB_ENV" + # Building for wasm32 requires a series of specific tests for the WebGPU backend. - name: check web if: matrix.kind == 'web' shell: bash @@ -190,29 +218,31 @@ jobs: set -e # build for WebGPU - cargo clippy --target ${{ matrix.target }} --tests --features glsl,spirv,fragile-send-sync-non-atomic-wasm - cargo clippy --target ${{ matrix.target }} --tests --features glsl,spirv - cargo doc --target ${{ matrix.target }} --no-deps --features glsl,spirv + cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --features glsl,spirv,fragile-send-sync-non-atomic-wasm + cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --features glsl,spirv + cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --no-deps --features glsl,spirv # all features - cargo clippy --target ${{ matrix.target }} --tests --all-features - cargo doc --target ${{ matrix.target }} --no-deps --all-features + cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --all-features + cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --no-deps --all-features - - name: check em - if: matrix.kind == 'em' + # Building for platforms where the tests do not compile. + - name: check wgpu only + if: matrix.kind == 'wgpu-only' shell: bash run: | set -e - # build for Emscripten - cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-hal --no-default-features + # check with no features + cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu -p wgpu-hal --no-default-features # Don't check samples since we use winit in our samples which has dropped support for Emscripten. - # all features - cargo clippy --target ${{ matrix.target }} -p wgpu-hal --all-features - cargo clippy --target ${{ matrix.target }} -p wgpu --all-features + # Check with all features. + cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-hal --all-features + cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu --all-features + # Building for native platforms with standard tests. - name: check native if: matrix.kind == 'native' shell: bash @@ -220,13 +250,13 @@ jobs: set -e # check with no features - cargo clippy --target ${{ matrix.target }} --no-default-features + cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --no-default-features # Check with all features. - cargo clippy --target ${{ matrix.target }} --tests --benches --all-features + cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --benches --all-features # build docs - cargo doc --target ${{ matrix.target }} --all-features --no-deps + cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --all-features --no-deps - name: check private item docs if: matrix.kind == 'native' @@ -235,7 +265,7 @@ jobs: set -e # wgpu_core package - cargo doc --target ${{ matrix.target }} \ + cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} \ --package wgpu-core \ --package wgpu-hal \ --package naga \ diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb3bb8f3e3..877f91aa318 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -162,6 +162,7 @@ By @wumpf in [#6849](https://github.com/gfx-rs/wgpu/pull/6849). - Move raytracing alignments into HAL instead of in core. By @Vecvec in [#6563](https://github.com/gfx-rs/wgpu/pull/6563). - Allow for statically linking DXC rather than including separate `.dll` files. By @DouglasDwyer in [#6574](https://github.com/gfx-rs/wgpu/pull/6574). - `DeviceType` and `AdapterInfo` now impl `Hash` by @cwfitzgerald in [#6868](https://github.com/gfx-rs/wgpu/pull/6868) +- Add build support for Apple Vision Pro. By @guusw in [#6611](https://github.com/gfx-rs/wgpu/pull/6611). - Add `wgsl_language_features` for obtaining available WGSL language feature by @sagudev in [#6814](https://github.com/gfx-rs/wgpu/pull/6814) ##### Vulkan @@ -171,6 +172,7 @@ By @wumpf in [#6849](https://github.com/gfx-rs/wgpu/pull/6849). ##### Metal - Allow using some 32-bit floating-point atomic operations (load, store, add, sub, exchange) in shaders. It requires Metal 3.0+ with Apple 7, 8, 9 or Mac 2. By @AsherJingkongChen in [#6234](https://github.com/gfx-rs/wgpu/pull/6234). +- Add build support for Apple Vision Pro. By @guusw in [#6611](https://github.com/gfx-rs/wgpu/pull/6611). #### Changes diff --git a/deno_webgpu/Cargo.toml b/deno_webgpu/Cargo.toml index af1a3ed686a..d8776c0d408 100644 --- a/deno_webgpu/Cargo.toml +++ b/deno_webgpu/Cargo.toml @@ -36,7 +36,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(target_vendor = "apple")'.dependencies.wgpu-core] workspace = true features = ["metal"] diff --git a/naga/build.rs b/naga/build.rs index e263f626a90..e647f1fdd0a 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(target_vendor = "apple", 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 b37f373ddc1..c87037ca81d 100644 --- a/naga/fuzz/Cargo.toml +++ b/naga/fuzz/Cargo.toml @@ -15,7 +15,7 @@ arbitrary = { version = "1.4.1", features = ["derive"] } # See https://github.com/rust-fuzz/libfuzzer/issues/126 libfuzzer-sys = ">0.4.0,<=0.4.7" -[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/xtask/src/validate.rs b/naga/xtask/src/validate.rs index 99defa33031..2006aa83ae2 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!(target_vendor = "apple"), // 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..4d35481678c 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(target_vendor = "apple", 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 9362eeeb930..5bab0ee2a28 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_vendor = "apple"))), not(all(feature = "dx12", windows)), not(feature = "gles"), ), diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 4817a22e220..ed4df09e15e 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -177,7 +177,7 @@ glutin_wgl_sys = { workspace = true, optional = true } [target.'cfg(all(windows, not(target_arch = "aarch64")))'.dependencies] mach-dxcompiler-rs = { workspace = true, optional = true } -[target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies] +[target.'cfg(target_vendor = "apple")'.dependencies] # backend: Metal block = { workspace = true, optional = true } @@ -221,7 +221,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 510f2a35f61..9a648c60eaa 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(target_vendor = "apple", feature = "metal") }, vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") }, // ⚠️ Keep in sync with target.cfg() definition in Cargo.toml and cfg_alias in `wgpu` crate ⚠️ static_dxc: { all(target_os = "windows", feature = "static-dxc", not(target_arch = "aarch64")) } diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 1418e671913..22612036825 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -797,7 +797,7 @@ impl Example { cfg_if::cfg_if! { // Apple + Metal - if #[cfg(all(any(target_os = "macos", target_os = "ios"), feature = "metal"))] { + if #[cfg(all(target_vendor = "apple", 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..bd086c2dce4 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,8 @@ 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 +265,8 @@ 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 b81ef865257..be077b72bf9 100644 --- a/wgpu-hal/examples/ray-traced-triangle/main.rs +++ b/wgpu-hal/examples/ray-traced-triangle/main.rs @@ -1107,7 +1107,7 @@ impl Example { cfg_if::cfg_if! { // Apple + Metal - if #[cfg(all(any(target_os = "macos", target_os = "ios"), feature = "metal"))] { + if #[cfg(all(target_vendor = "apple", 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..24d5a125b4c 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!(target_vendor = "apple") { unsafe { khronos_egl::DynamicInstance::::load_required_from_filename( "libEGL.dylib", diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index abc600922e9..e63a2a3cce1 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -121,7 +121,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/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 11dfb6651f1..cde18162eae 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1003,7 +1003,7 @@ impl PhysicalDeviceProperties { } // Require `VK_KHR_portability_subset` on macOS/iOS - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(target_vendor = "apple")] 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 5292fa628a9..2c88013b571 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 86a75152235..4513fae279d 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -150,7 +150,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(target_vendor = "apple")'.dependencies.wgc] workspace = true # We want the wgpu-core Direct3D backend and OpenGL (via WGL) on Windows. @@ -159,12 +159,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_vendor = "apple"))))'.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_vendor = "apple")))'.dependencies.wgc] workspace = true features = ["gles"] @@ -175,7 +175,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_vendor = "apple")))'.dependencies] hal = { workspace = true, features = ["renderdoc"] } [target.'cfg(windows)'.dependencies] diff --git a/wgpu/build.rs b/wgpu/build.rs index c3218093d55..d853281dfa4 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(target_vendor = "apple", 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") }, diff --git a/wgpu/src/api/instance.rs b/wgpu/src/api/instance.rs index 8f43d0aaa9a..37c205de6f2 100644 --- a/wgpu/src/api/instance.rs +++ b/wgpu/src/api/instance.rs @@ -82,9 +82,7 @@ impl Instance { } // Vulkan on Mac/iOS is only available through vulkan-portability. - if (cfg!(target_os = "ios") || cfg!(target_os = "macos")) - && cfg!(feature = "vulkan-portability") - { + if cfg!(target_vendor = "apple") && cfg!(feature = "vulkan-portability") { backends = backends.union(Backends::VULKAN); }