Vulkan: Share destroySurface() implementation
The macOS, Windows, and XCB implementations are identical and can be moved to QBasicPlatformVulkanInstance. Change-Id: I1380b2bd03080710084a1458bdce3a362ba5c287 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
d02e7b46a1
commit
fec8a9323b
@ -256,6 +256,11 @@ void QBasicPlatformVulkanInstance::initInstance(QVulkanInstance *instance, const
|
|||||||
if (!m_getPhysDevSurfaceSupport)
|
if (!m_getPhysDevSurfaceSupport)
|
||||||
qWarning("Failed to find vkGetPhysicalDeviceSurfaceSupportKHR");
|
qWarning("Failed to find vkGetPhysicalDeviceSurfaceSupportKHR");
|
||||||
|
|
||||||
|
m_destroySurface = reinterpret_cast<PFN_vkDestroySurfaceKHR>(
|
||||||
|
m_vkGetInstanceProcAddr(m_vkInst, "vkDestroySurfaceKHR"));
|
||||||
|
if (!m_destroySurface)
|
||||||
|
qWarning("Failed to find vkDestroySurfaceKHR");
|
||||||
|
|
||||||
if (!flags.testFlag(QVulkanInstance::NoDebugOutputRedirect))
|
if (!flags.testFlag(QVulkanInstance::NoDebugOutputRedirect))
|
||||||
setupDebugOutput();
|
setupDebugOutput();
|
||||||
}
|
}
|
||||||
@ -310,6 +315,12 @@ bool QBasicPlatformVulkanInstance::supportsPresent(VkPhysicalDevice physicalDevi
|
|||||||
return supported;
|
return supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QBasicPlatformVulkanInstance::destroySurface(VkSurfaceKHR surface) const
|
||||||
|
{
|
||||||
|
if (m_destroySurface && surface)
|
||||||
|
m_destroySurface(m_vkInst, surface, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
static VKAPI_ATTR VkBool32 VKAPI_CALL defaultDebugCallbackFunc(VkDebugReportFlagsEXT flags,
|
static VKAPI_ATTR VkBool32 VKAPI_CALL defaultDebugCallbackFunc(VkDebugReportFlagsEXT flags,
|
||||||
VkDebugReportObjectTypeEXT objectType,
|
VkDebugReportObjectTypeEXT objectType,
|
||||||
uint64_t object,
|
uint64_t object,
|
||||||
|
@ -72,6 +72,7 @@ public:
|
|||||||
QByteArrayList enabledExtensions() const override;
|
QByteArrayList enabledExtensions() const override;
|
||||||
PFN_vkVoidFunction getInstanceProcAddr(const char *name) override;
|
PFN_vkVoidFunction getInstanceProcAddr(const char *name) override;
|
||||||
bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window) override;
|
bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window) override;
|
||||||
|
void destroySurface(VkSurfaceKHR surface) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void init(QLibrary *lib);
|
void init(QLibrary *lib);
|
||||||
@ -80,6 +81,7 @@ protected:
|
|||||||
VkInstance m_vkInst;
|
VkInstance m_vkInst;
|
||||||
PFN_vkGetInstanceProcAddr m_vkGetInstanceProcAddr;
|
PFN_vkGetInstanceProcAddr m_vkGetInstanceProcAddr;
|
||||||
PFN_vkGetPhysicalDeviceSurfaceSupportKHR m_getPhysDevSurfaceSupport;
|
PFN_vkGetPhysicalDeviceSurfaceSupportKHR m_getPhysDevSurfaceSupport;
|
||||||
|
PFN_vkDestroySurfaceKHR m_destroySurface;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupDebugOutput();
|
void setupDebugOutput();
|
||||||
|
@ -60,13 +60,11 @@ public:
|
|||||||
|
|
||||||
VkSurfaceKHR *createSurface(QWindow *window);
|
VkSurfaceKHR *createSurface(QWindow *window);
|
||||||
VkSurfaceKHR createSurface(NSView *view);
|
VkSurfaceKHR createSurface(NSView *view);
|
||||||
void destroySurface(VkSurfaceKHR surface);
|
|
||||||
private:
|
private:
|
||||||
QVulkanInstance *m_instance = nullptr;
|
QVulkanInstance *m_instance = nullptr;
|
||||||
QLibrary m_lib;
|
QLibrary m_lib;
|
||||||
VkSurfaceKHR m_nullSurface = nullptr;
|
VkSurfaceKHR m_nullSurface = nullptr;
|
||||||
PFN_vkCreateMacOSSurfaceMVK m_createSurface = nullptr;
|
PFN_vkCreateMacOSSurfaceMVK m_createSurface = nullptr;
|
||||||
PFN_vkDestroySurfaceKHR m_destroySurface = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -86,14 +86,6 @@ VkSurfaceKHR QCocoaVulkanInstance::createSurface(NSView *view)
|
|||||||
qWarning("Failed to find vkCreateMacOSSurfaceMVK");
|
qWarning("Failed to find vkCreateMacOSSurfaceMVK");
|
||||||
return m_nullSurface;
|
return m_nullSurface;
|
||||||
}
|
}
|
||||||
if (!m_destroySurface) {
|
|
||||||
m_destroySurface = reinterpret_cast<PFN_vkDestroySurfaceKHR>(
|
|
||||||
m_vkGetInstanceProcAddr(m_vkInst, "vkDestroySurfaceKHR"));
|
|
||||||
}
|
|
||||||
if (!m_destroySurface) {
|
|
||||||
qWarning("Failed to find vkDestroySurfaceKHR");
|
|
||||||
return m_nullSurface;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkMacOSSurfaceCreateInfoMVK surfaceInfo;
|
VkMacOSSurfaceCreateInfoMVK surfaceInfo;
|
||||||
surfaceInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
|
surfaceInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
|
||||||
@ -109,11 +101,5 @@ VkSurfaceKHR QCocoaVulkanInstance::createSurface(NSView *view)
|
|||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCocoaVulkanInstance::destroySurface(VkSurfaceKHR surface)
|
|
||||||
{
|
|
||||||
if (m_destroySurface && surface)
|
|
||||||
m_destroySurface(m_vkInst, surface, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -44,8 +44,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
QWindowsVulkanInstance::QWindowsVulkanInstance(QVulkanInstance *instance)
|
QWindowsVulkanInstance::QWindowsVulkanInstance(QVulkanInstance *instance)
|
||||||
: m_instance(instance),
|
: m_instance(instance),
|
||||||
m_getPhysDevPresSupport(nullptr),
|
m_getPhysDevPresSupport(nullptr),
|
||||||
m_createSurface(nullptr),
|
m_createSurface(nullptr)
|
||||||
m_destroySurface(nullptr)
|
|
||||||
{
|
{
|
||||||
if (qEnvironmentVariableIsSet("QT_VULKAN_LIB"))
|
if (qEnvironmentVariableIsSet("QT_VULKAN_LIB"))
|
||||||
m_lib.setFileName(QString::fromUtf8(qgetenv("QT_VULKAN_LIB")));
|
m_lib.setFileName(QString::fromUtf8(qgetenv("QT_VULKAN_LIB")));
|
||||||
@ -106,14 +105,6 @@ VkSurfaceKHR QWindowsVulkanInstance::createSurface(HWND win)
|
|||||||
qWarning("Failed to find vkCreateWin32SurfaceKHR");
|
qWarning("Failed to find vkCreateWin32SurfaceKHR");
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
if (!m_destroySurface) {
|
|
||||||
m_destroySurface = reinterpret_cast<PFN_vkDestroySurfaceKHR>(
|
|
||||||
m_vkGetInstanceProcAddr(m_vkInst, "vkDestroySurfaceKHR"));
|
|
||||||
}
|
|
||||||
if (!m_destroySurface) {
|
|
||||||
qWarning("Failed to find vkDestroySurfaceKHR");
|
|
||||||
return surface;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkWin32SurfaceCreateInfoKHR surfaceInfo;
|
VkWin32SurfaceCreateInfoKHR surfaceInfo;
|
||||||
memset(&surfaceInfo, 0, sizeof(surfaceInfo));
|
memset(&surfaceInfo, 0, sizeof(surfaceInfo));
|
||||||
@ -127,10 +118,4 @@ VkSurfaceKHR QWindowsVulkanInstance::createSurface(HWND win)
|
|||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWindowsVulkanInstance::destroySurface(VkSurfaceKHR surface)
|
|
||||||
{
|
|
||||||
if (m_destroySurface && surface)
|
|
||||||
m_destroySurface(m_vkInst, surface, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -61,14 +61,12 @@ public:
|
|||||||
bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window) override;
|
bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window) override;
|
||||||
|
|
||||||
VkSurfaceKHR createSurface(HWND win);
|
VkSurfaceKHR createSurface(HWND win);
|
||||||
void destroySurface(VkSurfaceKHR surface);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVulkanInstance *m_instance;
|
QVulkanInstance *m_instance;
|
||||||
QLibrary m_lib;
|
QLibrary m_lib;
|
||||||
PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR m_getPhysDevPresSupport;
|
PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR m_getPhysDevPresSupport;
|
||||||
PFN_vkCreateWin32SurfaceKHR m_createSurface;
|
PFN_vkCreateWin32SurfaceKHR m_createSurface;
|
||||||
PFN_vkDestroySurfaceKHR m_destroySurface;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -46,8 +46,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
QXcbVulkanInstance::QXcbVulkanInstance(QVulkanInstance *instance)
|
QXcbVulkanInstance::QXcbVulkanInstance(QVulkanInstance *instance)
|
||||||
: m_instance(instance),
|
: m_instance(instance),
|
||||||
m_getPhysDevPresSupport(nullptr),
|
m_getPhysDevPresSupport(nullptr),
|
||||||
m_createSurface(nullptr),
|
m_createSurface(nullptr)
|
||||||
m_destroySurface(nullptr)
|
|
||||||
{
|
{
|
||||||
if (qEnvironmentVariableIsSet("QT_VULKAN_LIB"))
|
if (qEnvironmentVariableIsSet("QT_VULKAN_LIB"))
|
||||||
m_lib.setFileName(QString::fromUtf8(qgetenv("QT_VULKAN_LIB")));
|
m_lib.setFileName(QString::fromUtf8(qgetenv("QT_VULKAN_LIB")));
|
||||||
@ -114,14 +113,6 @@ VkSurfaceKHR QXcbVulkanInstance::createSurface(QXcbWindow *window)
|
|||||||
qWarning("Failed to find vkCreateXcbSurfaceKHR");
|
qWarning("Failed to find vkCreateXcbSurfaceKHR");
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
if (!m_destroySurface) {
|
|
||||||
m_destroySurface = reinterpret_cast<PFN_vkDestroySurfaceKHR>(
|
|
||||||
m_vkGetInstanceProcAddr(m_vkInst, "vkDestroySurfaceKHR"));
|
|
||||||
}
|
|
||||||
if (!m_destroySurface) {
|
|
||||||
qWarning("Failed to find vkDestroySurfaceKHR");
|
|
||||||
return surface;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkXcbSurfaceCreateInfoKHR surfaceInfo;
|
VkXcbSurfaceCreateInfoKHR surfaceInfo;
|
||||||
memset(&surfaceInfo, 0, sizeof(surfaceInfo));
|
memset(&surfaceInfo, 0, sizeof(surfaceInfo));
|
||||||
@ -135,12 +126,6 @@ VkSurfaceKHR QXcbVulkanInstance::createSurface(QXcbWindow *window)
|
|||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QXcbVulkanInstance::destroySurface(VkSurfaceKHR surface)
|
|
||||||
{
|
|
||||||
if (m_destroySurface && surface)
|
|
||||||
m_destroySurface(m_vkInst, surface, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QXcbVulkanInstance::presentQueued(QWindow *window)
|
void QXcbVulkanInstance::presentQueued(QWindow *window)
|
||||||
{
|
{
|
||||||
QXcbWindow *w = static_cast<QXcbWindow *>(window->handle());
|
QXcbWindow *w = static_cast<QXcbWindow *>(window->handle());
|
||||||
|
@ -64,14 +64,12 @@ public:
|
|||||||
void presentQueued(QWindow *window) override;
|
void presentQueued(QWindow *window) override;
|
||||||
|
|
||||||
VkSurfaceKHR createSurface(QXcbWindow *window);
|
VkSurfaceKHR createSurface(QXcbWindow *window);
|
||||||
void destroySurface(VkSurfaceKHR surface);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVulkanInstance *m_instance;
|
QVulkanInstance *m_instance;
|
||||||
QLibrary m_lib;
|
QLibrary m_lib;
|
||||||
PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR m_getPhysDevPresSupport;
|
PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR m_getPhysDevPresSupport;
|
||||||
PFN_vkCreateXcbSurfaceKHR m_createSurface;
|
PFN_vkCreateXcbSurfaceKHR m_createSurface;
|
||||||
PFN_vkDestroySurfaceKHR m_destroySurface;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
Reference in New Issue
Block a user