| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2015 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 "qdispatchcompute.h" | 
| 41 | #include "qdispatchcompute_p.h" | 
| 42 | #include <Qt3DRender/qframegraphnodecreatedchange.h> | 
| 43 |  | 
| 44 | QT_BEGIN_NAMESPACE | 
| 45 |  | 
| 46 | namespace Qt3DRender { | 
| 47 | /*! | 
| 48 |     \class Qt3DRender::QDispatchCompute | 
| 49 |     \inmodule Qt3DRender | 
| 50 |     \since 5.7 | 
| 51 |     \ingroup framegraph | 
| 52 |     \brief FrameGraph node to issue work for the compute shader on GPU. | 
| 53 |  | 
| 54 |     A Qt3DRender::QDispatchCompute allows work to be issued for the compute shader to | 
| 55 |     run on the GPU. The workGroupX, workGroupY and workGroupZ properties specify the work group | 
| 56 |     sizes for the compute shader invocation. QComputeCommand components need to be added | 
| 57 |     to entities to instruct Qt3D to select the materials and geometry from the entities | 
| 58 |     for the compute invocation. The work group sizes for the shader invocation will be | 
| 59 |     the maximum of the work group sizes specified in QDispatchCompute and QComputeCommand. | 
| 60 |  | 
| 61 |  */ | 
| 62 |  | 
| 63 | /*! | 
| 64 |     \qmltype DispatchCompute | 
| 65 |     \inqmlmodule Qt3D.Render | 
| 66 |     \instantiates Qt3DRender::QDispatchCompute | 
| 67 |     \inherits FrameGraphNode | 
| 68 |     \since 5.7 | 
| 69 |     \brief FrameGraph node to issue work for the compute shader on GPU. | 
| 70 |  | 
| 71 |     A DispatchCompute allows work to be issued for the compute shader to run on the GPU. | 
| 72 |     The workGroupX, workGroupY and workGroupZ properties specify the work group sizes for | 
| 73 |     the compute shader invocation. ComputeCommand components need to be added | 
| 74 |     to entities to instruct Qt3D to select the materials and geometry from the entities | 
| 75 |     for the compute invocation. The work group sizes for the shader invocation will be | 
| 76 |     the maximum of the work group sizes specified in DispatchCompute and ComputeCommand. | 
| 77 | */ | 
| 78 |  | 
| 79 | /*! | 
| 80 |     \qmlproperty int DispatchCompute::workGroupX | 
| 81 |     Specifies X workgroup size. | 
| 82 |  */ | 
| 83 |  | 
| 84 | /*! | 
| 85 |     \qmlproperty int DispatchCompute::workGroupY | 
| 86 |     Specifies Y workgroup size. | 
| 87 |  */ | 
| 88 |  | 
| 89 | /*! | 
| 90 |     \qmlproperty int DispatchCompute::workGroupZ | 
| 91 |     Specifies Z workgroup size. | 
| 92 |  */ | 
| 93 |  | 
| 94 | /*! | 
| 95 |     The constructor creates an instance with the specified \a parent. | 
| 96 |  */ | 
| 97 | QDispatchCompute::QDispatchCompute(Qt3DCore::QNode *parent) | 
| 98 |     : QFrameGraphNode(*new QDispatchComputePrivate(), parent) | 
| 99 | { | 
| 100 | } | 
| 101 |  | 
| 102 | /*! \internal */ | 
| 103 | QDispatchCompute::~QDispatchCompute() | 
| 104 | { | 
| 105 | } | 
| 106 |  | 
| 107 | int QDispatchCompute::workGroupX() const | 
| 108 | { | 
| 109 |     Q_D(const QDispatchCompute); | 
| 110 |     return d->m_workGroupX; | 
| 111 | } | 
| 112 |  | 
| 113 | int QDispatchCompute::workGroupY() const | 
| 114 | { | 
| 115 |     Q_D(const QDispatchCompute); | 
| 116 |     return d->m_workGroupY; | 
| 117 | } | 
| 118 |  | 
| 119 | int QDispatchCompute::workGroupZ() const | 
| 120 | { | 
| 121 |     Q_D(const QDispatchCompute); | 
| 122 |     return d->m_workGroupZ; | 
| 123 | } | 
| 124 |  | 
| 125 | /*! | 
| 126 |     \property Qt3DRender::QDispatchCompute::workGroupX | 
| 127 |     Specifies X workgroup. | 
| 128 |  */ | 
| 129 | void QDispatchCompute::setWorkGroupX(int workGroupX) | 
| 130 | { | 
| 131 |     Q_D(QDispatchCompute); | 
| 132 |     if (d->m_workGroupX != workGroupX) { | 
| 133 |         d->m_workGroupX = workGroupX; | 
| 134 |         emit workGroupXChanged(); | 
| 135 |     } | 
| 136 | } | 
| 137 |  | 
| 138 | /*! | 
| 139 |     \property Qt3DRender::QDispatchCompute::workGroupY | 
| 140 |     Specifies Y workgroup. | 
| 141 |  */ | 
| 142 | void QDispatchCompute::setWorkGroupY(int workGroupY) | 
| 143 | { | 
| 144 |     Q_D(QDispatchCompute); | 
| 145 |     if (d->m_workGroupY != workGroupY) { | 
| 146 |         d->m_workGroupY = workGroupY; | 
| 147 |         emit workGroupYChanged(); | 
| 148 |     } | 
| 149 | } | 
| 150 |  | 
| 151 | /*! | 
| 152 |     \property Qt3DRender::QDispatchCompute::workGroupZ | 
| 153 |     Specifies Z workgroup. | 
| 154 |  */ | 
| 155 | void QDispatchCompute::setWorkGroupZ(int workGroupZ) | 
| 156 | { | 
| 157 |     Q_D(QDispatchCompute); | 
| 158 |     if (d->m_workGroupZ != workGroupZ) { | 
| 159 |         d->m_workGroupZ = workGroupZ; | 
| 160 |         emit workGroupZChanged(); | 
| 161 |     } | 
| 162 |  | 
| 163 | } | 
| 164 |  | 
| 165 | Qt3DCore::QNodeCreatedChangeBasePtr QDispatchCompute::createNodeCreationChange() const | 
| 166 | { | 
| 167 |     auto creationChange = QFrameGraphNodeCreatedChangePtr<QDispatchComputeData>::create(arguments: this); | 
| 168 |     auto &data = creationChange->data; | 
| 169 |     Q_D(const QDispatchCompute); | 
| 170 |     data.workGroupX = d->m_workGroupX; | 
| 171 |     data.workGroupY = d->m_workGroupY; | 
| 172 |     data.workGroupZ = d->m_workGroupZ; | 
| 173 |     return creationChange; | 
| 174 | } | 
| 175 |  | 
| 176 | } // Qt3DRender | 
| 177 |  | 
| 178 | QT_END_NAMESPACE | 
| 179 |  | 
| 180 |  |