Sorry, this patch set is for Opencl-1.2 branch
On Thu, 2014-05-15 at 16:43 +0800, junyan...@inbox.com wrote: > From: Junyan He <junyan...@linux.intel.com> > > Add more check for Image creating according to the spec. > Update the according image utest cases to pass it. > The 1d image creating is also be added. > > Signed-off-by: Junyan He <junyan...@linux.intel.com> > --- > src/cl_api.c | 36 ++++++++++++++++++++++++++++++++++++ > src/cl_mem.c | 24 ++++++++++++++++++------ > utests/compiler_copy_image.cpp | 4 ++++ > utests/compiler_copy_image1.cpp | 4 ++++ > utests/compiler_copy_image_3d.cpp | 3 +++ > utests/compiler_fill_image.cpp | 4 ++++ > utests/compiler_fill_image0.cpp | 4 ++++ > 7 files changed, 73 insertions(+), 6 deletions(-) > > diff --git a/src/cl_api.c b/src/cl_api.c > index 9c22819..b26936e 100644 > --- a/src/cl_api.c > +++ b/src/cl_api.c > @@ -506,7 +506,43 @@ clCreateImage(cl_context context, > cl_mem mem = NULL; > cl_int err = CL_SUCCESS; > CHECK_CONTEXT (context); > + if (image_format == NULL) { > + err = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; > + goto error; > + } > + if (image_format->image_channel_order < CL_R || > + image_format->image_channel_order > CL_RGBx) { > + err = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; > + goto error; > + } > + if (image_format->image_channel_data_type < CL_SNORM_INT8 || > + image_format->image_channel_data_type > CL_FLOAT) { > + err = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; > + goto error; > + } > + > + if (image_desc == NULL) { > + err = CL_INVALID_IMAGE_DESCRIPTOR; > + goto error; > + } > + if (image_desc->image_type <= CL_MEM_OBJECT_BUFFER || > + image_desc->image_type > CL_MEM_OBJECT_IMAGE1D_BUFFER) { > + err = CL_INVALID_IMAGE_DESCRIPTOR; > + goto error; > + } > + /* buffer refers to a valid buffer memory object if image_type is > + CL_MEM_OBJECT_IMAGE1D_BUFFER. Otherwise it must be NULL. */ > + if (image_desc->image_type != CL_MEM_OBJECT_IMAGE1D_BUFFER && > + image_desc->buffer) { > + err = CL_INVALID_IMAGE_DESCRIPTOR; > + goto error; > + } > + if (image_desc->num_mip_levels || image_desc->num_samples) { > + err = CL_INVALID_IMAGE_DESCRIPTOR; > + goto error; > + } > > + /* Other details check for image_desc will leave to image create. */ > mem = cl_mem_new_image(context, > flags, > image_format, > diff --git a/src/cl_mem.c b/src/cl_mem.c > index 3f1b389..0250f0a 100644 > --- a/src/cl_mem.c > +++ b/src/cl_mem.c > @@ -544,10 +544,22 @@ _cl_mem_new_image(cl_context ctx, > err = CL_INVALID_IMAGE_SIZE; \ > goto error; \ > } while (0); > + > if (UNLIKELY(w == 0)) DO_IMAGE_ERROR; > - if (UNLIKELY(h == 0)) DO_IMAGE_ERROR; > + if (UNLIKELY(h == 0 && image_type != CL_MEM_OBJECT_IMAGE1D)) > DO_IMAGE_ERROR; > > - if (image_type == CL_MEM_OBJECT_IMAGE2D) { > + if (image_type == CL_MEM_OBJECT_IMAGE1D) { > + size_t min_pitch = bpp * w; > + if (data && pitch == 0) > + pitch = min_pitch; > + > + depth = 1; > + h = 1; > + if (UNLIKELY(w > ctx->device->image2d_max_width)) DO_IMAGE_ERROR; > + if (UNLIKELY(data && min_pitch > pitch)) DO_IMAGE_ERROR; > + if (UNLIKELY(!data && pitch != 0)) DO_IMAGE_ERROR; > + tiling = CL_NO_TILE; > + } else if (image_type == CL_MEM_OBJECT_IMAGE2D) { > size_t min_pitch = bpp * w; > if (data && pitch == 0) > pitch = min_pitch; > @@ -560,9 +572,7 @@ _cl_mem_new_image(cl_context ctx, > if (cl_driver_get_ver(ctx->drv) != 6) > tiling = CL_TILE_Y; > depth = 1; > - } > - > - if (image_type == CL_MEM_OBJECT_IMAGE3D) { > + } else if (image_type == CL_MEM_OBJECT_IMAGE3D) { > size_t min_pitch = bpp * w; > if (data && pitch == 0) > pitch = min_pitch; > @@ -580,7 +590,9 @@ _cl_mem_new_image(cl_context ctx, > /* Pick up tiling mode (we do only linear on SNB) */ > if (cl_driver_get_ver(ctx->drv) != 6) > tiling = CL_TILE_Y; > - } > + } else > + assert(0); > + > #undef DO_IMAGE_ERROR > > /* Tiling requires to align both pitch and height */ > diff --git a/utests/compiler_copy_image.cpp b/utests/compiler_copy_image.cpp > index 04c9544..dac8d50 100644 > --- a/utests/compiler_copy_image.cpp > +++ b/utests/compiler_copy_image.cpp > @@ -1,3 +1,4 @@ > +#include <string.h> > #include "utest_helper.hpp" > > static void compiler_copy_image(void) > @@ -8,6 +9,9 @@ static void compiler_copy_image(void) > cl_image_desc desc; > cl_sampler sampler; > > + memset(&desc, 0x0, sizeof(cl_image_desc)); > + memset(&format, 0x0, sizeof(cl_image_format)); > + > // Setup kernel and images > OCL_CREATE_KERNEL("test_copy_image"); > buf_data[0] = (uint32_t*) malloc(sizeof(uint32_t) * w * h); > diff --git a/utests/compiler_copy_image1.cpp b/utests/compiler_copy_image1.cpp > index a9ef3f4..fe52dbf 100644 > --- a/utests/compiler_copy_image1.cpp > +++ b/utests/compiler_copy_image1.cpp > @@ -1,3 +1,4 @@ > +#include <string.h> > #include "utest_helper.hpp" > > static void compiler_copy_image1(void) > @@ -8,6 +9,9 @@ static void compiler_copy_image1(void) > cl_image_desc desc; > cl_sampler sampler; > > + memset(&desc, 0x0, sizeof(cl_image_desc)); > + memset(&format, 0x0, sizeof(cl_image_format)); > + > // Setup kernel and images > OCL_CREATE_KERNEL("test_copy_image1"); > buf_data[0] = (uint32_t*) malloc(sizeof(uint32_t) * w * h); > diff --git a/utests/compiler_copy_image_3d.cpp > b/utests/compiler_copy_image_3d.cpp > index 3f14f91..4fddc0e 100644 > --- a/utests/compiler_copy_image_3d.cpp > +++ b/utests/compiler_copy_image_3d.cpp > @@ -10,6 +10,9 @@ static void compiler_copy_image_3d(void) > cl_image_desc desc; > cl_sampler sampler; > > + memset(&desc, 0x0, sizeof(cl_image_desc)); > + memset(&format, 0x0, sizeof(cl_image_format)); > + > // Setup kernel and images > OCL_CREATE_KERNEL("test_copy_image_3d"); > buf_data[0] = (uint32_t*) malloc(sizeof(uint32_t) * w * h * depth); > diff --git a/utests/compiler_fill_image.cpp b/utests/compiler_fill_image.cpp > index c9242b2..5a38b8c 100644 > --- a/utests/compiler_fill_image.cpp > +++ b/utests/compiler_fill_image.cpp > @@ -1,3 +1,4 @@ > +#include <string.h> > #include "utest_helper.hpp" > > static void compiler_fill_image(void) > @@ -8,6 +9,9 @@ static void compiler_fill_image(void) > cl_image_format format; > cl_image_desc desc; > > + memset(&desc, 0x0, sizeof(cl_image_desc)); > + memset(&format, 0x0, sizeof(cl_image_format)); > + > format.image_channel_order = CL_RGBA; > format.image_channel_data_type = CL_UNSIGNED_INT8; > desc.image_type = CL_MEM_OBJECT_IMAGE2D; > diff --git a/utests/compiler_fill_image0.cpp b/utests/compiler_fill_image0.cpp > index 7c8f40e..e6e0b1d 100644 > --- a/utests/compiler_fill_image0.cpp > +++ b/utests/compiler_fill_image0.cpp > @@ -1,3 +1,4 @@ > +#include <string.h> > #include "utest_helper.hpp" > > static void compiler_fill_image0(void) > @@ -7,6 +8,9 @@ static void compiler_fill_image0(void) > cl_image_format format; > cl_image_desc desc; > > + memset(&desc, 0x0, sizeof(cl_image_desc)); > + memset(&format, 0x0, sizeof(cl_image_format)); > + > format.image_channel_order = CL_RGBA; > format.image_channel_data_type = CL_UNSIGNED_INT8; > desc.image_type = CL_MEM_OBJECT_IMAGE2D; _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/beignet