From dd345e7253d858d086f13b74648c1a971d25dc51 Mon Sep 17 00:00:00 2001 From: Simon Richter Date: Fri, 19 Apr 2013 08:12:58 +0200 Subject: [PATCH] Fix pitch parameter in clCreateImage2D 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 Signed-off-by: Zhigang Gong --- src/cl_mem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cl_mem.c b/src/cl_mem.c index e89aafa..a197383 100644 --- a/src/cl_mem.c +++ b/src/cl_mem.c @@ -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) -- 2.7.4