Move cache key calculation to QOpenGLProgramBinaryCache
This class will likely be used by the OpenGL backend of QRhi as well. Therefore, we need to make it more self-contained and independent. Change-Id: If046ed41e25c70cc9abb45219b451f9179feaa1c Reviewed-by: Christian Strømme <christian.stromme@qt.io>
This commit is contained in:
parent
c06627a230
commit
0628932fef
@ -45,6 +45,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QSaveFile>
|
#include <QSaveFile>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
@ -94,6 +95,15 @@ GLEnvInfo::GLEnvInfo()
|
|||||||
glversion = QByteArray(version);
|
glversion = QByteArray(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray QOpenGLProgramBinaryCache::ProgramDesc::cacheKey() const
|
||||||
|
{
|
||||||
|
QCryptographicHash keyBuilder(QCryptographicHash::Sha1);
|
||||||
|
for (const QOpenGLProgramBinaryCache::ShaderDesc &shader : shaders)
|
||||||
|
keyBuilder.addData(shader.source);
|
||||||
|
|
||||||
|
return keyBuilder.result().toHex();
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool qt_ensureWritableDir(const QString &name)
|
static inline bool qt_ensureWritableDir(const QString &name)
|
||||||
{
|
{
|
||||||
QDir::root().mkpath(name);
|
QDir::root().mkpath(name);
|
||||||
|
@ -71,6 +71,7 @@ public:
|
|||||||
};
|
};
|
||||||
struct ProgramDesc {
|
struct ProgramDesc {
|
||||||
QVector<ShaderDesc> shaders;
|
QVector<ShaderDesc> shaders;
|
||||||
|
QByteArray cacheKey() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
QOpenGLProgramBinaryCache();
|
QOpenGLProgramBinaryCache();
|
||||||
|
@ -47,7 +47,6 @@
|
|||||||
#include <QtCore/qvarlengtharray.h>
|
#include <QtCore/qvarlengtharray.h>
|
||||||
#include <QtCore/qvector.h>
|
#include <QtCore/qvector.h>
|
||||||
#include <QtCore/qloggingcategory.h>
|
#include <QtCore/qloggingcategory.h>
|
||||||
#include <QtCore/qcryptographichash.h>
|
|
||||||
#include <QtCore/qcoreapplication.h>
|
#include <QtCore/qcoreapplication.h>
|
||||||
#include <QtGui/qtransform.h>
|
#include <QtGui/qtransform.h>
|
||||||
#include <QtGui/QColor>
|
#include <QtGui/QColor>
|
||||||
@ -3819,11 +3818,7 @@ bool QOpenGLShaderProgramPrivate::linkBinary()
|
|||||||
|
|
||||||
Q_Q(QOpenGLShaderProgram);
|
Q_Q(QOpenGLShaderProgram);
|
||||||
|
|
||||||
QCryptographicHash keyBuilder(QCryptographicHash::Sha1);
|
const QByteArray cacheKey = binaryProgram.cacheKey();
|
||||||
for (const QOpenGLProgramBinaryCache::ShaderDesc &shader : qAsConst(binaryProgram.shaders))
|
|
||||||
keyBuilder.addData(shader.source);
|
|
||||||
|
|
||||||
const QByteArray cacheKey = keyBuilder.result().toHex();
|
|
||||||
if (DBG_SHADER_CACHE().isEnabled(QtDebugMsg))
|
if (DBG_SHADER_CACHE().isEnabled(QtDebugMsg))
|
||||||
qCDebug(DBG_SHADER_CACHE, "program with %d shaders, cache key %s",
|
qCDebug(DBG_SHADER_CACHE, "program with %d shaders, cache key %s",
|
||||||
binaryProgram.shaders.count(), cacheKey.constData());
|
binaryProgram.shaders.count(), cacheKey.constData());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user