use mutexes to prevent threads from interfering with each other while sharing shaders

This commit is contained in:
itsmattkc
2019-12-10 01:45:39 +11:00
parent da3ff98774
commit 1f5ae6f9bd
3 changed files with 22 additions and 2 deletions
@@ -230,3 +230,13 @@ QString OpenGLShader::CodeAlphaAssociate(const QString &function_name)
" return vec4(col.rgb * col.a, col.a);\n"
"}\n").arg(function_name);
}
void OpenGLShader::Lock()
{
lock_.lock();
}
void OpenGLShader::Unlock()
{
lock_.unlock();
}
+5
View File
@@ -2,6 +2,7 @@
#define OPENGLSHADER_H
#include <memory>
#include <QMutex>
#include <QOpenGLShaderProgram>
#include <OpenColorIO/OpenColorIO.h>
@@ -32,7 +33,11 @@ public:
static QString CodeAlphaReassociate(const QString& function_name);
static QString CodeAlphaAssociate(const QString& function_name);
void Lock();
void Unlock();
private:
QMutex lock_;
};
#endif // OPENGLSHADER_H
+7 -2
View File
@@ -157,6 +157,8 @@ void OpenGLWorker::RunNodeAccelerated(const Node *node, const NodeValueDatabase
buffer_.Bind();
// Lock the shader so no other thread interferes as we set parameters and draw (and we don't interfere with any others)
shader->Lock();
shader->bind();
unsigned int input_texture_count = 0;
@@ -266,6 +268,11 @@ void OpenGLWorker::RunNodeAccelerated(const Node *node, const NodeValueDatabase
// Blit this texture through this shader
olive::gl::Blit(shader);
// Make sure all OpenGL functions are complete by this point before unlocking the shader (or another thread may
// change its parameters before our drawing in this thread is done)
functions_->glFinish();
shader->Unlock();
// Release any textures we bound before
while (input_texture_count > 0) {
input_texture_count--;
@@ -281,8 +288,6 @@ void OpenGLWorker::RunNodeAccelerated(const Node *node, const NodeValueDatabase
buffer_.Detach();
functions_->glFinish();
output_params->Push(NodeParam::kTexture, QVariant::fromValue(output));
}