summaryrefslogtreecommitdiffstats
path: root/src/render/framegraph/qmemorybarrier.cpp
blob: 8b9354aa9d74b86b26711a052c6d2e74ae7c5e2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qmemorybarrier.h"
#include "qmemorybarrier_p.h"

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.

    When a QMemoryBarrier node is found in a FrameGraph branch, the barrier
    will be enforced prior to any draw or compute command even if these are
    defined deeper in the branch.

    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.

    When a QMemoryBarrier node is found in a FrameGraph branch, the barrier
    will be enforced prior to any draw or compute command even if these are
    defined deeper in the branch.

    For OpenGL rendering, this page gives more info about the
    \l {https://www.opengl.org/wiki/Memory_Model}{Memory Model}
*/

/*!
    \enum Qt3DRender::QMemoryBarrier::Operation

    This enum type describes types of buffer to be cleared.
    \value None
    \value ElementArray
    \value Uniform
    \value TextureFetch
    \value ShaderImageAccess
    \value Command
    \value PixelBuffer
    \value TextureUpdate
    \value BufferUpdate
    \value FrameBuffer
    \value TransformFeedback
    \value AtomicCounter
    \value ShaderStorage
    \value QueryBuffer
    \value VertexAttributeArray
    \value All
*/


QMemoryBarrierPrivate::QMemoryBarrierPrivate()
    : QFrameGraphNodePrivate()
    , m_waitOperations(QMemoryBarrier::None)
{
}

QMemoryBarrier::QMemoryBarrier(Qt3DCore::QNode *parent)
    : QFrameGraphNode(*new QMemoryBarrierPrivate(), parent)
{
}

QMemoryBarrier::~QMemoryBarrier()
{
}

void QMemoryBarrier::setWaitOperations(QMemoryBarrier::Operations waitOperations)
{
    Q_D(QMemoryBarrier);
    if (waitOperations != d->m_waitOperations) {
        d->m_waitOperations = waitOperations;
        emit waitOperationsChanged(waitOperations);
        d->notifyPropertyChange("waitOperations", QVariant::fromValue(waitOperations));  // TODOSYNC
    }
}

QMemoryBarrier::Operations QMemoryBarrier::waitOperations() const
{
    Q_D(const QMemoryBarrier);
    return d->m_waitOperations;
}

QMemoryBarrier::QMemoryBarrier(QMemoryBarrierPrivate &dd, Qt3DCore::QNode *parent)
    : QFrameGraphNode(dd, parent)
{
}

} // Qt3DRender

QT_END_NAMESPACE

#include "moc_qmemorybarrier.cpp"