Make Vulkan optional on Apple

This commit is contained in:
Dzmitry Malyshau 2019-09-07 21:26:28 -04:00
parent 88204b9d86
commit fe89c52834
5 changed files with 19 additions and 3 deletions

View File

@ -59,6 +59,7 @@ script:
- cargo test
# TODO: enable GL backend
#- (cd wgpu-native && cargo check --features local,glutin)
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then (cd wgpu-native && cargo check --features gfx-backend-vulkan); fi
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then cargo check --release; fi
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then cargo +nightly install cbindgen; fi
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]] && [[ $TRAVIS_OS_NAME == "windows" ]]; then

View File

@ -30,7 +30,6 @@ lazy_static = "1.1.0"
log = "0.4"
hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "a084a1f2fec6c9ed928c53e2dc8c1761782b9019" }
gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "a084a1f2fec6c9ed928c53e2dc8c1761782b9019" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "a084a1f2fec6c9ed928c53e2dc8c1761782b9019", features = ["x11"] }
parking_lot = "0.9"
raw-window-handle = "0.1"
rendy-memory = { git = "https://github.com/amethyst/rendy", rev = "a8ac0de977a28d09592d615f8857461622833443" }
@ -40,7 +39,12 @@ vec_map = "0.8"
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "a084a1f2fec6c9ed928c53e2dc8c1761782b9019" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "a084a1f2fec6c9ed928c53e2dc8c1761782b9019", optional = true }
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "a084a1f2fec6c9ed928c53e2dc8c1761782b9019", features = ["x11"] }
[target.'cfg(windows)'.dependencies]
gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "a084a1f2fec6c9ed928c53e2dc8c1761782b9019" }
gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "a084a1f2fec6c9ed928c53e2dc8c1761782b9019" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "a084a1f2fec6c9ed928c53e2dc8c1761782b9019" }

View File

@ -378,6 +378,7 @@ impl<B: GfxBackend> Default for Hub<B> {
#[derive(Debug, Default)]
pub struct Hubs {
#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))]
vulkan: Hub<backend::Vulkan>,
#[cfg(any(target_os = "ios", target_os = "macos"))]
metal: Hub<backend::Metal>,
@ -408,6 +409,7 @@ pub trait GfxBackend: hal::Backend {
fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface;
}
#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))]
impl GfxBackend for backend::Vulkan {
const VARIANT: Backend = Backend::Vulkan;
fn hub() -> &'static Hub<Self> {

View File

@ -32,6 +32,7 @@ use std::marker::PhantomData;
#[derive(Debug)]
pub struct Instance {
#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))]
vulkan: Option<gfx_backend_vulkan::Instance>,
#[cfg(any(target_os = "ios", target_os = "macos"))]
metal: gfx_backend_metal::Instance,
@ -44,7 +45,7 @@ pub struct Instance {
impl Instance {
pub(crate) fn new(name: &str, version: u32) -> Self {
Instance {
//TODO: reconsider once `create` returns a `Result`
#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))]
vulkan: gfx_backend_vulkan::Instance::create(name, version).ok(),
#[cfg(any(target_os = "ios", target_os = "macos"))]
metal: gfx_backend_metal::Instance::create(name, version).unwrap(),
@ -62,6 +63,7 @@ type GfxSurface<B> = <B as hal::Backend>::Surface;
pub struct Surface {
pub(crate) swap_chain: Option<SwapChainId>,
pub(crate) ref_count: RefCount,
#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))]
pub(crate) vulkan: Option<GfxSurface<backend::Vulkan>>,
#[cfg(any(target_os = "ios", target_os = "macos"))]
pub(crate) metal: GfxSurface<backend::Metal>,
@ -167,6 +169,7 @@ pub fn wgpu_create_surface(raw_handle: raw_window_handle::RawWindowHandle) -> Su
Rwh::IOS(h) => Surface {
swap_chain: None,
ref_count,
#[cfg(feature = "gfx-backend-vulkan")]
vulkan: None,
metal: instance
.metal
@ -176,6 +179,7 @@ pub fn wgpu_create_surface(raw_handle: raw_window_handle::RawWindowHandle) -> Su
Rwh::MacOS(h) => Surface {
swap_chain: None,
ref_count,
#[cfg(feature = "gfx-backend-vulkan")]
vulkan: instance
.vulkan
.as_ref()
@ -245,6 +249,7 @@ pub extern "C" fn wgpu_create_surface_from_metal_layer(layer: *mut std::ffi::c_v
let surface = Surface {
swap_chain: None,
ref_count: LifeGuard::new().ref_count,
#[cfg(feature = "gfx-backend-vulkan")]
vulkan: None, //TODO: currently requires `NSView`
metal: GLOBAL
.instance
@ -296,6 +301,7 @@ pub fn request_adapter(
let id_dx12 = find_input(Backend::Dx12);
let id_dx11 = find_input(Backend::Dx11);
#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))]
let mut adapters_vk = match instance.vulkan {
Some(ref inst) if id_vulkan.is_some() => {
let adapters = inst.enumerate_adapters();
@ -361,6 +367,7 @@ pub fn request_adapter(
let mut token = Token::root();
let mut selected = preferred_gpu.unwrap_or(0);
#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))]
{
if selected < adapters_vk.len() {
let adapter = Adapter {
@ -421,7 +428,7 @@ pub fn request_adapter(
}
selected -= adapters_dx11.len();
}
let _ = (selected, id_metal, id_dx12, id_dx11);
let _ = (selected, id_vulkan, id_metal, id_dx12, id_dx11);
None
}

View File

@ -6,6 +6,7 @@ pub mod backend {
pub use gfx_backend_empty::Backend as Empty;
#[cfg(any(target_os = "ios", target_os = "macos"))]
pub use gfx_backend_metal::Backend as Metal;
#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))]
pub use gfx_backend_vulkan::Backend as Vulkan;
}
@ -202,6 +203,7 @@ pub enum InputState {}
macro_rules! gfx_select {
($id:expr => $function:ident( $($param:expr),+ )) => {
match $id.backend() {
#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))]
$crate::Backend::Vulkan => $function::<$crate::backend::Vulkan>( $($param),+ ),
#[cfg(any(target_os = "ios", target_os = "macos"))]
$crate::Backend::Metal => $function::<$crate::backend::Metal>( $($param),+ ),