Cocoa: Update MoltenVK support for LunarG SDK

GLFW now checks for the libvulkan.1.dylib loader instead of what is now
the ICD.  This removes checking for libMoltenVK.dylib to avoid cryptic
errors.  This unfortunately also breaks compatibility with the
standalone MoltenVK SDK.

This also removes support for the static loader library as that is not
present in the LunarG SDK.

Related to #870.
This commit is contained in:
Camilla Löwy 2018-03-01 21:01:30 +01:00
parent 8d98a6e37d
commit ab3bfb4205
7 changed files with 25 additions and 38 deletions

View File

@ -28,12 +28,10 @@ if (WIN32)
"$ENV{VK_SDK_PATH}/Bin32")
endif()
elseif (APPLE)
set(CMAKE_FIND_FRAMEWORK NEVER)
find_library(VULKAN_LIBRARY MoltenVK)
set(CMAKE_FIND_FRAMEWORK ONLY)
find_library(VULKAN_STATIC_LIBRARY MoltenVK)
find_library(VULKAN_LIBRARY vulkan.1 HINTS
"$ENV{VULKAN_SDK}/macOS/lib")
find_path(VULKAN_INCLUDE_DIR NAMES vulkan/vulkan.h HINTS
"${VULKAN_LIBRARY}/Headers")
"$ENV{VULKAN_SDK}/macOS/include")
else()
find_path(VULKAN_INCLUDE_DIR NAMES vulkan/vulkan.h HINTS
"$ENV{VULKAN_SDK}/include")

View File

@ -141,15 +141,6 @@ if (MINGW)
endif()
endif()
if (APPLE)
# Dependencies required by the MoltenVK static library
set(GLFW_VULKAN_DEPS
"-lc++"
"-framework Cocoa"
"-framework Metal"
"-framework QuartzCore")
endif()
#--------------------------------------------------------------------
# Detect and select backend APIs
#--------------------------------------------------------------------
@ -180,7 +171,7 @@ endif()
#--------------------------------------------------------------------
if (GLFW_VULKAN_STATIC)
if (VULKAN_FOUND AND VULKAN_STATIC_LIBRARY)
list(APPEND glfw_LIBRARIES "${VULKAN_STATIC_LIBRARY}" ${GLFW_VULKAN_DEPS})
list(APPEND glfw_LIBRARIES "${VULKAN_STATIC_LIBRARY}")
if (BUILD_SHARED_LIBS)
message(WARNING "Linking Vulkan loader static library into GLFW")
endif()

View File

@ -106,9 +106,9 @@ located in the `deps/` directory.
- [stb\_image\_write](https://github.com/nothings/stb) for writing images to disk
- [Vulkan headers](https://www.khronos.org/registry/vulkan/) for Vulkan tests
The Vulkan example additionally requires the Vulkan SDK to be installed, or it
will not be included in the build. On macOS you need to provide the path to the
MoltenVK SDK manually as it has no standard installation location.
The Vulkan example additionally requires the LunarG Vulkan SDK to be installed,
or it will not be included in the build. On macOS you need to provide the path
to the SDK manually as it has no standard installation location.
The documentation is generated with [Doxygen](http://doxygen.org/) if CMake can
find that tool.

View File

@ -132,7 +132,7 @@ mode on platforms where this is available, specifically Windows and X11.
@subsection news_33_moltenvk Support for Vulkan on macOS via MoltenVK
GLFW now supports the `VK_MVK_macos_surface` window surface creation extension
provided by [MoltenVK](https://moltengl.com/moltenvk/).
provided by MoltenVK in the [LunarG Vulkan SDK](https://vulkan.lunarg.com/).
@see @ref vulkan_guide

View File

@ -10,21 +10,14 @@ documentation and is not a replacement for either. It assumes some familiarity
with Vulkan concepts like loaders, devices, queues and surfaces and leaves it to
the Vulkan documentation to explain the details of Vulkan functions.
To develop for Vulkan you should install an SDK for your platform, for example
the [LunarG Vulkan SDK](https://vulkan.lunarg.com/) for Windows and Linux or
[MoltenVK](https://moltengl.com/moltenvk/) for macOS. Apart from headers and
link libraries, they should also provide the validation layers necessary for
development.
To develop for Vulkan you should download the [LunarG Vulkan
SDK](https://vulkan.lunarg.com/) for your platform. Apart from headers and link
libraries, they also provide the validation layers necessary for development.
The GLFW library does not need the Vulkan SDK to enable support for Vulkan.
However, any Vulkan-specific test and example programs are built only if the
CMake files find a Vulkan SDK.
@macos Because MoltenVK is typically not installed system-wide, you will need to
point CMake to it using the `CMAKE_FRAMEWORK_PATH` variable when configuring the
GLFW source tree. Set this variable to the `MoltenVK/macOS` subdirectory of the
SDK, either on the command-line or in the CMake GUI.
For details on a specific function in this category, see the @ref vulkan. There
are also guides for the other areas of the GLFW API.
@ -39,7 +32,7 @@ are also guides for the other areas of the GLFW API.
By default, GLFW will look for the Vulkan loader on demand at runtime via its
standard name (`vulkan-1.dll` on Windows, `libvulkan.so.1` on Linux and other
Unix-like systems and `libMoltenVK.dylib` on macOS). This means that GLFW does
Unix-like systems and `libvulkan.1.dylib` on macOS). This means that GLFW does
not need to be linked against the loader. However, it also means that if you
are using the static library form of the Vulkan loader GLFW will either fail to
find it or (worse) use the wrong one.
@ -48,9 +41,14 @@ The @ref GLFW_VULKAN_STATIC CMake option makes GLFW link directly against the
static library form. Not linking against the Vulkan loader will then be
a compile-time error.
@macos When using the static library form of MoltenVK (i.e. `MetalVK.framework`
and not `libMoltenVK.dylib`) you must also link against its dependencies: the
`Cocoa`, `Metal` and `QuartzCore` system frameworks and the `libc++` library.
@macos Because the Vulkan loader and ICD are not installed globally on macOS,
you need to set up the application bundle according to the LunarG SDK
documentation. To help the GLFW CMake files find the SDK, you can set the
`VULKAN_SDK` environment variable.
@code{.sh}
env VULKAN_SDK=/example/path/to/vulkansdk-macos cmake .
@endcode
@section vulkan_include Including the Vulkan and GLFW header files
@ -164,9 +162,9 @@ If it fails it will return `NULL` and GLFW will not be able to create Vulkan
window surfaces. You can still use Vulkan for off-screen rendering and compute
work.
The returned array will always contain `VK_KHR_surface`, so if you don't
require any additional extensions you can pass this list directly to the
`VkInstanceCreateInfo` struct.
If successful the returned array will always include `VK_KHR_surface`, so if
you don't require any additional extensions you can pass this list directly to
the `VkInstanceCreateInfo` struct.
@code
VkInstanceCreateInfo ici;

View File

@ -54,7 +54,7 @@ GLFWbool _glfwInitVulkan(int mode)
#elif defined(_GLFW_WIN32)
_glfw.vk.handle = _glfw_dlopen("vulkan-1.dll");
#elif defined(_GLFW_COCOA)
_glfw.vk.handle = _glfw_dlopen("libMoltenVK.dylib");
_glfw.vk.handle = _glfw_dlopen("libvulkan.1.dylib");
#else
_glfw.vk.handle = _glfw_dlopen("libvulkan.so.1");
#endif

View File

@ -55,7 +55,7 @@ if (VULKAN_FOUND)
add_executable(vulkan WIN32 vulkan.c ${ICON})
target_include_directories(vulkan PRIVATE "${VULKAN_INCLUDE_DIR}")
if (GLFW_VULKAN_STATIC)
target_link_libraries(vulkan "${VULKAN_STATIC_LIBRARY}" ${GLFW_VULKAN_DEPS})
target_link_libraries(vulkan "${VULKAN_STATIC_LIBRARY}")
else()
target_link_libraries(vulkan "${VULKAN_LIBRARY}")
endif()