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
qqnxvulkaninstance.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 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 "qqnxwindow.h"
8
10
11Q_LOGGING_CATEGORY(lcQpaQnxVulkan, "qt.qpa.qnx.vulkan")
12
13QQnxVulkanInstance::QQnxVulkanInstance(QVulkanInstance *instance)
14 : m_instance(instance),
15 m_createSurface(nullptr),
16 m_getPhysDevScreenPresSupport(nullptr)
17{
18 loadVulkanLibrary(QStringLiteral("vulkan"), 1);
19}
20
24
26{
27 initInstance(m_instance, QByteArrayList() << QByteArrayLiteral("VK_QNX_screen_surface"));
28
29 if (!m_vkInst)
30 return;
31
32 m_getPhysDevScreenPresSupport =
33 reinterpret_cast<PFN_vkGetPhysicalDeviceScreenPresentationSupportQNX>(
34 m_vkGetInstanceProcAddr(m_vkInst,
35 "vkGetPhysicalDeviceScreenPresentationSupportQNX"));
36 if (!m_getPhysDevScreenPresSupport)
37 qCWarning(lcQpaQnxVulkan, "Failed to find vkGetPhysicalDeviceScreenPresentationSupportQNX");
38}
39
40bool QQnxVulkanInstance::supportsPresent(VkPhysicalDevice physicalDevice,
41 uint32_t queueFamilyIndex,
42 QWindow *window)
43{
44 if (window->surfaceType() != QSurface::VulkanSurface) {
45 qCWarning(lcQpaQnxVulkan, "supportsPresent: called on non-Vulkan window");
46 return false;
47 }
48
49 // Prefer the QNX-specific check: it doesn't require a VkSurfaceKHR to exist yet,
50 // avoiding premature surface creation in the Vulkan driver.
51 if (m_getPhysDevScreenPresSupport) {
52 QQnxWindow *w = static_cast<QQnxWindow *>(window->handle());
53 if (!w) {
54 qCWarning(lcQpaQnxVulkan, "supportsPresent: window has no platform handle");
55 return false;
56 }
57 return m_getPhysDevScreenPresSupport(physicalDevice, queueFamilyIndex, w->nativeHandle());
58 }
59
60 // Fallback: generic surface support check (requires the surface to already exist).
61 if (m_getPhysDevSurfaceSupport) {
62 VkSurfaceKHR surface = QVulkanInstance::surfaceForWindow(window);
63 if (surface) {
64 VkBool32 supported = false;
65 VkResult err = m_getPhysDevSurfaceSupport(physicalDevice, queueFamilyIndex, surface, &supported);
66 if (err != VK_SUCCESS) {
67 qCWarning(lcQpaQnxVulkan, "vkGetPhysicalDeviceSurfaceSupportKHR failed: %d", err);
68 return true;
69 }
70 return bool(supported);
71 }
72 }
73
74 return true;
75}
76
78{
79 VkSurfaceKHR surface = VK_NULL_HANDLE;
80
81 if (!m_vkInst) {
82 qCWarning(lcQpaQnxVulkan, "createSurface: Vulkan instance not available");
83 return VK_NULL_HANDLE;
84 }
85
86 if (!m_createSurface) {
87 m_createSurface = reinterpret_cast<PFN_vkCreateScreenSurfaceQNX>(
88 m_vkGetInstanceProcAddr(m_vkInst, "vkCreateScreenSurfaceQNX"));
89 }
90 if (!m_createSurface) {
91 qCWarning(lcQpaQnxVulkan, "Failed to find vkCreateScreenSurfaceQNX");
92 return surface;
93 }
94
95 if (!window->nativeHandle()) {
96 qCWarning(lcQpaQnxVulkan, "Window has no native screen_window_t handle");
97 return surface;
98 }
99
100 VkScreenSurfaceCreateInfoQNX surfaceInfo;
101 memset(&surfaceInfo, 0, sizeof(surfaceInfo));
102 surfaceInfo.sType = VK_STRUCTURE_TYPE_SCREEN_SURFACE_CREATE_INFO_QNX;
103 surfaceInfo.context = window->screenContext();
104 surfaceInfo.window = window->nativeHandle();
105
106 VkResult err = m_createSurface(m_vkInst, &surfaceInfo, nullptr, &surface);
107
108 if (err != VK_SUCCESS) {
109 qCWarning(lcQpaQnxVulkan, "Failed to create Vulkan screen surface: %d", err);
110 } else {
111 qCDebug(lcQpaQnxVulkan, "Created Vulkan surface %p for window %p", surface, window->nativeHandle());
112 }
113
114 return surface;
115}
116
117QT_END_NAMESPACE
void createOrAdoptInstance() override
VkSurfaceKHR createSurface(QQnxWindow *window)
The QQnxWindow is the base class of the various classes used as instances of QPlatformWindow in the Q...
Definition qqnxwindow.h:31
Combined button and popup list for selecting options.