1// Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qmemorybarrier.h"
5#include "qmemorybarrier_p.h"
6
7QT_BEGIN_NAMESPACE
8
9namespace Qt3DRender {
10
11/*!
12 \class Qt3DRender::QMemoryBarrier
13 \inmodule Qt3DRender
14 \since 5.9
15 \ingroup framegraph
16 \brief Class to emplace a memory barrier.
17
18 A Qt3DRender::QMemoryBarrier FrameGraph node is used to emplace a specific
19 memory barrier at a specific time of the rendering. This is required to
20 properly synchronize drawing and compute commands on the GPU.
21
22 The barrier defines the ordering of memory operations issued by a prior
23 command. This means that if command1 is manipulating a buffer that is to be
24 used as a vertex attribute buffer in a following command2, then the memory
25 barrier should be placed after command1 and setting the appropriate barrier
26 type for vertex attribute buffer.
27
28 When a QMemoryBarrier node is found in a FrameGraph branch, the barrier
29 will be enforced prior to any draw or compute command even if these are
30 defined deeper in the branch.
31
32 For OpenGL rendering, this page gives more info about the
33 \l {https://www.opengl.org/wiki/Memory_Model}{Memory Model}
34 */
35
36/*!
37 \qmltype MemoryBarrier
38 \inqmlmodule Qt3D.Render
39 \instantiates Qt3DRender::QMemoryBarrier
40 \inherits FrameGraphNode
41 \since 5.9
42 \brief Class to place a memory barrier.
43
44 A MemoryBarrier FrameGraph node is used to emplace a specific
45 memory barrier at a specific time of the rendering. This is required to
46 properly synchronize drawing and compute commands on the GPU.
47
48 The barrier defines the ordering of memory operations issued by a prior
49 command. This means that if command1 is manipulating a buffer that is to be
50 used as a vertex attribute buffer in a following command2, then the memory
51 barrier should be placed after command1 and setting the appropriate barrier
52 type for vertex attribute buffer.
53
54 When a QMemoryBarrier node is found in a FrameGraph branch, the barrier
55 will be enforced prior to any draw or compute command even if these are
56 defined deeper in the branch.
57
58 For OpenGL rendering, this page gives more info about the
59 \l {https://www.opengl.org/wiki/Memory_Model}{Memory Model}
60*/
61
62/*!
63 \enum QMemoryBarrier::Operation
64
65 This enum type describes types of buffer to be cleared.
66 \value None
67 \value ElementArray
68 \value Uniform
69 \value TextureFetch
70 \value ShaderImageAccess
71 \value Command
72 \value PixelBuffer
73 \value TextureUpdate
74 \value BufferUpdate
75 \value FrameBuffer
76 \value TransformFeedback
77 \value AtomicCounter
78 \value ShaderStorage
79 \value QueryBuffer
80 \value VertexAttributeArray
81 \value All
82*/
83
84
85QMemoryBarrierPrivate::QMemoryBarrierPrivate()
86 : QFrameGraphNodePrivate()
87 , m_waitOperations(QMemoryBarrier::None)
88{
89}
90
91QMemoryBarrier::QMemoryBarrier(Qt3DCore::QNode *parent)
92 : QFrameGraphNode(*new QMemoryBarrierPrivate(), parent)
93{
94}
95
96QMemoryBarrier::~QMemoryBarrier()
97{
98}
99
100void QMemoryBarrier::setWaitOperations(QMemoryBarrier::Operations waitOperations)
101{
102 Q_D(QMemoryBarrier);
103 if (waitOperations != d->m_waitOperations) {
104 d->m_waitOperations = waitOperations;
105 emit waitOperationsChanged(barrierTypes: waitOperations);
106 d->notifyPropertyChange(name: "waitOperations", value: QVariant::fromValue(value: waitOperations)); // TODOSYNC
107 }
108}
109
110QMemoryBarrier::Operations QMemoryBarrier::waitOperations() const
111{
112 Q_D(const QMemoryBarrier);
113 return d->m_waitOperations;
114}
115
116QMemoryBarrier::QMemoryBarrier(QMemoryBarrierPrivate &dd, Qt3DCore::QNode *parent)
117 : QFrameGraphNode(dd, parent)
118{
119}
120
121} // Qt3DRender
122
123QT_END_NAMESPACE
124
125#include "moc_qmemorybarrier.cpp"
126

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