From fa35c0a0f4aaae35ab3d129266199008d89928fa Mon Sep 17 00:00:00 2001 From: Jinlei Li Date: Fri, 18 Feb 2022 07:24:00 +0800 Subject: [PATCH] Re-allow vk backend on Apple platforms via vulkan-portability feature --- wgpu-core/Cargo.toml | 1 + wgpu-core/build.rs | 2 +- wgpu-core/src/instance.rs | 2 ++ wgpu-core/src/lib.rs | 5 ++++- wgpu-hal/src/metal/surface.rs | 9 +++------ wgpu-hal/src/vulkan/adapter.rs | 4 ++++ wgpu/Cargo.toml | 1 + 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 6e2b72453..d1dc8ab7c 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -21,6 +21,7 @@ replay = ["serde", "wgt/replay", "arrayvec/serde", "naga/deserialize"] # Enable serializable compute/render passes, and bundle encoders. serial-pass = ["serde", "wgt/serde", "arrayvec/serde"] id32 = [] +vulkan-portability = ["hal/vulkan"] [dependencies] arrayvec = "0.7" diff --git a/wgpu-core/build.rs b/wgpu-core/build.rs index ed0959da8..ae7e3870c 100644 --- a/wgpu-core/build.rs +++ b/wgpu-core/build.rs @@ -7,7 +7,7 @@ fn main() { unix_wo_apple: {all(unix, not(apple))}, // Backends - vulkan: { all(not(wasm), any(windows, unix_wo_apple)) }, + vulkan: { all(not(wasm), any(windows, unix_wo_apple, feature = "vulkan-portability")) }, metal: { all(not(wasm), apple) }, dx12: { all(not(wasm), windows) }, dx11: { all(false, not(wasm), windows) }, diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 117123be1..2542a6b76 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -514,6 +514,8 @@ impl Global { }, //acquired_texture: None, }), + #[cfg(vulkan)] + vulkan: None, #[cfg(gl)] gl: None, }; diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 3a3ff8476..81b414429 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -202,7 +202,10 @@ macro_rules! gfx_select { // Note: For some reason the cfg aliases defined in build.rs don't succesfully apply in this // macro so we must specify their equivalents manually match $id.backend() { - #[cfg(all(not(target_arch = "wasm32"), not(target_os = "ios"), not(target_os = "macos")))] + #[cfg(any( + all(not(target_arch = "wasm32"), not(target_os = "ios"), not(target_os = "macos")), + feature = "vulkan-portability" + ))] wgt::Backend::Vulkan => $global.$method::<$crate::api::Vulkan>( $($param),* ), #[cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))] wgt::Backend::Metal => $global.$method::<$crate::api::Metal>( $($param),* ), diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index b4ba96b74..35651a7f8 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -210,12 +210,9 @@ impl crate::Surface for super::Surface { render_layer.set_presents_with_transaction(self.present_with_transaction); // opt-in to Metal EDR // EDR potentially more power used in display and more bandwidth, memory footprint. - #[cfg(target_os = "macos")] - { - let wants_edr = self.raw_swapchain_format == mtl::MTLPixelFormat::RGBA16Float; - if wants_edr != render_layer.wants_extended_dynamic_range_content() { - render_layer.set_wants_extended_dynamic_range_content(wants_edr); - } + let wants_edr = self.raw_swapchain_format == mtl::MTLPixelFormat::RGBA16Float; + if wants_edr != render_layer.wants_extended_dynamic_range_content() { + render_layer.set_wants_extended_dynamic_range_content(wants_edr); } // this gets ignored on iOS for certain OS/device combinations (iphone5s iOS 10.3) diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index bc03d8e7d..73736ee46 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -630,6 +630,9 @@ impl PhysicalDeviceCapabilities { extensions.push(vk::ExtDepthClipEnableFn::name()); } + #[cfg(any(target_os = "macos", target_os = "ios"))] + extensions.push(vk::KhrPortabilitySubsetFn::name()); + extensions } @@ -1494,6 +1497,7 @@ impl crate::Adapter for super::Adapter { wgt::TextureFormat::Rgba8UnormSrgb, wgt::TextureFormat::Bgra8Unorm, wgt::TextureFormat::Bgra8UnormSrgb, + wgt::TextureFormat::Rgba16Float, ]; let formats = supported_formats .iter() diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 23d10e473..b855b206c 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -84,6 +84,7 @@ replay = ["serde", "wgc/replay"] angle = ["wgc/angle"] webgl = ["wgc"] emscripten = ["webgl"] +vulkan-portability = ["wgc/vulkan-portability"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc] package = "wgpu-core"