From b539b79b08a00e2c29b028ae31659c9a4fc187bb Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Mon, 3 Oct 2016 15:53:49 +0200 Subject: Add QMemoryBarrier frontend FrameGraph node Change-Id: I8a3157644453af864275d73f5f2e12019d85a33d Reviewed-by: Paul Lemire --- src/render/framegraph/framegraph.pri | 7 +- src/render/framegraph/qframegraphnode.cpp | 6 ++ src/render/framegraph/qmemorybarrier.cpp | 160 ++++++++++++++++++++++++++++++ src/render/framegraph/qmemorybarrier.h | 101 +++++++++++++++++++ src/render/framegraph/qmemorybarrier_p.h | 77 ++++++++++++++ 5 files changed, 349 insertions(+), 2 deletions(-) create mode 100644 src/render/framegraph/qmemorybarrier.cpp create mode 100644 src/render/framegraph/qmemorybarrier.h create mode 100644 src/render/framegraph/qmemorybarrier_p.h diff --git a/src/render/framegraph/framegraph.pri b/src/render/framegraph/framegraph.pri index 523fecd05..622ca9fb9 100644 --- a/src/render/framegraph/framegraph.pri +++ b/src/render/framegraph/framegraph.pri @@ -46,7 +46,9 @@ HEADERS += \ $$PWD/qrendercapture_p.h \ $$PWD/rendercapture_p.h \ $$PWD/qframegraphnodecreatedchange.h \ - $$PWD/qframegraphnodecreatedchange_p.h + $$PWD/qframegraphnodecreatedchange_p.h \ + $$PWD/qmemorybarrier.h \ + $$PWD/qmemorybarrier_p.h SOURCES += \ $$PWD/cameraselectornode.cpp \ @@ -80,4 +82,5 @@ SOURCES += \ $$PWD/rendersurfaceselector.cpp \ $$PWD/qrendercapture.cpp \ $$PWD/rendercapture.cpp \ - $$PWD/qframegraphnodecreatedchange.cpp + $$PWD/qframegraphnodecreatedchange.cpp \ + $$PWD/qmemorybarrier.cpp diff --git a/src/render/framegraph/qframegraphnode.cpp b/src/render/framegraph/qframegraphnode.cpp index 92f07ad06..0a60edef7 100644 --- a/src/render/framegraph/qframegraphnode.cpp +++ b/src/render/framegraph/qframegraphnode.cpp @@ -106,6 +106,9 @@ QFrameGraphNodePrivate::QFrameGraphNodePrivate() \row \li Qt3DRender::QViewport \li Specify viewport + \row + \li Qt3DRender::QMemoryBarrier + \li Places a memory barrier \endtable */ @@ -167,6 +170,9 @@ QFrameGraphNodePrivate::QFrameGraphNodePrivate() \row \li Viewport \li Specify viewport + \row + \li MemoryBarrier + \li Places a memory barrier \endtable */ diff --git a/src/render/framegraph/qmemorybarrier.cpp b/src/render/framegraph/qmemorybarrier.cpp new file mode 100644 index 000000000..37df337a5 --- /dev/null +++ b/src/render/framegraph/qmemorybarrier.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D 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 "qmemorybarrier.h" +#include "qmemorybarrier_p.h" +#include + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +/*! + \class Qt3DRender::QMemoryBarrier + \inmodule Qt3DRender + \since 5.9 + \ingroup framegraph + \brief Class to emplace a memory barrier + + A Qt3DRender::QMemoryBarrier FrameGraph node is used to emplace a specific + memory barrier at a specific time of the rendering. This is required to + properly synchronize drawing and compute commands on the GPU. + + The barrier defines the ordering of memory operations issued by a prior + command. This means that if command1 is manipulating a buffer that is to be + used as a vertex attribute buffer in a following command2, then the memory + barrier should be placed after command1 and setting the appropriate barrier + type for vertex attribute buffer. + + For OpenGL rendering, this page gives more info about the + \l {https://www.opengl.org/wiki/Memory_Model}{Memory Model} + */ + +/*! + \qmltype MemoryBarrier + \inqmlmodule Qt3D.Render + \instantiates Qt3DRender::QMemoryBarrier + \inherits FrameGraphNode + \since 5.9 + \brief Class to place a memory barrier + + A MemoryBarrier FrameGraph node is used to emplace a specific + memory barrier at a specific time of the rendering. This is required to + properly synchronize drawing and compute commands on the GPU. + + The barrier defines the ordering of memory operations issued by a prior + command. This means that if command1 is manipulating a buffer that is to be + used as a vertex attribute buffer in a following command2, then the memory + barrier should be placed after command1 and setting the appropriate barrier + type for vertex attribute buffer. + + For OpenGL rendering, this page gives more info about the + \l {https://www.opengl.org/wiki/Memory_Model}{Memory Model} +*/ + +/*! + \enum QMemoryBarrier::BarrierType + + This enum type describes types of buffer to be cleared. + \value None + \value ElementArrayBarrier + \value UniformBarrier + \value TextureFetchBarrier + \value ShaderImageAccessBarrier + \value CommandBarrier + \value PixelBufferBarrier + \value TextureUpdateBarrier + \value BufferUpdateBarrier + \value FrameBufferBarrier + \value TransformFeedbackBarrier + \value AtomicCounterBarrier + \value ShaderStorageBarrier + \value QueryBufferBarrier + \value AllBarrier +*/ + + +QMemoryBarrierPrivate::QMemoryBarrierPrivate() + : QFrameGraphNodePrivate() + , m_barrierTypes(QMemoryBarrier::None) +{ +} + +QMemoryBarrier::QMemoryBarrier(Qt3DCore::QNode *parent) + : QFrameGraphNode(*new QMemoryBarrierPrivate(), parent) +{ +} + +QMemoryBarrier::~QMemoryBarrier() +{ +} + +void QMemoryBarrier::setBarrierTypes(QMemoryBarrier::BarrierTypes barrierTypes) +{ + Q_D(QMemoryBarrier); + if (barrierTypes != d->m_barrierTypes) { + d->m_barrierTypes = barrierTypes; + emit barrierTypesChanged(barrierTypes); + } +} + +QMemoryBarrier::BarrierTypes QMemoryBarrier::barrierTypes() const +{ + Q_D(const QMemoryBarrier); + return d->m_barrierTypes; +} + +QMemoryBarrier::QMemoryBarrier(QMemoryBarrierPrivate &dd, Qt3DCore::QNode *parent) + : QFrameGraphNode(dd, parent) +{ +} + +Qt3DCore::QNodeCreatedChangeBasePtr QMemoryBarrier::createNodeCreationChange() const +{ + auto creationChange = QFrameGraphNodeCreatedChangePtr::create(this); + QMemoryBarrierData &data = creationChange->data; + Q_D(const QMemoryBarrier); + data.barrierTypes = d->m_barrierTypes; + return creationChange; +} + + +} // Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/framegraph/qmemorybarrier.h b/src/render/framegraph/qmemorybarrier.h new file mode 100644 index 000000000..8ad7d6232 --- /dev/null +++ b/src/render/framegraph/qmemorybarrier.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D 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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QMEMORYBARRIER_H +#define QT3DRENDER_QMEMORYBARRIER_H + +#include + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QMemoryBarrierPrivate; + +class QT3DRENDERSHARED_EXPORT QMemoryBarrier : public QFrameGraphNode +{ + Q_OBJECT + Q_PROPERTY(QMemoryBarrier::BarrierTypes barrierTypes READ barrierTypes WRITE setBarrierTypes NOTIFY barrierTypesChanged) +public: + explicit QMemoryBarrier(Qt3DCore::QNode *parent = nullptr); + ~QMemoryBarrier(); + + enum BarrierType { + None = 0, + VertexAttributeArrayBarrier = (1 << 0), + ElementArrayBarrier = (1 << 1), + UniformBarrier = (1 << 2), + TextureFetchBarrier = (1 << 3), + ShaderImageAccessBarrier = (1 << 4), + CommandBarrier = (1 << 5), + PixelBufferBarrier = (1 << 6), + TextureUpdateBarrier = (1 << 7), + BufferUpdateBarrier = (1 << 8), + FrameBufferBarrier = (1 << 9), + TransformFeedbackBarrier = (1 << 10), + AtomicCounterBarrier = (1 << 11), + ShaderStorageBarrier = (1 << 12), + QueryBufferBarrier = (1 << 13), + AllBarrier = (1 << 14) + }; + Q_ENUM(BarrierType) + Q_DECLARE_FLAGS(BarrierTypes, BarrierType) + +public Q_SLOTS: + void setBarrierTypes(QMemoryBarrier::BarrierTypes barrierTypes); + BarrierTypes barrierTypes() const; + +Q_SIGNALS: + void barrierTypesChanged(QMemoryBarrier::BarrierTypes barrierTypes); + +protected: + explicit QMemoryBarrier(QMemoryBarrierPrivate &dd, Qt3DCore::QNode *parent = nullptr); + +private: + Q_DECLARE_PRIVATE(QMemoryBarrier) + Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE; +}; + +} // Qt3DRender + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(Qt3DRender::QMemoryBarrier::BarrierTypes) + +#endif // QT3DRENDER_QMEMORYBARRIER_H diff --git a/src/render/framegraph/qmemorybarrier_p.h b/src/render/framegraph/qmemorybarrier_p.h new file mode 100644 index 000000000..09df0c89c --- /dev/null +++ b/src/render/framegraph/qmemorybarrier_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D 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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QMEMORYBARRIER_P_H +#define QT3DRENDER_QMEMORYBARRIER_P_H +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QMemoryBarrierPrivate : public QFrameGraphNodePrivate +{ +public: + QMemoryBarrierPrivate(); + + Q_DECLARE_PUBLIC(QMemoryBarrier) + QMemoryBarrier::BarrierTypes m_barrierTypes; +}; + +struct QMemoryBarrierData +{ + QMemoryBarrier::BarrierTypes barrierTypes; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE +#endif // QT3DRENDER_QMEMORYBARRIER_P_H -- cgit v1.2.3