diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-03-12 14:32:34 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-03-16 13:00:43 +0000 |
commit | d109e6dd5d6a18e715b979f3d3ef845946b1b787 (patch) | |
tree | 5aeb69dc83efbf4d4b02f8c84a8795b3daa0d4b9 /examples/multimedia/video/qmlvideofilter_opencl/main.cpp | |
parent | 2099a8c3c77eea56b95a60e12f265b4eb1d8913d (diff) |
Improvide device selection in the video filter example
The non-OS X path also uses clGetGLContextInfoKHR when available,
instead of just blindly taking the first GPU device for the platform.
This way we get the correct OpenCL device in case the application is using an
OpenGL context on the same vendor's second GPU.
On Windows desktop OpenGL is now correctly forced and therefore there is
no need to waste time on runtime checks for ANGLE later on.
Remove the hard-coded custom pathes from the .pro file.
Also fixes error reporting on the OS X specific path.
Change-Id: I8d6ab867510d113d5135b61e66822381e81c995a
Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
Diffstat (limited to 'examples/multimedia/video/qmlvideofilter_opencl/main.cpp')
-rw-r--r-- | examples/multimedia/video/qmlvideofilter_opencl/main.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/examples/multimedia/video/qmlvideofilter_opencl/main.cpp b/examples/multimedia/video/qmlvideofilter_opencl/main.cpp index af5aa8f65..0ca5e35e8 100644 --- a/examples/multimedia/video/qmlvideofilter_opencl/main.cpp +++ b/examples/multimedia/video/qmlvideofilter_opencl/main.cpp @@ -181,8 +181,6 @@ CLFilterRunnable::CLFilterRunnable(CLFilter *filter) : CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(), 0 }; #elif defined(Q_OS_LINUX) - // An elegant alternative to glXGetCurrentContext. This will even survive - // (without interop) when using something other than GLX. QVariant nativeGLXHandle = QOpenGLContext::currentContext()->nativeHandle(); QGLXNativeContext nativeGLXContext; if (!nativeGLXHandle.isNull() && nativeGLXHandle.canConvert<QGLXNativeContext>()) @@ -191,6 +189,7 @@ CLFilterRunnable::CLFilterRunnable(CLFilter *filter) : qWarning("Failed to get the underlying GLX context from the current QOpenGLContext"); cl_context_properties contextProps[] = { CL_CONTEXT_PLATFORM, (cl_context_properties) platform, CL_GL_CONTEXT_KHR, (cl_context_properties) nativeGLXContext.context(), + CL_GLX_DISPLAY_KHR, (cl_context_properties) glXGetCurrentDisplay(), 0 }; #endif @@ -203,16 +202,22 @@ CLFilterRunnable::CLFilterRunnable(CLFilter *filter) : // Get the GPU device id #if defined(Q_OS_OSX) // On OS X, get the "online" device/GPU. This is required for OpenCL/OpenGL context sharing. - if (clGetGLContextInfoAPPLE(m_clContext, CGLGetCurrentContext(), - CL_CGL_DEVICE_FOR_CURRENT_VIRTUAL_SCREEN_APPLE, - sizeof(cl_device_id), &m_clDeviceId, NULL) != CL_SUCCESS) { + err = clGetGLContextInfoAPPLE(m_clContext, CGLGetCurrentContext(), + CL_CGL_DEVICE_FOR_CURRENT_VIRTUAL_SCREEN_APPLE, + sizeof(cl_device_id), &m_clDeviceId, 0); + if (err != CL_SUCCESS) { qWarning("Failed to get OpenCL device for current screen: %d", err); return; } #else - if (clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &m_clDeviceId, 0) != CL_SUCCESS) { - qWarning("Failed to get OpenCL device"); - return; + clGetGLContextInfoKHR_fn getGLContextInfo = (clGetGLContextInfoKHR_fn) clGetExtensionFunctionAddress("clGetGLContextInfoKHR"); + if (!getGLContextInfo || getGLContextInfo(contextProps, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, + sizeof(cl_device_id), &m_clDeviceId, 0) != CL_SUCCESS) { + err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &m_clDeviceId, 0); + if (err != CL_SUCCESS) { + qWarning("Failed to get OpenCL device: %d", err); + return; + } } #endif @@ -291,15 +296,9 @@ QVideoFrame CLFilterRunnable::run(QVideoFrame *input, const QVideoSurfaceFormat Q_UNUSED(flags); // This example supports RGB data only, either in system memory (typical with cameras on all - // platforms) or as an OpenGL texture (e.g. video playback on OS X or on Windows with ANGLE). + // platforms) or as an OpenGL texture (e.g. video playback on OS X). // The latter is the fast path where everything happens on GPU. THe former involves a texture upload. - // ANGLE is not compatible with this example since we only do CL-GL interop, not D3D9/11. - if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) { - qWarning("ANGLE is not supported"); - return *input; - } - if (!input->isValid() || (input->handleType() != QAbstractVideoBuffer::NoHandle && input->handleType() != QAbstractVideoBuffer::GLTextureHandle)) { @@ -483,6 +482,9 @@ QVideoFrame InfoFilterRunnable::run(QVideoFrame *input, const QVideoSurfaceForma int main(int argc, char **argv) { +#ifdef Q_OS_WIN // avoid ANGLE on Windows + QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); +#endif QGuiApplication app(argc, argv); qmlRegisterType<CLFilter>("qmlvideofilter.cl.test", 1, 0, "CLFilter"); |