Error when create image with clCreateImage2D

I have a simple problem with clCreateImage2D.

When I create the memory object with CL_MEM_READ_ONLY creation is a success.
But when I create the memory object with CL_MEM_WRITE_ONLY I got an error code

Why ?

cl_image_format image_format;
image_format.image_channel_order = CL_BGRA;
image_format.image_channel_data_type = CL_UNSIGNED_INT8;

cl_mem image1;
image1 = clCreateImage2D(context, CL_MEM_READ_ONLY, &image_format, 512, 512, 512*4, NULL, &err);

cl_mem image2;
image2 = clCreateImage2D(context, CL_MEM_WRITE_ONLY, &image_format, 512, 512, 512*4, NULL, &err);

This will probably not help, but it’s possible that the OpenCL implementation you are using only supports BGRA8888 formats for reading, not for writing. What happens if you pass CL_MEM_READ_WRITE as flags?

Same problem, but I have found a solution.

If I don’t specify the Image row pitch (0 instead of the value), the function is correctly executed
with Read Only and Write Only.

If think it’s a bug in the Apple OpenCL implementation.

Thanks for your help.

When host_ptr is NULL, image_row_pitch must be zero (here it is 512*4), but no error code is specified for this case.

Ah! Thanks, ajs2, you are completely right :smiley: