Skip to content

Add VisionOS Support #6888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 50 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
Expand All @@ -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: |
Expand Down Expand Up @@ -183,50 +210,53 @@ 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
run: |
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
run: |
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'
Expand All @@ -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 \
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion naga/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
}
Expand Down
2 changes: 1 addition & 1 deletion naga/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion naga/xtask/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn collect_validation_jobs(jobs: &mut Vec<Job>, 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,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
}
}
2 changes: 1 addition & 1 deletion wgpu-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")) }
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/examples/halmark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ impl<A: hal::Api> Example<A> {

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
Expand Down
8 changes: 5 additions & 3 deletions wgpu-hal/examples/raw-gles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -256,15 +256,17 @@ 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")
}

#[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<hal::api::Gles>, width: u32, height: u32) {
use hal::{Adapter as _, CommandEncoder as _, Device as _, Queue as _};
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/examples/ray-traced-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ impl<A: hal::Api> Example<A> {

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
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<khronos_egl::EGL1_4>::load_required_from_filename(
"libEGL.dylib",
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl crate::Instance for Instance {
window_handle: raw_window_handle::RawWindowHandle,
) -> Result<Surface, crate::InstanceError> {
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()) })
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/vulkan/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
{
Expand Down
8 changes: 4 additions & 4 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"]

Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion wgpu/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") },
Expand Down
4 changes: 1 addition & 3 deletions wgpu/src/api/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading