Creates a 1D image, 1D image buffer, 1D image array, 2D image, 2D image array or 3D image object.
cl_mem clCreateImage(cl_context context,
cl_mem_flags flags,
const cl_image_format *image_format,
const cl_image_desc *image_desc,
void *host_ptr,
cl_int *errcode_ret)context-
A valid OpenCL context on which the image object is to be created.
flags-
A bit-field that is used to specify allocation and usage information about the image memory object being created and is described in the table below.
For all image types except
CL_MEM_OBJECT_IMAGE1D_BUFFER, if value specified forflagsis 0, the default is used which isCL_MEM_READ_WRITE.For
CL_MEM_OBJECT_IMAGE1D_BUFFERimage type, or an image created from another memory object (image or buffer), if theCL_MEM_READ_WRITE,CL_MEM_READ_ONLYorCL_MEM_WRITE_ONLYvalues are not specified inflags, they are inherited from the corresponding memory access qualifers associated withmem_object. TheCL_MEM_USE_HOST_PTR,CL_MEM_ALLOC_HOST_PTRandCL_MEM_COPY_HOST_PTRvalues cannot be specified inflagsbut are inherited from the corresponding memory access qualifiers associated withmem_object. IfCL_MEM_COPY_HOST_PTRis specified in the memory access qualifier values associated withmem_objectit does not imply any additional copies when the image is created frommem_object. If theCL_MEM_HOST_WRITE_ONLY,CL_MEM_HOST_READ_ONLYorCL_MEM_HOST_NO_ACCESSvalues are not specified inflags, they are inherited from the corresponding memory access qualifiers associated withmem_object. image_format-
A pointer to a structure that describes format properties of the image to be allocated. See
cl_image_formatfor a detailed description of the image format descriptor. image_desc-
A pointer to a structure that describes type and dimensions of the image to be allocated. See
cl_image_descfor more information. host_ptr-
A pointer to the image data that may already be allocated by the application. Refer to table below for a description of how large the buffer that
host_ptrpoints to must be.Image Type Size of buffer that host_ptrpoints toCL_MEM_OBJECT_IMAGE1D≥ image_row_pitchCL_MEM_OBJECT_IMAGE1D_BUFFER≥ image_row_pitchCL_MEM_OBJECT_IMAGE2D≥ image_row_pitch * image_heightCL_MEM_OBJECT_IMAGE3D≥ image_slice_pitch * image_depthCL_MEM_OBJECT_IMAGE1D_ARRAY≥ image_slice_pitch * image_array_sizeCL_MEM_OBJECT_IMAGE2D_ARRAY≥ image_slice_pitch * image_array_sizeclCreateImagecan be used to create a 2D image from a buffer object or a 2D image from another 2D image object.A 2D image can be created from a buffer by specifying a buffer object in the
image_desc→mem_objectpassed toclCreateImageforimage_desc→image_type=CL_MEM_OBJECT_IMAGE2D. Ifimage_desc→mem_objectis created withCL_MEM_USE_HOST_PTR, thehost_ptrspecified toclCreateBuffermust be aligned to the minimum of theCL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENTvalue for all devices in the context associated withimage_desc→mem_objectand that support images.A 2D image can be created from another 2D image object by specifying an image object in the
image_desc→mem_objectpassed toclCreateImageforimage_desc→image_type=CL_MEM_OBJECT_IMAGE2D. This allows users to create a new image object that shares the image data store withmem_objectbut views the pixels in the image with a different channel order and channel type. The restrictions are:(1) all the values specified in
image_descexcept formem_objectmust match the image descriptor information associated withmem_object.(2) The
image_descused for creation ofmem_objectmay not be equivalent to image descriptor information associated withmem_object. To ensure the values inimage_descwill match one can querymem_objectfor associated information usingclGetImageInfofunction described in section 5.3.7.(3) the channel data type specified in
image_formatmust match the channel data type associated withmem_object. The channel order values supported are:image_channel_order specified in image_format image channel order of mem_object CL_sBGRACL_BGRACL_BGRACL_sBGRACL_sRGBACL_RGBACL_RGBACL_sRGBACL_sRGBCL_RGBCL_RGBCL_sRGBCL_sRGBxCL_RGBxCL_RGBxCL_sRGBxCL_DEPTHCL_R(4) The channel order specified must have the same number of channels as the channel order of
mem_object.This allows developers to create a sRGB view of the image from a linear RGB view or vice-versa i.e. the pixels stored in the image can be accessed aslinear RGB or sRGB values.
For a 3D image or 2D image array, the image data specified by
host_ptris stored as a linear sequence of adjacent 2D image slices or 2D images respectively. Each 2D image is a linear sequence of adjacent scanlines. Each scanline is a linear sequence of image elements.For a 2D image, the image data specified by
host_ptris stored as a linear sequence of adjacent scanlines. Each scanline is a linear sequence of image elements.For a 1D image array, the image data specified by
host_ptris stored as a linear sequence of adjacent 1D images respectively. Each 1D image or 1D image buffer is a single scanline which is a linear sequence of adjacent elements. errcode_ret-
Will return an appropriate error code. If
errcode_retis NULL, no error code is returned.
If the cl_khr_mipmap_image extension is enabled, then a mip-mapped 1D image, 1D image array, 2D image, 2D image array or 3D image is created by specifying num_mip_levels to be a value > 1 in cl_image_desc passed to clCreateImage.
The dimensions of a mip-mapped image can be a power of two or a non-power of two.
Each successively smaller mipmap level is half the size of the previous level.
If this half value is a fractional value, it is rounded down to the nearest integer.
The following restrictions apply when mip-mapped images are created with clCreateImage.
-
CL_MEM_USE_HOST_PTRorCL_MEM_COPY_HOST_PTRcannot be specified if a mipmapped image is created. -
The
host_ptrargument toclCreateImagemust be a NULL value. -
Mip-mapped images cannot be created for
CL_MEM_OBJECT_IMAGE1D_BUFFERimages, depth images or multi-sampled (i.e. msaa) images.
clCreateImage returns a valid non-zero image object and errcode_ret is set to CL_SUCCESS if the image object is created successfully.
Otherwise, it returns a NULL value with one of the following error values returned in errcode_ret:
-
CL_INVALID_CONTEXTifcontextis not a valid context. -
CL_INVALID_VALUEif values specified inflagsare not valid. -
CL_INVALID_IMAGE_FORMAT_DESCRIPTORif values specified inimage_formatare not valid or ifimage_formatis NULL. -
CL_INVALID_IMAGE_FORMAT_DESCRIPTORif a 2D image is created from a buffer and the row pitch and base address alignment does not follow the rules described for creating a 2D image from a buffer. -
CL_INVALID_IMAGE_FORMAT_DESCRIPTORif a 2D image is created from a 2D image object and the rules described above are not followed. -
CL_INVALID_IMAGE_DESCRIPTORif values specified inimage_descare not valid or ifimage_descis NULL. -
CL_INVALID_IMAGE_SIZEif image dimensions specified inimage_descexceed the maximum image dimensions described in the table of allowed values forparam_nameforclGetDeviceInfofor all devices incontext. -
CL_INVALID_HOST_PTRifhost_ptris NULL andCL_MEM_USE_HOST_PTRorCL_MEM_COPY_HOST_PTRare set inflagsor ifhost_ptris not NULL butCL_MEM_COPY_HOST_PTRorCL_MEM_USE_HOST_PTRare not set inflags. -
CL_INVALID_VALUEif an image buffer is being created and the buffer object was created withCL_MEM_WRITE_ONLYandflagsspecifiesCL_MEM_READ_WRITEorCL_MEM_READ_ONLY, or if the buffer object was created withCL_MEM_READ_ONLYandflagsspecifiesCL_MEM_READ_WRITEorCL_MEM_WRITE_ONLY, or ifflagsspecifiesCL_MEM_USE_HOST_PTRorCL_MEM_ALLOC_HOST_PTRorCL_MEM_COPY_HOST_PTR. -
CL_INVALID_VALUEif an image buffer is being created or an image is being created from another memory object (image or buffer) and themem_objectobject was created withCL_MEM_HOST_WRITE_ONLYandflagsspecifiesCL_MEM_HOST_READ_ONLY, or ifmem_objectwas created withCL_MEM_HOST_READ_ONLYandflagsspecifiesCL_MEM_HOST_WRITE_ONLY, or ifmem_objectwas created withCL_MEM_HOST_NO_ACCESSandflagsspecifiesCL_MEM_HOST_READ_ONLYorCL_MEM_HOST_WRITE_ONLY. -
CL_IMAGE_FORMAT_NOT_SUPPORTEDif theimage_formatis not supported. -
CL_MEM_OBJECT_ALLOCATION_FAILUREif there is a failure to allocate memory for image object. -
CL_INVALID_OPERATIONif there are no devices incontextthat support images (i.e.CL_DEVICE_IMAGE_SUPPORT(specified in the table of OpenCL Device Queries forclGetDeviceInfo) isCL_FALSE). -
CL_OUT_OF_RESOURCESif there is a failure to allocate resources required by the OpenCL implementation on the device. -
CL_OUT_OF_HOST_MEMORYif there is a failure to allocate resources required by the OpenCL implementation on the host.