1/****************************************************************************
2**
3** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qmemorybarrier.h"
41#include "qmemorybarrier_p.h"
42#include <Qt3DRender/qframegraphnodecreatedchange.h>
43
44QT_BEGIN_NAMESPACE
45
46namespace Qt3DRender {
47
48/*!
49 \class Qt3DRender::QMemoryBarrier
50 \inmodule Qt3DRender
51 \since 5.9
52 \ingroup framegraph
53 \brief Class to emplace a memory barrier.
54
55 A Qt3DRender::QMemoryBarrier FrameGraph node is used to emplace a specific
56 memory barrier at a specific time of the rendering. This is required to
57 properly synchronize drawing and compute commands on the GPU.
58
59 The barrier defines the ordering of memory operations issued by a prior
60 command. This means that if command1 is manipulating a buffer that is to be
61 used as a vertex attribute buffer in a following command2, then the memory
62 barrier should be placed after command1 and setting the appropriate barrier
63 type for vertex attribute buffer.
64
65 When a QMemoryBarrier node is found in a FrameGraph branch, the barrier
66 will be enforced prior to any draw or compute command even if these are
67 defined deeper in the branch.
68
69 For OpenGL rendering, this page gives more info about the
70 \l {https://www.opengl.org/wiki/Memory_Model}{Memory Model}
71 */
72
73/*!
74 \qmltype MemoryBarrier
75 \inqmlmodule Qt3D.Render
76 \instantiates Qt3DRender::QMemoryBarrier
77 \inherits FrameGraphNode
78 \since 5.9
79 \brief Class to place a memory barrier.
80
81 A MemoryBarrier FrameGraph node is used to emplace a specific
82 memory barrier at a specific time of the rendering. This is required to
83 properly synchronize drawing and compute commands on the GPU.
84
85 The barrier defines the ordering of memory operations issued by a prior
86 command. This means that if command1 is manipulating a buffer that is to be
87 used as a vertex attribute buffer in a following command2, then the memory
88 barrier should be placed after command1 and setting the appropriate barrier
89 type for vertex attribute buffer.
90
91 When a QMemoryBarrier node is found in a FrameGraph branch, the barrier
92 will be enforced prior to any draw or compute command even if these are
93 defined deeper in the branch.
94
95 For OpenGL rendering, this page gives more info about the
96 \l {https://www.opengl.org/wiki/Memory_Model}{Memory Model}
97*/
98
99/*!
100 \enum QMemoryBarrier::Operation
101
102 This enum type describes types of buffer to be cleared.
103 \value None
104 \value ElementArray
105 \value Uniform
106 \value TextureFetch
107 \value ShaderImageAccess
108 \value Command
109 \value PixelBuffer
110 \value TextureUpdate
111 \value BufferUpdate
112 \value FrameBuffer
113 \value TransformFeedback
114 \value AtomicCounter
115 \value ShaderStorage
116 \value QueryBuffer
117 \value VertexAttributeArray
118 \value All
119*/
120
121
122QMemoryBarrierPrivate::QMemoryBarrierPrivate()
123 : QFrameGraphNodePrivate()
124 , m_waitOperations(QMemoryBarrier::None)
125{
126}
127
128QMemoryBarrier::QMemoryBarrier(Qt3DCore::QNode *parent)
129 : QFrameGraphNode(*new QMemoryBarrierPrivate(), parent)
130{
131}
132
133QMemoryBarrier::~QMemoryBarrier()
134{
135}
136
137void QMemoryBarrier::setWaitOperations(QMemoryBarrier::Operations waitOperations)
138{
139 Q_D(QMemoryBarrier);
140 if (waitOperations != d->m_waitOperations) {
141 d->m_waitOperations = waitOperations;
142 emit waitOperationsChanged(barrierTypes: waitOperations);
143 d->notifyPropertyChange(name: "waitOperations", value: QVariant::fromValue(value: waitOperations)); // TODOSYNC
144 }
145}
146
147QMemoryBarrier::Operations QMemoryBarrier::waitOperations() const
148{
149 Q_D(const QMemoryBarrier);
150 return d->m_waitOperations;
151}
152
153QMemoryBarrier::QMemoryBarrier(QMemoryBarrierPrivate &dd, Qt3DCore::QNode *parent)
154 : QFrameGraphNode(dd, parent)
155{
156}
157
158Qt3DCore::QNodeCreatedChangeBasePtr QMemoryBarrier::createNodeCreationChange() const
159{
160 auto creationChange = QFrameGraphNodeCreatedChangePtr<QMemoryBarrierData>::create(arguments: this);
161 QMemoryBarrierData &data = creationChange->data;
162 Q_D(const QMemoryBarrier);
163 data.waitOperations = d->m_waitOperations;
164 return creationChange;
165}
166
167
168} // Qt3DRender
169
170QT_END_NAMESPACE
171

source code of qt3d/src/render/framegraph/qmemorybarrier.cpp