[Bf-blender-cvs] [871835e] compositor-2016: Sequencer's histogram view: OMP -> BLI_task.

Bastien Montagne noreply at git.blender.org
Wed Jun 8 21:49:46 CEST 2016


Commit: 871835eb3de63a2ef70762967fa4e72665ce0b1f
Author: Bastien Montagne
Date:   Mon May 23 23:23:51 2016 +0200
Branches: compositor-2016
https://developer.blender.org/rB871835eb3de63a2ef70762967fa4e72665ce0b1f

Sequencer's histogram view: OMP -> BLI_task.

New code using loop/finalize model is about 45% faster (from 4.4ms tp 2.4ms per frame,
overall playback of single shot in sequencer in this preview mode goes from 40 to 45fps).

===================================================================

M	source/blender/editors/space_sequencer/CMakeLists.txt
M	source/blender/editors/space_sequencer/sequencer_scopes.c

===================================================================

diff --git a/source/blender/editors/space_sequencer/CMakeLists.txt b/source/blender/editors/space_sequencer/CMakeLists.txt
index 778ccf9..6dce962 100644
--- a/source/blender/editors/space_sequencer/CMakeLists.txt
+++ b/source/blender/editors/space_sequencer/CMakeLists.txt
@@ -28,6 +28,7 @@ set(INC
 	../../makesdna
 	../../makesrna
 	../../windowmanager
+	../../../../intern/atomic
 	../../../../intern/guardedalloc
 	../../../../intern/glew-mx
 )
diff --git a/source/blender/editors/space_sequencer/sequencer_scopes.c b/source/blender/editors/space_sequencer/sequencer_scopes.c
index c197aab..80cb42c 100644
--- a/source/blender/editors/space_sequencer/sequencer_scopes.c
+++ b/source/blender/editors/space_sequencer/sequencer_scopes.c
@@ -30,11 +30,14 @@
 #include <string.h>
 
 #include "BLI_utildefines.h"
+#include "BLI_task.h"
 
 #include "IMB_colormanagement.h"
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 
+#include "atomic_ops.h"
+
 #include "sequencer_intern.h"
 
 /* XXX, why is this function better then BLI_math version?
@@ -450,41 +453,57 @@ static void draw_histogram_bar(ImBuf *ibuf, int x, float val, int col)
 
 #define HIS_STEPS 512
 
-static ImBuf *make_histogram_view_from_ibuf_byte(ImBuf *ibuf)
+typedef struct MakeHistogramViewData {
+	const ImBuf *ibuf;
+	uint32_t (*bins)[HIS_STEPS];
+} MakeHistogramViewData;
+
+static void make_histogram_view_from_ibuf_byte_cb_ex(
+        void *userdata, void *userdata_chunk, const int y, const int UNUSED(threadid))
 {
-	ImBuf *rval = IMB_allocImBuf(515, 128, 32, IB_rect);
-	int x, y;
-	unsigned int nr, ng, nb;
+	MakeHistogramViewData *data = userdata;
+	const ImBuf *ibuf = data->ibuf;
 	const unsigned char *src = (unsigned char *)ibuf->rect;
 
-	unsigned int bins[3][HIS_STEPS];
-
-	memset(bins, 0, sizeof(bins));
+	uint32_t (*cur_bins)[HIS_STEPS] = userdata_chunk;
 
-#pragma omp parallel for shared(bins, src, ibuf) private(x, y) if (ibuf->y >= 256)
-	for (y = 0; y < ibuf->y; y++) {
-		unsigned int cur_bins[3][HIS_STEPS];
+	for (int x = 0; x < ibuf->x; x++) {
+		const unsigned char *pixel = src + (y * ibuf->x + x) * 4;
 
-		memset(cur_bins, 0, sizeof(cur_bins));
+		for (int j = 3; j--;) {
+			cur_bins[j][pixel[j]]++;
+		}
+	}
+}
 
-		for (x = 0; x < ibuf->x; x++) {
-			const unsigned char *pixel = src + (y * ibuf->x + x) * 4;
+static void make_histogram_view_from_ibuf_finalize(void *userdata, void *userdata_chunk)
+{
+	MakeHistogramViewData *data = userdata;
+	uint32_t (*bins)[HIS_STEPS] = data->bins;
 
-			cur_bins[0][pixel[0]]++;
-			cur_bins[1][pixel[1]]++;
-			cur_bins[2][pixel[2]]++;
-		}
+	uint32_t (*cur_bins)[HIS_STEPS] = userdata_chunk;
 
-#pragma omp critical
-		{
-			int i;
-			for (i = 0; i < HIS_STEPS; i++) {
-				bins[0][i] += cur_bins[0][i];
-				bins[1][i] += cur_bins[1][i];
-				bins[2][i] += cur_bins[2][i];
-			}
+	for (int j = 3; j--;) {
+		for (int i = 0; i < HIS_STEPS; i++) {
+			bins[j][i] += cur_bins[j][i];
 		}
 	}
+}
+
+static ImBuf *make_histogram_view_from_ibuf_byte(ImBuf *ibuf)
+{
+	ImBuf *rval = IMB_allocImBuf(515, 128, 32, IB_rect);
+	int x;
+	unsigned int nr, ng, nb;
+
+	unsigned int bins[3][HIS_STEPS];
+
+	memset(bins, 0, sizeof(bins));
+
+	MakeHistogramViewData data = {.ibuf = ibuf, .bins = bins};
+	BLI_task_parallel_range_finalize(
+	            0, ibuf->y, &data, bins, sizeof(bins), make_histogram_view_from_ibuf_byte_cb_ex,
+	            make_histogram_view_from_ibuf_finalize, ibuf->y >= 256, false);
 
 	nr = nb = ng = 0;
 	for (x = 0; x < HIS_STEPS; x++) {
@@ -528,40 +547,38 @@ BLI_INLINE int get_bin_float(float f)
 	return (int) (((f + 0.25f) / 1.5f) * 512);
 }
 
-static ImBuf *make_histogram_view_from_ibuf_float(ImBuf *ibuf)
+static void make_histogram_view_from_ibuf_float_cb_ex(
+        void *userdata, void *userdata_chunk, const int y, const int UNUSED(threadid))
 {
-	ImBuf *rval = IMB_allocImBuf(515, 128, 32, IB_rect);
-	int nr, ng, nb, x, y;
+	const MakeHistogramViewData *data = userdata;
+	const ImBuf *ibuf = data->ibuf;
 	const float *src = ibuf->rect_float;
 
-	unsigned int bins[3][HIS_STEPS];
+	uint32_t (*cur_bins)[HIS_STEPS] = userdata_chunk;
 
-	memset(bins, 0, sizeof(bins));
+	for (int x = 0; x < ibuf->x; x++) {
+		const float *pixel = src + (y * ibuf->x + x) * 4;
 
-#pragma omp parallel for shared(bins, src, ibuf) private(x, y) if (ibuf->y >= 256)
-	for (y = 0; y < ibuf->y; y++) {
-		unsigned int cur_bins[3][HIS_STEPS];
+		for (int j = 3; j--;) {
+			cur_bins[j][get_bin_float(pixel[j])]++;
+		}
+	}
+}
 
-		memset(cur_bins, 0, sizeof(cur_bins));
+static ImBuf *make_histogram_view_from_ibuf_float(ImBuf *ibuf)
+{
+	ImBuf *rval = IMB_allocImBuf(515, 128, 32, IB_rect);
+	int nr, ng, nb;
+	int x;
 
-		for (x = 0; x < ibuf->x; x++) {
-			const float *pixel = src + (y * ibuf->x + x) * 4;
+	unsigned int bins[3][HIS_STEPS];
 
-			cur_bins[0][get_bin_float(pixel[0])]++;
-			cur_bins[1][get_bin_float(pixel[1])]++;
-			cur_bins[2][get_bin_float(pixel[2])]++;
-		}
+	memset(bins, 0, sizeof(bins));
 
-#pragma omp critical
-		{
-			int i;
-			for (i = 0; i < HIS_STEPS; i++) {
-				bins[0][i] += cur_bins[0][i];
-				bins[1][i] += cur_bins[1][i];
-				bins[2][i] += cur_bins[2][i];
-			}
-		}
-	}
+	MakeHistogramViewData data = {.ibuf = ibuf, .bins = bins};
+	BLI_task_parallel_range_finalize(
+	            0, ibuf->y, &data, bins, sizeof(bins), make_histogram_view_from_ibuf_float_cb_ex,
+	            make_histogram_view_from_ibuf_finalize, ibuf->y >= 256, false);
 
 	nr = nb = ng = 0;
 	for (x = 0; x < HIS_STEPS; x++) {




More information about the Bf-blender-cvs mailing list