OpenImageIO/oiio — pull request #532 by lgritz (2013-03-04 06:46:24+00:00)
Title: maketx speedups and parallelizing format conversion

Continuing to relentlessly pound on maketx performance.

Two new optimizations:

1. In maketexture(), use specialized iterators for resize, and use the new iterator wrap modes to simplify the loop logic for resize and block copies.

2. Make multithread/parallel versions of convert_image() and convert_from_float() -- utility functions that are used when reading/writing images to copy and convert data.

These two changes, combined, speed up maketx by approximately an additional 8-25% (depending on the image size, data formats involved, and number of cores available).

Change 2, especially, goes well beyond just maketx, and can speed up any image read or write when format conversion is involved (e.g., reading a non-float32 data file into a float32 buffer, or writing a float32 buffer to a non-float32 file -- that is, most reads and writes).

Here are the dramatic results for imagespeed_test when reading a 4k x 4k, 4-channel 'half' OpenEXR file into a float buffer (for a variety of read methods that OIIO provides), on a machine with 12 cores:

before after
read_image : 30.1 Mpel/s 73.6 Mpel/s
read_scanline (1 at a time) : 6.4 Mpel/s 6.5 Mpel/s
read_scanlines (64 at a time) : 19.2 Mpel/s 32.4 Mpel/s
ImageBuf read : 24.1 Mpel/s 45.6 Mpel/s
ImageCache get_pixels : 25.2 Mpel/s 49.9 Mpel/s
ImageBuf read (autotile) : 14.4 Mpel/s 20.1 Mpel/s
ImageCache get_pixels (autotile) : 15.4 Mpel/s 22.3 Mpel/s
ImageBuf read (autotile+autoscanline) : 15.5 Mpel/s 23.4 Mpel/s
ImageCache get_pixels (autotile+autoscanline): 16.0 Mpel/s 24.9 Mpel/s

Compared to Release 1.1.3, when I started really pounding on it a couple months ago, maketx on multi-core machines is on average 2-3x faster in the current master (depending on image size, file and data formats, and how many cores are available). On a 12-core machine, maketx of a 4k x 4k 'half' 4-channel OpenEXR which was 7.3s in 1.1.3 is now only 1.3s in the current master (including this proposed patch).