Add Linux and AMD support to the OpenCL filter example
Change-Id: I1ea91f93677c53322c3867db6069e4362c58cebd Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
committed by
Laszlo Agocs
parent
b35a55f215
commit
f86a3b7bb3
@@ -1,18 +1,18 @@
|
|||||||
This example performs some simple OpenCL operations on camera or video input which
|
This example performs some simple OpenCL operations on camera or video input
|
||||||
is assumed to be provided in RGB format. The OpenCL operation is done on an
|
which is assumed to be provided in RGB format. The OpenCL operation is done on
|
||||||
OpenGL texture using CL-GL interop, without any further readbacks or copies
|
an OpenGL texture using CL-GL interop, without any further readbacks or copies
|
||||||
(except for the initial texture upload, when necessary).
|
(except for the initial texture upload, when necessary).
|
||||||
|
|
||||||
Currently only OS X and Windows with desktop OpenGL (opengl32.dll) are supported.
|
Currently OS X, Windows with real OpenGL (opengl32.dll) and Linux (GLX only) are
|
||||||
On Windows you may need to edit testplugin.pro to specify the location of the OpenCL
|
supported. Note that an OpenCL implementation with GPU support is required. The
|
||||||
headers and libraries.
|
platform and device selection logic supports NVIDIA, AMD and Intel. Porting to
|
||||||
|
other platforms is probably simple, see clCreateContextFromType.
|
||||||
|
|
||||||
Note that an OpenCL implementation with GPU support is required.
|
On Windows you may need to edit testplugin.pro to specify the location of the
|
||||||
The platform and device selection logic supports NVIDIA and Intel.
|
OpenCL headers and libraries.
|
||||||
Porting to other platforms is probably simple, see clCreateContextFromType.
|
|
||||||
Note however that YUV formats, that are commonly used also for camera input
|
YUV formats are not supported in this example. This is probably not an issue an
|
||||||
on some platforms, are not supported in this example.
|
OS X and Windows, but will most likely disable the example on Linux.
|
||||||
|
|
||||||
Pass the name of a video file to perform video playback or launch without
|
Pass the name of a video file to perform video playback or launch without
|
||||||
arguments to use the camera.
|
arguments to use the camera.
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,10 @@
|
|||||||
#include <CL/opencl.h>
|
#include <CL/opencl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
#include <QtPlatformHeaders/QGLXNativeContext>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "rgbframehelper.h"
|
#include "rgbframehelper.h"
|
||||||
|
|
||||||
static const char *openclSrc =
|
static const char *openclSrc =
|
||||||
@@ -119,10 +123,17 @@ CLFilterRunnable::CLFilterRunnable(CLFilter *filter) :
|
|||||||
|
|
||||||
// Set up OpenCL.
|
// Set up OpenCL.
|
||||||
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||||
cl_int err;
|
|
||||||
cl_uint n;
|
cl_uint n;
|
||||||
if (clGetPlatformIDs(0, 0, &n) != CL_SUCCESS) {
|
cl_int err = clGetPlatformIDs(0, 0, &n);
|
||||||
qWarning("Failed to get platform ID count");
|
if (err != CL_SUCCESS) {
|
||||||
|
qWarning("Failed to get platform ID count (error %d)", err);
|
||||||
|
if (err == -1001) {
|
||||||
|
qDebug("Could not find OpenCL implementation. ICD missing?"
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
" Check /etc/OpenCL/vendors."
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
@@ -140,6 +151,7 @@ CLFilterRunnable::CLFilterRunnable(CLFilter *filter) :
|
|||||||
qDebug("GL_VENDOR: %s", vendor);
|
qDebug("GL_VENDOR: %s", vendor);
|
||||||
const bool isNV = vendor && strstr(vendor, "NVIDIA");
|
const bool isNV = vendor && strstr(vendor, "NVIDIA");
|
||||||
const bool isIntel = vendor && strstr(vendor, "Intel");
|
const bool isIntel = vendor && strstr(vendor, "Intel");
|
||||||
|
const bool isAMD = vendor && strstr(vendor, "ATI");
|
||||||
qDebug("Found %u OpenCL platforms:", n);
|
qDebug("Found %u OpenCL platforms:", n);
|
||||||
for (cl_uint i = 0; i < n; ++i) {
|
for (cl_uint i = 0; i < n; ++i) {
|
||||||
QByteArray name;
|
QByteArray name;
|
||||||
@@ -153,6 +165,8 @@ CLFilterRunnable::CLFilterRunnable(CLFilter *filter) :
|
|||||||
platform = platformIds[i];
|
platform = platformIds[i];
|
||||||
else if (isIntel && name.contains(QByteArrayLiteral("Intel")))
|
else if (isIntel && name.contains(QByteArrayLiteral("Intel")))
|
||||||
platform = platformIds[i];
|
platform = platformIds[i];
|
||||||
|
else if (isAMD && name.contains(QByteArrayLiteral("AMD")))
|
||||||
|
platform = platformIds[i];
|
||||||
}
|
}
|
||||||
qDebug("Using platform %p", platform);
|
qDebug("Using platform %p", platform);
|
||||||
|
|
||||||
@@ -166,6 +180,18 @@ CLFilterRunnable::CLFilterRunnable(CLFilter *filter) :
|
|||||||
CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(),
|
CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(),
|
||||||
CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(),
|
CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(),
|
||||||
0 };
|
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>())
|
||||||
|
nativeGLXContext = nativeGLXHandle.value<QGLXNativeContext>();
|
||||||
|
else
|
||||||
|
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(),
|
||||||
|
0 };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_clContext = clCreateContextFromType(contextProps, CL_DEVICE_TYPE_GPU, 0, 0, &err);
|
m_clContext = clCreateContextFromType(contextProps, CL_DEVICE_TYPE_GPU, 0, 0, &err);
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ OTHER_FILES = main.qml
|
|||||||
target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/video/qmlvideofilter_opencl
|
target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/video/qmlvideofilter_opencl
|
||||||
INSTALLS += target
|
INSTALLS += target
|
||||||
|
|
||||||
# Edit these as necessary
|
osx: LIBS += -framework OpenCL
|
||||||
osx {
|
unix: !osx: LIBS += -lOpenCL
|
||||||
LIBS += -framework OpenCL
|
win32:!winrt {
|
||||||
} else {
|
# Edit these as necessary
|
||||||
INCLUDEPATH += c:/cuda/include
|
INCLUDEPATH += c:/cuda/include
|
||||||
LIBPATH += c:/cuda/lib/x64
|
LIBPATH += c:/cuda/lib/x64
|
||||||
LIBS += -lopengl32 -lOpenCL
|
LIBS += -lopengl32 -lOpenCL
|
||||||
|
|||||||
Reference in New Issue
Block a user