From 257bd49c1f47ba5fca6930082fdcf108f9d24e3f Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 14 Aug 2019 19:45:17 +0200 Subject: Guard with a mutex in QOpenGLProgramBinaryCache where needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While there is likely no example of it in Qt itself, applications can use QOpenGLShaderProgram instances on different threads. These instances have nothing to do with each other but they do share a global cache object. This becomes problematic without proper synchronization. Change-Id: I80faf73f34af7e67349eee916bb3f216e22c07fd Fixes: QTBUG-77469 Reviewed-by: Christian Strømme --- src/gui/opengl/qopenglprogrambinarycache.cpp | 2 ++ src/gui/opengl/qopenglprogrambinarycache_p.h | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src/gui/opengl') diff --git a/src/gui/opengl/qopenglprogrambinarycache.cpp b/src/gui/opengl/qopenglprogrambinarycache.cpp index af48cdacc7..40237b9935 100644 --- a/src/gui/opengl/qopenglprogrambinarycache.cpp +++ b/src/gui/opengl/qopenglprogrambinarycache.cpp @@ -263,6 +263,7 @@ public: bool QOpenGLProgramBinaryCache::load(const QByteArray &cacheKey, uint programId) { + QMutexLocker lock(&m_mutex); if (m_memCache.contains(cacheKey)) { const MemCacheEntry *e = m_memCache[cacheKey]; return setProgramBinary(programId, e->format, e->blob.constData(), e->blob.size()); @@ -401,6 +402,7 @@ void QOpenGLProgramBinaryCache::save(const QByteArray &cacheKey, uint programId) GLint outSize = 0; #if defined(QT_OPENGL_ES_2) if (context->isOpenGLES() && context->format().majorVersion() < 3) { + QMutexLocker lock(&m_mutex); initializeProgramBinaryOES(context); getProgramBinaryOES(programId, blobSize, &outSize, &blobFormat, p); } else diff --git a/src/gui/opengl/qopenglprogrambinarycache_p.h b/src/gui/opengl/qopenglprogrambinarycache_p.h index 9fade08e66..e181a6ab81 100644 --- a/src/gui/opengl/qopenglprogrambinarycache_p.h +++ b/src/gui/opengl/qopenglprogrambinarycache_p.h @@ -54,6 +54,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -99,6 +100,7 @@ private: void initializeProgramBinaryOES(QOpenGLContext *context); bool m_programBinaryOESInitialized = false; #endif + QMutex m_mutex; }; QT_END_NAMESPACE -- cgit v1.2.3 From c47f4361751a13cf729e9f0ea8d9646391732e5d Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 16 Aug 2019 11:39:20 +0200 Subject: Avoid double QCache lookup in QOpenGLProgramBinaryCache Change-Id: I4384a15f0b89e1f6d7f59bff1816fc2e6fc6adfe Reviewed-by: Marc Mutz --- src/gui/opengl/qopenglprogrambinarycache.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/gui/opengl') diff --git a/src/gui/opengl/qopenglprogrambinarycache.cpp b/src/gui/opengl/qopenglprogrambinarycache.cpp index 40237b9935..c3fb375a20 100644 --- a/src/gui/opengl/qopenglprogrambinarycache.cpp +++ b/src/gui/opengl/qopenglprogrambinarycache.cpp @@ -264,10 +264,8 @@ public: bool QOpenGLProgramBinaryCache::load(const QByteArray &cacheKey, uint programId) { QMutexLocker lock(&m_mutex); - if (m_memCache.contains(cacheKey)) { - const MemCacheEntry *e = m_memCache[cacheKey]; + if (const MemCacheEntry *e = m_memCache.object(cacheKey)) return setProgramBinary(programId, e->format, e->blob.constData(), e->blob.size()); - } QByteArray buf; const QString fn = cacheFileName(cacheKey); -- cgit v1.2.3