Skip to content

Commit

Permalink
MythRenderOpenGL: Initial compute shader support
Browse files Browse the repository at this point in the history
(cherry picked from commit 599a7ba)
  • Loading branch information
mark-kendall committed Mar 8, 2020
1 parent b9ca35c commit cad10ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
35 changes: 31 additions & 4 deletions mythtv/libs/libmythui/opengl/mythrenderopengl.cpp
Expand Up @@ -385,8 +385,13 @@ bool MythRenderOpenGL::Init(void)
if (hasExtension("GL_NVX_gpu_memory_info"))
m_extraFeatures |= kGLNVMemory;

// Check 16 bit FBOs
Check16BitFBO();

// Check for compute shaders
if (QOpenGLShader::hasOpenGLShaders(QOpenGLShader::Compute))
m_extraFeatures |= kGLComputeShaders;

DebugFeatures();

m_extraFeaturesUsed = m_extraFeatures;
Expand Down Expand Up @@ -442,7 +447,7 @@ void MythRenderOpenGL::DebugFeatures(void)
LOG(VB_GENERAL, LOG_INFO, LOC + QString("16bit framebuffers : %1").arg(GLYesNo(m_extraFeatures & kGL16BitFBO)));
LOG(VB_GENERAL, LOG_INFO, LOC + QString("Unpack Subimage : %1").arg(GLYesNo(m_extraFeatures & kGLExtSubimage)));
LOG(VB_GENERAL, LOG_INFO, LOC + QString("GL_RED/GL_R8 : %1").arg(GLYesNo(!(m_extraFeatures & kGLLegacyTextures))));
//LOG(VB_GENERAL, LOG_INFO, LOC + QString("Compute shaders : %1").arg(GLYesNo(QOpenGLShader::hasOpenGLShaders(QOpenGLShader::Compute))));
//LOG(VB_GENERAL, LOG_INFO, LOC + QString("Compute shaders : %1").arg(GLYesNo(m_extraFeatures & kGLComputeShaders)));

// warnings
if (m_maxTextureUnits < 3)
Expand Down Expand Up @@ -760,9 +765,9 @@ MythGLTexture* MythRenderOpenGL::CreateFramebufferTexture(QOpenGLFramebufferObje
return nullptr;

auto *texture = new MythGLTexture(Framebuffer->texture());
texture->m_size = texture->m_totalSize = Framebuffer->size();
texture->m_vbo = CreateVBO(kVertexSize);
texture->m_flip = false;
texture->m_size = texture->m_totalSize = Framebuffer->size();
texture->m_vbo = CreateVBO(kVertexSize);
texture->m_flip = false;
return texture;
}

Expand Down Expand Up @@ -1550,6 +1555,28 @@ QOpenGLShaderProgram *MythRenderOpenGL::CreateShaderProgram(const QString &Verte
return program;
}

QOpenGLShaderProgram* MythRenderOpenGL::CreateComputeShader(const QString &Source)
{
if (!(m_extraFeaturesUsed & kGLComputeShaders) || Source.isEmpty())
return nullptr;

OpenGLLocker locker(this);
auto *program = new QOpenGLShaderProgram();
if (!program->addShaderFromSourceCode(QOpenGLShader::Compute, Source))
return ShaderError(program, Source);

if (VERBOSE_LEVEL_CHECK(VB_GENERAL, LOG_DEBUG))
{
QList<QOpenGLShader*> shaders = program->shaders();
foreach (QOpenGLShader* shader, shaders)
LOG(VB_GENERAL, LOG_DEBUG, "\n" + shader->sourceCode());
}

if (!program->link())
return ShaderError(program, "");
return program;
}

void MythRenderOpenGL::DeleteShaderProgram(QOpenGLShaderProgram *Program)
{
makeCurrent();
Expand Down
4 changes: 3 additions & 1 deletion mythtv/libs/libmythui/opengl/mythrenderopengl.h
Expand Up @@ -37,7 +37,8 @@ enum GLFeatures
kGLTiled = 0x0010,
kGLLegacyTextures = 0x0020,
kGLNVMemory = 0x0040,
kGL16BitFBO = 0x0080
kGL16BitFBO = 0x0080,
kGLComputeShaders = 0x0100
};

#define TEX_OFFSET 8
Expand Down Expand Up @@ -136,6 +137,7 @@ class MUI_PUBLIC MythRenderOpenGL : public QOpenGLContext, public QOpenGLFunctio
void ClearFramebuffer(void);

QOpenGLShaderProgram* CreateShaderProgram(const QString &Vertex, const QString &Fragment);
QOpenGLShaderProgram* CreateComputeShader(const QString &Source);
void DeleteShaderProgram(QOpenGLShaderProgram* Program);
bool EnableShaderProgram(QOpenGLShaderProgram* Program);
void SetShaderProgramParams(QOpenGLShaderProgram* Program, const QMatrix4x4 &Value, const char* Uniform);
Expand Down

0 comments on commit cad10ad

Please sign in to comment.