From 9b89071c9cdd2a341ba16db44cd4625303fb6e2f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 5 May 2016 23:33:40 +0200 Subject: Multi-thread generated image creation Gives about 2x speedup on laptop when creating new hires generated image, regardless of it's type (color, color grid, uv grid). --- source/blender/imbuf/IMB_imbuf.h | 3 ++ source/blender/imbuf/intern/divers.c | 70 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) (limited to 'source/blender/imbuf') diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 2c97d9bc21f..383a5f19c4a 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -439,6 +439,9 @@ void IMB_buffer_float_from_byte(float *rect_to, const unsigned char *rect_from, void IMB_buffer_float_from_float(float *rect_to, const float *rect_from, int channels_from, int profile_to, int profile_from, bool predivide, int width, int height, int stride_to, int stride_from); +void IMB_buffer_float_from_float_threaded(float *rect_to, const float *rect_from, + int channels_from, int profile_to, int profile_from, bool predivide, + int width, int height, int stride_to, int stride_from); void IMB_buffer_float_from_float_mask(float *rect_to, const float *rect_from, int channels_from, int width, int height, int stride_to, int stride_from, char *mask); void IMB_buffer_byte_from_byte(unsigned char *rect_to, const unsigned char *rect_from, diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c index 3aabf7e18cc..62fd623ecfa 100644 --- a/source/blender/imbuf/intern/divers.c +++ b/source/blender/imbuf/intern/divers.c @@ -532,6 +532,76 @@ void IMB_buffer_float_from_float(float *rect_to, const float *rect_from, } } +typedef struct FloatToFloatThreadData { + float *rect_to; + const float *rect_from; + int channels_from; + int profile_to; + int profile_from; + bool predivide; + int width; + int stride_to; + int stride_from; +} FloatToFloatThreadData; + +static void imb_buffer_float_from_float_thread_do(void *data_v, + int start_scanline, + int num_scanlines) +{ + FloatToFloatThreadData *data = (FloatToFloatThreadData *)data_v; + size_t offset_from = ((size_t)start_scanline) * data->stride_from * data->channels_from; + size_t offset_to = ((size_t)start_scanline) * data->stride_to * data->channels_from; + IMB_buffer_float_from_float(data->rect_to + offset_to, + data->rect_from + offset_from, + data->channels_from, + data->profile_to, + data->profile_from, + data->predivide, + data->width, + num_scanlines, + data->stride_to, + data->stride_from); +} + +void IMB_buffer_float_from_float_threaded(float *rect_to, + const float *rect_from, + int channels_from, + int profile_to, + int profile_from, + bool predivide, + int width, + int height, + int stride_to, + int stride_from) +{ + if (((size_t)width) * height < 64 * 64) { + IMB_buffer_float_from_float(rect_to, + rect_from, + channels_from, + profile_to, + profile_from, + predivide, + width, + height, + stride_to, + stride_from); + } + else { + FloatToFloatThreadData data; + data.rect_to = rect_to; + data.rect_from = rect_from; + data.channels_from = channels_from; + data.profile_to = profile_to; + data.profile_from = profile_from; + data.predivide = predivide; + data.width = width; + data.stride_to = stride_to; + data.stride_from = stride_from; + IMB_processor_apply_threaded_scanlines( + height, imb_buffer_float_from_float_thread_do, &data); + } +} + /* float to float pixels, output 4-channel RGBA */ void IMB_buffer_float_from_float_mask(float *rect_to, const float *rect_from, int channels_from, int width, int height, int stride_to, int stride_from, char *mask) -- cgit v1.2.3