Use libvulkan.dylib instead of MoltenVK by default on macOS (#948)

This commit is contained in:
Nicholas Lordello 2018-04-19 09:48:33 +02:00 committed by Pierre Krieger
parent 800c1789d9
commit 37fcd507d0
5 changed files with 34 additions and 12 deletions

View File

@ -1,5 +1,7 @@
# Unreleased
- Use dynamically loaded `libvulkan` like on other platforms instead of linking to MoltenVK on macOS
# Version 0.9.0 (2018-03-13)
- Updated winit to version 0.11.

View File

@ -29,10 +29,11 @@ What does vulkano do?
- Tries to be convenient to use. Nobody is going to use a library that requires you to browse
the documentation for hours for every single operation.
Note that vulkano does **not** require you to install the official Vulkan SDK. This is not
something specific to vulkano (you don't need the SDK to write programs that use Vulkan, even
Note that in general vulkano does **not** require you to install the official Vulkan SDK. This is
not something specific to vulkano (you don't need the SDK to write programs that use Vulkan, even
without vulkano), but many people are unaware of that and install the SDK thinking that it is
required.
required. However, macOS and iOS platforms do require a little more Vulkan setup since it is not
natively supported. See below for more details.
## Development status
@ -46,6 +47,22 @@ To get started you are encouraged to read the examples in
[the `vulkano-examples` repository](https://github.com/vulkano-rs/vulkano-examples), starting with
[the `triangle` example](https://github.com/vulkano-rs/vulkano-examples/blob/master/triangle/main.rs).
## macOS and iOS Setup
Vulkan is not natively supported by macOS and iOS. However, there exists [MoltenVK](https://github.com/KhronosGroup/MoltenVK)
a Vulkan implementation on top of Apple's Metal API. This allows vulkano to build and run on macOS
and iOS platforms.
The easiest way to get vulkano up and running on macOS is to install the
[Vulkan SDK for macOS](https://vulkan.lunarg.com/sdk/home). Vulkano will by default, as it does on
other platforms, look for `libvulkan.1.dylib` (included as part of the SDK). Note that it is still
possible to link with the MoltenVK framework (as vulkano did in previous versions) by adding the
appropriate cargo output lines to your build script and implementing your own
`vulkano::instance::loader::Loader` that calls the MoltenVK `vkGetInstanceProcAddr` implementation.
On iOS vulkano links directly to the MoltenVK framework. There is nothing else to do besides
installing it. Note that the Vulkan SDK for macOS also comes with the iOS framework.
## Donate
[![Become a patron](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/tomaka)

View File

@ -26,7 +26,7 @@ use cocoa::appkit::{NSView, NSWindow};
#[cfg(target_os = "macos")]
use cocoa::base::id as cocoa_id;
#[cfg(target_os = "macos")]
use metal::*;
use metal::CoreAnimationLayer;
#[cfg(target_os = "macos")]
use objc::runtime::YES;

View File

@ -6,19 +6,19 @@
// at your option. All files in the project carrying such
// notice may not be copied, modified, or distributed except
// according to those terms.
use std::env;
fn main() {
let target = env::var("TARGET").unwrap();
if target.contains("apple-darwin") {
if target.contains("apple-ios") {
println!("cargo:rustc-link-search=framework=/Library/Frameworks/");
println!("cargo:rustc-link-lib=c++");
println!("cargo:rustc-link-lib=framework=MoltenVK");
println!("cargo:rustc-link-lib=framework=IOKit");
println!("cargo:rustc-link-lib=framework=Metal");
println!("cargo:rustc-link-lib=framework=IOSurface");
println!("cargo:rustc-link-lib=framework=QuartzCore");
println!("cargo:rustc-link-lib=framework=Metal");
println!("cargo:rustc-link-lib=framework=UIKit");
println!("cargo:rustc-link-lib=framework=Foundation");
}
}

View File

@ -168,18 +168,17 @@ macro_rules! statically_linked_vulkan_loader {
/// This function tries to auto-guess where to find the Vulkan implementation, and loads it in a
/// `lazy_static!`. The content of the lazy_static is then returned, or an error if we failed to
/// load Vulkan.
pub fn auto_loader(
)
pub fn auto_loader()
-> Result<&'static FunctionPointers<Box<Loader + Send + Sync>>, LoadingError>
{
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg(target_os = "ios")]
#[allow(non_snake_case)]
fn def_loader_impl() -> Result<Box<Loader + Send + Sync>, LoadingError> {
let loader = statically_linked_vulkan_loader!();
Ok(Box::new(loader))
}
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
#[cfg(not(target_os = "ios"))]
fn def_loader_impl() -> Result<Box<Loader + Send + Sync>, LoadingError> {
#[cfg(windows)]
fn get_path() -> &'static Path {
@ -189,6 +188,10 @@ pub fn auto_loader(
fn get_path() -> &'static Path {
Path::new("libvulkan.so.1")
}
#[cfg(target_os = "macos")]
fn get_path() -> &'static Path {
Path::new("libvulkan.1.dylib")
}
#[cfg(target_os = "android")]
fn get_path() -> &'static Path {
Path::new("libvulkan.so")