C Specification

The cl_image_desc image descriptor structure describes the image type and dimensions of an image or image array when creating an image using clCreateImage or clCreateImageWithProperties, and is defined as:

// Provided by CL_VERSION_1_2
typedef struct cl_image_desc {
    cl_mem_object_type    image_type;
    size_t                image_width;
    size_t                image_height;
    size_t                image_depth;
    size_t                image_array_size;
    size_t                image_row_pitch;
    size_t                image_slice_pitch;
    cl_uint               num_mip_levels;
    cl_uint               num_samples;
    union {
        cl_mem buffer;
        cl_mem mem_object;
    };
} cl_image_desc;

Members

  • image_type describes the image type and must be either CL_MEM_OBJECT_IMAGE1D, CL_MEM_OBJECT_IMAGE1D_BUFFER, CL_MEM_OBJECT_IMAGE1D_ARRAY, CL_MEM_OBJECT_IMAGE2D, CL_MEM_OBJECT_IMAGE2D_ARRAY, or CL_MEM_OBJECT_IMAGE3D.

  • image_width is the width of the image in pixels. For a 1D image, 1D image array, 2D image, or 2D image array, the image width must be greater than or equal to one and less than or equal to the value returned for CL_DEVICE_IMAGE2D_MAX_WIDTH for all devices in the context. For a 3D image, the image width must be greater than or equal to one and less than or equal to the value returned for CL_DEVICE_IMAGE3D_MAX_WIDTH for all devices in the context. For a 1D image buffer, the image width must be greater than or equal to one and less than or equal to the value returned for CL_DEVICE_IMAGE_MAX_BUFFER_SIZE for all devices in the context.

  • image_height is the height of the image in pixels. It is only used if the image is a 2D image, 2D image array, or 3D image. For a 2D image or 2D image array, the image height must greater than or equal to one and less than or equal to the value returned for CL_DEVICE_IMAGE2D_MAX_HEIGHT for all devices in the context. For a 3D image, the image height must be greater than or equal to one and less than or equal to the value returned for CL_DEVICE_IMAGE3D_MAX_HEIGHT for all devices in the context.

  • image_depth is the depth of the image in pixels. It is only used if the image is a 3D image. For a 3D image, the image depth must be greater than or equal to one and less than or equal to the value returned for CL_DEVICE_IMAGE3D_MAX_DEPTH for all devices in the context.

  • image_array_size [1] is the number of images in the image array. It is only used if the image is a 1D image array or 2D image array. For a 1D image array or 2D image array, the image array size must be greater than or equal to one and less than or equal to the value returned for CL_DEVICE_IMAGE_MAX_ARRAY_SIZE for all devices in the context.

  • image_row_pitch is the scan-line pitch in bytes. The image_row_pitch must be zero if host_ptr is NULL, the image is not an image created from an external memory handle, and the image is not a 2D image created from a buffer.
    If image_row_pitch is zero and host_ptr is not NULL, then the image row pitch is calculated as image_width times the size of an image element in bytes.
    If image_row_pitch is zero and the image is created from an external memory handle, then the image row pitch is implementation-defined.
    If image_row_pitch is non-zero, then it must be greater than or equal to the image_width times the size of an image element in bytes, and must be a multiple of the size of an image element in bytes.
    For an image created from a buffer, the image_row_pitch must also:

    • be a multiple of the CL_IMAGE_REQUIREMENTS_ROW_PITCH_ALIGNMENT_EXT value for the image_format, image_type, and flags used to create the image, if the cl_ext_image_requirements_info extension is supported, or

    • be a multiple of the maximum of the CL_DEVICE_IMAGE_PITCH_ALIGNMENT value for all devices in the context that support images, otherwise.

  • image_slice_pitch is the size in bytes of each 2D slice in a 3D image, or the size in bytes of each image in a 1D or 2D image array. The image_slice_pitch must be zero if host_ptr is NULL and the image is not an image created from an external memory handle, If image_slice_pitch is zero and host_ptr is not NULL then the image slice pitch is calculated as the image row pitch × image_height for a 2D image array or a 3D image, and as the image row pitch for a 1D image array. If image_slice_pitch is zero and the image is created from an external memory handle, then the image slice pitch is implementation-defined. The image slice pitch must be ≥ the image row pitch × image_height for a 2D image array or a 3D image, must be ≥ the image row pitch for a 1D image array, and must be a multiple of the image row pitch. For an image created from a buffer, the image slice pitch must be a multiple of the CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT value for the image_format, image_type and flags used to create the image, if the cl_ext_image_from_buffer extension is supported.

  • num_mip_levels must be 0, indicating that the image has a single mipmap level, unless the cl_khr_mipmap_image extension is supported. When the cl_khr_mipmap_image extension is supported, num_mip_levels may additionally specify the total number of mipmap levels in the image, including the base level [2].

  • num_samples must be 0.

  • mem_object may refer to a valid buffer or image memory object. mem_object can be a buffer memory object if image_type is CL_MEM_OBJECT_IMAGE1D_BUFFER or CL_MEM_OBJECT_IMAGE2D , or any other image_type if the cl_ext_image_from_buffer extension is supported. [3] mem_object can be an image object if image_type is CL_MEM_OBJECT_IMAGE2D [4]. Otherwise it must be NULL. The image pixels are taken from the memory objects data store. When the contents of the specified memory objects data store are modified, those changes are reflected in the contents of the image object and vice-versa at corresponding synchronization points.

Description

For a 1D image buffer created from a buffer object, the image_width × size of element in bytes must be ≤ size of the buffer object. The image data in the buffer object is stored as a single scanline which is a linear sequence of adjacent elements.

For a 1D image created from a buffer object, the image_width × size of element in bytes must be ≤ size of the buffer object. The image data in the buffer object is stored as a single scanline which is a linear sequence of adjacent elements.

For a 1D image array created from a buffer object, the image_slice_pitch × image_array_size must be ≤ size of the buffer object specified by mem_object. The image data in the buffer object is stored as a linear sequence of adjacent 1D slices. Each slice is a single scanline padded to image_slice_pitch bytes. Each scanline is a linear sequence of image elements.

For a 2D image created from a buffer object, the image_row_pitch × image_height must be ≤ size of the buffer object specified by mem_object. The image data in the buffer object is stored as a linear sequence of adjacent scanlines. Each scanline is a linear sequence of image elements padded to image_row_pitch bytes.

For a 2D image array created from a buffer object, the image_slice_pitch × image_array_size must be ≤ size of the buffer object specified by mem_object. The image data in the buffer object is stored as a linear sequence of adjacent 2D slices. Each slice is a linear sequence of adjacent scanlines padded to image_slice_pitch bytes. Each scanline is a linear sequence of image elements padded to image_row_pitch bytes.

For a 3D image created from a buffer object, the image_slice_pitch × image_depth must be ≤ size of the buffer object specified by mem_object. The image data in the buffer object is stored as a linear sequence of adjacent 2D slices padded to image_slice_pitch bytes. Each slice is a linear sequence of adjacent scanlines. Each scanline is a linear sequence of image elements padded to image_row_pitch bytes.

For an image object created from another image object, the values specified in the image descriptor except for mem_object must match the image descriptor information associated with mem_object.

Image elements are stored according to their image format as described in Image Format Descriptor.

If the buffer object specified by mem_object was created with CL_MEM_USE_HOST_PTR, the host_ptr specified to clCreateBuffer or clCreateBufferWithProperties must

  • Be aligned to the CL_IMAGE_REQUIREMENTS_BASE_ADDRESS_ALIGNMENT_EXT value for the returned for parameters compatible with those used to create the image, if the cl_ext_image_requirements_info extension is supported, or

  • Be aligned to the maximum of the CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT value for all devices in the context associated with the buffer specified by mem_object that support images, otherwise.

Creating a 2D image object from another 2D image object creates a new 2D image object that shares the image data store with mem_object but views the pixels in the image with a different image channel order. Restrictions are:

  • All of the values specified in image_desc must match the image descriptor information associated with mem_object, except for mem_object.

  • The image channel data type specified in image_format must match the image channel data type associated with mem_object.

  • The image channel order specified in image_format must be compatible with the image channel order associated with mem_object, as described in the Compatible Image Channel Orders table.

The image channel order compatibility constraint allows creation of 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 as linear RGB or sRGB values.
Table 1. Compatible Image Channel Orders
Image Channel Order in image_format: Image Channel Order associated with mem_object:

CL_sBGRA

CL_BGRA

CL_BGRA

CL_sBGRA

CL_sRGBA

CL_RGBA

CL_RGBA

CL_sRGBA

CL_sRGB

CL_RGB

CL_RGB

CL_sRGB

CL_sRGBx

CL_RGBx

CL_RGBx

CL_sRGBx

CL_DEPTH

CL_R

Concurrent reading from, writing to and copying between both a buffer object and buffer or image object associated with the buffer object is undefined. Only reading from both a buffer object and buffer or image object associated with the buffer object is defined.

Writing to an image created from a buffer and then reading from this buffer in a kernel even if appropriate synchronization operations (such as a barrier) are performed between the writes and reads is undefined. Similarly, writing to the buffer and reading from the image created from this buffer with appropriate synchronization between the writes and reads is undefined.

See Also

Document Notes

For more information, see the OpenCL Specification

This page is extracted from the OpenCL Specification. Fixes and changes should be made to the Specification, not directly.

Copyright 2014-2025 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0


1. Note that reading and writing 2D image arrays from a kernel with image_array_size equal to one may perform worse than 2D images.
2. Therefore, specifying num_mip_levels equal to either 0 or 1 creates an image with a single mipmap level.
3. To create an image from a buffer object that shares the data store between the image and buffer object.
4. To create an image object from another image object that share the data store between these image objects.