summaryrefslogtreecommitdiffstats
path: root/src/render/jobs
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2018-06-20 12:23:37 +0200
committerPaul Lemire <paul.lemire@kdab.com>2018-06-25 04:39:23 +0000
commitf6a0587ef0a90f2e8333ea012aafdd956bca91f6 (patch)
treee3d28bf525a7a33c3ae3437473ae140358b01612 /src/render/jobs
parentbe0cd9c0b19f1f1b72d2bc165e948d162b998f88 (diff)
Fix race condition when executing multiple filterlayerjobs at once
The updating of referenced layer ids for each Entity should only be performed once and not by multiple jobs. Therefore, this update was moved into a dedicated job which is now a dependency of the filterentityjob instances. Change-Id: Ie8ecc49a7c6c7d41a1f1f0d18619b5e142b68204 Task-number: QTBUG-68942 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/jobs')
-rw-r--r--src/render/jobs/filterlayerentityjob.cpp47
-rw-r--r--src/render/jobs/job_common_p.h1
-rw-r--r--src/render/jobs/jobs.pri6
-rw-r--r--src/render/jobs/updateentitylayersjob.cpp106
-rw-r--r--src/render/jobs/updateentitylayersjob_p.h92
5 files changed, 205 insertions, 47 deletions
diff --git a/src/render/jobs/filterlayerentityjob.cpp b/src/render/jobs/filterlayerentityjob.cpp
index 0ed2ed559..e206ef968 100644
--- a/src/render/jobs/filterlayerentityjob.cpp
+++ b/src/render/jobs/filterlayerentityjob.cpp
@@ -52,47 +52,6 @@ namespace Render {
namespace {
int layerFilterJobCounter = 0;
-
-// TO DO: This will be moved to a dedicated job with smarter
-// heuristics in a later commit
-void addLayerIdToEntityChildren(const QVector<Entity *> &children,
- const Qt3DCore::QNodeId layerId)
-{
- for (Entity *child : children) {
- child->addRecursiveLayerId(layerId);
- addLayerIdToEntityChildren(child->children(), layerId);
- }
-}
-
-void updateEntityLayers(NodeManagers *manager)
-{
- EntityManager *entityManager = manager->renderNodesManager();
-
- const QVector<HEntity> handles = entityManager->activeHandles();
-
- // Clear list of recursive layerIds
- for (const HEntity &handle : handles) {
- Entity *entity = entityManager->data(handle);
- entity->clearRecursiveLayerIds();
- }
-
- LayerManager *layerManager = manager->layerManager();
-
- // Set recursive layerIds on children
- for (const HEntity &handle : handles) {
- Entity *entity = entityManager->data(handle);
- const Qt3DCore::QNodeIdVector entityLayers = entity->componentsUuid<Layer>();
-
- for (const Qt3DCore::QNodeId layerId : entityLayers) {
- Layer *layer = layerManager->lookupResource(layerId);
- if (layer->recursive()) {
- // Find all children of the entity and add the layers to them
- addLayerIdToEntityChildren(entity->children(), layerId);
- }
- }
- }
-}
-
} // anonymous
FilterLayerEntityJob::FilterLayerEntityJob()
@@ -107,12 +66,10 @@ void FilterLayerEntityJob::run()
{
m_filteredEntities.clear();
- if (hasLayerFilter()) { // LayerFilter set -> filter
- updateEntityLayers(m_manager);
+ if (hasLayerFilter()) // LayerFilter set -> filter
filterLayerAndEntity();
- } else { // No LayerFilter set -> retrieve all
+ else // No LayerFilter set -> retrieve all
selectAllEntities();
- }
// sort needed for set_intersection in RenderViewBuilder
std::sort(m_filteredEntities.begin(), m_filteredEntities.end());
diff --git a/src/render/jobs/job_common_p.h b/src/render/jobs/job_common_p.h
index 648f07a9b..03e2cc90e 100644
--- a/src/render/jobs/job_common_p.h
+++ b/src/render/jobs/job_common_p.h
@@ -106,6 +106,7 @@ namespace JobTypes {
ProximityFiltering,
SyncFilterEntityByLayer,
SyncMaterialGatherer,
+ UpdateLayerEntity
};
} // JobTypes
diff --git a/src/render/jobs/jobs.pri b/src/render/jobs/jobs.pri
index abb3f605c..472531681 100644
--- a/src/render/jobs/jobs.pri
+++ b/src/render/jobs/jobs.pri
@@ -30,7 +30,8 @@ HEADERS += \
$$PWD/updateskinningpalettejob_p.h \
$$PWD/filterproximitydistancejob_p.h \
$$PWD/abstractpickingjob_p.h \
- $$PWD/raycastingjob_p.h
+ $$PWD/raycastingjob_p.h \
+ $$PWD/updateentitylayersjob_p.h
SOURCES += \
$$PWD/updateworldtransformjob.cpp \
@@ -59,5 +60,6 @@ SOURCES += \
$$PWD/updateskinningpalettejob.cpp \
$$PWD/filterproximitydistancejob.cpp \
$$PWD/abstractpickingjob.cpp \
- $$PWD/raycastingjob.cpp
+ $$PWD/raycastingjob.cpp \
+ $$PWD/updateentitylayersjob.cpp
diff --git a/src/render/jobs/updateentitylayersjob.cpp b/src/render/jobs/updateentitylayersjob.cpp
new file mode 100644
index 000000000..1fa34684f
--- /dev/null
+++ b/src/render/jobs/updateentitylayersjob.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "updateentitylayersjob_p.h"
+#include <Qt3DRender/private/managers_p.h>
+#include <Qt3DRender/private/nodemanagers_p.h>
+#include <Qt3DRender/private/entity_p.h>
+#include <Qt3DRender/private/job_common_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+namespace Render {
+
+namespace {
+
+void addLayerIdToEntityChildren(const QVector<Entity *> &children,
+ const Qt3DCore::QNodeId layerId)
+{
+ for (Entity *child : children) {
+ child->addRecursiveLayerId(layerId);
+ addLayerIdToEntityChildren(child->children(), layerId);
+ }
+}
+
+} // anonymous
+
+UpdateEntityLayersJob::UpdateEntityLayersJob()
+ : m_manager(nullptr)
+{
+ SET_JOB_RUN_STAT_TYPE(this, JobTypes::UpdateLayerEntity, 0);
+
+}
+
+void UpdateEntityLayersJob::run()
+{
+ Q_ASSERT(m_manager);
+ EntityManager *entityManager = m_manager->renderNodesManager();
+
+ const QVector<HEntity> handles = entityManager->activeHandles();
+
+ // Clear list of recursive layerIds
+ for (const HEntity &handle : handles) {
+ Entity *entity = entityManager->data(handle);
+ entity->clearRecursiveLayerIds();
+ }
+
+ LayerManager *layerManager = m_manager->layerManager();
+
+ // Set recursive layerIds on children
+ for (const HEntity &handle : handles) {
+ Entity *entity = entityManager->data(handle);
+ const Qt3DCore::QNodeIdVector entityLayers = entity->componentsUuid<Layer>();
+
+ for (const Qt3DCore::QNodeId layerId : entityLayers) {
+ Layer *layer = layerManager->lookupResource(layerId);
+ if (layer->recursive()) {
+ // Find all children of the entity and add the layers to them
+ addLayerIdToEntityChildren(entity->children(), layerId);
+ }
+ }
+ }
+}
+
+} // Render
+
+} // Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/jobs/updateentitylayersjob_p.h b/src/render/jobs/updateentitylayersjob_p.h
new file mode 100644
index 000000000..8c73899d9
--- /dev/null
+++ b/src/render/jobs/updateentitylayersjob_p.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#ifndef QT3DRENDER_RENDER_UPDATEENTITYLAYERSJOB_P_H
+#define QT3DRENDER_RENDER_UPDATEENTITYLAYERSJOB_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <Qt3DRender/private/qt3drender_global_p.h>
+#include <Qt3DCore/qaspectjob.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+namespace Render {
+
+class Entity;
+class NodeManagers;
+
+
+class QT3DRENDERSHARED_PRIVATE_EXPORT UpdateEntityLayersJob: public Qt3DCore::QAspectJob
+{
+public:
+ UpdateEntityLayersJob();
+
+ inline void setManager(NodeManagers *manager) { m_manager = manager; }
+ inline NodeManagers *manager() const { return m_manager; }
+
+ // QAspectJob interface
+ void run() final;
+
+private:
+ NodeManagers *m_manager;
+};
+
+
+typedef QSharedPointer<UpdateEntityLayersJob> UpdateEntityLayersJobPtr;
+
+} // Render
+
+} // Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_RENDER_UPDATEENTITYLAYERSJOB_P_H