1// Copyright (C) 2018 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 "qsetfence.h"
5#include "qsetfence_p.h"
6
7QT_BEGIN_NAMESPACE
8
9namespace Qt3DRender {
10
11QSetFencePrivate::QSetFencePrivate()
12 : QFrameGraphNodePrivate()
13 , m_handleType(QSetFence::NoHandle)
14 , m_handle(QVariant())
15{
16}
17
18/*!
19 \class Qt3DRender::QSetFence
20 \inmodule Qt3DRender
21 \brief FrameGraphNode used to insert a fence in the graphics command stream.
22
23 Fence allow to synchronosize GPU and CPU workloads. GPU commands usually
24 are non-blocking. When issued, commands are inserted in command buffers
25 which will be read at a later time by the GPU. In some cases, you want to
26 continue processing or issue specific command only when you are sure a
27 command has been executed by the hardware. Fences are a way to do so. This
28 is especially important when using 3rd party engines with Qt3D, Qt3D should
29 only access shared resources when we know the other engine command are done
30 modifying the resource.
31
32 QSetFence is a FrameGraph node that inserts a fence into the command
33 stream. It can then be used in conjunction with \l QWaitFence or by
34 extracting the underlying handle.
35
36 The handle property will be updated once the renderer has created the
37 underlying fence resource. The handle will remain valid as long as it
38 remains in the unsignaled state. Once it has reached the signaled state, it
39 will be destroyed and a new handle will be created. That means that
40 depending on how long it takes for the fence to be signaled, the same
41 handle could be used over several frames.
42
43 \since 5.13
44 */
45QSetFence::QSetFence(Qt3DCore::QNode *parent)
46 : QFrameGraphNode(*new QSetFencePrivate(), parent)
47{
48}
49
50QSetFence::~QSetFence()
51{
52}
53
54QSetFence::QSetFence(QSetFencePrivate &dd, Qt3DCore::QNode *parent)
55 : QFrameGraphNode(dd, parent)
56{
57}
58
59/*!
60 \qmlproperty HandleType SetFence::handleType
61
62 Specifies the type of handle being used. Currently only OpenGL Fence ids
63 are supported.
64*/
65/*!
66 \property Qt3DRender::QSetFence::handleType
67
68 Specifies the type of handle being used. Currently only OpenGL Fence ids
69 are supported.
70*/
71QSetFence::HandleType QSetFence::handleType() const
72{
73 Q_D(const QSetFence);
74 return d->m_handleType;
75}
76
77void QSetFencePrivate::setHandleType(QSetFence::HandleType type)
78{
79 Q_Q(QSetFence);
80 if (m_handleType != type) {
81 const bool blocked = q->blockNotifications(block: true);
82 m_handleType = type;
83 emit q->handleTypeChanged(handleType: type);
84 q->blockNotifications(block: blocked);
85 }
86}
87
88/*!
89 \qmlproperty variant SetFence::handle
90
91 Holds the underlying fence handle wrapped in a variant.
92*/
93/*!
94 \property Qt3DRender::QSetFence::handle
95
96 Holds the underlying fence handle wrapped in a QVariant.
97*/
98QVariant QSetFence::handle() const
99{
100 Q_D(const QSetFence);
101 return d->m_handle;
102}
103
104void QSetFencePrivate::setHandle(QVariant handle)
105{
106 Q_Q(QSetFence);
107 if (m_handle != handle) {
108 const bool blocked = q->blockNotifications(block: true);
109 m_handle = handle;
110 emit q->handleChanged(handle);
111 q->blockNotifications(block: blocked);
112 }
113}
114
115} // Qt3DRender
116
117QT_END_NAMESPACE
118
119#include "moc_qsetfence.cpp"
120

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