From e1ed2c3864e2b9aeeebec25de60ab62eb254b591 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 26 Sep 2019 14:56:32 +0200 Subject: Share and enable shader disk cache in QRhi OpenGL backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The expectation for it is to function identically to what we get with QOpenGLShaderProgram. (same environment variables, same logging categories, etc.). QOpenGLProgramBinaryCache is now shared between the QOpenGL convenience classes (like QOpenGLShaderProgram) and QRhi. To achieve more modularity and to prepare for QOpenGLShaderProgram and friends moving out of QtGui, this class cannot depend on QOpenGLShader* anymore. This involves adding some minor conversions between QRhi and QOpenGL enums for example. Change-Id: I2f4664e074823ea536281aea8006a6db159a7381 Reviewed-by: Christian Strømme --- src/gui/opengl/qopenglprogrambinarycache_p.h | 43 +++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'src/gui/opengl/qopenglprogrambinarycache_p.h') diff --git a/src/gui/opengl/qopenglprogrambinarycache_p.h b/src/gui/opengl/qopenglprogrambinarycache_p.h index fb01e61872..f1cf24cd87 100644 --- a/src/gui/opengl/qopenglprogrambinarycache_p.h +++ b/src/gui/opengl/qopenglprogrambinarycache_p.h @@ -52,21 +52,26 @@ // #include -#include #include #include +#include +#include QT_BEGIN_NAMESPACE +// These classes are also used by the OpenGL backend of QRhi. They must +// therefore stay independent from QOpenGLShader(Program). Must rely only on +// QOpenGLContext/Functions. + class QOpenGLProgramBinaryCache { public: struct ShaderDesc { ShaderDesc() { } - ShaderDesc(QOpenGLShader::ShaderType type, const QByteArray &source = QByteArray()) - : type(type), source(source) + ShaderDesc(QShader::Stage stage, const QByteArray &source = QByteArray()) + : stage(stage), source(source) { } - QOpenGLShader::ShaderType type; + QShader::Stage stage; QByteArray source; }; struct ProgramDesc { @@ -104,6 +109,36 @@ private: QMutex m_mutex; }; +// While unlikely, one application can in theory use contexts with different versions +// or profiles. Therefore any version- or extension-specific checks must be done on a +// per-context basis, not just once per process. QOpenGLSharedResource enables this, +// although it's once-per-sharing-context-group, not per-context. Still, this should +// be good enough in practice. +class QOpenGLProgramBinarySupportCheck : public QOpenGLSharedResource +{ +public: + QOpenGLProgramBinarySupportCheck(QOpenGLContext *context); + void invalidateResource() override { } + void freeResource(QOpenGLContext *) override { } + + bool isSupported() const { return m_supported; } + +private: + bool m_supported; +}; + +class QOpenGLProgramBinarySupportCheckWrapper +{ +public: + QOpenGLProgramBinarySupportCheck *get(QOpenGLContext *context) + { + return m_resource.value(context); + } + +private: + QOpenGLMultiGroupSharedResource m_resource; +}; + QT_END_NAMESPACE #endif -- cgit v1.2.3