diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-06-20 15:16:23 +1000 |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-06-20 15:17:58 +1000 |
commit | 2e6ffb2e8b2415201862305327734a8210e545fa (patch) | |
tree | f3899b113397f83e13ba1bac57289c453a8f3f98 | |
parent | 78ae8986c9dab74f383ba80bcbd54d102936286c (diff) |
Add support for OpenCL 1.1 sub-buffers.
-rw-r--r-- | config.tests/unix/opencl11/opencl11.cpp | 14 | ||||
-rw-r--r-- | doc/src/opencl11.qdoc | 4 | ||||
-rw-r--r-- | src/opencl/qclbuffer.cpp | 65 | ||||
-rw-r--r-- | src/opencl/qclbuffer.h | 6 | ||||
-rw-r--r-- | src/opencl/qclext_p.h | 6 |
5 files changed, 89 insertions, 6 deletions
diff --git a/config.tests/unix/opencl11/opencl11.cpp b/config.tests/unix/opencl11/opencl11.cpp index 3290b2e..87692cb 100644 --- a/config.tests/unix/opencl11/opencl11.cpp +++ b/config.tests/unix/opencl11/opencl11.cpp @@ -47,14 +47,16 @@ #include <CL/cl.h> #endif -// Try to link against the function in the library, even if the -// installed system header happens to be for OpenCL 1.0. -#if !defined(CL_VERSION_1_1) -extern cl_event clCreateUserEvent(cl_context, cl_int *); -#endif - int main(int, char **) { clCreateUserEvent(0, 0); + + cl_buffer_region region; + region.origin = 0; + region.size = 0; + clCreateSubBuffer + (0, CL_MEM_READ_WRITE, + CL_BUFFER_CREATE_TYPE_REGION, ®ion, 0); + return 0; } diff --git a/doc/src/opencl11.qdoc b/doc/src/opencl11.qdoc index 7d43078..000d98e 100644 --- a/doc/src/opencl11.qdoc +++ b/doc/src/opencl11.qdoc @@ -66,6 +66,10 @@ created with QCLContext::createCommandQueue(). \o New channel orders have been added to QCLImageFormat for the \c CL_Rx, \c CL_RGx, and \c CL_RGBx values. + \o Support for sub-buffers in QCLBuffer: + \l{QCLBuffer::createSubBuffer()}{createSubBuffer()}, + \l{QCLBuffer::createSubBuffer()}{parentBuffer()}, and + \l{QCLBuffer::createSubBuffer()}{offset()}. \endlist \l{index.html}{Return to Home} diff --git a/src/opencl/qclbuffer.cpp b/src/opencl/qclbuffer.cpp index fb4d43b..6702be5 100644 --- a/src/opencl/qclbuffer.cpp +++ b/src/opencl/qclbuffer.cpp @@ -42,6 +42,7 @@ #include "qclbuffer.h" #include "qclimage.h" #include "qclcontext.h" +#include "qclext_p.h" QT_BEGIN_NAMESPACE @@ -462,4 +463,68 @@ QCLEvent QCLBuffer::mapAsync return QCLEvent(); } +/*! + Creates a new buffer that refers to the \a size bytes, + starting at \a offset within this buffer. The data in + the new buffer will be accessed according to \a access. + + Sub-buffers are an OpenCL 1.1 feature. On OpenCL 1.0, + this function will return a null buffer. + + \sa parentBuffer(), offset() +*/ +QCLBuffer QCLBuffer::createSubBuffer + (size_t offset, size_t size, QCLMemoryObject::Access access) +{ +#ifdef QT_OPENCL_1_1 + cl_int error; + cl_buffer_region region; + region.origin = offset; + region.size = size; + cl_mem mem = clCreateSubBuffer + (memoryId(), cl_mem_flags(access), + CL_BUFFER_CREATE_TYPE_REGION, ®ion, &error); + context()->reportError("QCLBuffer::createSubBuffer:", error); + return QCLBuffer(context(), mem); +#else + Q_UNUSED(offset); + Q_UNUSED(size); + Q_UNUSED(access); + return QCLBuffer(); +#endif +} + +/*! + Returns the parent of this buffer if it is a sub-buffer; + null otherwise. + + \sa createSubBuffer(), offset() +*/ +QCLBuffer QCLBuffer::parentBuffer() const +{ + cl_mem parent; + if (clGetMemObjectInfo(memoryId(), CL_MEM_ASSOCIATED_MEMOBJECT, + sizeof(parent), &parent, 0) != CL_SUCCESS) + return QCLBuffer(); + if (parent) + clRetainMemObject(parent); + return QCLBuffer(context(), parent); +} + +/*! + Returns the offset of this buffer within its parentBuffer() + if it is a sub-buffer; zero otherwise. + + \sa createSubBuffer(), parentBuffer() +*/ +size_t QCLBuffer::offset() const +{ + size_t value; + if (clGetMemObjectInfo(memoryId(), CL_MEM_OFFSET, + sizeof(value), &value, 0) != CL_SUCCESS) + return 0; + else + return value; +} + QT_END_NAMESPACE diff --git a/src/opencl/qclbuffer.h b/src/opencl/qclbuffer.h index 8c19dd6..4e9a561 100644 --- a/src/opencl/qclbuffer.h +++ b/src/opencl/qclbuffer.h @@ -102,6 +102,12 @@ public: QCLEvent mapAsync(void **ptr, size_t offset, size_t size, QCLMemoryObject::Access access, const QCLEventList &after = QCLEventList()); + + QCLBuffer createSubBuffer + (size_t offset, size_t size, QCLMemoryObject::Access access); + + QCLBuffer parentBuffer() const; + size_t offset() const; }; QT_END_NAMESPACE diff --git a/src/opencl/qclext_p.h b/src/opencl/qclext_p.h index b881393..68a17b7 100644 --- a/src/opencl/qclext_p.h +++ b/src/opencl/qclext_p.h @@ -84,6 +84,12 @@ #ifndef CL_COMMAND_USER #define CL_COMMAND_USER 0x1204 #endif +#ifndef CL_MEM_ASSOCIATED_MEMOBJECT +#define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107 +#endif +#ifndef CL_MEM_OFFSET +#define CL_MEM_OFFSET 0x1108 +#endif // OpenCL-OpenGL sharing. #ifndef CL_INVALID_CL_SHAREGROUP_REFERENCE_KHR |