Skip to content

Commit

Permalink
Basic Vulkan enablers
Browse files Browse the repository at this point in the history
For Android, Windows and xcb. Verified on Win10 with NVIDIA, Win10
with AMD, Android with Tegra K1, Android aarch64 with Tegra X1, and
Linux aarch64 with Tegra X1 (Jetson TX1, L4T).

Introduce QPA-based Vulkan library loader, core function resolver, and
instance creation support. In addition to creating a new VkInstance,
adopting an existing one from an external engine is supported as well.

The WSI specifics are hidden in the platform plugins. Vulkan-capable
windows use the new surface type VulkanSurface and are associated with
a QVulkanInstance.

On Windows VULKAN_SDK is picked up automatically so finding vulkan.h
needs no additional manual steps once the LunarG SDK is installed.

[ChangeLog][QtGui] Added support for rendering to QWindow via the Vulkan
graphics API.

Task-number: QTBUG-55981
Change-Id: I50fa92d313fa440e0cc73939c6d7510ca317fbc9
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Oswald Buddenhagen <[email protected]>
Reviewed-by: Andy Nichols <[email protected]>
  • Loading branch information
alpqr committed Mar 17, 2017
1 parent a512c9c commit f1a23a5
Show file tree
Hide file tree
Showing 63 changed files with 9,981 additions and 19 deletions.
58 changes: 58 additions & 0 deletions config.tests/qpa/vulkan/vulkan.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the config.tests of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

// This is a header-only test. Qt does not rely on linking to a Vulkan library directly.

#include <vulkan/vulkan.h>

// The pData parameter has changed from uint32_t* to void* at some point.
// Ensure the headers have the updated one to prevent compile errors later on.
PFN_vkCmdUpdateBuffer cmdUpdBuf;
void testUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData)
{
cmdUpdBuf(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
}

int main(int, char **)
{
VkInstanceCreateInfo info;
testUpdateBuffer(0, 0, 0, 0, 0);

return 0;
}
1 change: 1 addition & 0 deletions config.tests/qpa/vulkan/vulkan.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SOURCES = vulkan.cpp
1 change: 1 addition & 0 deletions mkspecs/common/linux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ QMAKE_LIBS_OPENGL = -lGL
QMAKE_LIBS_OPENGL_ES2 = -lGLESv2
QMAKE_LIBS_OPENVG = -lOpenVG
QMAKE_LIBS_THREAD = -lpthread
QMAKE_LIBS_VULKAN =

QMAKE_INCDIR_WAYLAND =
QMAKE_LIBS_WAYLAND_CLIENT = -lwayland-client
Expand Down
1 change: 1 addition & 0 deletions mkspecs/common/msvc-desktop.conf
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ VCSOLUTION_EXTENSION = .sln
VCPROJ_KEYWORD = Qt4VSv1.0

include(windows-gles.conf)
include(windows-vulkan.conf)
5 changes: 5 additions & 0 deletions mkspecs/common/windows-vulkan.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Pick up the VULKAN_SDK env var set by the LunarG SDK so that the Vulkan
# headers are found out-of-the-box on typical Windows setups.

QMAKE_INCDIR_VULKAN = $(VULKAN_SDK)\\include
QMAKE_LIBS_VULKAN =
1 change: 1 addition & 0 deletions mkspecs/win32-g++/qmake.conf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ QMAKE_OBJCOPY = $${CROSS_COMPILE}objcopy
QMAKE_NM = $${CROSS_COMPILE}nm -P

include(../common/windows-gles.conf)
include(../common/windows-vulkan.conf)
include(../common/gcc-base.conf)

load(qt_config)
1 change: 1 addition & 0 deletions mkspecs/win32-icc/qmake.conf
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ QMAKE_LIB = xilib /NOLOGO
DSP_EXTENSION = .dsp

include(../common/windows-gles.conf)
include(../common/windows-vulkan.conf)

load(qt_config)
15 changes: 15 additions & 0 deletions src/gui/configure.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"qpa-platform-guard": "boolean",
"sm": { "type": "boolean", "name": "sessionmanager" },
"tslib": "boolean",
"vulkan": "boolean",
"xcb": { "type": "enum", "values": [ "no", "yes", "qt", "system" ] },
"xcb-xlib": "boolean",
"xinput2": "boolean",
Expand Down Expand Up @@ -211,6 +212,14 @@
"-lts"
]
},
"vulkan": {
"label": "Vulkan",
"test": "qpa/vulkan",
"sources": [
{ "type": "pkgConfig", "args": "vulkan" },
{ "type": "makeSpec", "spec": "VULKAN" }
]
},
"wayland_server": {
"label": "Wayland Server",
"test": "qpa/wayland-server",
Expand Down Expand Up @@ -605,6 +614,11 @@
"condition": "features.opengl-desktop || features.opengl-dynamic || features.opengles2",
"output": [ "publicFeature", "feature" ]
},
"vulkan": {
"label": "Vulkan",
"condition": "libs.vulkan",
"output": [ "publicFeature" ]
},
"openvg": {
"label": "OpenVG",
"condition": "libs.openvg",
Expand Down Expand Up @@ -1096,6 +1110,7 @@ QMAKE_LIBDIR_OPENGL[_ES2] and QMAKE_LIBS_OPENGL[_ES2] in the mkspec for your pla
"opengles31"
]
},
"vulkan",
"sessionmanager"
]
},
Expand Down
1 change: 1 addition & 0 deletions src/gui/gui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ include(math3d/math3d.pri)
include(opengl/opengl.pri)
include(animation/animation.pri)
include(itemmodels/itemmodels.pri)
include(vulkan/vulkan.pri)

QMAKE_LIBS += $$QMAKE_LIBS_GUI

Expand Down
22 changes: 22 additions & 0 deletions src/gui/kernel/qplatformintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,26 @@ void QPlatformIntegration::setApplicationIcon(const QIcon &icon) const
Q_UNUSED(icon);
}

#if QT_CONFIG(vulkan)

/*!
Factory function for QPlatformVulkanInstance. The \a instance parameter is a
pointer to the instance for which a platform-specific backend needs to be
created.
Returns a pointer to a QPlatformOpenGLContext instance or \c NULL if the context could
not be created.
\sa QVulkanInstance
\since 5.10
*/
QPlatformVulkanInstance *QPlatformIntegration::createPlatformVulkanInstance(QVulkanInstance *instance) const
{
Q_UNUSED(instance);
qWarning("This plugin does not support createPlatformVulkanInstance");
return nullptr;
}

#endif // QT_CONFIG(vulkan)

QT_END_NAMESPACE
6 changes: 6 additions & 0 deletions src/gui/kernel/qplatformintegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class QPlatformSessionManager;
class QKeyEvent;
class QPlatformOffscreenSurface;
class QOffscreenSurface;
class QPlatformVulkanInstance;
class QVulkanInstance;

class Q_GUI_EXPORT QPlatformIntegration
{
Expand Down Expand Up @@ -190,6 +192,10 @@ class Q_GUI_EXPORT QPlatformIntegration

virtual void beep() const;

#if QT_CONFIG(vulkan)
virtual QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) const;
#endif

protected:
void screenAdded(QPlatformScreen *screen, bool isPrimary = false);
void destroyScreen(QPlatformScreen *screen);
Expand Down
2 changes: 2 additions & 0 deletions src/gui/kernel/qsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ QT_BEGIN_NAMESPACE
requires the use of private API.
\value OpenVGSurface The surface is an OpenVG compatible surface and can be used
in conjunction with OpenVG contexts.
\value VulkanSurface The surface is a Vulkan compatible surface and can be used
in conjunction with the Vulkan graphics API.
*/


Expand Down
1 change: 1 addition & 0 deletions src/gui/kernel/qsurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Q_GUI_EXPORT QSurface
OpenGLSurface,
RasterGLSurface,
OpenVGSurface,
VulkanSurface
};

virtual ~QSurface();
Expand Down
24 changes: 24 additions & 0 deletions src/gui/kernel/qwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,30 @@ QDebug operator<<(QDebug debug, const QWindow *window)
}
#endif // !QT_NO_DEBUG_STREAM

#if QT_CONFIG(vulkan)

/*!
Associates this window with the specified Vulkan \a instance.
\a instance must stay valid as long as this QWindow instance exists.
*/
void QWindow::setVulkanInstance(QVulkanInstance *instance)
{
Q_D(QWindow);
d->vulkanInstance = instance;
}

/*!
\return the associrated Vulkan instance or \c null if there is none.
*/
QVulkanInstance *QWindow::vulkanInstance() const
{
Q_D(const QWindow);
return d->vulkanInstance;
}

#endif // QT_CONFIG(vulkan)

QT_END_NAMESPACE

#include "moc_qwindow.cpp"
8 changes: 8 additions & 0 deletions src/gui/kernel/qwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class QWindowContainer;
#ifndef QT_NO_DEBUG_STREAM
class QDebug;
#endif
#if QT_CONFIG(vulkan)
class QVulkanInstance;
#endif

class Q_GUI_EXPORT QWindow : public QObject, public QSurface
{
Expand Down Expand Up @@ -269,6 +272,11 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface

static QWindow *fromWinId(WId id);

#if QT_CONFIG(vulkan)
void setVulkanInstance(QVulkanInstance *instance);
QVulkanInstance *vulkanInstance() const;
#endif

public Q_SLOTS:
Q_REVISION(1) void requestActivate();

Expand Down
7 changes: 7 additions & 0 deletions src/gui/kernel/qwindow_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class Q_GUI_EXPORT QWindowPrivate : public QObjectPrivate
, hasCursor(false)
#endif
, compositing(false)
#if QT_CONFIG(vulkan)
, vulkanInstance(nullptr)
#endif
{
isWindow = true;
}
Expand Down Expand Up @@ -196,6 +199,10 @@ class Q_GUI_EXPORT QWindowPrivate : public QObjectPrivate

bool compositing;
QElapsedTimer lastComposeTime;

#if QT_CONFIG(vulkan)
QVulkanInstance *vulkanInstance;
#endif
};


Expand Down
88 changes: 88 additions & 0 deletions src/gui/vulkan/qplatformvulkaninstance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qplatformvulkaninstance.h"

QT_BEGIN_NAMESPACE

/*!
\class QPlatformVulkanInstance
\since 5.10
\internal
\preliminary
\ingroup qpa
\brief The QPlatformVulkanInstance class provides an abstraction for Vulkan instances.
The platform Vulkan instance is responsible for loading a Vulkan library,
resolving the basic entry points for creating instances, providing support
for creating new or adopting existing VkInstances, and abstracting some
WSI-specifics like checking if a given queue family can be used to present
using a given window.
\note platform plugins will typically subclass not this class, but rather
QBasicVulkanPlatformInstance.
\note Vulkan instance creation is split into two phases: a new
QPlatformVulkanInstance is expected to load the Vulkan library and do basic
initialization, after which the supported layers and extensions can be
queried. Everything else is deferred into createOrAdoptInstance().
*/

class QPlatformVulkanInstancePrivate
{
public:
QPlatformVulkanInstancePrivate() { }
};

QPlatformVulkanInstance::QPlatformVulkanInstance()
: d_ptr(new QPlatformVulkanInstancePrivate)
{
}

QPlatformVulkanInstance::~QPlatformVulkanInstance()
{
}

void QPlatformVulkanInstance::presentQueued(QWindow *window)
{
Q_UNUSED(window);
}

QT_END_NAMESPACE
Loading

0 comments on commit f1a23a5

Please sign in to comment.