Allow macOS developers to optionally use an SDK version of Vulkan.
This looks for VULKAN_SDK at build time, and if present it tells Filament to use the `libvulkan.1.dylib` that's located there. Otherwise it falls back to our old loading strategy, which uses a bundled version of MoltenVK that allows us to avoid requiring installation of the LunarG SDK. I tried this out an it works for me... Closes issue #238.
This commit is contained in:
@@ -247,6 +247,19 @@ else()
|
||||
set(IMPORT_EXECUTABLES ${FILAMENT}/${IMPORT_EXECUTABLES_DIR}/ImportExecutables-${CMAKE_BUILD_TYPE}.cmake)
|
||||
endif()
|
||||
|
||||
# ==================================================================================================
|
||||
# Try to find Vulkan if the SDK is installed, otherwise fall back to the bundled version.
|
||||
# This needs to stay in our top-level CMakeLists because it sets up variables that are used by the
|
||||
# "bluevk" and "samples" targets.
|
||||
# ==================================================================================================
|
||||
|
||||
find_library(Vulkan_LIBRARY NAMES vulkan HINTS "$ENV{VULKAN_SDK}/lib" "$ENV{VULKAN_SDK}/macOS/lib")
|
||||
if (Vulkan_LIBRARY)
|
||||
set(Vulkan_FOUND ON)
|
||||
message(STATUS "Found Vulkan library in SDK: ${Vulkan_LIBRARY}.")
|
||||
add_definitions(-DFILAMENT_VKLIBRARY_PATH=\"${Vulkan_LIBRARY}\")
|
||||
endif()
|
||||
|
||||
# ==================================================================================================
|
||||
# Sub-projects
|
||||
# ==================================================================================================
|
||||
|
||||
@@ -28,12 +28,18 @@ static const char* VKLIBRARY_PATH = "libvulkan.1.dylib";
|
||||
static void* module = nullptr;
|
||||
|
||||
bool loadLibrary() {
|
||||
|
||||
#ifndef FILAMENT_VKLIBRARY_PATH
|
||||
// Rather than looking in the working directory, look for the dylib in the same folder that the
|
||||
// executable lives in. This allows MacOS users to run Vulkan-based Filament apps from anywhere.
|
||||
const Path executableFolder = Path::getCurrentExecutable().getParent();
|
||||
const Path dylibPath = executableFolder.concat(VKLIBRARY_PATH);
|
||||
const Path jsonPath = executableFolder.concat("MoltenVK_icd.json");
|
||||
setenv("VK_ICD_FILENAMES", jsonPath.c_str(), 1);
|
||||
#else
|
||||
const Path dylibPath = FILAMENT_VKLIBRARY_PATH;
|
||||
#endif
|
||||
|
||||
module = dlopen(dylibPath.c_str(), RTLD_NOW | RTLD_LOCAL);
|
||||
return module != nullptr;
|
||||
}
|
||||
|
||||
@@ -156,7 +156,8 @@ endif()
|
||||
# Copy the MoltenVK dylibs and JSON on MacOS
|
||||
# ==================================================================================================
|
||||
|
||||
if (APPLE)
|
||||
if (APPLE AND NOT Vulkan_LIBRARY)
|
||||
message(STATUS "No Vulkan SDK was found, using prebuilt MoltenVK.")
|
||||
set(MOLTENVK_DIR "../third_party/moltenvk")
|
||||
configure_file(
|
||||
${MOLTENVK_DIR}/libvulkan.1.dylib
|
||||
|
||||
Reference in New Issue
Block a user