Runtime: set size member of cl_image created by clCreateImageFromFdINTEL.

Submitted by Chuanbo Weng on July 1, 2016, 8:01 a.m.

Details

Message ID 1467360078-22806-1-git-send-email-chuanbo.weng@intel.com
State New
Headers show
Series "Runtime: set size member of cl_image created by clCreateImageFromFdINTEL." ( rev: 1 ) in Beignet

Not browsing as part of any series.

Commit Message

Chuanbo Weng July 1, 2016, 8:01 a.m.
The size need to be set, so clGetMemObjectInfo(.., CL_MEM_SIZE, ..) can
return actual size of this cl_image instead of 0.
Also some code refinement to make logic more clear.

Signed-off-by: Chuanbo Weng <chuanbo.weng@intel.com>
---
 src/cl_mem.c             | 17 +++++++++++------
 src/intel/intel_driver.c |  6 ++++++
 2 files changed, 17 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/cl_mem.c b/src/cl_mem.c
index e6eda66..37ea2d8 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -2189,14 +2189,16 @@  LOCAL cl_mem cl_mem_new_libva_image(cl_context ctx,
   }
 
   mem = cl_mem_allocate(CL_MEM_IMAGE_TYPE, ctx, 0, 0, 0, NULL, NULL, &err);
-  if (mem == NULL || err != CL_SUCCESS) {
-    err = CL_OUT_OF_HOST_MEMORY;
+  if (mem == NULL || err != CL_SUCCESS)
     goto error;
-  }
 
   image = cl_mem_image(mem);
 
   mem->bo = cl_buffer_get_image_from_libva(ctx, bo_name, image);
+  if (mem->bo == NULL) {
+    err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
+    goto error;
+  }
 
   image->w = width;
   image->h = height;
@@ -2287,14 +2289,17 @@  LOCAL cl_mem cl_mem_new_image_from_fd(cl_context ctx,
   }
 
   mem = cl_mem_allocate(CL_MEM_IMAGE_TYPE, ctx, 0, 0, 0, NULL, NULL, &err);
-  if (mem == NULL || err != CL_SUCCESS) {
-    err = CL_OUT_OF_HOST_MEMORY;
+  if (mem == NULL || err != CL_SUCCESS)
     goto error;
-  }
 
   image = cl_mem_image(mem);
 
   mem->bo = cl_buffer_get_image_from_fd(ctx, fd, image_sz, image);
+  if (mem->bo == NULL) {
+    err = CL_MEM_OBJECT_ALLOCATION_FAILURE;
+    goto error;
+  }
+  mem->size = image_sz;
 
   image->w = width;
   image->h = height;
diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c
index 03d9d34..663efae 100644
--- a/src/intel/intel_driver.c
+++ b/src/intel/intel_driver.c
@@ -730,6 +730,9 @@  cl_buffer intel_share_image_from_libva(cl_context ctx,
 
   intel_bo = intel_driver_share_buffer_from_name((intel_driver_t *)ctx->drv, "shared from libva", bo_name);
 
+  if (intel_bo == NULL)
+    return NULL;
+
   drm_intel_bo_get_tiling(intel_bo, &intel_tiling, &intel_swizzle_mode);
   image->tiling = get_cl_tiling(intel_tiling);
 
@@ -760,6 +763,9 @@  cl_buffer intel_share_image_from_fd(cl_context ctx,
 
   intel_bo = intel_driver_share_buffer_from_fd((intel_driver_t *)ctx->drv, fd, image_size);
 
+  if (intel_bo == NULL)
+    return NULL;
+
   drm_intel_bo_get_tiling(intel_bo, &intel_tiling, &intel_swizzle_mode);
   image->tiling = get_cl_tiling(intel_tiling);