Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 70e76ec9 authored by Corey O'Connor's avatar Corey O'Connor

Partition gl sync into specific funciton.

Make gl client sync function pointer a member variable. In case there is some per-context aspect.
parent 00ec0341
......@@ -65,11 +65,6 @@
#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull
#endif
#ifndef Q_OS_WIN
using ClientWaitSync_fp = GLenum (*)(GLsync, GLbitfield, GLuint64);
static ClientWaitSync_fp ClientWaitSync = nullptr;
#endif
using namespace Mlt;
GLWidget::GLWidget(int id, QObject *parent)
......@@ -96,7 +91,6 @@ GLWidget::GLWidget(int id, QObject *parent)
, m_texCoordLocation(0)
, m_colorspaceLocation(0)
, m_zoom(1.0f)
, m_openGLSync(false)
, m_sendFrame(false)
, m_isZoneMode(false)
, m_isLoopMode(false)
......@@ -104,6 +98,8 @@ GLWidget::GLWidget(int id, QObject *parent)
, m_shareContext(nullptr)
, m_audioWaveDisplayed(false)
, m_fbo(nullptr)
, m_openGLSync(false)
, m_ClientWaitSync(nullptr)
{
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
......@@ -136,14 +132,8 @@ GLWidget::GLWidget(int id, QObject *parent)
connect(&m_refreshTimer, &QTimer::timeout, this, &GLWidget::refresh);
m_producer = &*m_blackClip;
// C & D
if (KdenliveSettings::gpu_accel()) {
m_glslManager = new Mlt::Filter(*m_monitorProfile, "glsl.manager");
// fallback to A || B
if (!m_glslManager->is_valid()) {
disableGPUAccel();
}
if (!initGPUAccel()) {
disableGPUAccel();
}
connect(this, &QQuickWindow::sceneGraphInitialized, this, &GLWidget::initializeGL, Qt::DirectConnection);
......@@ -201,32 +191,13 @@ void GLWidget::initializeGL()
qCDebug(KDENLIVE_LOG) << "OpenGL OpenGLES: " << openglContext()->isOpenGLES();
// C & D
if ((m_glslManager != nullptr) && openglContext()->isOpenGLES()) {
// fallback on A || B
if (onlyGLESGPUAccel()) {
disableGPUAccel();
}
createShader();
#if !defined(Q_OS_WIN)
// getProcAddress is not working for me on Windows.
// C & D
if (KdenliveSettings::gpu_accel()) {
m_openGLSync = false;
// D
if ((m_glslManager != nullptr) && openglContext()->hasExtension("GL_ARB_sync")) {
ClientWaitSync = (ClientWaitSync_fp)openglContext()->getProcAddress("glClientWaitSync");
if (ClientWaitSync) {
m_openGLSync = true;
} else {
qCDebug(KDENLIVE_LOG) << " / / // NO GL SYNC, ERROR";
// fallback on A || B
// TODO: fallback on A || B || C?
disableGPUAccel();
}
}
}
#endif
m_openGLSync = initGPUAccelSync();
// C & D
if (m_glslManager) {
......@@ -240,7 +211,11 @@ void GLWidget::initializeGL()
m_shareContext->setShareContext(openglContext());
m_shareContext->create();
}
m_frameRenderer = new FrameRenderer(openglContext(), &m_offscreenSurface);
m_frameRenderer = new FrameRenderer(openglContext(),
&m_offscreenSurface,
m_ClientWaitSync);
m_frameRenderer->sendAudioForAnalysis = KdenliveSettings::monitor_audio();
openglContext()->makeCurrent(this);
......@@ -490,6 +465,13 @@ void GLWidget::releaseSharedFrameTextures() {
}
}
bool GLWidget::initGPUAccel() {
if (!KdenliveSettings::gpu_accel()) return false;
m_glslManager = new Mlt::Filter(*m_monitorProfile, "glsl.manager");
return m_glslManager->is_valid();
}
// C & D
// TODO: insure safe, idempotent on all pipelines.
void GLWidget::disableGPUAccel() {
......@@ -501,6 +483,35 @@ void GLWidget::disableGPUAccel() {
emit gpuNotSupported();
}
bool GLWidget::onlyGLESGPUAccel() const {
return (m_glslManager != nullptr) && openglContext()->isOpenGLES();
}
#if defined(Q_OS_WIN)
bool GLWidget::initGPUAccelSync() {
// no-op
// TODO: getProcAddress is not working on Windows?
return false;
}
#else
bool GLWidget::initGPUAccelSync() {
if (!KdenliveSettings::gpu_accel()) return false;
if (m_glslManager == nullptr) return false;
if (!openglContext()->hasExtension("GL_ARB_sync")) return false;
m_ClientWaitSync = (ClientWaitSync_fp)openglContext()->getProcAddress("glClientWaitSync");
if (m_ClientWaitSync) {
return true;
} else {
qCDebug(KDENLIVE_LOG) << " / / // NO GL SYNC, ERROR";
// fallback on A || B
// TODO: fallback on A || B || C?
disableGPUAccel();
return false;
}
}
#endif
void GLWidget::paintGL()
{
QOpenGLFunctions *f = openglContext()->functions();
......@@ -1566,11 +1577,14 @@ void RenderThread::run()
}
}
FrameRenderer::FrameRenderer(QOpenGLContext *shareContext, QSurface *surface)
FrameRenderer::FrameRenderer(QOpenGLContext *shareContext,
QSurface *surface,
GLWidget::ClientWaitSync_fp clientWaitSync)
: QThread(nullptr)
, m_semaphore(3)
, m_context(nullptr)
, m_surface(surface)
, m_ClientWaitSync(clientWaitSync)
, m_gl32(nullptr)
, sendAudioForAnalysis(false)
{
......@@ -1650,8 +1664,9 @@ void FrameRenderer::showGLFrame(Mlt::Frame frame)
check_error(m_context->functions());
}
#else
if (ClientWaitSync) {
ClientWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
// D
if (m_ClientWaitSync) {
m_ClientWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
check_error(m_context->functions());
}
#endif // Q_OS_WIN
......
......@@ -74,6 +74,7 @@ public:
friend class MonitorController;
friend class Monitor;
friend class MonitorProxy;
using ClientWaitSync_fp = GLenum (*)(GLsync, GLbitfield, GLuint64);
GLWidget(int id, QObject *parent = nullptr);
~GLWidget();
......@@ -256,8 +257,6 @@ protected:
SharedFrame m_sharedFrame;
QOpenGLContext *m_shareContext;
bool m_openGLSync;
bool acquireSharedFrameTextures();
void bindShaderProgram();
void createGPUAccelFragmentProg();
......@@ -266,6 +265,22 @@ protected:
void disableGPUAccel();
void releaseSharedFrameTextures();
// pipeline A - YUV gl texture w/o GPU filter acceleration
// pipeline B - YUV gl texture multithreaded w/o GPU filter acceleration
// pipeline A & B
// pipeline C - RGB gl texture multithreaded w/ GPU filter acceleration and no sync
// pipeline D - RGB gl texture multithreaded w/ GPU filter acceleration and sync
bool m_openGLSync;
// pipeline C & D
bool initGPUAccel();
bool initGPUAccelSync();
bool onlyGLESGPUAccel() const;
// pipeline A & B & C & D
// not null iff D
ClientWaitSync_fp m_ClientWaitSync;
protected:
void resizeEvent(QResizeEvent *event) override;
void mousePressEvent(QMouseEvent *) override;
......@@ -294,7 +309,9 @@ class FrameRenderer : public QThread
{
Q_OBJECT
public:
explicit FrameRenderer(QOpenGLContext *shareContext, QSurface *surface);
explicit FrameRenderer(QOpenGLContext *shareContext,
QSurface *surface,
GLWidget::ClientWaitSync_fp clientWaitSync);
~FrameRenderer();
QSemaphore *semaphore() { return &m_semaphore; }
QOpenGLContext *context() const { return m_context; }
......@@ -315,6 +332,7 @@ private:
SharedFrame m_displayFrame;
QOpenGLContext *m_context;
QSurface *m_surface;
GLWidget::ClientWaitSync_fp m_ClientWaitSync;
public:
GLuint m_renderTexture[3];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment