skia2/tools/gpu/vk/VkTestUtils.cpp
Chris Dalton 3a67b8e46b Add support for building with MoltenVK
Bug: skia:
Change-Id: If55785d7fcc6e2c92c961ac390700add874c8d6d
Reviewed-on: https://skia-review.googlesource.com/125601
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2018-05-03 16:26:01 +00:00

52 lines
1.5 KiB
C++

/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "VkTestUtils.h"
#ifdef SK_VULKAN
#include "../ports/SkOSLibrary.h"
namespace sk_gpu_test {
bool LoadVkLibraryAndGetProcAddrFuncs(PFN_vkGetInstanceProcAddr* instProc,
PFN_vkGetDeviceProcAddr* devProc) {
#ifdef SK_MOLTENVK
// MoltenVK is a statically linked framework, so there is no Vulkan library to load.
*instProc = &vkGetInstanceProcAddr;
*devProc = &vkGetDeviceProcAddr;
return true;
#else
static void* vkLib = nullptr;
static PFN_vkGetInstanceProcAddr localInstProc = nullptr;
static PFN_vkGetDeviceProcAddr localDevProc = nullptr;
if (!vkLib) {
#if defined _WIN32
vkLib = DynamicLoadLibrary("vulkan-1.dll");
#else
vkLib = DynamicLoadLibrary("libvulkan.so");
#endif
if (!vkLib) {
return false;
}
localInstProc = (PFN_vkGetInstanceProcAddr) GetProcedureAddress(vkLib,
"vkGetInstanceProcAddr");
localDevProc = (PFN_vkGetDeviceProcAddr) GetProcedureAddress(vkLib,
"vkGetDeviceProcAddr");
}
if (!localInstProc || !localDevProc) {
return false;
}
*instProc = localInstProc;
*devProc = localDevProc;
return true;
#endif
}
}
#endif