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.he@linux.intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
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,
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_IMAGE1D) {
+ size_t min_pitch = bpp * w;
+ if (data && pitch == 0)
+ pitch = min_pitch;
- if (image_type == CL_MEM_OBJECT_IMAGE2D) {
+ 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;
if (cl_driver_get_ver(ctx->drv) != 6)
tiling = cl_get_default_tiling();
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;
/* Pick up tiling mode (we do only linear on SNB) */
if (cl_driver_get_ver(ctx->drv) != 6)
tiling = cl_get_default_tiling();
- }
+ } else
+ assert(0);
+
#undef DO_IMAGE_ERROR
/* Tiling requires to align both pitch and height */
+#include <string.h>
#include "utest_helper.hpp"
static void compiler_copy_image(void)
const size_t w = 512;
const size_t h = 512;
cl_image_format format;
+ 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);
format.image_channel_order = CL_RGBA;
format.image_channel_data_type = CL_UNSIGNED_INT8;
- OCL_CREATE_IMAGE2D(buf[0], CL_MEM_COPY_HOST_PTR, &format, w, h, w * sizeof(uint32_t), buf_data[0]);
-
- OCL_CREATE_IMAGE2D(buf[1], 0, &format, w, h, 0, NULL);
+ desc.image_type = CL_MEM_OBJECT_IMAGE2D;
+ desc.image_width = w;
+ desc.image_height = h;
+ desc.image_row_pitch = w * sizeof(uint32_t);
+ OCL_CREATE_IMAGE(buf[0], CL_MEM_COPY_HOST_PTR, &format, &desc, buf_data[0]);
+
+ desc.image_row_pitch = 0;
+ OCL_CREATE_IMAGE(buf[1], 0, &format, &desc, NULL);
OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_NEAREST);
free(buf_data[0]);
buf_data[0] = NULL;
+#include <string.h>
#include "utest_helper.hpp"
static void compiler_copy_image1(void)
const size_t w = 512;
const size_t h = 512;
cl_image_format format;
+ 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);
format.image_channel_order = CL_RGBA;
format.image_channel_data_type = CL_UNSIGNED_INT8;
- OCL_CREATE_IMAGE2D(buf[0], CL_MEM_COPY_HOST_PTR, &format, w, h, w * sizeof(uint32_t), buf_data[0]);
+ desc.image_type = CL_MEM_OBJECT_IMAGE2D;
+ desc.image_width = w;
+ desc.image_height = h;
+ desc.image_row_pitch = w * sizeof(uint32_t);
+ OCL_CREATE_IMAGE(buf[0], CL_MEM_COPY_HOST_PTR, &format, &desc, buf_data[0]);
OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_NEAREST);
- OCL_CREATE_IMAGE2D(buf[1], 0, &format, w, h, 0, NULL);
- OCL_CREATE_IMAGE2D(buf[2], 0, &format, w, h, 0, NULL);
- OCL_CREATE_IMAGE2D(buf[3], 0, &format, w, h, 0, NULL);
- OCL_CREATE_IMAGE2D(buf[4], 0, &format, w, h, 0, NULL);
- OCL_CREATE_IMAGE2D(buf[5], 0, &format, w, h, 0, NULL);
+ desc.image_row_pitch = 0;
+ OCL_CREATE_IMAGE(buf[1], 0, &format, &desc, NULL);
+ OCL_CREATE_IMAGE(buf[2], 0, &format, &desc, NULL);
+ OCL_CREATE_IMAGE(buf[3], 0, &format, &desc, NULL);
+ OCL_CREATE_IMAGE(buf[4], 0, &format, &desc, NULL);
+ OCL_CREATE_IMAGE(buf[5], 0, &format, &desc, NULL);
free(buf_data[0]);
buf_data[0] = NULL;
const size_t h = 512;
const size_t depth = 4;
cl_image_format format;
+ 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);
format.image_channel_order = CL_RGBA;
format.image_channel_data_type = CL_UNORM_INT8;
- OCL_CREATE_IMAGE3D(buf[0], CL_MEM_COPY_HOST_PTR, &format, w, h, depth, w*4, w*h*4, buf_data[0]);
- OCL_CREATE_IMAGE3D(buf[1], 0, &format, w, h, depth, 0, 0, NULL);
+ desc.image_type = CL_MEM_OBJECT_IMAGE3D;
+ desc.image_width = w;
+ desc.image_height = h;
+ desc.image_depth = depth;
+ desc.image_row_pitch = 0;
+ desc.image_slice_pitch = 0;
+
+ OCL_CREATE_IMAGE(buf[0], CL_MEM_COPY_HOST_PTR, &format, &desc, buf_data[0]);
+ OCL_CREATE_IMAGE(buf[1], 0, &format, &desc, NULL);
+ memset(&desc, 0, sizeof(desc));
+ desc.image_type = CL_MEM_OBJECT_IMAGE2D;
+ desc.image_width = w;
+ desc.image_height = h;
+ desc.image_depth = 1;
for(uint32_t i = 0; i < depth; i++)
- OCL_CREATE_IMAGE2D(buf[2 + i], 0, &format, w, h, 0, NULL);
+ OCL_CREATE_IMAGE(buf[2 + i], 0, &format, &desc, NULL);
+
OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_NEAREST);
free(buf_data[0]);
buf_data[0] = NULL;
+#include <string.h>
#include "utest_helper.hpp"
static void compiler_fill_image(void)
const size_t h = 512;
uint32_t color = 0x12345678;
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;
+ desc.image_width = w;
+ desc.image_height = h;
+ desc.image_row_pitch = 0;
// Setup kernel and images
OCL_CREATE_KERNEL("test_fill_image");
- OCL_CREATE_IMAGE2D(buf[0], 0, &format, w, h, 0, NULL);
+ OCL_CREATE_IMAGE(buf[0], 0, &format, &desc, NULL);
// Run the kernel
OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+#include <string.h>
#include "utest_helper.hpp"
static void compiler_fill_image0(void)
const size_t w = 512;
const size_t h = 512;
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;
+ desc.image_width = w;
+ desc.image_height = h;
+ desc.image_row_pitch = 0;
// Setup kernel and images
OCL_CREATE_KERNEL("test_fill_image0");
- OCL_CREATE_IMAGE2D(buf[0], 0, &format, w, h, 0, NULL);
+ OCL_CREATE_IMAGE(buf[0], 0, &format, &desc, NULL);
// Run the kernel
OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);