summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2017-04-28 08:17:46 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2017-08-22 12:08:44 +0000
commit53e2e982ceb1ff3c18eb8ffe4fc271eed2f603d1 (patch)
tree11419692e368cde0894b43e8dcf4f54456e9c564
parent4188591629f89e127ba3a64df65df5db5f586699 (diff)
RenderQueue: make it hold its mutex
Allows to slightly clean up the renderer and remove things from the past. Change-Id: I04da9c4f9039df0de22e4da1dbd9193741e92a4d Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/render/backend/commandexecuter.cpp5
-rw-r--r--src/render/backend/commandexecuter_p.h2
-rw-r--r--src/render/backend/renderer.cpp9
-rw-r--r--src/render/backend/renderer_p.h4
-rw-r--r--src/render/backend/renderqueue_p.h4
-rw-r--r--src/render/backend/renderthread.cpp11
6 files changed, 13 insertions, 22 deletions
diff --git a/src/render/backend/commandexecuter.cpp b/src/render/backend/commandexecuter.cpp
index 84bf7455a..cd1ec0e2b 100644
--- a/src/render/backend/commandexecuter.cpp
+++ b/src/render/backend/commandexecuter.cpp
@@ -303,8 +303,9 @@ CommandExecuter::CommandExecuter(Render::Renderer *renderer)
// Render thread
void CommandExecuter::performAsynchronousCommandExecution(const QVector<Render::RenderView *> &views)
{
- // The renderer's mutex is already locked
+ QMutexLocker lock(&m_pendingCommandsMutex);
const QVector<Qt3DCore::Debug::AsynchronousCommandReply *> shellCommands = std::move(m_pendingCommands);
+ lock.unlock();
for (auto *reply : shellCommands) {
if (reply->commandName() == QLatin1String("glinfo")) {
@@ -375,7 +376,7 @@ QVariant CommandExecuter::executeCommand(const QStringList &args)
(args.first() == QLatin1String("glinfo") ||
args.first() == QLatin1String("rendercommands"))) {
auto reply = new Qt3DCore::Debug::AsynchronousCommandReply(args.first());
- QMutexLocker lock(m_renderer->mutex());
+ QMutexLocker lock(&m_pendingCommandsMutex);
m_pendingCommands.push_back(reply);
return QVariant::fromValue(reply);
}
diff --git a/src/render/backend/commandexecuter_p.h b/src/render/backend/commandexecuter_p.h
index 896164543..2d90bf4d6 100644
--- a/src/render/backend/commandexecuter_p.h
+++ b/src/render/backend/commandexecuter_p.h
@@ -50,6 +50,7 @@
#include <QVector>
#include <QVariant>
+#include <QMutex>
QT_BEGIN_NAMESPACE
@@ -82,6 +83,7 @@ public:
private:
Render::Renderer *m_renderer;
QVector<Qt3DCore::Debug::AsynchronousCommandReply *> m_pendingCommands;
+ QMutex m_pendingCommandsMutex;
};
} // Debug
diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp
index b056d4380..099c20c25 100644
--- a/src/render/backend/renderer.cpp
+++ b/src/render/backend/renderer.cpp
@@ -564,7 +564,7 @@ void Renderer::doRender()
const bool canSubmit = isReadyToSubmit();
// Lock the mutex to protect access to the renderQueue while we look for its state
- QMutexLocker locker(&m_renderQueueMutex);
+ QMutexLocker locker(m_renderQueue->mutex());
const bool queueIsComplete = m_renderQueue->isFrameQueueComplete();
const bool queueIsEmpty = m_renderQueue->targetRenderViewCount() == 0;
@@ -704,7 +704,7 @@ void Renderer::doRender()
// we allow the render thread to proceed
void Renderer::enqueueRenderView(Render::RenderView *renderView, int submitOrder)
{
- QMutexLocker locker(&m_renderQueueMutex); // Prevent out of order execution
+ QMutexLocker locker(m_renderQueue->mutex()); // Prevent out of order execution
// We cannot use a lock free primitive here because:
// - QVector is not thread safe
// - Even if the insert is made correctly, the isFrameComplete call
@@ -722,8 +722,7 @@ void Renderer::enqueueRenderView(Render::RenderView *renderView, int submitOrder
bool Renderer::canRender() const
{
- // Make sure that we've not been told to terminate whilst waiting on
- // the above wait condition
+ // Make sure that we've not been told to terminate
if (m_renderThread && !m_running.load()) {
qCDebug(Rendering) << "RenderThread termination requested whilst waiting";
return false;
@@ -1513,7 +1512,7 @@ QVector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs()
renderBinJobs.push_back(m_textureGathererJob);
}
- QMutexLocker lock(&m_renderQueueMutex);
+ QMutexLocker lock(m_renderQueue->mutex());
if (m_renderQueue->wasReset()) { // Have we rendered yet? (Scene3D case)
// Traverse the current framegraph. For each leaf node create a
// RenderView and set its configuration then create a job to
diff --git a/src/render/backend/renderer_p.h b/src/render/backend/renderer_p.h
index d27944f54..6b1e52a25 100644
--- a/src/render/backend/renderer_p.h
+++ b/src/render/backend/renderer_p.h
@@ -261,9 +261,6 @@ public:
ViewSubmissionResultData submitRenderViews(const QVector<Render::RenderView *> &renderViews);
- QMutex* mutex() { return &m_renderQueueMutex; }
-
-
#ifdef QT3D_RENDER_UNIT_TESTS
public:
#else
@@ -292,7 +289,6 @@ private:
QScopedPointer<RenderThread> m_renderThread;
QScopedPointer<VSyncFrameAdvanceService> m_vsyncFrameAdvanceService;
- QMutex m_renderQueueMutex;
QSemaphore m_submitRenderViewsSemaphore;
QSemaphore m_waitForInitializationToBeCompleted;
diff --git a/src/render/backend/renderqueue_p.h b/src/render/backend/renderqueue_p.h
index 611f5849a..e565115f2 100644
--- a/src/render/backend/renderqueue_p.h
+++ b/src/render/backend/renderqueue_p.h
@@ -53,6 +53,7 @@
#include <QVector>
#include <QtGlobal>
+#include <QMutex>
QT_BEGIN_NAMESPACE
@@ -81,12 +82,15 @@ public:
inline bool wasReset() const { return m_wasReset; }
+ inline QMutex *mutex() { return &m_mutex; }
+
private:
bool m_noRender;
bool m_wasReset;
int m_targetRenderViewCount;
int m_currentRenderViewCount;
QVector<RenderView *> m_currentWorkQueue;
+ QMutex m_mutex;
};
} // namespace Render
diff --git a/src/render/backend/renderthread.cpp b/src/render/backend/renderthread.cpp
index 03cbb7a5f..6b95ed396 100644
--- a/src/render/backend/renderthread.cpp
+++ b/src/render/backend/renderthread.cpp
@@ -75,23 +75,12 @@ void RenderThread::waitForStart( Priority priority )
// RenderThread context
void RenderThread::run()
{
- // We lock the renderer's mutex here before returning control to the calling
- // thread (the Aspect Thread). This is
- // to ensure that the Renderer's initialize() waitCondition is reached before
- // other threads try to wake it up. This is guaranteed by having the
- // Renderer::setSurface() function try to lock the renderer's mutex too.
- // That function will block until the mutex is unlocked by the wait condition
- // in the initialize() call below.
- QMutexLocker locker(m_renderer->mutex());
-
- // Now we have ensured we will reach the wait condition as described above,
// return control to the aspect thread that created us.
m_semaphore.release();
// This call to Renderer::initialize() waits for a surface to be set on the
// renderer in the context of the Aspect Thread
m_renderer->initialize();
- locker.unlock();
// Enter the main OpenGL submission loop.
m_renderer->render();