From 432df3f8c8504b333ecc76df4ce19a7b2c04ae77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 25 Apr 2018 23:27:35 +0200 Subject: [PATCH] Vulkan: share library loading implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The macOS, Windows, and XCB implementations are identical and can be moved to QBasicPlatformVulkanInstance. Change-Id: Id84b27ffd87f86afe3798c4ad2743ba05e6190d3 Reviewed-by: Tor Arne Vestbø --- .../qbasicvulkanplatforminstance.cpp | 15 +++++++++++++++ .../qbasicvulkanplatforminstance_p.h | 4 ++++ .../platforms/cocoa/qcocoavulkaninstance.h | 1 - .../platforms/cocoa/qcocoavulkaninstance.mm | 12 +----------- .../platforms/windows/qwindowsvulkaninstance.cpp | 12 +----------- .../platforms/windows/qwindowsvulkaninstance.h | 1 - src/plugins/platforms/xcb/qxcbvulkaninstance.cpp | 12 +----------- src/plugins/platforms/xcb/qxcbvulkaninstance.h | 1 - 8 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp index d8b4e0a7e0..b9c5669b3f 100644 --- a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp +++ b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp @@ -82,6 +82,21 @@ QBasicPlatformVulkanInstance::~QBasicPlatformVulkanInstance() m_vkDestroyInstance(m_vkInst, nullptr); } +void QBasicPlatformVulkanInstance::loadVulkanLibrary(const QString &defaultLibraryName) +{ + if (qEnvironmentVariableIsSet("QT_VULKAN_LIB")) + m_vulkanLib.setFileName(QString::fromUtf8(qgetenv("QT_VULKAN_LIB"))); + else + m_vulkanLib.setFileName(defaultLibraryName); + + if (!m_vulkanLib.load()) { + qWarning("Failed to load %s: %s", qPrintable(m_vulkanLib.fileName()), qPrintable(m_vulkanLib.errorString())); + return; + } + + init(&m_vulkanLib); +} + void QBasicPlatformVulkanInstance::init(QLibrary *lib) { if (m_vkGetInstanceProcAddr) diff --git a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h index 7395ee0323..566140b032 100644 --- a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h +++ b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h @@ -51,6 +51,7 @@ // We mean it. // +#include #include QT_BEGIN_NAMESPACE @@ -75,6 +76,7 @@ public: void destroySurface(VkSurfaceKHR surface) const; protected: + void loadVulkanLibrary(const QString &defaultLibraryName); void init(QLibrary *lib); void initInstance(QVulkanInstance *instance, const QByteArrayList &extraExts); @@ -86,6 +88,8 @@ protected: private: void setupDebugOutput(); + QLibrary m_vulkanLib; + bool m_ownsVkInst; VkResult m_errorCode; QVulkanInfoVector m_supportedLayers; diff --git a/src/plugins/platforms/cocoa/qcocoavulkaninstance.h b/src/plugins/platforms/cocoa/qcocoavulkaninstance.h index ea8e4972fb..018488a0a1 100644 --- a/src/plugins/platforms/cocoa/qcocoavulkaninstance.h +++ b/src/plugins/platforms/cocoa/qcocoavulkaninstance.h @@ -40,7 +40,6 @@ #ifndef QCOCOAVULKANINSTANCE_H #define QCOCOAVULKANINSTANCE_H -#include #include #include diff --git a/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm b/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm index c010e12662..b00fde6c6f 100644 --- a/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm +++ b/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm @@ -45,17 +45,7 @@ QT_BEGIN_NAMESPACE QCocoaVulkanInstance::QCocoaVulkanInstance(QVulkanInstance *instance) : m_instance(instance) { - if (qEnvironmentVariableIsSet("QT_VULKAN_LIB")) - m_lib.setFileName(QString::fromUtf8(qgetenv("QT_VULKAN_LIB"))); - else - m_lib.setFileName(QStringLiteral("vulkan")); - - if (!m_lib.load()) { - qWarning("Failed to load %s: %s", qPrintable(m_lib.fileName()), qPrintable(m_lib.errorString())); - return; - } - - init(&m_lib); + loadVulkanLibrary(QStringLiteral("vulkan")); } QCocoaVulkanInstance::~QCocoaVulkanInstance() diff --git a/src/plugins/platforms/windows/qwindowsvulkaninstance.cpp b/src/plugins/platforms/windows/qwindowsvulkaninstance.cpp index f2e44e0141..5ffb4375ce 100644 --- a/src/plugins/platforms/windows/qwindowsvulkaninstance.cpp +++ b/src/plugins/platforms/windows/qwindowsvulkaninstance.cpp @@ -46,17 +46,7 @@ QWindowsVulkanInstance::QWindowsVulkanInstance(QVulkanInstance *instance) m_getPhysDevPresSupport(nullptr), m_createSurface(nullptr) { - if (qEnvironmentVariableIsSet("QT_VULKAN_LIB")) - m_lib.setFileName(QString::fromUtf8(qgetenv("QT_VULKAN_LIB"))); - else - m_lib.setFileName(QStringLiteral("vulkan-1")); - - if (!m_lib.load()) { - qWarning("Failed to load %s: %s", qPrintable(m_lib.fileName()), qPrintable(m_lib.errorString())); - return; - } - - init(&m_lib); + loadVulkanLibrary(QStringLiteral("vulkan-1")); } void QWindowsVulkanInstance::createOrAdoptInstance() diff --git a/src/plugins/platforms/windows/qwindowsvulkaninstance.h b/src/plugins/platforms/windows/qwindowsvulkaninstance.h index a99766e940..f4d54c28f2 100644 --- a/src/plugins/platforms/windows/qwindowsvulkaninstance.h +++ b/src/plugins/platforms/windows/qwindowsvulkaninstance.h @@ -64,7 +64,6 @@ public: private: QVulkanInstance *m_instance; - QLibrary m_lib; PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR m_getPhysDevPresSupport; PFN_vkCreateWin32SurfaceKHR m_createSurface; }; diff --git a/src/plugins/platforms/xcb/qxcbvulkaninstance.cpp b/src/plugins/platforms/xcb/qxcbvulkaninstance.cpp index 5a6a4ef809..b3f8a5832d 100644 --- a/src/plugins/platforms/xcb/qxcbvulkaninstance.cpp +++ b/src/plugins/platforms/xcb/qxcbvulkaninstance.cpp @@ -48,17 +48,7 @@ QXcbVulkanInstance::QXcbVulkanInstance(QVulkanInstance *instance) m_getPhysDevPresSupport(nullptr), m_createSurface(nullptr) { - if (qEnvironmentVariableIsSet("QT_VULKAN_LIB")) - m_lib.setFileName(QString::fromUtf8(qgetenv("QT_VULKAN_LIB"))); - else - m_lib.setFileName(QStringLiteral("vulkan")); - - if (!m_lib.load()) { - qWarning("Failed to load %s: %s", qPrintable(m_lib.fileName()), qPrintable(m_lib.errorString())); - return; - } - - init(&m_lib); + loadVulkanLibrary(QStringLiteral("vulkan")); } QXcbVulkanInstance::~QXcbVulkanInstance() diff --git a/src/plugins/platforms/xcb/qxcbvulkaninstance.h b/src/plugins/platforms/xcb/qxcbvulkaninstance.h index c5981d3605..53f7345254 100644 --- a/src/plugins/platforms/xcb/qxcbvulkaninstance.h +++ b/src/plugins/platforms/xcb/qxcbvulkaninstance.h @@ -67,7 +67,6 @@ public: private: QVulkanInstance *m_instance; - QLibrary m_lib; PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR m_getPhysDevPresSupport; PFN_vkCreateXcbSurfaceKHR m_createSurface; };