From fec8a9323b853ca0cefdbb755fcc74ca6bdfab03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 25 Apr 2018 22:35:49 +0200 Subject: [PATCH] Vulkan: Share destroySurface() 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: I1380b2bd03080710084a1458bdce3a362ba5c287 Reviewed-by: Tor Arne Vestbø --- .../qbasicvulkanplatforminstance.cpp | 11 +++++++++++ .../qbasicvulkanplatforminstance_p.h | 2 ++ .../platforms/cocoa/qcocoavulkaninstance.h | 2 -- .../platforms/cocoa/qcocoavulkaninstance.mm | 14 -------------- .../windows/qwindowsvulkaninstance.cpp | 17 +---------------- .../platforms/windows/qwindowsvulkaninstance.h | 2 -- .../platforms/xcb/qxcbvulkaninstance.cpp | 17 +---------------- src/plugins/platforms/xcb/qxcbvulkaninstance.h | 2 -- 8 files changed, 15 insertions(+), 52 deletions(-) diff --git a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp index 382d142334..d8b4e0a7e0 100644 --- a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp +++ b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp @@ -256,6 +256,11 @@ void QBasicPlatformVulkanInstance::initInstance(QVulkanInstance *instance, const if (!m_getPhysDevSurfaceSupport) qWarning("Failed to find vkGetPhysicalDeviceSurfaceSupportKHR"); + m_destroySurface = reinterpret_cast( + m_vkGetInstanceProcAddr(m_vkInst, "vkDestroySurfaceKHR")); + if (!m_destroySurface) + qWarning("Failed to find vkDestroySurfaceKHR"); + if (!flags.testFlag(QVulkanInstance::NoDebugOutputRedirect)) setupDebugOutput(); } @@ -310,6 +315,12 @@ bool QBasicPlatformVulkanInstance::supportsPresent(VkPhysicalDevice physicalDevi 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, VkDebugReportObjectTypeEXT objectType, uint64_t object, diff --git a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h index 748b138f01..7395ee0323 100644 --- a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h +++ b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h @@ -72,6 +72,7 @@ public: QByteArrayList enabledExtensions() const override; PFN_vkVoidFunction getInstanceProcAddr(const char *name) override; bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window) override; + void destroySurface(VkSurfaceKHR surface) const; protected: void init(QLibrary *lib); @@ -80,6 +81,7 @@ protected: VkInstance m_vkInst; PFN_vkGetInstanceProcAddr m_vkGetInstanceProcAddr; PFN_vkGetPhysicalDeviceSurfaceSupportKHR m_getPhysDevSurfaceSupport; + PFN_vkDestroySurfaceKHR m_destroySurface; private: void setupDebugOutput(); diff --git a/src/plugins/platforms/cocoa/qcocoavulkaninstance.h b/src/plugins/platforms/cocoa/qcocoavulkaninstance.h index c9c6cf7e3f..ea8e4972fb 100644 --- a/src/plugins/platforms/cocoa/qcocoavulkaninstance.h +++ b/src/plugins/platforms/cocoa/qcocoavulkaninstance.h @@ -60,13 +60,11 @@ public: VkSurfaceKHR *createSurface(QWindow *window); VkSurfaceKHR createSurface(NSView *view); - void destroySurface(VkSurfaceKHR surface); private: QVulkanInstance *m_instance = nullptr; QLibrary m_lib; VkSurfaceKHR m_nullSurface = nullptr; PFN_vkCreateMacOSSurfaceMVK m_createSurface = nullptr; - PFN_vkDestroySurfaceKHR m_destroySurface = nullptr; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm b/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm index 5da929766f..c010e12662 100644 --- a/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm +++ b/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm @@ -86,14 +86,6 @@ VkSurfaceKHR QCocoaVulkanInstance::createSurface(NSView *view) qWarning("Failed to find vkCreateMacOSSurfaceMVK"); return m_nullSurface; } - if (!m_destroySurface) { - m_destroySurface = reinterpret_cast( - m_vkGetInstanceProcAddr(m_vkInst, "vkDestroySurfaceKHR")); - } - if (!m_destroySurface) { - qWarning("Failed to find vkDestroySurfaceKHR"); - return m_nullSurface; - } VkMacOSSurfaceCreateInfoMVK surfaceInfo; surfaceInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK; @@ -109,11 +101,5 @@ VkSurfaceKHR QCocoaVulkanInstance::createSurface(NSView *view) return surface; } -void QCocoaVulkanInstance::destroySurface(VkSurfaceKHR surface) -{ - if (m_destroySurface && surface) - m_destroySurface(m_vkInst, surface, nullptr); -} - QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowsvulkaninstance.cpp b/src/plugins/platforms/windows/qwindowsvulkaninstance.cpp index d81ee8ba29..f2e44e0141 100644 --- a/src/plugins/platforms/windows/qwindowsvulkaninstance.cpp +++ b/src/plugins/platforms/windows/qwindowsvulkaninstance.cpp @@ -44,8 +44,7 @@ QT_BEGIN_NAMESPACE QWindowsVulkanInstance::QWindowsVulkanInstance(QVulkanInstance *instance) : m_instance(instance), m_getPhysDevPresSupport(nullptr), - m_createSurface(nullptr), - m_destroySurface(nullptr) + m_createSurface(nullptr) { if (qEnvironmentVariableIsSet("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"); return surface; } - if (!m_destroySurface) { - m_destroySurface = reinterpret_cast( - m_vkGetInstanceProcAddr(m_vkInst, "vkDestroySurfaceKHR")); - } - if (!m_destroySurface) { - qWarning("Failed to find vkDestroySurfaceKHR"); - return surface; - } VkWin32SurfaceCreateInfoKHR surfaceInfo; memset(&surfaceInfo, 0, sizeof(surfaceInfo)); @@ -127,10 +118,4 @@ VkSurfaceKHR QWindowsVulkanInstance::createSurface(HWND win) return surface; } -void QWindowsVulkanInstance::destroySurface(VkSurfaceKHR surface) -{ - if (m_destroySurface && surface) - m_destroySurface(m_vkInst, surface, nullptr); -} - QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowsvulkaninstance.h b/src/plugins/platforms/windows/qwindowsvulkaninstance.h index ca60ab7627..a99766e940 100644 --- a/src/plugins/platforms/windows/qwindowsvulkaninstance.h +++ b/src/plugins/platforms/windows/qwindowsvulkaninstance.h @@ -61,14 +61,12 @@ public: bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window) override; VkSurfaceKHR createSurface(HWND win); - void destroySurface(VkSurfaceKHR surface); private: QVulkanInstance *m_instance; QLibrary m_lib; PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR m_getPhysDevPresSupport; PFN_vkCreateWin32SurfaceKHR m_createSurface; - PFN_vkDestroySurfaceKHR m_destroySurface; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/qxcbvulkaninstance.cpp b/src/plugins/platforms/xcb/qxcbvulkaninstance.cpp index 4d540defa9..5a6a4ef809 100644 --- a/src/plugins/platforms/xcb/qxcbvulkaninstance.cpp +++ b/src/plugins/platforms/xcb/qxcbvulkaninstance.cpp @@ -46,8 +46,7 @@ QT_BEGIN_NAMESPACE QXcbVulkanInstance::QXcbVulkanInstance(QVulkanInstance *instance) : m_instance(instance), m_getPhysDevPresSupport(nullptr), - m_createSurface(nullptr), - m_destroySurface(nullptr) + m_createSurface(nullptr) { if (qEnvironmentVariableIsSet("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"); return surface; } - if (!m_destroySurface) { - m_destroySurface = reinterpret_cast( - m_vkGetInstanceProcAddr(m_vkInst, "vkDestroySurfaceKHR")); - } - if (!m_destroySurface) { - qWarning("Failed to find vkDestroySurfaceKHR"); - return surface; - } VkXcbSurfaceCreateInfoKHR surfaceInfo; memset(&surfaceInfo, 0, sizeof(surfaceInfo)); @@ -135,12 +126,6 @@ VkSurfaceKHR QXcbVulkanInstance::createSurface(QXcbWindow *window) return surface; } -void QXcbVulkanInstance::destroySurface(VkSurfaceKHR surface) -{ - if (m_destroySurface && surface) - m_destroySurface(m_vkInst, surface, nullptr); -} - void QXcbVulkanInstance::presentQueued(QWindow *window) { QXcbWindow *w = static_cast(window->handle()); diff --git a/src/plugins/platforms/xcb/qxcbvulkaninstance.h b/src/plugins/platforms/xcb/qxcbvulkaninstance.h index dbe057d944..c5981d3605 100644 --- a/src/plugins/platforms/xcb/qxcbvulkaninstance.h +++ b/src/plugins/platforms/xcb/qxcbvulkaninstance.h @@ -64,14 +64,12 @@ public: void presentQueued(QWindow *window) override; VkSurfaceKHR createSurface(QXcbWindow *window); - void destroySurface(VkSurfaceKHR surface); private: QVulkanInstance *m_instance; QLibrary m_lib; PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR m_getPhysDevPresSupport; PFN_vkCreateXcbSurfaceKHR m_createSurface; - PFN_vkDestroySurfaceKHR m_destroySurface; }; QT_END_NAMESPACE