summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2010-06-20 12:02:55 +1000
committerRhys Weatherley <rhys.weatherley@nokia.com>2010-06-20 12:56:31 +1000
commit2bb2f5bc5187eb7bd467a55ed7e95fd381577ea5 (patch)
tree1d2034da1bcfb7e5dd1400b55e533e6eeab9e35f
parent0b8c164ec34f300eeb93dd6e69fde495d932cb7a (diff)
Add support for OpenCL 1.1 user events.
-rwxr-xr-xconfigure2
-rw-r--r--src/opencl/opencl.pro2
-rw-r--r--src/opencl/qclcontext.cpp22
-rw-r--r--src/opencl/qclcontext.h3
-rw-r--r--src/opencl/qclevent.cpp12
-rw-r--r--src/opencl/qclevent.h4
-rw-r--r--src/opencl/qclext_p.h12
-rw-r--r--src/opencl/qcluserevent.cpp160
-rw-r--r--src/opencl/qcluserevent.h87
9 files changed, 302 insertions, 2 deletions
diff --git a/configure b/configure
index 6196570..1f403f2 100755
--- a/configure
+++ b/configure
@@ -504,7 +504,7 @@ QMAKE_OPTIONS=""
if [ "x$CFG_OPENCLGL" != "xyes" ] ; then
QMAKE_OPTIONS="$QMAKE_OPTIONS CONFIG+=no_cl_gl"
fi
-if [ "x$CFG_OPENCL_1_1" != "xyes" ] ; then
+if [ "x$CFG_OPENCL_1_1" = "xyes" ] ; then
QMAKE_OPTIONS="$QMAKE_OPTIONS CONFIG+=opencl_1_1"
fi
if [ "x$CFG_GCOV" = "xyes" ] ; then
diff --git a/src/opencl/opencl.pro b/src/opencl/opencl.pro
index 67ca673..63b5a48 100644
--- a/src/opencl/opencl.pro
+++ b/src/opencl/opencl.pro
@@ -44,6 +44,7 @@ HEADERS += \
qclplatform.h \
qclprogram.h \
qclsampler.h \
+ qcluserevent.h \
qclvector.h \
qclworksize.h
@@ -60,6 +61,7 @@ SOURCES += \
qclplatform.cpp \
qclprogram.cpp \
qclsampler.cpp \
+ qcluserevent.cpp \
qclvector.cpp \
qclworksize.cpp
diff --git a/src/opencl/qclcontext.cpp b/src/opencl/qclcontext.cpp
index f9a7b6b..6d65d09 100644
--- a/src/opencl/qclcontext.cpp
+++ b/src/opencl/qclcontext.cpp
@@ -1272,6 +1272,28 @@ QList<QCLImageFormat> QCLContext::supportedImage3DFormats
}
/*!
+ Creates a user event. Returns null if user events are not
+ supported.
+
+ User events are a feature of OpenCL 1.1 which allows an application
+ to insert a marker into the command queue. Commands that depend
+ upon the marker will not be executed until the application triggers
+ the user event with QCLUserEvent::setFinished().
+*/
+QCLUserEvent QCLContext::createUserEvent()
+{
+#ifdef QT_OPENCL_1_1
+ Q_D(QCLContext);
+ cl_int error = CL_INVALID_CONTEXT;
+ cl_event event = clCreateUserEvent(d->id, &error);
+ reportError("QCLContext::createUserEvent:", error);
+ return QCLUserEvent(event, true);
+#else
+ return QCLUserEvent();
+#endif
+}
+
+/*!
Flushes all previously queued commands to the device associated
with the active command queue. The commands are delivered to
the device, but no guarantees are given that they will be executed.
diff --git a/src/opencl/qclcontext.h b/src/opencl/qclcontext.h
index 94cd983..39cba14 100644
--- a/src/opencl/qclcontext.h
+++ b/src/opencl/qclcontext.h
@@ -49,6 +49,7 @@
#include "qclimage.h"
#include "qclsampler.h"
#include "qclprogram.h"
+#include "qcluserevent.h"
#include <QtCore/qscopedpointer.h>
#include <QtCore/qsize.h>
#include <QtCore/qbytearray.h>
@@ -146,6 +147,8 @@ public:
QList<QCLImageFormat> supportedImage2DFormats(cl_mem_flags flags) const;
QList<QCLImageFormat> supportedImage3DFormats(cl_mem_flags flags) const;
+ QCLUserEvent createUserEvent();
+
void flush();
void finish();
diff --git a/src/opencl/qclevent.cpp b/src/opencl/qclevent.cpp
index 79e76f6..98a545f 100644
--- a/src/opencl/qclevent.cpp
+++ b/src/opencl/qclevent.cpp
@@ -42,6 +42,7 @@
#include "qclevent.h"
#include "qclcommandqueue.h"
#include "qclcontext.h"
+#include "qclext_p.h"
#include <QtCore/qdebug.h>
#include <QtCore/qtconcurrentrun.h>
@@ -105,7 +106,7 @@ QT_BEGIN_NAMESPACE
Event lists can be used to order commands when out-of-order
command execution is in use.
- \sa QCLCommandQueue::isOutOfOrder(), QCLEventList
+ \sa QCLCommandQueue::isOutOfOrder(), QCLEventList, QCLUserEvent
*/
/*!
@@ -478,6 +479,15 @@ QDebug operator<<(QDebug dbg, const QCLEvent &event)
commandName = "clEnqueueAcquireGLObjects"; break;
case CL_COMMAND_RELEASE_GL_OBJECTS:
commandName = "clEnqueueReleaseGLObjects"; break;
+ // OpenCL 1.1 event types.
+ case CL_COMMAND_READ_BUFFER_RECT:
+ commandName = "clEnqueueReadBufferRect"; break;
+ case CL_COMMAND_WRITE_BUFFER_RECT:
+ commandName = "clEnqueueWriteBufferRect"; break;
+ case CL_COMMAND_COPY_BUFFER_RECT:
+ commandName = "clEnqueueCopyBufferRect"; break;
+ case CL_COMMAND_USER:
+ commandName = "clCreateUserEvent"; break;
default:
commandName = "Unknown"; break;
}
diff --git a/src/opencl/qclevent.h b/src/opencl/qclevent.h
index 57aeeca..55f8348 100644
--- a/src/opencl/qclevent.h
+++ b/src/opencl/qclevent.h
@@ -52,6 +52,8 @@ QT_BEGIN_NAMESPACE
QT_MODULE(CL)
+class QCLUserEvent;
+
class Q_CL_EXPORT QCLEvent
{
public:
@@ -92,6 +94,8 @@ public:
private:
cl_event m_id;
+
+ friend class QCLUserEvent;
};
class Q_CL_EXPORT QCLEventList
diff --git a/src/opencl/qclext_p.h b/src/opencl/qclext_p.h
index e593a5b..b881393 100644
--- a/src/opencl/qclext_p.h
+++ b/src/opencl/qclext_p.h
@@ -72,6 +72,18 @@
#ifndef CL_DEVICE_OPENCL_C_VERSION
#define CL_DEVICE_OPENCL_C_VERSION 0x103D
#endif
+#ifndef CL_COMMAND_READ_BUFFER_RECT
+#define CL_COMMAND_READ_BUFFER_RECT 0x1201
+#endif
+#ifndef CL_COMMAND_WRITE_BUFFER_RECT
+#define CL_COMMAND_WRITE_BUFFER_RECT 0x1202
+#endif
+#ifndef CL_COMMAND_COPY_BUFFER_RECT
+#define CL_COMMAND_COPY_BUFFER_RECT 0x1203
+#endif
+#ifndef CL_COMMAND_USER
+#define CL_COMMAND_USER 0x1204
+#endif
// OpenCL-OpenGL sharing.
#ifndef CL_INVALID_CL_SHAREGROUP_REFERENCE_KHR
diff --git a/src/opencl/qcluserevent.cpp b/src/opencl/qcluserevent.cpp
new file mode 100644
index 0000000..2f715e9
--- /dev/null
+++ b/src/opencl/qcluserevent.cpp
@@ -0,0 +1,160 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtOpenCL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcluserevent.h"
+#include "qclcontext.h"
+#include "qclext_p.h"
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QCLUserEvent
+ \brief The QCLUserEvent class represents OpenCL 1.1 user events.
+ \since 4.7
+ \ingroup opencl
+
+ User events are a feature of OpenCL 1.1 which allows an application
+ to insert a marker into the command queue. Commands that depend
+ upon the marker will not be executed until the application triggers
+ the user event with setFinished().
+
+ User events are constructed with QCLContext::createUserEvent(),
+ which will return null if the OpenCL implementation does not
+ support OpenCL 1.1.
+
+ \sa QCLEvent, QCLContext::createUserEvent()
+*/
+
+/*!
+ \fn QCLUserEvent::QCLUserEvent()
+
+ Constructs a null user event.
+*/
+
+/*!
+ Constructs an OpenCL event object from the native identifier \a id.
+ This class takes over ownership of \a id and will release it in
+ the destructor.
+
+ If \a id is not a user event, then the newly constructed event
+ will be set to null, and \a id will be released.
+*/
+QCLUserEvent::QCLUserEvent(cl_event id)
+ : QCLEvent(id)
+{
+ validateEvent();
+}
+
+/*!
+ Constructs a copy of \a other. The \c{clRetainEvent()} function
+ will be called to update the reference count on eventId().
+
+ If \a other is not a user event, then the newly constructed event
+ will be set to null.
+*/
+QCLUserEvent::QCLUserEvent(const QCLEvent &other)
+ : QCLEvent(other)
+{
+ validateEvent();
+}
+
+/*!
+ Assigns \a other to this OpenCL event object. The current eventId() will
+ be released with \c{clReleaseEvent()}, and the new eventId() will be
+ retained with \c{clRetainEvent()}.
+
+ If \a other is not a user event, then this event will be
+ set to null.
+*/
+QCLUserEvent &QCLUserEvent::operator=(const QCLEvent &other)
+{
+ if (m_id != other.m_id) {
+ if (m_id)
+ clReleaseEvent(m_id);
+ m_id = other.m_id;
+ if (m_id)
+ clRetainEvent(m_id);
+ validateEvent();
+ }
+ return *this;
+}
+
+/*!
+ \fn void QCLUserEvent::setFinished()
+
+ Sets this user event to the finished state. Any queued
+ commands that depend upon this event can now proceed.
+
+ \sa setStatus()
+*/
+
+/*!
+ Sets the \a status of this user event. The \a status should
+ be either \c{CL_COMPLETE} or a negative OpenCL error code.
+
+ \sa setFinished()
+*/
+void QCLUserEvent::setStatus(cl_int status)
+{
+#ifdef QT_OPENCL_1_1
+ if (m_id) {
+ cl_int error = clSetUserEventStatus(m_id, status);
+ if (error != CL_SUCCESS) {
+ qWarning() << "QCLUserEvent::setStatus:"
+ << QCLContext::errorName(error);
+ }
+ }
+#endif
+}
+
+/*!
+ \internal
+*/
+void QCLUserEvent::validateEvent()
+{
+ if (commandType() != CL_COMMAND_USER) {
+ clReleaseEvent(m_id);
+ m_id = 0;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/opencl/qcluserevent.h b/src/opencl/qcluserevent.h
new file mode 100644
index 0000000..73d7b58
--- /dev/null
+++ b/src/opencl/qcluserevent.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtOpenCL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCLUSEREVENT_H
+#define QCLUSEREVENT_H
+
+#include "qclevent.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(CL)
+
+class QCLContext;
+
+class Q_CL_EXPORT QCLUserEvent : public QCLEvent
+{
+public:
+ QCLUserEvent() : QCLEvent() {}
+ QCLUserEvent(cl_event id);
+ QCLUserEvent(const QCLEvent &other);
+
+ QCLUserEvent &operator=(const QCLEvent &other);
+
+ void setFinished();
+ void setStatus(cl_int status);
+
+private:
+ void validateEvent();
+
+ // Used by QCLContext::createUserEvent() to avoid
+ // the overhead of validateEvent().
+ QCLUserEvent(cl_event id, bool dummy)
+ : QCLEvent(id) { Q_UNUSED(dummy); }
+
+ friend class QCLContext;
+};
+
+inline void QCLUserEvent::setFinished()
+{
+ setStatus(CL_COMPLETE);
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif