aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/gpu/vk
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2017-11-09 15:20:26 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-09 21:04:37 +0000
commit77d6feaa69d95c42f4e77195e92de33917995544 (patch)
tree105d7145e53d14cc2ead22f2e5807cb34b5fb481 /tools/gpu/vk
parent0f3c73220a25eba9bf11583db3d0f76a2c4f6331 (diff)
Dynamically load the vulkan library in our test tools
Bug: skia: Change-Id: I7c1f6cbb2b50ca284f40cf4b9ef49a76083b38c6 Reviewed-on: https://skia-review.googlesource.com/68643 Reviewed-by: Chris Dalton <csmartdalton@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'tools/gpu/vk')
-rw-r--r--tools/gpu/vk/VkTestContext.cpp10
-rw-r--r--tools/gpu/vk/VkTestUtils.cpp40
-rw-r--r--tools/gpu/vk/VkTestUtils.h21
3 files changed, 68 insertions, 3 deletions
diff --git a/tools/gpu/vk/VkTestContext.cpp b/tools/gpu/vk/VkTestContext.cpp
index e329583a03..daaa55bfa0 100644
--- a/tools/gpu/vk/VkTestContext.cpp
+++ b/tools/gpu/vk/VkTestContext.cpp
@@ -10,9 +10,9 @@
#ifdef SK_VULKAN
#include "GrContext.h"
+#include "VkTestUtils.h"
#include "vk/GrVkInterface.h"
#include "vk/GrVkUtil.h"
-#include <vulkan/vulkan.h>
namespace {
/**
@@ -114,8 +114,12 @@ public:
if (sharedContext) {
backendContext = sharedContext->getVkBackendContext();
} else {
- backendContext.reset(GrVkBackendContext::Create(vkGetInstanceProcAddr,
- vkGetDeviceProcAddr));
+ PFN_vkGetInstanceProcAddr instProc;
+ PFN_vkGetDeviceProcAddr devProc;
+ if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
+ return nullptr;
+ }
+ backendContext.reset(GrVkBackendContext::Create(instProc, devProc));
}
if (!backendContext) {
return nullptr;
diff --git a/tools/gpu/vk/VkTestUtils.cpp b/tools/gpu/vk/VkTestUtils.cpp
new file mode 100644
index 0000000000..62fd312ecf
--- /dev/null
+++ b/tools/gpu/vk/VkTestUtils.cpp
@@ -0,0 +1,40 @@
+/*
+ * 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"
+
+#include "../ports/SkOSLibrary.h"
+
+namespace sk_gpu_test {
+
+bool LoadVkLibraryAndGetProcAddrFuncs(PFN_vkGetInstanceProcAddr* instProc,
+ PFN_vkGetDeviceProcAddr* devProc) {
+ 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;
+}
+}
diff --git a/tools/gpu/vk/VkTestUtils.h b/tools/gpu/vk/VkTestUtils.h
new file mode 100644
index 0000000000..43e9dfdbdc
--- /dev/null
+++ b/tools/gpu/vk/VkTestUtils.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef VkTestUtils_DEFINED
+#define VkTestUtils_DEFINED
+
+#ifdef SK_VULKAN
+
+#include "vk/GrVkDefines.h"
+
+namespace sk_gpu_test {
+ bool LoadVkLibraryAndGetProcAddrFuncs(PFN_vkGetInstanceProcAddr*, PFN_vkGetDeviceProcAddr*);
+}
+
+#endif
+#endif
+