C Specification

The cl_image_desc image descriptor structure describes the type and dimensions of an image or image array, and is defined as:

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;
    #ifdef __GNUC__
    __extension__   /* Prevents warnings about anonymous union in -pedantic builds */
#endif
    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 2D image and image array, the image width must be a value ≥ 1 and ≤ CL_​DEVICE_​IMAGE2D_​MAX_​WIDTH. For a 3D image, the image width must be a value ≥1 and ≤ CL_​DEVICE_​IMAGE3D_​MAX_​WIDTH. For a 1D image buffer, the image width must be a value ≥1 and ≤ CL_​DEVICE_​IMAGE_​MAX_​BUFFER_​SIZE. For a 1D image and 1D image array, the image width must be a value ≥1 and ≤ CL_​DEVICE_​IMAGE2D_​MAX_​WIDTH.

  • image_height is the height of the image in pixels. This is only used if the image is a 2D or 3D image, or a 2D image array. For a 2D image or image array, the image height must be a value ≥ 1 and ≤ CL_​DEVICE_​IMAGE2D_​MAX_​HEIGHT. For a 3D image, the image height must be a value ≥ 1 and ≤ CL_​DEVICE_​IMAGE3D_​MAX_​HEIGHT.

  • image_depth is the depth of the image in pixels. This is only used if the image is a 3D image and must be a value ≥ 1 and ≤ CL_​DEVICE_​IMAGE3D_​MAX_​DEPTH.

  • image_array_size5 is the number of images in the image array. This is only used if the image is a 1D or 2D image array. The values for image_array_size, if specified, must be a value ≥ 1 and ≤ CL_​DEVICE_​IMAGE_​MAX_​ARRAY_​SIZE.

    5

    Note that reading and writing 2D image arrays from a kernel with image_array_size=1 may be lower performance than 2D images.

  • image_row_pitch is the scan-line pitch in bytes. This must be 0 if host_ptr is NULL and can be either 0 or ≥ image_width × size of element in bytes if host_ptr is not NULL. If host_ptr is not NULL and image_row_pitch = 0, image_row_pitch is calculated as image_width × size of element in bytes. If image_row_pitch is not 0, it must be a multiple of the image element size in bytes. For a 2D image created from a buffer, the pitch specified (or computed if pitch specified is 0) must be a multiple of the maximum of the CL_​DEVICE_​IMAGE_​PITCH_​ALIGNMENT value for all devices in the context associated with the buffer specified by mem_object that support images.

  • image_slice_pitch is the size in bytes of each 2D slice in the 3D image or the size in bytes of each image in a 1D or 2D image array. This must be 0 if host_ptr is NULL. If host_ptr is not NULL, image_slice_pitch can be either 0 or ≥ image_row_pitch × image_height for a 2D image array or 3D image and can be either 0 or ≥ image_row_pitch for a 1D image array. If host_ptr is not NULL and image_slice_pitch = 0, image_slice_pitch is calculated as image_row_pitch × image_height for a 2D image array or 3D image and image_row_pitch for a 1D image array. If image_slice_pitch is not 0, it must be a multiple of the image_row_pitch.

  • num_mip_levels and 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_​IMAGE2D6. mem_object can be an image object if image_type is CL_​MEM_​OBJECT_​IMAGE2D7. 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

6

To create a 2D image from a buffer object that share the data store between the image and buffer object.

7

To create an image object from another image object that share the data store between these image objects.

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 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 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 must 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.

Creating a 2D image object from another 2D image object allows users to create a new image object that shares the image data store with mem_object but views the pixels in the image with a different channel order. The restrictions are:

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

  • The image_desc used for creation of mem_object may not be equivalent to image descriptor information associated with mem_object. To ensure the values in `image_desc will match one can query mem_object for associated information using clGetImageInfo function described in Image Object Queries.

  • the channel data type specified in image_format must match the channel data type associated with mem_object. The channel order values8 supported are:

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 (c) 2014-2020 Khronos Group. This work is licensed under a Creative Commons Attribution 4.0 International License.