Skip to content

Commit

Permalink
add tvos support
Browse files Browse the repository at this point in the history
  • Loading branch information
darkwater committed Apr 10, 2024
1 parent cc0ee7b commit f5c82ef
Show file tree
Hide file tree
Showing 22 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion deno_webgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ workspace = true
features = ["raw-window-handle", "trace", "replay", "serde", "strict_asserts", "wgsl", "gles"]

# 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 = "tvos"))'.dependencies.wgpu-core]
workspace = true
features = ["metal"]

Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod macros {
feature = "vulkan-portability"
))]
wgpu_types::Backend::Vulkan => $($c)*.$method::<wgpu_core::api::Vulkan> $params,
#[cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))]
#[cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "tvos", target_os = "macos")))]
wgpu_types::Backend::Metal => $($c)*.$method::<wgpu_core::api::Metal> $params,
#[cfg(all(not(target_arch = "wasm32"), windows))]
wgpu_types::Backend::Dx12 => $($c)*.$method::<wgpu_core::api::Dx12> $params,
Expand Down
4 changes: 2 additions & 2 deletions naga/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "tvos")))'.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 = "tvos")))'.dependencies.naga]
path = ".."
version = "0.19.0"
features = ["arbitrary", "spv-in", "wgsl-in", "glsl-in"]
Expand Down
2 changes: 1 addition & 1 deletion naga/fuzz/fuzz_targets/glsl_parser.rs
Original file line number Diff line number Diff line change
@@ -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 = "tvos")))]
mod fuzz {
use arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;
Expand Down
2 changes: 1 addition & 1 deletion naga/fuzz/fuzz_targets/ir.rs
Original file line number Diff line number Diff line change
@@ -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 = "tvos")))]
mod fuzz {
use libfuzzer_sys::fuzz_target;

Expand Down
2 changes: 1 addition & 1 deletion naga/fuzz/fuzz_targets/spv_parser.rs
Original file line number Diff line number Diff line change
@@ -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 = "tvos")))]
mod fuzz {
use libfuzzer_sys::fuzz_target;
use naga::front::spv::{Frontend, Options};
Expand Down
2 changes: 1 addition & 1 deletion naga/fuzz/fuzz_targets/wgsl_parser.rs
Original file line number Diff line number Diff line change
@@ -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 = "tvos")))]
mod fuzz {
use libfuzzer_sys::fuzz_target;
use naga::front::wgsl::Frontend;
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!(any(target_os = "macos", target_os = "ios", target_os = "tvos")),
// 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(any(target_os = "ios", target_os = "tvos", target_os = "macos"), feature = "metal") },
vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") }
}
}
6 changes: 3 additions & 3 deletions 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_os = "macos", target_os = "ios", target_os = "tvos"))),
not(all(feature = "dx12", windows)),
not(feature = "gles"),
),
Expand Down Expand Up @@ -225,12 +225,12 @@ 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, "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_metal, gfx_if_metal_hidden, "metal" if all(feature = "metal", any(target_os = "macos", target_os = "ios", target_os = "tvos")) }
define_backend_caller! { gfx_if_dx12, gfx_if_dx12_hidden, "dx12" if all(feature = "dx12", windows) }
define_backend_caller! { gfx_if_gles, gfx_if_gles_hidden, "gles" if feature = "gles" }
define_backend_caller! { gfx_if_empty, gfx_if_empty_hidden, "empty" if all(
not(any(feature = "metal", feature = "vulkan", feature = "gles")),
any(target_os = "macos", target_os = "ios"),
any(target_os = "macos", target_os = "ios", target_os = "tvos"),
) }

/// Dispatch on an [`Id`]'s backend to a backend-generic method.
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ d3d12 = { path = "../d3d12/", version = "0.19.0", optional = true, features = [
"libloading",
] }

[target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies]
[target.'cfg(any(target_os="macos", target_os="ios", target_os="tvos"))'.dependencies]
# backend: Metal
block = { version = "0.1", optional = true }

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(any(target_os = "ios", target_os = "tvos", target_os = "macos"), feature = "metal") },
vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") }
}
}
2 changes: 1 addition & 1 deletion wgpu-hal/examples/halmark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,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(any(target_os = "macos", target_os = "ios", target_os = "tvos"), feature = "metal"))] {
type Api = hal::api::Metal;
}
// Wasm + Vulkan
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 @@ -1037,7 +1037,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(any(target_os = "macos", target_os = "ios", target_os = "tvos"), 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 @@ -719,7 +719,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 = "tvos")) {
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 @@ -98,7 +98,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 = "tvos"))]
raw_window_handle::RawWindowHandle::UiKit(handle) => {
let _ = &self.managed_metal_layer_delegate;
Ok(unsafe { Surface::from_view(handle.ui_view.as_ptr(), None) })
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/metal/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl super::Surface {
let new_layer: *mut Object = msg_send![class, new];
let frame: CGRect = msg_send![main_layer, bounds];
let () = msg_send![new_layer, setFrame: frame];
#[cfg(target_os = "ios")]
#[cfg(any(target_os = "ios", target_os = "tvos"))]
{
// Unlike NSView, UIView does not allow to replace main layer.
let () = msg_send![main_layer, addSublayer: new_layer];
Expand Down Expand Up @@ -203,7 +203,7 @@ impl crate::Surface for super::Surface {
// create one as a sublayer. However, when the view changes size,
// its sublayers are not automatically resized, and we must resize
// it here. The drawable size and the layer size don't correlate
#[cfg(target_os = "ios")]
#[cfg(any(target_os = "ios", target_os = "tvos"))]
{
if let Some(view) = self.view {
let main_layer: *mut Object = msg_send![view.as_ptr(), layer];
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 @@ -925,7 +925,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 = "tvos"))]
extensions.push(vk::KhrPortabilitySubsetFn::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 @@ -887,7 +887,7 @@ impl crate::Instance for super::Instance {
{
self.create_surface_from_view(handle.ns_view.as_ptr())
}
#[cfg(all(target_os = "ios", feature = "metal"))]
#[cfg(all(any(target_os = "ios", target_os = "tvos"), feature = "metal"))]
(Rwh::UiKit(handle), _)
if self.shared.extensions.contains(&ext::MetalSurface::name()) =>
{
Expand Down
8 changes: 4 additions & 4 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ features = ["raw-window-handle"]

# 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 = "tvos"))'.dependencies.wgc]
workspace = true

# We want the wgpu-core Direct3D backend and OpenGL (via WGL) on Windows.
Expand All @@ -133,12 +133,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"), not(target_os = "tvos"), 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"), not(target_os = "tvos"), not(target_os = "macos")))'.dependencies.wgc]
workspace = true
features = ["gles"]

Expand All @@ -149,7 +149,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"), not(target_os = "tvos"), not(target_os = "macos")))'.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(any(target_os = "ios", target_os = "tvos", 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") },
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,7 @@ impl Instance {
}

// Vulkan on Mac/iOS is only available through vulkan-portability.
if (cfg!(target_os = "ios") || cfg!(target_os = "macos"))
if (cfg!(target_os = "ios") || cfg!(target_os = "tvos") || cfg!(target_os = "macos"))
&& cfg!(feature = "vulkan-portability")
{
backends = backends.union(Backends::VULKAN);
Expand Down

0 comments on commit f5c82ef

Please sign in to comment.