summaryrefslogtreecommitdiffstats
path: root/src/render/materialsystem
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2018-01-23 12:16:53 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2018-02-01 20:59:51 +0000
commitbb548a48c0e5f9e07ccc84c69b4e7e38c8c751cf (patch)
tree5890cfcb15caef64fba278a3fad0318a1e52a448 /src/render/materialsystem
parent02ebfda6c3aaedd2becdc4f0ce4a39025e95b726 (diff)
Compile failing shaders once only and avoid asserting on failure
This way a material with a broken shader will fail once (and won't be retried unless the shader code gets changed), and the application will continue gracefully, without asserting. Task-number: QTBUG-65936 Change-Id: I7003e8c6f7d9094280d7757c1020b485f93e3b37 Reviewed-by: Svenn-Arne Dragly <svenn-arne.dragly@qt.io> Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/materialsystem')
-rw-r--r--src/render/materialsystem/shadercache.cpp18
-rw-r--r--src/render/materialsystem/shadercache_p.h2
2 files changed, 15 insertions, 5 deletions
diff --git a/src/render/materialsystem/shadercache.cpp b/src/render/materialsystem/shadercache.cpp
index 4ddf26799..ce29622ad 100644
--- a/src/render/materialsystem/shadercache.cpp
+++ b/src/render/materialsystem/shadercache.cpp
@@ -62,18 +62,28 @@ ShaderCache::~ShaderCache()
*
* \return A pointer to the shader program if it is cached, nullptr otherwise
*/
-QOpenGLShaderProgram *ShaderCache::getShaderProgramAndAddRef(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId)
+QOpenGLShaderProgram *ShaderCache::getShaderProgramAndAddRef(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId, bool *wasPresent)
{
- auto shaderProgram = m_programHash.value(dna, nullptr);
- if (shaderProgram) {
+ auto shaderProgram = m_programHash.constFind(dna);
+
+ // Some callers may wish to differentiate between a result of null due to
+ // not having anything in the cache and a result of null due to the cache
+ // containing a program the shaders of which failed to compile.
+ if (wasPresent)
+ *wasPresent = shaderProgram != m_programHash.constEnd();
+
+ if (shaderProgram != m_programHash.constEnd()) {
// Ensure we store the fact that shaderPeerId references this shader
QMutexLocker lock(&m_refsMutex);
QVector<Qt3DCore::QNodeId> &programRefs = m_programRefs[dna];
auto it = std::lower_bound(programRefs.begin(), programRefs.end(), shaderPeerId);
if (*it != shaderPeerId)
programRefs.insert(it, shaderPeerId);
+
+ return *shaderProgram;
}
- return shaderProgram;
+
+ return nullptr;
}
/*!
diff --git a/src/render/materialsystem/shadercache_p.h b/src/render/materialsystem/shadercache_p.h
index 24a55876e..bda629ee5 100644
--- a/src/render/materialsystem/shadercache_p.h
+++ b/src/render/materialsystem/shadercache_p.h
@@ -71,7 +71,7 @@ class QT3DRENDERSHARED_PRIVATE_EXPORT ShaderCache
public:
~ShaderCache();
- QOpenGLShaderProgram *getShaderProgramAndAddRef(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId);
+ QOpenGLShaderProgram *getShaderProgramAndAddRef(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId, bool *wasPresent = nullptr);
void insert(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId, QOpenGLShaderProgram *program);
void removeRef(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId);
void purge();