aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYinhang Liu <yinhangx.liu@intel.com>2017-12-18 19:48:53 +0800
committerwindyuan <feng.yuan@intel.com>2017-12-19 17:39:10 +0800
commitd656676b8d13980755e6220a3e857ba3c5f5f798 (patch)
treea1001ba120a060daa74c0c2635dcfd2a2b13d2a0
parent2a75e8171d5707e7f440823f92cc48c730570550 (diff)
downloadlibxcam-d656676b8d13980755e6220a3e857ba3c5f5f798.tar.gz
standard-OCL: remove private dependence
* disable cl_intel.h downloading * separate cl_va_memory.h from cl_memory.h * separate cl_intel_context.h from cl_context.h * fix some undefined errors
-rw-r--r--capi/xcam_handle.cpp7
-rw-r--r--configure.ac22
-rw-r--r--modules/ocl/Makefile.am4
-rw-r--r--modules/ocl/cl_context.cpp106
-rw-r--r--modules/ocl/cl_context.h19
-rw-r--r--modules/ocl/cl_device.cpp11
-rw-r--r--modules/ocl/cl_memory.cpp191
-rw-r--r--modules/ocl/cl_memory.h55
-rw-r--r--modules/ocl/cl_utils.cpp14
-rw-r--r--modules/ocl/cl_utils.h3
-rw-r--r--modules/ocl/intel/cl_intel_context.cpp144
-rw-r--r--modules/ocl/intel/cl_intel_context.h56
-rw-r--r--modules/ocl/intel/cl_va_memory.cpp191
-rw-r--r--modules/ocl/intel/cl_va_memory.h79
14 files changed, 538 insertions, 364 deletions
diff --git a/capi/xcam_handle.cpp b/capi/xcam_handle.cpp
index f9680a9..37a99b1 100644
--- a/capi/xcam_handle.cpp
+++ b/capi/xcam_handle.cpp
@@ -23,6 +23,9 @@
#include <dma_video_buffer.h>
#include "context_priv.h"
#include <stdarg.h>
+#if HAVE_LIBDRM
+#include <drm_bo_buffer.h>
+#endif
using namespace XCam;
@@ -154,9 +157,7 @@ external_buf_to_drm_buf (XCamVideoBuffer *buf)
video_buf = dma_buf;
XCAM_ASSERT (display.ptr ());
drm_buf = display->convert_to_drm_bo_buf (display, video_buf);
-
- video_buf = drm_buf;
- return video_buf;
+ return drm_buf;
#else
XCAM_LOG_ERROR ("VideoBuffer doesn't support drm buf");
diff --git a/configure.ac b/configure.ac
index 6ea8cb0..e98ad18 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,16 +128,18 @@ if test "$HAVE_LIBCL" -eq 1; then
AC_MSG_ERROR([gawk not found])
fi
- HAVE_CL_INTEL_H=1
- AC_CHECK_HEADERS([CL/cl_intel.h], [HAVE_CL_INTEL_H=1], [HAVE_CL_INTEL_H=0])
- if test "$HAVE_CL_INTEL_H" -eq 0; then
- # https://raw.githubusercontent.com/intel/beignet/Release_v1.3/include/CL/cl_intel.h
- XCAM_WGET(
- [https://cgit.freedesktop.org/beignet/plain/include/CL/cl_intel.h?id=Release_v1.3.0],
- [./ext/beignet/include/CL/cl_intel.h],
- [6a6619073cb35e6987b7379a5a1a1497])
-
- CPPFLAGS="$CPPFLAGS -I\$(top_srcdir)/ext/beignet/include"
+ if test "$HAVE_LIBDRM" -eq 1; then
+ HAVE_CL_INTEL_H=1
+ AC_CHECK_HEADERS([CL/cl_intel.h], [HAVE_CL_INTEL_H=1], [HAVE_CL_INTEL_H=0])
+ if test "$HAVE_CL_INTEL_H" -eq 0; then
+ # https://raw.githubusercontent.com/intel/beignet/Release_v1.3/include/CL/cl_intel.h
+ XCAM_WGET(
+ [https://cgit.freedesktop.org/beignet/plain/include/CL/cl_intel.h?id=Release_v1.3.0],
+ [./ext/beignet/include/CL/cl_intel.h],
+ [6a6619073cb35e6987b7379a5a1a1497])
+
+ CPPFLAGS="$CPPFLAGS -I\$(top_srcdir)/ext/beignet/include"
+ fi
fi
fi
diff --git a/modules/ocl/Makefile.am b/modules/ocl/Makefile.am
index 8661d35..dc09d6d 100644
--- a/modules/ocl/Makefile.am
+++ b/modules/ocl/Makefile.am
@@ -83,6 +83,8 @@ xcam_ocl_sources += cv_image_deblurring.cpp
endif
if HAVE_LIBDRM
+xcam_ocl_sources += intel/cl_intel_context.cpp
+xcam_ocl_sources += intel/cl_va_memory.cpp
xcam_ocl_sources += cl_image_bo_buffer.cpp
endif
@@ -160,6 +162,8 @@ nobase_libxcam_oclinclude_HEADERS += cv_image_deblurring.h
endif
if HAVE_LIBDRM
+nobase_libxcam_oclinclude_HEADERS += intel/cl_intel_context.h
+nobase_libxcam_oclinclude_HEADERS += intel/cl_va_memory.h
nobase_libxcam_oclinclude_HEADERS += cl_image_bo_buffer.h
endif
diff --git a/modules/ocl/cl_context.cpp b/modules/ocl/cl_context.cpp
index 5ff47e2..e8d179f 100644
--- a/modules/ocl/cl_context.cpp
+++ b/modules/ocl/cl_context.cpp
@@ -422,92 +422,6 @@ CLContext::insert_kernel (SmartPtr<CLKernel> &kernel)
#endif
cl_mem
-CLContext::create_va_buffer (uint32_t bo_name)
-{
- cl_mem mem_id = NULL;
- cl_int errcode = CL_SUCCESS;
- if (!is_valid())
- return NULL;
-
- clCreateBufferFromLibvaIntel_fn oclCreateBufferFromLibvaIntel =
- (clCreateBufferFromLibvaIntel_fn) _device->get_extension_function (OCL_EXT_NAME_CREATE_BUFFER_FROM_LIBVA_INTEL);
- XCAM_FAIL_RETURN(ERROR, oclCreateBufferFromLibvaIntel, NULL, "create buffer failed since extension was not found");
-
- mem_id = oclCreateBufferFromLibvaIntel (_context_id, bo_name, &errcode);
- XCAM_FAIL_RETURN(
- WARNING,
- errcode == CL_SUCCESS,
- NULL,
- "create cl memory from va image failed");
- return mem_id;
-}
-
-cl_mem
-CLContext::import_dma_buffer (const cl_import_buffer_info_intel &import_info)
-{
- cl_mem mem_id = NULL;
- cl_int errcode = CL_SUCCESS;
- if (!is_valid())
- return NULL;
-
- clCreateBufferFromFdINTEL_fn oclCreateBufferFromFdINTEL =
- (clCreateBufferFromFdINTEL_fn) _device->get_extension_function (OCL_EXT_NAME_CREATE_BUFFER_FROM_FD_INTEL);
- XCAM_FAIL_RETURN(ERROR, oclCreateBufferFromFdINTEL, NULL, "import buffer failed since extension was not found");
-
- mem_id = oclCreateBufferFromFdINTEL (_context_id, &import_info, &errcode);
- XCAM_FAIL_RETURN(
- WARNING,
- errcode == CL_SUCCESS,
- NULL,
- "import cl memory from dma buffer failed");
-
- return mem_id;
-}
-
-cl_mem
-CLContext::create_va_image (const cl_libva_image &image_info)
-{
- cl_mem mem_id = NULL;
- cl_int errcode = CL_SUCCESS;
- if (!is_valid())
- return NULL;
-
- clCreateImageFromLibvaIntel_fn oclCreateImageFromLibvaIntel =
- (clCreateImageFromLibvaIntel_fn) _device->get_extension_function (OCL_EXT_NAME_CREATE_IMAGE_FROM_LIBVA_INTEL);
- XCAM_FAIL_RETURN(ERROR, oclCreateImageFromLibvaIntel, NULL, "create image failed since extension was not found");
-
- mem_id = oclCreateImageFromLibvaIntel (_context_id, &image_info, &errcode);
- XCAM_FAIL_RETURN(
- WARNING,
- errcode == CL_SUCCESS,
- NULL,
- "create cl memory from va image failed");
- return mem_id;
-}
-
-cl_mem
-CLContext::import_dma_image (const cl_import_image_info_intel &import_info)
-{
- cl_mem mem_id = NULL;
- cl_int errcode = CL_SUCCESS;
- if (!is_valid())
- return NULL;
-
- clCreateImageFromFdINTEL_fn oclCreateImageFromFdINTEL =
- (clCreateImageFromFdINTEL_fn) _device->get_extension_function (OCL_EXT_NAME_CREATE_IMAGE_FROM_FD_INTEL);
- XCAM_FAIL_RETURN(ERROR, oclCreateImageFromFdINTEL, NULL, "create image failed since extension was not found");
-
- mem_id = oclCreateImageFromFdINTEL (_context_id, &import_info, &errcode);
- XCAM_FAIL_RETURN(
- WARNING,
- errcode == CL_SUCCESS,
- NULL,
- "import cl memory from dma image failed, errcode:%d", errcode);
-
- return mem_id;
-}
-
-cl_mem
CLContext::create_image (
cl_mem_flags flags, const cl_image_format& format,
const cl_image_desc &image_info, void *host_ptr)
@@ -785,26 +699,6 @@ CLContext::enqueue_unmap (
return XCAM_RETURN_NO_ERROR;
}
-int32_t
-CLContext::export_mem_fd (cl_mem mem_id)
-{
- cl_int errcode = CL_SUCCESS;
- int32_t fd = -1;
-
- clGetMemObjectFdIntel_fn oclGetMemObjectFdIntel =
- (clGetMemObjectFdIntel_fn) _device->get_extension_function (OCL_EXT_NAME_GET_MEM_OBJECT_FD_INTEL);
- XCAM_FAIL_RETURN(ERROR, oclGetMemObjectFdIntel, -1, "export fd failed since extension was not found");
-
- XCAM_ASSERT (mem_id);
- errcode = oclGetMemObjectFdIntel (_context_id, mem_id, &fd);
- XCAM_FAIL_RETURN (
- WARNING,
- errcode == CL_SUCCESS,
- -1,
- "export cl mem fd failed");
- return fd;
-}
-
CLCommandQueue::CLCommandQueue (SmartPtr<CLContext> &context, cl_command_queue id)
: _context (context)
, _cmd_queue_id (id)
diff --git a/modules/ocl/cl_context.h b/modules/ocl/cl_context.h
index b234e2c..61c3771 100644
--- a/modules/ocl/cl_context.h
+++ b/modules/ocl/cl_context.h
@@ -25,7 +25,6 @@
#include <map>
#include <list>
#include <CL/cl.h>
-#include <CL/cl_intel.h>
#include <ocl/cl_event.h>
namespace XCam {
@@ -34,6 +33,10 @@ class CLKernel;
class CLDevice;
class CLCommandQueue;
+class CLVaBuffer;
+class CLVaImage;
+class CLIntelContext;
+
/* default context:
* SmartPtr<CLContext> context = CLDevice::instance()->get_context();
*/
@@ -47,19 +50,21 @@ class CLContext {
friend class CLMemory;
friend class CLBuffer;
friend class CLSubBuffer;
- friend class CLVaBuffer;
friend class CLImage;
- friend class CLVaImage;
friend class CLImage2D;
friend class CLImage2DArray;
+ friend class CLVaBuffer;
+ friend class CLVaImage;
+ friend class CLIntelContext;
+
public:
enum KernelBuildType {
KERNEL_BUILD_BINARY = 0,
KERNEL_BUILD_SOURCE,
};
- ~CLContext ();
+ virtual ~CLContext ();
cl_context get_context_id () {
return _context_id;
}
@@ -109,10 +114,6 @@ private:
SmartPtr<CLCommandQueue> get_default_cmd_queue ();
//Memory, Image
- cl_mem create_va_buffer (uint32_t bo_name);
- cl_mem import_dma_buffer (const cl_import_buffer_info_intel &import_info);
- cl_mem create_va_image (const cl_libva_image &image_info);
- cl_mem import_dma_image (const cl_import_image_info_intel &image_info);
cl_mem create_image (
cl_mem_flags flags, const cl_image_format& format,
const cl_image_desc &image_info, void *host_ptr = NULL);
@@ -165,8 +166,6 @@ private:
CLEventList &events_wait = CLEvent::EmptyList,
SmartPtr<CLEvent> &event_out = CLEvent::NullEvent);
- int32_t export_mem_fd (cl_mem mem_id);
-
// return valid event count
static uint32_t event_list_2_id_array (
CLEventList &events_wait,
diff --git a/modules/ocl/cl_device.cpp b/modules/ocl/cl_device.cpp
index 948ce0e..c3f2a41 100644
--- a/modules/ocl/cl_device.cpp
+++ b/modules/ocl/cl_device.cpp
@@ -20,6 +20,9 @@
#include "cl_device.h"
#include "cl_context.h"
+#if HAVE_LIBDRM
+#include "intel/cl_intel_context.h"
+#endif
namespace XCam {
@@ -188,7 +191,13 @@ CLDevice::query_device_info (cl_device_id device_id, CLDevieInfo &info)
bool
CLDevice::create_default_context ()
{
- SmartPtr<CLContext> context = new CLContext (_instance);
+ SmartPtr<CLContext> context;
+
+#if HAVE_LIBDRM
+ context = new CLIntelContext (_instance);
+#else
+ context = new CLContext (_instance);
+#endif
if (!context->is_valid())
return false;
diff --git a/modules/ocl/cl_memory.cpp b/modules/ocl/cl_memory.cpp
index d8c725c..90e7d0e 100644
--- a/modules/ocl/cl_memory.cpp
+++ b/modules/ocl/cl_memory.cpp
@@ -21,19 +21,19 @@
#include "cl_utils.h"
#include "cl_memory.h"
#if HAVE_LIBDRM
-#include "cl_image_bo_buffer.h"
+#include "intel/cl_va_memory.h"
#endif
namespace XCam {
CLImageDesc::CLImageDesc ()
: format {CL_R, CL_UNORM_INT8}
-, width (0)
-, height (0)
-, row_pitch (0)
-, slice_pitch (0)
-, array_size (0)
-, size (0)
+ , width (0)
+ , height (0)
+ , row_pitch (0)
+ , slice_pitch (0)
+ , array_size (0)
+ , size (0)
{
}
@@ -80,7 +80,13 @@ CLMemory::export_fd ()
if (_mem_fd >= 0)
return _mem_fd;
- _mem_fd = _context->export_mem_fd (_mem_id);
+#if HAVE_LIBDRM
+ SmartPtr<CLIntelContext> context = _context.dynamic_cast_ptr<CLIntelContext> ();
+ _mem_fd = context->export_mem_fd (_mem_id);
+#endif
+ if (_mem_fd < 0)
+ XCAM_LOG_ERROR ("invalid fd:%d", _mem_fd);
+
return _mem_fd;
}
@@ -259,44 +265,6 @@ CLBuffer::enqueue_map (
return ret;
}
-#if HAVE_LIBDRM
-CLVaBuffer::CLVaBuffer (
- const SmartPtr<CLContext> &context,
- SmartPtr<DrmBoBuffer> &bo)
- : CLBuffer (context)
- , _bo (bo)
-{
- init_va_buffer (context, bo);
-}
-
-bool
-CLVaBuffer::init_va_buffer (const SmartPtr<CLContext> &context, SmartPtr<DrmBoBuffer> &bo)
-{
- cl_mem mem_id = NULL;
- uint32_t bo_name = 0;
- cl_import_buffer_info_intel import_buffer_info;
-
- xcam_mem_clear (import_buffer_info);
- import_buffer_info.fd = bo->get_fd ();
- import_buffer_info.size = bo->get_size ();
- if (import_buffer_info.fd != -1) {
- mem_id = context->import_dma_buffer (import_buffer_info);
- }
-
- if (mem_id == NULL) {
- drm_intel_bo_flink (bo->get_bo (), &bo_name);
- mem_id = context->create_va_buffer (bo_name);
- if (mem_id == NULL) {
- XCAM_LOG_WARNING ("CLVaBuffer create va buffer failed");
- return false;
- }
- }
-
- set_mem_id (mem_id);
- return true;
-}
-#endif
-
CLImage::CLImage (const SmartPtr<CLContext> &context)
: CLMemory (context)
{
@@ -568,137 +536,6 @@ CLImage::enqueue_map (
return ret;
}
-#if HAVE_LIBDRM
-CLVaImage::CLVaImage (
- const SmartPtr<CLContext> &context,
- SmartPtr<DrmBoBuffer> &bo,
- uint32_t offset,
- bool single_plane)
- : CLImage (context)
- , _bo (bo)
-{
- CLImageDesc cl_desc;
-
- const VideoBufferInfo & video_info = bo->get_video_info ();
- if (!video_info_2_cl_image_desc (video_info, cl_desc)) {
- XCAM_LOG_WARNING ("CLVaImage create va image failed on default videoinfo");
- return;
- }
- if (single_plane) {
- cl_desc.array_size = 0;
- cl_desc.slice_pitch = 0;
- } else if (!merge_multi_plane (video_info, cl_desc)) {
- XCAM_LOG_WARNING ("CLVaImage create va image failed on merging planes");
- return;
- }
-
- init_va_image (context, bo, cl_desc, offset);
-}
-
-CLVaImage::CLVaImage (
- const SmartPtr<CLContext> &context,
- SmartPtr<DrmBoBuffer> &bo,
- const CLImageDesc &image_info,
- uint32_t offset)
- : CLImage (context)
- , _bo (bo)
-{
- init_va_image (context, bo, image_info, offset);
-}
-
-bool
-CLVaImage::merge_multi_plane (
- const VideoBufferInfo &video_info,
- CLImageDesc &cl_desc)
-{
- if (cl_desc.array_size <= 1)
- return true;
-
- switch (video_info.format) {
- case V4L2_PIX_FMT_NV12:
- cl_desc.height = video_info.aligned_height + video_info.height / 2;
- break;
-
- case XCAM_PIX_FMT_RGB48_planar:
- case XCAM_PIX_FMT_RGB24_planar:
- cl_desc.height = video_info.aligned_height * 3;
- break;
-
- case XCAM_PIX_FMT_SGRBG16_planar:
- case XCAM_PIX_FMT_SGRBG8_planar:
- cl_desc.height = video_info.aligned_height * 4;
- break;
-
- default:
- XCAM_LOG_WARNING ("CLVaImage unknown format(%s) plane change", xcam_fourcc_to_string(video_info.format));
- return false;
- }
- cl_desc.array_size = 0;
- cl_desc.slice_pitch = 0;
- return true;
-}
-
-bool
-CLVaImage::init_va_image (
- const SmartPtr<CLContext> &context, SmartPtr<DrmBoBuffer> &bo,
- const CLImageDesc &cl_desc, uint32_t offset)
-{
-
- uint32_t bo_name = 0;
- cl_mem mem_id = 0;
- bool need_create = true;
- cl_libva_image va_image_info;
- cl_import_image_info_intel import_image_info;
-
- xcam_mem_clear (va_image_info);
- xcam_mem_clear (import_image_info);
- import_image_info.offset = va_image_info.offset = offset;
- import_image_info.width = va_image_info.width = cl_desc.width;
- import_image_info.height = va_image_info.height = cl_desc.height;
- import_image_info.fmt = va_image_info.fmt = cl_desc.format;
- import_image_info.row_pitch = va_image_info.row_pitch = cl_desc.row_pitch;
- import_image_info.size = cl_desc.size;
- import_image_info.type = CL_MEM_OBJECT_IMAGE2D;
-
- XCAM_ASSERT (bo.ptr ());
-
- SmartPtr<CLImageBoBuffer> cl_image_buffer = bo.dynamic_cast_ptr<CLImageBoBuffer> ();
- if (cl_image_buffer.ptr ()) {
- SmartPtr<CLImage> cl_image_data = cl_image_buffer->get_cl_image ();
- XCAM_ASSERT (cl_image_data.ptr ());
- CLImageDesc old_desc = cl_image_data->get_image_desc ();
- if (cl_desc == old_desc) {
- need_create = false;
- mem_id = cl_image_data->get_mem_id ();
- }
- }
-
- if (need_create) {
- import_image_info.fd = bo->get_fd();
- if (import_image_info.fd != -1)
- mem_id = context->import_dma_image (import_image_info);
-
- if (mem_id == NULL) {
- if (drm_intel_bo_flink (bo->get_bo (), &bo_name) == 0) {
- va_image_info.bo_name = bo_name;
- mem_id = context->create_va_image (va_image_info);
- }
- if (mem_id == NULL) {
- XCAM_LOG_WARNING ("create va image failed");
- return false;
- }
- }
- } else {
- va_image_info.bo_name = uint32_t(-1);
- }
-
- set_mem_id (mem_id, need_create);
- init_desc_by_image ();
- _va_image_info = va_image_info;
- return true;
-}
-#endif
-
CLImage2D::CLImage2D (
const SmartPtr<CLContext> &context,
const VideoBufferInfo &video_info,
diff --git a/modules/ocl/cl_memory.h b/modules/ocl/cl_memory.h
index 7d4ffca..acc3fc5 100644
--- a/modules/ocl/cl_memory.h
+++ b/modules/ocl/cl_memory.h
@@ -24,9 +24,6 @@
#include "ocl/cl_context.h"
#include "ocl/cl_event.h"
#include "video_buffer.h"
-#if HAVE_LIBDRM
-#include "drm_bo_buffer.h"
-#endif
#include <unistd.h>
@@ -171,25 +168,6 @@ private:
uint32_t _size;
};
-#if HAVE_LIBDRM
-class CLVaBuffer
- : public CLBuffer
-{
-public:
- explicit CLVaBuffer (
- const SmartPtr<CLContext> &context,
- SmartPtr<DrmBoBuffer> &bo);
-
-private:
- bool init_va_buffer (const SmartPtr<CLContext> &context, SmartPtr<DrmBoBuffer> &bo);
-
- XCAM_DEAD_COPY (CLVaBuffer);
-
-private:
- SmartPtr<DrmBoBuffer> _bo;
-};
-#endif
-
class CLImage
: public CLMemory
{
@@ -227,39 +205,6 @@ private:
CLImageDesc _image_desc;
};
-#if HAVE_LIBDRM
-class CLVaImage
- : public CLImage
-{
-public:
- explicit CLVaImage (
- const SmartPtr<CLContext> &context,
- SmartPtr<DrmBoBuffer> &bo,
- uint32_t offset = 0,
- bool single_plane = false);
- explicit CLVaImage (
- const SmartPtr<CLContext> &context,
- SmartPtr<DrmBoBuffer> &bo,
- const CLImageDesc &image_info,
- uint32_t offset = 0);
- ~CLVaImage () {}
-
-private:
- bool init_va_image (
- const SmartPtr<CLContext> &context, SmartPtr<DrmBoBuffer> &bo,
- const CLImageDesc &cl_desc, uint32_t offset);
- bool merge_multi_plane (
- const VideoBufferInfo &video_info,
- CLImageDesc &cl_desc);
-
- XCAM_DEAD_COPY (CLVaImage);
-
-private:
- SmartPtr<DrmBoBuffer> _bo;
- cl_libva_image _va_image_info;
-};
-#endif
-
class CLImage2D
: public CLImage
{
diff --git a/modules/ocl/cl_utils.cpp b/modules/ocl/cl_utils.cpp
index 87d4402..55b59f5 100644
--- a/modules/ocl/cl_utils.cpp
+++ b/modules/ocl/cl_utils.cpp
@@ -20,6 +20,10 @@
#include "cl_utils.h"
#include "image_file_handle.h"
+#if HAVE_LIBDRM
+#include "intel/cl_intel_context.h"
+#include "intel/cl_va_memory.h"
+#endif
namespace XCam {
@@ -89,7 +93,10 @@ convert_to_clbuffer (
#if HAVE_LIBDRM
else {
SmartPtr<DrmBoBuffer> bo_buf = buf.dynamic_cast_ptr<DrmBoBuffer> ();
- cl_buf = new CLVaBuffer (context, bo_buf);
+ SmartPtr<CLIntelContext> ctx = context.dynamic_cast_ptr<CLIntelContext> ();
+ XCAM_ASSERT (bo_buf.ptr () && ctx.ptr ());
+
+ cl_buf = new CLVaBuffer (ctx, bo_buf);
}
#else
XCAM_UNUSED (context);
@@ -128,7 +135,10 @@ convert_to_climage (
#if HAVE_LIBDRM
else {
SmartPtr<DrmBoBuffer> bo_buf = buf.dynamic_cast_ptr<DrmBoBuffer> ();
- cl_image = new CLVaImage (context, bo_buf, desc, offset);
+ SmartPtr<CLIntelContext> ctx = context.dynamic_cast_ptr<CLIntelContext> ();
+ XCAM_ASSERT (bo_buf.ptr () && ctx.ptr ());
+
+ cl_image = new CLVaImage (ctx, bo_buf, desc, offset);
}
#endif
diff --git a/modules/ocl/cl_utils.h b/modules/ocl/cl_utils.h
index 67ed467..51d7fa1 100644
--- a/modules/ocl/cl_utils.h
+++ b/modules/ocl/cl_utils.h
@@ -26,6 +26,9 @@
#include "ocl/cl_context.h"
#include "ocl/cl_memory.h"
#include "ocl/cl_video_buffer.h"
+#if HAVE_LIBDRM
+#include "drm_bo_buffer.h"
+#endif
#define XCAM_CL_IMAGE_ALIGNMENT_X 4
diff --git a/modules/ocl/intel/cl_intel_context.cpp b/modules/ocl/intel/cl_intel_context.cpp
new file mode 100644
index 0000000..0d6c864
--- /dev/null
+++ b/modules/ocl/intel/cl_intel_context.cpp
@@ -0,0 +1,144 @@
+/*
+ * cl_intel_context.cpp - CL intel context
+ *
+ * Copyright (c) 2015 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Author: Wind Yuan <feng.yuan@intel.com>
+ */
+
+#include "cl_intel_context.h"
+#include "cl_device.h"
+#include "cl_va_memory.h"
+
+#define OCL_EXT_NAME_CREATE_BUFFER_FROM_LIBVA_INTEL "clCreateBufferFromLibvaIntel"
+#define OCL_EXT_NAME_CREATE_BUFFER_FROM_FD_INTEL "clCreateBufferFromFdINTEL"
+#define OCL_EXT_NAME_CREATE_IMAGE_FROM_LIBVA_INTEL "clCreateImageFromLibvaIntel"
+#define OCL_EXT_NAME_CREATE_IMAGE_FROM_FD_INTEL "clCreateImageFromFdINTEL"
+#define OCL_EXT_NAME_GET_MEM_OBJECT_FD_INTEL "clGetMemObjectFdIntel"
+
+namespace XCam {
+
+CLIntelContext::CLIntelContext (SmartPtr<CLDevice> &device)
+ : CLContext (device)
+{
+}
+
+cl_mem
+CLIntelContext::create_va_buffer (uint32_t bo_name)
+{
+ cl_mem mem_id = NULL;
+ cl_int errcode = CL_SUCCESS;
+ if (!is_valid())
+ return NULL;
+
+ clCreateBufferFromLibvaIntel_fn oclCreateBufferFromLibvaIntel =
+ (clCreateBufferFromLibvaIntel_fn) _device->get_extension_function (OCL_EXT_NAME_CREATE_BUFFER_FROM_LIBVA_INTEL);
+ XCAM_FAIL_RETURN(ERROR, oclCreateBufferFromLibvaIntel, NULL, "create buffer failed since extension was not found");
+
+ mem_id = oclCreateBufferFromLibvaIntel (_context_id, bo_name, &errcode);
+ XCAM_FAIL_RETURN(
+ WARNING,
+ errcode == CL_SUCCESS,
+ NULL,
+ "create cl memory from va image failed");
+ return mem_id;
+}
+
+cl_mem
+CLIntelContext::import_dma_buffer (const cl_import_buffer_info_intel &import_info)
+{
+ cl_mem mem_id = NULL;
+ cl_int errcode = CL_SUCCESS;
+ if (!is_valid())
+ return NULL;
+
+ clCreateBufferFromFdINTEL_fn oclCreateBufferFromFdINTEL =
+ (clCreateBufferFromFdINTEL_fn) _device->get_extension_function (OCL_EXT_NAME_CREATE_BUFFER_FROM_FD_INTEL);
+ XCAM_FAIL_RETURN(ERROR, oclCreateBufferFromFdINTEL, NULL, "import buffer failed since extension was not found");
+
+ mem_id = oclCreateBufferFromFdINTEL (_context_id, &import_info, &errcode);
+ XCAM_FAIL_RETURN(
+ WARNING,
+ errcode == CL_SUCCESS,
+ NULL,
+ "import cl memory from dma buffer failed");
+
+ return mem_id;
+}
+
+cl_mem
+CLIntelContext::create_va_image (const cl_libva_image &image_info)
+{
+ cl_mem mem_id = NULL;
+ cl_int errcode = CL_SUCCESS;
+ if (!is_valid())
+ return NULL;
+
+ clCreateImageFromLibvaIntel_fn oclCreateImageFromLibvaIntel =
+ (clCreateImageFromLibvaIntel_fn) _device->get_extension_function (OCL_EXT_NAME_CREATE_IMAGE_FROM_LIBVA_INTEL);
+ XCAM_FAIL_RETURN(ERROR, oclCreateImageFromLibvaIntel, NULL, "create image failed since extension was not found");
+
+ mem_id = oclCreateImageFromLibvaIntel (_context_id, &image_info, &errcode);
+ XCAM_FAIL_RETURN(
+ WARNING,
+ errcode == CL_SUCCESS,
+ NULL,
+ "create cl memory from va image failed");
+ return mem_id;
+}
+
+cl_mem
+CLIntelContext::import_dma_image (const cl_import_image_info_intel &import_info)
+{
+ cl_mem mem_id = NULL;
+ cl_int errcode = CL_SUCCESS;
+ if (!is_valid())
+ return NULL;
+
+ clCreateImageFromFdINTEL_fn oclCreateImageFromFdINTEL =
+ (clCreateImageFromFdINTEL_fn) _device->get_extension_function (OCL_EXT_NAME_CREATE_IMAGE_FROM_FD_INTEL);
+ XCAM_FAIL_RETURN(ERROR, oclCreateImageFromFdINTEL, NULL, "create image failed since extension was not found");
+
+ mem_id = oclCreateImageFromFdINTEL (_context_id, &import_info, &errcode);
+ XCAM_FAIL_RETURN(
+ WARNING,
+ errcode == CL_SUCCESS,
+ NULL,
+ "import cl memory from dma image failed, errcode:%d", errcode);
+
+ return mem_id;
+}
+
+int32_t
+CLIntelContext::export_mem_fd (cl_mem mem_id)
+{
+ cl_int errcode = CL_SUCCESS;
+ int32_t fd = -1;
+
+ clGetMemObjectFdIntel_fn oclGetMemObjectFdIntel =
+ (clGetMemObjectFdIntel_fn) _device->get_extension_function (OCL_EXT_NAME_GET_MEM_OBJECT_FD_INTEL);
+ XCAM_FAIL_RETURN(ERROR, oclGetMemObjectFdIntel, -1, "export fd failed since extension was not found");
+
+ XCAM_ASSERT (mem_id);
+ errcode = oclGetMemObjectFdIntel (_context_id, mem_id, &fd);
+ XCAM_FAIL_RETURN (
+ WARNING,
+ errcode == CL_SUCCESS,
+ -1,
+ "export cl mem fd failed");
+ return fd;
+}
+
+};
diff --git a/modules/ocl/intel/cl_intel_context.h b/modules/ocl/intel/cl_intel_context.h
new file mode 100644
index 0000000..bd7a78e
--- /dev/null
+++ b/modules/ocl/intel/cl_intel_context.h
@@ -0,0 +1,56 @@
+/*
+ * cl_intel_context.h - CL intel context
+ *
+ * Copyright (c) 2015 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Author: Wind Yuan <feng.yuan@intel.com>
+ */
+
+#ifndef XCAM_CL_INTEL_CONTEXT_H
+#define XCAM_CL_INTEL_CONTEXT_H
+
+#include <CL/cl_intel.h>
+#include <ocl/cl_context.h>
+
+namespace XCam {
+
+class CLIntelContext
+ : public CLContext
+{
+ friend class CLMemory;
+ friend class CLDevice;
+ friend class CLVaBuffer;
+ friend class CLVaImage;
+
+public:
+ ~CLIntelContext () {}
+
+private:
+ explicit CLIntelContext (SmartPtr<CLDevice> &device);
+
+ cl_mem create_va_buffer (uint32_t bo_name);
+ cl_mem import_dma_buffer (const cl_import_buffer_info_intel &import_info);
+ cl_mem create_va_image (const cl_libva_image &image_info);
+ cl_mem import_dma_image (const cl_import_image_info_intel &image_info);
+
+ int32_t export_mem_fd (cl_mem mem_id);
+
+private:
+ XCAM_DEAD_COPY (CLIntelContext);
+};
+
+};
+
+#endif //XCAM_CL_CONTEXT_H
diff --git a/modules/ocl/intel/cl_va_memory.cpp b/modules/ocl/intel/cl_va_memory.cpp
new file mode 100644
index 0000000..27b3658
--- /dev/null
+++ b/modules/ocl/intel/cl_va_memory.cpp
@@ -0,0 +1,191 @@
+/*
+ * cl_va_memory.cpp - CL va memory
+ *
+ * Copyright (c) 2015 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Author: Wind Yuan <feng.yuan@intel.com>
+ */
+
+#include "cl_va_memory.h"
+#include "cl_image_bo_buffer.h"
+
+namespace XCam {
+
+CLVaBuffer::CLVaBuffer (
+ const SmartPtr<CLIntelContext> &context,
+ SmartPtr<DrmBoBuffer> &bo)
+ : CLBuffer (context)
+ , _bo (bo)
+{
+ init_va_buffer (context, bo);
+}
+
+bool
+CLVaBuffer::init_va_buffer (const SmartPtr<CLIntelContext> &context, SmartPtr<DrmBoBuffer> &bo)
+{
+ cl_mem mem_id = NULL;
+ uint32_t bo_name = 0;
+ cl_import_buffer_info_intel import_buffer_info;
+
+ xcam_mem_clear (import_buffer_info);
+ import_buffer_info.fd = bo->get_fd ();
+ import_buffer_info.size = bo->get_size ();
+ if (import_buffer_info.fd != -1) {
+ mem_id = context->import_dma_buffer (import_buffer_info);
+ }
+
+ if (mem_id == NULL) {
+ drm_intel_bo_flink (bo->get_bo (), &bo_name);
+ mem_id = context->create_va_buffer (bo_name);
+ if (mem_id == NULL) {
+ XCAM_LOG_WARNING ("CLVaBuffer create va buffer failed");
+ return false;
+ }
+ }
+
+ set_mem_id (mem_id);
+ return true;
+}
+
+CLVaImage::CLVaImage (
+ const SmartPtr<CLIntelContext> &context,
+ SmartPtr<DrmBoBuffer> &bo,
+ uint32_t offset,
+ bool single_plane)
+ : CLImage (context)
+ , _bo (bo)
+{
+ CLImageDesc cl_desc;
+
+ const VideoBufferInfo & video_info = bo->get_video_info ();
+ if (!video_info_2_cl_image_desc (video_info, cl_desc)) {
+ XCAM_LOG_WARNING ("CLVaImage create va image failed on default videoinfo");
+ return;
+ }
+ if (single_plane) {
+ cl_desc.array_size = 0;
+ cl_desc.slice_pitch = 0;
+ } else if (!merge_multi_plane (video_info, cl_desc)) {
+ XCAM_LOG_WARNING ("CLVaImage create va image failed on merging planes");
+ return;
+ }
+
+ init_va_image (context, bo, cl_desc, offset);
+}
+
+CLVaImage::CLVaImage (
+ const SmartPtr<CLIntelContext> &context,
+ SmartPtr<DrmBoBuffer> &bo,
+ const CLImageDesc &image_info,
+ uint32_t offset)
+ : CLImage (context)
+ , _bo (bo)
+{
+ init_va_image (context, bo, image_info, offset);
+}
+
+bool
+CLVaImage::merge_multi_plane (
+ const VideoBufferInfo &video_info,
+ CLImageDesc &cl_desc)
+{
+ if (cl_desc.array_size <= 1)
+ return true;
+
+ switch (video_info.format) {
+ case V4L2_PIX_FMT_NV12:
+ cl_desc.height = video_info.aligned_height + video_info.height / 2;
+ break;
+
+ case XCAM_PIX_FMT_RGB48_planar:
+ case XCAM_PIX_FMT_RGB24_planar:
+ cl_desc.height = video_info.aligned_height * 3;
+ break;
+
+ case XCAM_PIX_FMT_SGRBG16_planar:
+ case XCAM_PIX_FMT_SGRBG8_planar:
+ cl_desc.height = video_info.aligned_height * 4;
+ break;
+
+ default:
+ XCAM_LOG_WARNING ("CLVaImage unknown format(%s) plane change", xcam_fourcc_to_string(video_info.format));
+ return false;
+ }
+ cl_desc.array_size = 0;
+ cl_desc.slice_pitch = 0;
+ return true;
+}
+
+bool
+CLVaImage::init_va_image (
+ const SmartPtr<CLIntelContext> &context, SmartPtr<DrmBoBuffer> &bo,
+ const CLImageDesc &cl_desc, uint32_t offset)
+{
+
+ uint32_t bo_name = 0;
+ cl_mem mem_id = 0;
+ bool need_create = true;
+ cl_libva_image va_image_info;
+ cl_import_image_info_intel import_image_info;
+
+ xcam_mem_clear (va_image_info);
+ xcam_mem_clear (import_image_info);
+ import_image_info.offset = va_image_info.offset = offset;
+ import_image_info.width = va_image_info.width = cl_desc.width;
+ import_image_info.height = va_image_info.height = cl_desc.height;
+ import_image_info.fmt = va_image_info.fmt = cl_desc.format;
+ import_image_info.row_pitch = va_image_info.row_pitch = cl_desc.row_pitch;
+ import_image_info.size = cl_desc.size;
+ import_image_info.type = CL_MEM_OBJECT_IMAGE2D;
+
+ XCAM_ASSERT (bo.ptr ());
+
+ SmartPtr<CLImageBoBuffer> cl_image_buffer = bo.dynamic_cast_ptr<CLImageBoBuffer> ();
+ if (cl_image_buffer.ptr ()) {
+ SmartPtr<CLImage> cl_image_data = cl_image_buffer->get_cl_image ();
+ XCAM_ASSERT (cl_image_data.ptr ());
+ CLImageDesc old_desc = cl_image_data->get_image_desc ();
+ if (cl_desc == old_desc) {
+ need_create = false;
+ mem_id = cl_image_data->get_mem_id ();
+ }
+ }
+
+ if (need_create) {
+ import_image_info.fd = bo->get_fd();
+ if (import_image_info.fd != -1)
+ mem_id = context->import_dma_image (import_image_info);
+
+ if (mem_id == NULL) {
+ if (drm_intel_bo_flink (bo->get_bo (), &bo_name) == 0) {
+ va_image_info.bo_name = bo_name;
+ mem_id = context->create_va_image (va_image_info);
+ }
+ if (mem_id == NULL) {
+ XCAM_LOG_WARNING ("create va image failed");
+ return false;
+ }
+ }
+ } else {
+ va_image_info.bo_name = uint32_t(-1);
+ }
+
+ set_mem_id (mem_id, need_create);
+ init_desc_by_image ();
+ _va_image_info = va_image_info;
+ return true;
+}
+
+};
diff --git a/modules/ocl/intel/cl_va_memory.h b/modules/ocl/intel/cl_va_memory.h
new file mode 100644
index 0000000..91f1429
--- /dev/null
+++ b/modules/ocl/intel/cl_va_memory.h
@@ -0,0 +1,79 @@
+/*
+ * cl_va_memory.h - CL va memory
+ *
+ * Copyright (c) 2015 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Author: Wind Yuan <feng.yuan@intel.com>
+ */
+
+#ifndef XCAM_CL_VA_MEMORY_H
+#define XCAM_CL_VA_MEMORY_H
+
+#include "ocl/cl_memory.h"
+#include "ocl/intel/cl_intel_context.h"
+#include "drm_bo_buffer.h"
+
+namespace XCam {
+
+class CLVaBuffer
+ : public CLBuffer
+{
+public:
+ explicit CLVaBuffer (
+ const SmartPtr<CLIntelContext> &context,
+ SmartPtr<DrmBoBuffer> &bo);
+
+private:
+ bool init_va_buffer (const SmartPtr<CLIntelContext> &context, SmartPtr<DrmBoBuffer> &bo);
+
+ XCAM_DEAD_COPY (CLVaBuffer);
+
+private:
+ SmartPtr<DrmBoBuffer> _bo;
+};
+
+class CLVaImage
+ : public CLImage
+{
+public:
+ explicit CLVaImage (
+ const SmartPtr<CLIntelContext> &context,
+ SmartPtr<DrmBoBuffer> &bo,
+ uint32_t offset = 0,
+ bool single_plane = false);
+ explicit CLVaImage (
+ const SmartPtr<CLIntelContext> &context,
+ SmartPtr<DrmBoBuffer> &bo,
+ const CLImageDesc &image_info,
+ uint32_t offset = 0);
+ ~CLVaImage () {}
+
+private:
+ bool init_va_image (
+ const SmartPtr<CLIntelContext> &context, SmartPtr<DrmBoBuffer> &bo,
+ const CLImageDesc &cl_desc, uint32_t offset);
+ bool merge_multi_plane (
+ const VideoBufferInfo &video_info,
+ CLImageDesc &cl_desc);
+
+ XCAM_DEAD_COPY (CLVaImage);
+
+private:
+ SmartPtr<DrmBoBuffer> _bo;
+ cl_libva_image _va_image_info;
+};
+
+};
+#endif //