Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compile times of the most expensive source modules #1806

Merged
merged 1 commit into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion src/include/OpenImageIO/imagebufalgo_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ inline TypeDesc type_merge (TypeDesc a, TypeDesc b, TypeDesc c)
}

// Macro to call a type-specialzed version func<Rtype,Atype>(R,A,...) for
// the most common types, will auto-convert the rest to float.
// the most common types. It will auto-convert other cases to/from float.
#define OIIO_DISPATCH_COMMON_TYPES2(ret,name,func,Rtype,Atype,R,A,...) \
switch (Rtype.basetype) { \
case TypeDesc::FLOAT : \
Expand Down Expand Up @@ -385,6 +385,65 @@ inline TypeDesc type_merge (TypeDesc a, TypeDesc b, TypeDesc c)
}


// Macro to call a type-specialzed version func<Rtype,Atype>(R,A,...) for
// the most common types. It will auto-convert other cases to/from float.
// This is the case for when we don't actually write to the read-only R image.
#define OIIO_DISPATCH_COMMON_TYPES2_CONST(ret,name,func,Rtype,Atype,R,A,...) \
switch (Rtype.basetype) { \
case TypeDesc::FLOAT : \
OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,float,Atype,R,A,__VA_ARGS__); \
break; \
case TypeDesc::UINT8 : \
OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,unsigned char,Atype,R,A,__VA_ARGS__); \
break; \
case TypeDesc::HALF : \
OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,half,Atype,R,A,__VA_ARGS__); \
break; \
case TypeDesc::UINT16: \
OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,unsigned short,Atype,R,A,__VA_ARGS__); \
break; \
default: { \
/* other types: punt and convert to float, then copy back */ \
ImageBuf Rtmp; \
if ((R).initialized()) \
Rtmp.copy (R, TypeDesc::FLOAT); \
OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,float,Atype,Rtmp,A,__VA_ARGS__); \
} }


// Macro to call a type-specialzed version func<Rtype,Atype>(R,A,...) for
// the most common types, and even for uncommon types when src and dst types
// are identical. It will auto-convert other cases to float.
#define OIIO_DISPATCH_COMMON_OR_SAME_TYPES2(ret,name,func,Rtype,Atype,R,A,...) \
if (Rtype == Atype) { \
switch (Atype.basetype) { \
case TypeDesc::FLOAT : \
ret = func<float,float> (R, A, __VA_ARGS__); break; \
case TypeDesc::UINT8 : \
ret = func<unsigned char,unsigned char> (R, A, __VA_ARGS__); break; \
case TypeDesc::HALF : \
ret = func<half,half> (R, A, __VA_ARGS__); break; \
case TypeDesc::UINT16: \
ret = func<unsigned short,unsigned short> (R, A, __VA_ARGS__); break; \
case TypeDesc::INT8 : \
ret = func<char,char> (R, A, __VA_ARGS__); break; \
case TypeDesc::INT16 : \
ret = func<short,short> (R, A, __VA_ARGS__); break; \
case TypeDesc::UINT : \
ret = func<unsigned int,unsigned int> (R, A, __VA_ARGS__); break; \
case TypeDesc::INT : \
ret = func<int,int> (R, A, __VA_ARGS__); break; \
case TypeDesc::DOUBLE : \
ret = func<double,double> (R, A, __VA_ARGS__); break; \
default: \
(R).error ("%s: Unsupported pixel data format '%s'", name, Atype); \
ret = false; \
} \
} else { \
OIIO_DISPATCH_COMMON_TYPES2(ret,name,func,Rtype,Atype,R,A,__VA_ARGS__); \
}


// Helper, do not call from the outside world.
#define OIIO_DISPATCH_COMMON_TYPES3_HELP2(ret,name,func,Rtype,Atype,Btype,R,A,B,...) \
switch (Rtype.basetype) { \
Expand Down
3 changes: 3 additions & 0 deletions src/libOpenImageIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ list (APPEND libOpenImageIO_srcs
imageoutput.cpp iptc.cpp xmp.cpp
color_ocio.cpp
imagebufalgo.cpp
imagebufalgo_channels.cpp
imagebufalgo_compare.cpp
imagebufalgo_copy.cpp
imagebufalgo_deep.cpp
imagebufalgo_draw.cpp
imagebufalgo_mathops.cpp
imagebufalgo_orient.cpp
imagebufalgo_pixelmath.cpp
imagebufalgo_xform.cpp
imagebufalgo_yee.cpp imagebufalgo_opencv.cpp
Expand Down
9 changes: 5 additions & 4 deletions src/libOpenImageIO/imagebuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ ImageBuf::copy_pixels (const ImageBuf &src)
ImageBufAlgo::zero (*this);

bool ok;
OIIO_DISPATCH_TYPES2 (ok, "copy_pixels", copy_pixels_impl,
OIIO_DISPATCH_COMMON_TYPES2 (ok, "copy_pixels", copy_pixels_impl,
spec().format, src.spec().format, *this, src, roi);
return ok;
}
Expand Down Expand Up @@ -1701,7 +1701,8 @@ ImageBuf::setpixel (int i, const float *pixel, int maxchannels)

template<typename D, typename S>
static bool
get_pixels_ (const ImageBuf &buf, ROI whole_roi, ROI roi, void *r_,
get_pixels_ (const ImageBuf &buf, const ImageBuf &dummyarg,
ROI whole_roi, ROI roi, void *r_,
stride_t xstride, stride_t ystride, stride_t zstride,
int nthreads=0)
{
Expand Down Expand Up @@ -1733,8 +1734,8 @@ ImageBuf::get_pixels (ROI roi, TypeDesc format, void *result,
ImageSpec::auto_stride (xstride, ystride, zstride, format.size(),
roi.nchannels(), roi.width(), roi.height());
bool ok;
OIIO_DISPATCH_TYPES2 (ok, "get_pixels", get_pixels_,
format, spec().format, *this, roi, roi,
OIIO_DISPATCH_COMMON_TYPES2_CONST (ok, "get_pixels", get_pixels_,
format, spec().format, *this, *this, roi, roi,
result, xstride, ystride, zstride, threads());
return ok;
}
Expand Down
Loading