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)
|
||||
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))
|
||||
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,
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -86,14 +86,6 @@ VkSurfaceKHR QCocoaVulkanInstance::createSurface(NSView *view)
|
||||
qWarning("Failed to find vkCreateMacOSSurfaceMVK");
|
||||
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;
|
||||
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
|
||||
|
@ -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<PFN_vkDestroySurfaceKHR>(
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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<PFN_vkDestroySurfaceKHR>(
|
||||
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<QXcbWindow *>(window->handle());
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user