diff options
author | Chuanbo Weng <chuanbo.weng@intel.com> | 2015-11-06 15:57:38 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2015-11-10 10:51:37 +0800 |
commit | 323e2f2eb1e2589b8bc1fc0ac0bde8debc11d27b (patch) | |
tree | 673c328e17c7b5c3221b437537daa54718a9a40f /src/intel/intel_driver.c | |
parent | 2b5c3bfce7c5c0ca4d9947dc42b56693be290ef4 (diff) |
Add extension clCreateBufferFromFdINTEL to create cl buffer by external buffer object's fd.
Before this patch, Beignet can only create cl buffer from external bo by
its handle using clCreateBufferFromLibvaIntel. Render node is the first
choice of accessing gpu in currect Beignet implementation. DRM_IOCTL_GEM_OPEN
is used by clCreateBufferFromLibvaIntel but forbidden in Render node mode.
So it's necessary to add this extension to support buffer sharing between
different libraries.
v2:
Seperate clCreateMemObjectFromFdIntel into two extensions:
clCreateBufferFromFdINTEL and clCreateImageFromFdINTEL.
v3:
Fix rebase conflict: add a parameter when invoke cl_mem_allocate.
Signed-off-by: Chuanbo Weng <chuanbo.weng@intel.com>
Reviewed-by: "Yang, Rong R" <rong.r.yang@intel.com>
Diffstat (limited to 'src/intel/intel_driver.c')
-rw-r--r-- | src/intel/intel_driver.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c index 782a2deb..a9c147a9 100644 --- a/src/intel/intel_driver.c +++ b/src/intel/intel_driver.c @@ -371,7 +371,7 @@ intel_driver_unlock_hardware(intel_driver_t *driver) } LOCAL dri_bo* -intel_driver_share_buffer(intel_driver_t *driver, const char *sname, uint32_t name) +intel_driver_share_buffer_from_name(intel_driver_t *driver, const char *sname, uint32_t name) { dri_bo *bo = intel_bo_gem_create_from_name(driver->bufmgr, sname, @@ -383,6 +383,19 @@ intel_driver_share_buffer(intel_driver_t *driver, const char *sname, uint32_t na return bo; } +LOCAL dri_bo* +intel_driver_share_buffer_from_fd(intel_driver_t *driver, int fd, int size) +{ + dri_bo *bo = drm_intel_bo_gem_create_from_prime(driver->bufmgr, + fd, + size); + if (bo == NULL) { + fprintf(stderr, "drm_intel_bo_gem_create_from_prime create bo(size %d) from fd %d failed: %s\n", fd, size, strerror(errno)); + return NULL; + } + return bo; +} + LOCAL uint32_t intel_driver_shared_name(intel_driver_t *driver, dri_bo *bo) { @@ -697,7 +710,7 @@ cl_buffer intel_share_buffer_from_libva(cl_context ctx, { drm_intel_bo *intel_bo; - intel_bo = intel_driver_share_buffer((intel_driver_t *)ctx->drv, "shared from libva", bo_name); + intel_bo = intel_driver_share_buffer_from_name((intel_driver_t *)ctx->drv, "shared from libva", bo_name); if (intel_bo == NULL) return NULL; @@ -715,7 +728,7 @@ cl_buffer intel_share_image_from_libva(cl_context ctx, drm_intel_bo *intel_bo; uint32_t intel_tiling, intel_swizzle_mode; - intel_bo = intel_driver_share_buffer((intel_driver_t *)ctx->drv, "shared from libva", bo_name); + intel_bo = intel_driver_share_buffer_from_name((intel_driver_t *)ctx->drv, "shared from libva", bo_name); drm_intel_bo_get_tiling(intel_bo, &intel_tiling, &intel_swizzle_mode); image->tiling = get_cl_tiling(intel_tiling); @@ -723,6 +736,20 @@ cl_buffer intel_share_image_from_libva(cl_context ctx, return (cl_buffer)intel_bo; } +cl_buffer intel_share_buffer_from_fd(cl_context ctx, + int fd, + int buffer_size) +{ + drm_intel_bo *intel_bo; + + intel_bo = intel_driver_share_buffer_from_fd((intel_driver_t *)ctx->drv, fd, buffer_size); + + if (intel_bo == NULL) + return NULL; + + return (cl_buffer)intel_bo; +} + static cl_buffer intel_buffer_alloc_userptr(cl_buffer_mgr bufmgr, const char* name, void *data,size_t size, unsigned long flags) { #ifdef HAS_USERPTR @@ -877,5 +904,6 @@ intel_setup_callbacks(void) 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; cl_buffer_get_tiling_align = (cl_buffer_get_tiling_align_cb *)intel_buffer_get_tiling_align; + cl_buffer_get_buffer_from_fd = (cl_buffer_get_buffer_from_fd_cb *) intel_share_buffer_from_fd; intel_set_gpgpu_callbacks(intel_get_device_id()); } |