Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qxcbvulkaninstance.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6#include "qxcbwindow.h"
7#include "qxcbscreen.h"
8
10
11QXcbVulkanInstance::QXcbVulkanInstance(QVulkanInstance *instance)
12 : m_instance(instance),
13 m_getPhysDevPresSupport(nullptr),
14 m_createSurface(nullptr)
15{
16 loadVulkanLibrary(QStringLiteral("vulkan"), 1);
17}
18
22
24{
25 initInstance(m_instance, QByteArrayList() << QByteArrayLiteral("VK_KHR_xcb_surface"));
26
27 if (!m_vkInst)
28 return;
29
30 m_getPhysDevPresSupport = reinterpret_cast<PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR>(
31 m_vkGetInstanceProcAddr(m_vkInst, "vkGetPhysicalDeviceXcbPresentationSupportKHR"));
32 if (!m_getPhysDevPresSupport)
33 qWarning("Failed to find vkGetPhysicalDeviceXcbPresentationSupportKHR");
34}
35
36bool QXcbVulkanInstance::supportsPresent(VkPhysicalDevice physicalDevice,
37 uint32_t queueFamilyIndex,
38 QWindow *window)
39{
40 if (!m_getPhysDevPresSupport || !m_getPhysDevSurfaceSupport)
41 return true;
42
43 QXcbWindow *w = static_cast<QXcbWindow *>(window->handle());
44 if (!w) {
45 qWarning("Attempted to call supportsPresent() without a valid platform window");
46 return false;
47 }
48 xcb_connection_t *connection = w->xcbScreen()->xcb_connection();
49 bool ok = m_getPhysDevPresSupport(physicalDevice, queueFamilyIndex, connection, w->visualId());
50
51 VkSurfaceKHR surface = QVulkanInstance::surfaceForWindow(window);
52 VkBool32 supported = false;
53 m_getPhysDevSurfaceSupport(physicalDevice, queueFamilyIndex, surface, &supported);
54 ok &= bool(supported);
55
56 return ok;
57}
58
60{
61 VkSurfaceKHR surface = VK_NULL_HANDLE;
62
63 if (!m_createSurface) {
64 m_createSurface = reinterpret_cast<PFN_vkCreateXcbSurfaceKHR>(
65 m_vkGetInstanceProcAddr(m_vkInst, "vkCreateXcbSurfaceKHR"));
66 }
67 if (!m_createSurface) {
68 qWarning("Failed to find vkCreateXcbSurfaceKHR");
69 return surface;
70 }
71
72 VkXcbSurfaceCreateInfoKHR surfaceInfo;
73 memset(&surfaceInfo, 0, sizeof(surfaceInfo));
74 surfaceInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
75 surfaceInfo.connection = window->xcbScreen()->xcb_connection();
76 surfaceInfo.window = window->xcb_window();
77 VkResult err = m_createSurface(m_vkInst, &surfaceInfo, nullptr, &surface);
78 if (err != VK_SUCCESS)
79 qWarning("Failed to create Vulkan surface: %d", err);
80
81 return surface;
82}
83
84void QXcbVulkanInstance::presentQueued(QWindow *window)
85{
86 QXcbWindow *w = static_cast<QXcbWindow *>(window->handle());
87 if (!w) {
88 qWarning("Attempted to call presentQueued() without a valid platform window");
89 return;
90 }
91
92 if (w->needsSync())
93 w->postSyncWindowRequest();
94}
95
96QT_END_NAMESPACE
VkSurfaceKHR createSurface(QXcbWindow *window)
void createOrAdoptInstance() override
void presentQueued(QWindow *window) override
bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window) override