Fix pitch parameter in clCreateImage2D
authorSimon Richter <Simon.Richter@hogyros.de>
Fri, 19 Apr 2013 06:12:58 +0000 (08:12 +0200)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Fri, 19 Apr 2013 08:28:37 +0000 (16:28 +0800)
If the host_ptr is NULL, the pitch parameter must be 0.

The pitch parameter gives the number of bytes per scanline. Specifying 0
selects the minimum possible.

Signed-off-by: Simon Richter <Simon.Richter@hogyros.de>
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
src/cl_mem.c

index e89aafa..a197383 100644 (file)
@@ -284,9 +284,13 @@ _cl_mem_new_image(cl_context ctx,
   if (UNLIKELY(h == 0)) DO_IMAGE_ERROR;
 
   if (image_type == CL_MEM_OBJECT_IMAGE2D) {
+    size_t min_pitch = bpp * w;
+    if (data && pitch == 0)
+      pitch = min_pitch;
     if (UNLIKELY(w > ctx->device->image2d_max_width)) DO_IMAGE_ERROR;
     if (UNLIKELY(h > ctx->device->image2d_max_height)) DO_IMAGE_ERROR;
-    if (UNLIKELY(data && (bpp*w > pitch))) DO_IMAGE_ERROR;
+    if (UNLIKELY(data && min_pitch > pitch)) DO_IMAGE_ERROR;
+    if (UNLIKELY(!data && pitch != 0)) DO_IMAGE_ERROR;
 
     /* Pick up tiling mode (we do only linear on SNB) */
     if (cl_driver_get_ver(ctx->drv) != 6)