Vulkan: share library loading implementation
The macOS, Windows, and XCB implementations are identical and can be moved to QBasicPlatformVulkanInstance. Change-Id: Id84b27ffd87f86afe3798c4ad2743ba05e6190d3 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
fec8a9323b
commit
432df3f8c8
@ -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)
|
||||
|
@ -51,6 +51,7 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/QLibrary>
|
||||
#include <qpa/qplatformvulkaninstance.h>
|
||||
|
||||
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<QVulkanLayer> m_supportedLayers;
|
||||
|
@ -40,7 +40,6 @@
|
||||
#ifndef QCOCOAVULKANINSTANCE_H
|
||||
#define QCOCOAVULKANINSTANCE_H
|
||||
|
||||
#include <QtCore/QLibrary>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtVulkanSupport/private/qbasicvulkanplatforminstance_p.h>
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -64,7 +64,6 @@ public:
|
||||
|
||||
private:
|
||||
QVulkanInstance *m_instance;
|
||||
QLibrary m_lib;
|
||||
PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR m_getPhysDevPresSupport;
|
||||
PFN_vkCreateWin32SurfaceKHR m_createSurface;
|
||||
};
|
||||
|
@ -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()
|
||||
|
@ -67,7 +67,6 @@ public:
|
||||
|
||||
private:
|
||||
QVulkanInstance *m_instance;
|
||||
QLibrary m_lib;
|
||||
PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR m_getPhysDevPresSupport;
|
||||
PFN_vkCreateXcbSurfaceKHR m_createSurface;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user