Mali OpenCL SDK v1.1.0
 All Classes Files Functions Variables Macros Pages
Image Objects

An overview of OpenCL image objects including sample code.

Introduction

Textures (images) are a huge part of modern graphics applications. As such, graphics hardware has developed to allow high perfomance access and operations on textures.

To make use of this specialised hardware, OpenCL includes an optional image data type. These 'images objects' are supported on all Mali-T600 series GPUs.

Images represent large grids of data which can be processed in parallel. As such, image data and image operations are usually a good fit for accelerating in OpenCL.

Images data can be stored/manipulated by OpenCL in two ways; buffers and images.

Memory Buffers

Memory buffers are just plain arrays of data.

Because they are suitable for all forms of data (e.g. images, grids, linear arrays, etc.), various image operations are difficult:

  • To access image data at given coordinates, you must calculate the correct offset into the data.
  • You must use exact coordinates to access you data, or implement you own access methods for normalised (or other) coordinates.
  • You must also handle the case where the coordinates are outside of the image area.
  • Any algorithms or optimisations are usually fixed to the image format being used e.g. RGB888 (if you then change the image format, the algorithm/optimisations must be changed).
  • Image filtering (e.g. bilinear filtering) must be done manually.

Image Objects

Image objects are a specialist memory type which makes it easier to work with image data. Image objects:

  • support access by coordinates directly
  • support normalized coordinates
  • handle out-of-range coordinates (you can choose from various handling schemes)
  • provide an abstract image format (accessing RGB888 images is the same as accessing RGB565 images)
  • support bilinear filtering (accelerated by hardware)

Recommendations

Whether to use image objects or not depends on the application. You should take the following considerations into account:

  • Using image objects for image data simplifies the code needed to access and manipulate the data (see Image Objects).
  • When using image objects, only 1 pixel can be processed per cycle. Using buffers, if your image format is less than 32-bits per channel you can process multiple pixels per cycle.

    For example, if the image format is RGBA8888 (each pixel is 32-bits), using buffers, you can vectorize the algorithm to operate on 4 pixels at once (32-bits * 4 pixels = 128-bits, the recommended vector width for Mali-T600 series GPUs.) But with image objects the speed is fixed at one pixel per cycle.

    If the format is 32-bits per channel or greater, this advantage of image objects is lost because only one pixel can be processed per cycle using either method. For example, if the image format is RGBA32 (each pixel is 128-bits), only 1 pixel can be processed per cycle because 1 pixel fills the recommended vector width.

    For more information about vectorization, see Vectorizing your OpenCL code.

  • In more complex cases, maximum performance comes from balancing load across the system. On Mali-T600 series GPUS, image objects use the Texture pipeline which is seperate from the Load/Store and Arithmetic pipelines. As such, it might be beneficial to use both image objects and buffers in order to make maximum use of the system.

    For example, loading input images with image objects and then loading the data to alter the images in memory buffers (e.g. a convolution filter).

Sample Code

  • Image Scaling

    How to resize an image using OpenCL image objects.