From c795d31a1faf15853a1e8315bb60f73f9a534df5 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 5 May 2016 13:15:51 +0200 Subject: Simplify scanline threaded processor used by GPU_verify_image Just avoid some unneeded initialization functions when the threaded processor is simple enough to only depend on current chunk start scanline and number of scanlines. --- source/blender/imbuf/IMB_imbuf.h | 8 ++++ source/blender/imbuf/intern/imageprocess.c | 61 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) (limited to 'source/blender/imbuf') diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 043f1602a76..bd19271ff65 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -580,6 +580,14 @@ void IMB_processor_apply_threaded(int buffer_lines, int handle_size, void *init_ void *customdata), void *(do_thread) (void *)); +typedef void (*ScanlineThreadFunc) (void *custom_data, + int start_scanline, + int num_scanlines); +void IMB_processor_apply_threaded_scanlines(int buffer_lines, + ScanlineThreadFunc do_thread, + void *custom_data); + + /* ffmpeg */ void IMB_ffmpeg_init(void); const char *IMB_ffmpeg_last_error(void); diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c index 9e4bb957f66..ebcd6e088f4 100644 --- a/source/blender/imbuf/intern/imageprocess.c +++ b/source/blender/imbuf/intern/imageprocess.c @@ -374,6 +374,67 @@ void IMB_processor_apply_threaded(int buffer_lines, int handle_size, void *init_ BLI_task_pool_free(task_pool); } +typedef struct ScanlineGlobalData { + void *custom_data; + ScanlineThreadFunc do_thread; +} ScanlineGlobalData; + +typedef struct ScanlineTask { + int start_scanline; + int num_scanlines; +} ScanlineTask; + +static void processor_apply_scanline_func(TaskPool * __restrict pool, + void *taskdata, + int UNUSED(threadid)) +{ + ScanlineTask *task = (ScanlineTask *)taskdata; + ScanlineGlobalData *data = (ScanlineGlobalData*)BLI_task_pool_userdata(pool); + data->do_thread(data->custom_data, + task->start_scanline, + task->num_scanlines); +} + +void IMB_processor_apply_threaded_scanlines(int buffer_lines, + ScanlineThreadFunc do_thread, + void *custom_data) +{ + ScanlineGlobalData data; + data.custom_data = custom_data; + data.do_thread = do_thread; + const int lines_per_task = 64; + const int total_tasks = (buffer_lines + lines_per_task - 1) / lines_per_task; + TaskScheduler *task_scheduler = BLI_task_scheduler_get(); + TaskPool *task_pool = BLI_task_pool_create(task_scheduler, &data); + ScanlineTask *handles = MEM_mallocN(sizeof(ScanlineTask) * total_tasks, + "processor apply threaded handles"); + for (int i = 0, start_line = 0; i < total_tasks; i++) { + ScanlineTask *handle = &handles[i]; + handle->start_scanline = start_line; + if (i < total_tasks - 1) { + handle->num_scanlines = lines_per_task; + } + else { + handle->num_scanlines = buffer_lines - start_line; + } + + BLI_task_pool_push(task_pool, + processor_apply_scanline_func, + handle, + false, + TASK_PRIORITY_LOW); + + start_line += lines_per_task; + } + + /* work and wait until tasks are done */ + BLI_task_pool_work_and_wait(task_pool); + + /* Free memory. */ + MEM_freeN(handles); + BLI_task_pool_free(task_pool); +} + /* Alpha-under */ void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3]) -- cgit v1.2.3