[Beignet] [PATCH] Add clGetMemObjectFdIntel() api
Zhigang Gong
zhigang.gong at linux.intel.com
Wed Jan 15 23:12:40 PST 2014
On Fri, Jan 10, 2014 at 06:18:03PM +0800, Chuanbo Weng wrote:
> Use this api to share buffer between OpenCL and v4l2. After import
> the fd of OpenCL memory object to v4l2, v4l2 can directly read frame
> into this memory object by the way of DMABUF, without memory-copy.
>
> Signed-off-by: Chuanbo Weng <chuanbo.weng at intel.com>
> ---
> include/CL/cl_intel.h | 11 +++++++++++
> src/cl_api.c | 15 +++++++++++++++
> src/cl_driver.h | 3 +++
> src/cl_driver_defs.c | 1 +
> src/cl_mem.c | 8 ++++++++
> src/intel/intel_driver.c | 1 +
> 6 files changed, 39 insertions(+)
>
> diff --git a/include/CL/cl_intel.h b/include/CL/cl_intel.h
> index 3fd73da..f2fe9d4 100644
> --- a/include/CL/cl_intel.h
> +++ b/include/CL/cl_intel.h
> @@ -122,6 +122,17 @@ typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateImageFromLibvaIntel_fn)(
> const cl_libva_image * /* info */,
> cl_int * /* errcode_ret */);
>
> +/* Create buffer from libva's buffer object */
> +extern CL_API_ENTRY cl_int CL_API_CALL
> +clGetMemObjectFdIntel(cl_context /* context */,
> + cl_mem /* Memory Obejct */,
> + int* /* returned fd */);
> +
> +typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetMemObjectFdIntel_fn)(
> + cl_context /* context */,
> + cl_mem /* Memory Obejct */,
> + int* /* returned fd */);
> +
> #ifdef __cplusplus
> }
> #endif
> diff --git a/src/cl_api.c b/src/cl_api.c
> index 405a41a..d210203 100644
> --- a/src/cl_api.c
> +++ b/src/cl_api.c
> @@ -2668,6 +2668,7 @@ clGetExtensionFunctionAddress(const char *func_name)
> EXTFUNC(clReportUnfreedIntel)
> EXTFUNC(clCreateBufferFromLibvaIntel)
> EXTFUNC(clCreateImageFromLibvaIntel)
> + EXTFUNC(clGetMemObjectFdIntel)
> return NULL;
> }
>
> @@ -2807,3 +2808,17 @@ error:
> return mem;
> }
>
> +extern CL_API_ENTRY cl_int CL_API_CALL
> +clGetMemObjectFdIntel(cl_context context,
> + cl_mem memobj,
> + int* fd)
> +{
> + cl_int err = CL_SUCCESS;
> + CHECK_CONTEXT (context);
> + CHECK_MEM (memobj);
> +
> + err = cl_mem_get_fd(memobj, fd);
> +
> +error:
> + return err;
> +}
> diff --git a/src/cl_driver.h b/src/cl_driver.h
> index 96fc377..9dc2330 100644
> --- a/src/cl_driver.h
> +++ b/src/cl_driver.h
> @@ -297,6 +297,9 @@ extern cl_buffer_subdata_cb *cl_buffer_subdata;
> typedef int (cl_buffer_wait_rendering_cb) (cl_buffer);
> extern cl_buffer_wait_rendering_cb *cl_buffer_wait_rendering;
>
> +typedef int (cl_buffer_get_fd_cb)(cl_buffer, int *fd);
> +extern cl_buffer_get_fd_cb *cl_buffer_get_fd;
> +
> /* Get the device id */
> typedef int (cl_driver_get_device_id_cb)(void);
> extern cl_driver_get_device_id_cb *cl_driver_get_device_id;
> diff --git a/src/cl_driver_defs.c b/src/cl_driver_defs.c
> index 0a9012c..95a1a03 100644
> --- a/src/cl_driver_defs.c
> +++ b/src/cl_driver_defs.c
> @@ -47,6 +47,7 @@ LOCAL cl_buffer_subdata_cb *cl_buffer_subdata = NULL;
> LOCAL cl_buffer_wait_rendering_cb *cl_buffer_wait_rendering = NULL;
> LOCAL cl_buffer_get_buffer_from_libva_cb *cl_buffer_get_buffer_from_libva = NULL;
> LOCAL cl_buffer_get_image_from_libva_cb *cl_buffer_get_image_from_libva = NULL;
> +LOCAL cl_buffer_get_fd_cb *cl_buffer_get_fd = NULL;
>
> /* cl_khr_gl_sharing */
> LOCAL cl_gl_acquire_texture_cb *cl_gl_acquire_texture = NULL;
> diff --git a/src/cl_mem.c b/src/cl_mem.c
> index 5c4b197..3aaca66 100644
> --- a/src/cl_mem.c
> +++ b/src/cl_mem.c
> @@ -1336,3 +1336,11 @@ error:
> mem = NULL;
> goto exit;
> }
> +
> +LOCAL cl_int
> +cl_mem_get_fd(cl_mem mem,
> + int* fd)
> +{
> + cl_buffer_get_fd(mem->bo, fd);
why ignore the return value of drm_intel_bo_wait_rendering()?
> + return CL_SUCCESS;
> +}
> diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c
> index f88a105..5e474de 100644
> --- a/src/intel/intel_driver.c
> +++ b/src/intel/intel_driver.c
> @@ -682,5 +682,6 @@ intel_setup_callbacks(void)
> cl_buffer_unpin = (cl_buffer_unpin_cb *) drm_intel_bo_unpin;
> cl_buffer_subdata = (cl_buffer_subdata_cb *) drm_intel_bo_subdata;
> cl_buffer_wait_rendering = (cl_buffer_wait_rendering_cb *) drm_intel_bo_wait_rendering;
> + cl_buffer_get_fd = (cl_buffer_get_fd_cb *) drm_intel_bo_gem_export_to_prime;
> intel_set_gpgpu_callbacks();
> }
> --
> 1.7.9.5
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list