diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2019-09-19 09:57:53 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2019-09-25 11:41:37 +0200 |
commit | cca7720e68a3bf64dbf549b06ba13547cb29181c (patch) | |
tree | 508738a646160deb682dafba057ca168617cda53 | |
parent | e498e2fc16a09cab315ffaf88eea1679fe2a436d (diff) |
Update QComputeCommand to use direct sync
Change-Id: I5e755bbc7e3a948f7f2356d7110ac817ae32616a
Reviewed-by: Mike Krus <mike.krus@kdab.com>
-rw-r--r-- | src/render/backend/computecommand.cpp | 50 | ||||
-rw-r--r-- | src/render/backend/computecommand_p.h | 3 | ||||
-rw-r--r-- | src/render/frontend/qcomputecommand.cpp | 5 | ||||
-rw-r--r-- | src/render/frontend/qrenderaspect.cpp | 2 | ||||
-rw-r--r-- | tests/auto/render/computecommand/tst_computecommand.cpp | 44 | ||||
-rw-r--r-- | tests/auto/render/qcomputecommand/tst_qcomputecommand.cpp | 25 |
6 files changed, 48 insertions, 81 deletions
diff --git a/src/render/backend/computecommand.cpp b/src/render/backend/computecommand.cpp index 7079d0308..386c25fec 100644 --- a/src/render/backend/computecommand.cpp +++ b/src/render/backend/computecommand.cpp @@ -73,35 +73,35 @@ void ComputeCommand::cleanup() m_runType = QComputeCommand::Continuous; } -void ComputeCommand::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) +void ComputeCommand::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) { - const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QComputeCommandData>>(change); - const auto &data = typedChange->data; - m_workGroups[0] = data.workGroupX; - m_workGroups[1] = data.workGroupY; - m_workGroups[2] = data.workGroupZ; - m_runType = data.runType; - m_frameCount = data.frameCount; - markDirty(AbstractRenderer::ComputeDirty); -} + const QComputeCommand *node = qobject_cast<const QComputeCommand *>(frontEnd); + if (!node) + return; -void ComputeCommand::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) -{ - Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e); - if (e->type() == Qt3DCore::PropertyUpdated) { - if (propertyChange->propertyName() == QByteArrayLiteral("workGroupX")) - m_workGroups[0] = propertyChange->value().toInt(); - else if (propertyChange->propertyName() == QByteArrayLiteral("workGroupY")) - m_workGroups[1] = propertyChange->value().toInt(); - else if (propertyChange->propertyName() == QByteArrayLiteral("workGroupZ")) - m_workGroups[2] = propertyChange->value().toInt(); - else if (propertyChange->propertyName() == QByteArrayLiteral("frameCount")) - m_frameCount = propertyChange->value().toInt(); - else if (propertyChange->propertyName() == QByteArrayLiteral("runType")) - m_runType = static_cast<QComputeCommand::RunType>(propertyChange->value().toInt()); + BackendNode::syncFromFrontEnd(frontEnd, firstTime); + + if (m_workGroups[0] != node->workGroupX()) { + m_workGroups[0] = node->workGroupX(); + markDirty(AbstractRenderer::ComputeDirty); + } + if (m_workGroups[1] != node->workGroupY()) { + m_workGroups[1] = node->workGroupY(); + markDirty(AbstractRenderer::ComputeDirty); + } + if (m_workGroups[2] != node->workGroupZ()) { + m_workGroups[2] = node->workGroupZ(); + markDirty(AbstractRenderer::ComputeDirty); + } + if (node->runType() != m_runType) { + m_runType = node->runType(); + markDirty(AbstractRenderer::ComputeDirty); + } + const QComputeCommandPrivate *d = static_cast<const QComputeCommandPrivate *>(Qt3DCore::QNodePrivate::get(node)); + if (d->m_frameCount != m_frameCount) { + m_frameCount = d->m_frameCount; markDirty(AbstractRenderer::ComputeDirty); } - BackendNode::sceneChangeEvent(e); } // Called from buildComputeRenderCommands in a job diff --git a/src/render/backend/computecommand_p.h b/src/render/backend/computecommand_p.h index 10e10fd25..dc2069928 100644 --- a/src/render/backend/computecommand_p.h +++ b/src/render/backend/computecommand_p.h @@ -69,7 +69,7 @@ public: ~ComputeCommand(); void cleanup(); - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override; + void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; inline int x() const Q_DECL_NOTHROW { return m_workGroups[0]; } inline int y() const Q_DECL_NOTHROW { return m_workGroups[1]; } @@ -81,7 +81,6 @@ public: void updateFrameCount(); private: - void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) override; int m_workGroups[3]; int m_frameCount; QComputeCommand::RunType m_runType; diff --git a/src/render/frontend/qcomputecommand.cpp b/src/render/frontend/qcomputecommand.cpp index 8b176cd4f..b0bec42d4 100644 --- a/src/render/frontend/qcomputecommand.cpp +++ b/src/render/frontend/qcomputecommand.cpp @@ -156,10 +156,7 @@ QComputeCommandPrivate::QComputeCommandPrivate() void QComputeCommandPrivate::setFrameCount(int frameCount) { m_frameCount = frameCount; - const auto propertyChange = Qt3DCore::QPropertyUpdatedChangePtr::create(m_id); - propertyChange->setPropertyName("frameCount"); - propertyChange->setValue(m_frameCount); - notifyObservers(propertyChange); + update(); } /*! diff --git a/src/render/frontend/qrenderaspect.cpp b/src/render/frontend/qrenderaspect.cpp index 575e2c70e..c83b5cb69 100644 --- a/src/render/frontend/qrenderaspect.cpp +++ b/src/render/frontend/qrenderaspect.cpp @@ -268,7 +268,7 @@ void QRenderAspectPrivate::registerBackendTypes() // Geometry + Compute q->registerBackendType<QAttribute, true>(QSharedPointer<Render::NodeFunctor<Render::Attribute, Render::AttributeManager> >::create(m_renderer)); q->registerBackendType<QBuffer, true>(QSharedPointer<Render::BufferFunctor>::create(m_renderer, m_nodeManagers->bufferManager())); - q->registerBackendType<QComputeCommand>(QSharedPointer<Render::NodeFunctor<Render::ComputeCommand, Render::ComputeCommandManager> >::create(m_renderer)); + q->registerBackendType<QComputeCommand, true>(QSharedPointer<Render::NodeFunctor<Render::ComputeCommand, Render::ComputeCommandManager> >::create(m_renderer)); q->registerBackendType<QGeometry, true>(QSharedPointer<Render::NodeFunctor<Render::Geometry, Render::GeometryManager> >::create(m_renderer)); q->registerBackendType<QGeometryRenderer, true>(QSharedPointer<Render::GeometryRendererFunctor>::create(m_renderer, m_nodeManagers->geometryRendererManager())); q->registerBackendType<Qt3DCore::QArmature, true>(QSharedPointer<Render::NodeFunctor<Render::Armature, Render::ArmatureManager>>::create(m_renderer)); diff --git a/tests/auto/render/computecommand/tst_computecommand.cpp b/tests/auto/render/computecommand/tst_computecommand.cpp index a82c3eeaf..990c0cd98 100644 --- a/tests/auto/render/computecommand/tst_computecommand.cpp +++ b/tests/auto/render/computecommand/tst_computecommand.cpp @@ -87,7 +87,7 @@ private Q_SLOTS: // WHEN Qt3DRender::Render::ComputeCommand backendComputeCommand; backendComputeCommand.setRenderer(&renderer); - simulateInitialization(&computeCommand, &backendComputeCommand); + simulateInitializationSync(&computeCommand, &backendComputeCommand); // THEN QCOMPARE(backendComputeCommand.isEnabled(), true); @@ -105,7 +105,7 @@ private Q_SLOTS: Qt3DRender::Render::ComputeCommand backendComputeCommand; backendComputeCommand.setRenderer(&renderer); computeCommand.setEnabled(false); - simulateInitialization(&computeCommand, &backendComputeCommand); + simulateInitializationSync(&computeCommand, &backendComputeCommand); // THEN QCOMPARE(backendComputeCommand.peerId(), computeCommand.id()); @@ -118,16 +118,16 @@ private Q_SLOTS: { // GIVEN Qt3DRender::Render::ComputeCommand backendComputeCommand; + Qt3DRender::QComputeCommand computeCommand; TestRenderer renderer; backendComputeCommand.setRenderer(&renderer); + simulateInitializationSync(&computeCommand, &backendComputeCommand); { // WHEN const bool newValue = false; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("enabled"); - change->setValue(newValue); - backendComputeCommand.sceneChangeEvent(change); + computeCommand.setEnabled(newValue); + backendComputeCommand.syncFromFrontEnd(&computeCommand, false); // THEN QCOMPARE(backendComputeCommand.isEnabled(), newValue); @@ -135,10 +135,8 @@ private Q_SLOTS: { // WHEN const int newValue = 128; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("workGroupX"); - change->setValue(newValue); - backendComputeCommand.sceneChangeEvent(change); + computeCommand.setWorkGroupX(newValue); + backendComputeCommand.syncFromFrontEnd(&computeCommand, false); // THEN QCOMPARE(backendComputeCommand.x(), newValue); @@ -146,10 +144,8 @@ private Q_SLOTS: { // WHEN const int newValue = 64; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("workGroupY"); - change->setValue(newValue); - backendComputeCommand.sceneChangeEvent(change); + computeCommand.setWorkGroupY(newValue); + backendComputeCommand.syncFromFrontEnd(&computeCommand, false); // THEN QCOMPARE(backendComputeCommand.y(), newValue); @@ -157,10 +153,8 @@ private Q_SLOTS: { // WHEN const int newValue = 32; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("workGroupZ"); - change->setValue(newValue); - backendComputeCommand.sceneChangeEvent(change); + computeCommand.setWorkGroupZ(newValue); + backendComputeCommand.syncFromFrontEnd(&computeCommand, false); // THEN QCOMPARE(backendComputeCommand.z(), newValue); @@ -168,10 +162,8 @@ private Q_SLOTS: { // WHEN const Qt3DRender::QComputeCommand::RunType newValue = Qt3DRender::QComputeCommand::Manual; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("runType"); - change->setValue(newValue); - backendComputeCommand.sceneChangeEvent(change); + computeCommand.setRunType(newValue); + backendComputeCommand.syncFromFrontEnd(&computeCommand, false); // THEN QCOMPARE(backendComputeCommand.runType(), newValue); @@ -179,10 +171,8 @@ private Q_SLOTS: { // WHEN const int newValue = 32; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("frameCount"); - change->setValue(newValue); - backendComputeCommand.sceneChangeEvent(change); + computeCommand.trigger(newValue); + backendComputeCommand.syncFromFrontEnd(&computeCommand, false); // THEN QCOMPARE(backendComputeCommand.frameCount(), newValue); @@ -208,7 +198,7 @@ private Q_SLOTS: Qt3DCore::QBackendNodePrivate::get(&backendComputeCommand)->setArbiter(&arbiter); backendComputeCommand.setRenderer(&renderer); - simulateInitialization(&computeCommand, &backendComputeCommand); + simulateInitializationSync(&computeCommand, &backendComputeCommand); for (int i = 0; i < 5; ++i) { // WHEN diff --git a/tests/auto/render/qcomputecommand/tst_qcomputecommand.cpp b/tests/auto/render/qcomputecommand/tst_qcomputecommand.cpp index b46cc4ea0..4494e773b 100644 --- a/tests/auto/render/qcomputecommand/tst_qcomputecommand.cpp +++ b/tests/auto/render/qcomputecommand/tst_qcomputecommand.cpp @@ -342,13 +342,7 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QCOMPARE(arbiter.events.size(), 1); - { - auto change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); - QCOMPARE(change->propertyName(), "frameCount"); - QCOMPARE(change->value().value<int>(), 1); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - } + QCOMPARE(arbiter.events.size(), 0); QCOMPARE(arbiter.dirtyNodes.size(), 1); QCOMPARE(arbiter.dirtyNodes.front(), &computeCommand); QCOMPARE(computeCommand.isEnabled(), true); @@ -356,7 +350,6 @@ private Q_SLOTS: computeCommand.setEnabled(false); QCoreApplication::processEvents(); arbiter.dirtyNodes.clear(); - arbiter.events.clear(); } { @@ -365,13 +358,7 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QCOMPARE(arbiter.events.size(), 1); - { - auto change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); - QCOMPARE(change->propertyName(), "frameCount"); - QCOMPARE(change->value().value<int>(), 2); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - } + QCOMPARE(arbiter.events.size(), 0); QCOMPARE(arbiter.dirtyNodes.size(), 1); QCOMPARE(arbiter.dirtyNodes.front(), &computeCommand); QCOMPARE(computeCommand.isEnabled(), true); @@ -388,13 +375,7 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QCOMPARE(arbiter.events.size(), 1); - { - auto change = arbiter.events.at(0).staticCast<Qt3DCore::QPropertyUpdatedChange>(); - QCOMPARE(change->propertyName(), "frameCount"); - QCOMPARE(change->value().value<int>(), 1); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - } + QCOMPARE(arbiter.events.size(), 0); QCOMPARE(arbiter.dirtyNodes.size(), 1); QCOMPARE(arbiter.dirtyNodes.front(), &computeCommand); QCOMPARE(computeCommand.isEnabled(), true); |