[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49084] branches/soc-2011-tomato/source/ blender: Color management: threading fixes and partial buffer update refactor

Sergey Sharybin sergey.vfx at gmail.com
Fri Jul 20 16:16:25 CEST 2012


Revision: 49084
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49084
Author:   nazgul
Date:     2012-07-20 14:16:25 +0000 (Fri, 20 Jul 2012)
Log Message:
-----------
Color management: threading fixes and partial buffer update refactor

There used to be an issue in colormanage_cache_get which lead to
wrong reference number counter in cases when exposure / gamma
does not match values stored in cache. In this case cache handle
should be set to NULL, no callee function could always call
buffer release function (as it was intended to).

Made display buffer acquire / release functions thread safe.
This applies to "external" API only, internal helpers are
non-thread safe for performance issues, so if one uses them
he need to be careful.

Converted partial display buffer update into a single function
which still updates all display buffer ever created for given
image buffer. This means that it's not needed to create any
kind of context first and if there're display buffers created
in-between of partial updates they would also be updated with
next calls of partial updates.

This allowed to make render result nicely color managed during
rendering, meaning that render progress is visualisable with
color management for image editor set up.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/blenlib/BLI_threads.h
    branches/soc-2011-tomato/source/blender/blenlib/intern/threads.c
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_ViewerBaseOperation.h
    branches/soc-2011-tomato/source/blender/editors/render/render_internal.c
    branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c

Modified: branches/soc-2011-tomato/source/blender/blenlib/BLI_threads.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/BLI_threads.h	2012-07-20 14:02:51 UTC (rev 49083)
+++ branches/soc-2011-tomato/source/blender/blenlib/BLI_threads.h	2012-07-20 14:16:25 UTC (rev 49084)
@@ -77,6 +77,7 @@
 #define LOCK_OPENGL     5
 #define LOCK_NODES      6
 #define LOCK_MOVIECLIP  7
+#define LOCK_COLORMANAGE 8
 
 void    BLI_lock_thread(int type);
 void    BLI_unlock_thread(int type);

Modified: branches/soc-2011-tomato/source/blender/blenlib/intern/threads.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/intern/threads.c	2012-07-20 14:02:51 UTC (rev 49083)
+++ branches/soc-2011-tomato/source/blender/blenlib/intern/threads.c	2012-07-20 14:16:25 UTC (rev 49084)
@@ -113,6 +113,7 @@
 static pthread_mutex_t _opengl_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t _nodes_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t _movieclip_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t _colormanage_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_t mainid;
 static int thread_levels = 0;  /* threads can be invoked inside threads */
 
@@ -351,6 +352,8 @@
 		pthread_mutex_lock(&_nodes_lock);
 	else if (type == LOCK_MOVIECLIP)
 		pthread_mutex_lock(&_movieclip_lock);
+	else if (type == LOCK_COLORMANAGE)
+		pthread_mutex_lock(&_colormanage_lock);
 }
 
 void BLI_unlock_thread(int type)
@@ -371,6 +374,8 @@
 		pthread_mutex_unlock(&_nodes_lock);
 	else if (type == LOCK_MOVIECLIP)
 		pthread_mutex_unlock(&_movieclip_lock);
+	else if (type == LOCK_COLORMANAGE)
+		pthread_mutex_unlock(&_colormanage_lock);
 }
 
 /* Mutex Locks */

Modified: branches/soc-2011-tomato/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp	2012-07-20 14:02:51 UTC (rev 49083)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp	2012-07-20 14:16:25 UTC (rev 49084)
@@ -47,13 +47,10 @@
 	this->m_outputBufferDisplay = NULL;
 	this->m_active = false;
 	this->m_doColorManagement = true;
-	this->m_partialBufferUpdate = NULL;
 }
 
 void ViewerBaseOperation::initExecution()
 {
-	this->m_partialBufferUpdate = NULL;
-
 	if (isActiveViewerOutput()) {
 		initImage();
 	}
@@ -77,36 +74,35 @@
 		imb_addrectfloatImBuf(ibuf);
 		anImage->ok = IMA_OK_LOADED;
 
+		IMB_display_buffer_invalidate(ibuf);
+
 		BLI_unlock_thread(LOCK_DRAW_IMAGE);
 	}
 
-	this->m_partialBufferUpdate = IMB_partial_buffer_update_context_new(ibuf);
-
 	/* now we combine the input with ibuf */
 	this->m_outputBuffer = ibuf->rect_float;
 	this->m_outputBufferDisplay = (unsigned char *)ibuf->rect;
 
+	/* needed for display buffer update
+	 *
+	 * no need to lock / reference the image buffer because it's seems
+	 * to be the single place which changes buffers of viewer image
+	 * which is this node
+	 */
+	this->m_ibuf = ibuf;
+
 	BKE_image_release_ibuf(this->m_image, this->m_lock);
 }
 void ViewerBaseOperation:: updateImage(rcti *rect)
 {
-	IMB_partial_buffer_update_rect(this->m_partialBufferUpdate, this->m_outputBuffer, rect);
+	IMB_partial_display_buffer_update(this->m_ibuf, this->m_outputBuffer, getWidth(), 0, 0,
+	                                  rect->xmin, rect->ymin, rect->xmax, rect->ymax);
 
 	WM_main_add_notifier(NC_WINDOW | ND_DRAW, NULL);
 }
 
 void ViewerBaseOperation::deinitExecution()
 {
-	if (this->m_partialBufferUpdate) {
-		/* partial buffer context could be NULL if it's not active viewer node */
-
-		ImBuf *ibuf = BKE_image_acquire_ibuf(this->m_image, this->m_imageUser, &this->m_lock);
-
-		IMB_partial_buffer_update_free(this->m_partialBufferUpdate, ibuf);
-
-		BKE_image_release_ibuf(this->m_image, this->m_lock);
-	}
-
 	this->m_outputBuffer = NULL;
 }
 

Modified: branches/soc-2011-tomato/source/blender/compositor/operations/COM_ViewerBaseOperation.h
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_ViewerBaseOperation.h	2012-07-20 14:02:51 UTC (rev 49083)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_ViewerBaseOperation.h	2012-07-20 14:16:25 UTC (rev 49084)
@@ -39,8 +39,8 @@
 	OrderOfChunks m_chunkOrder;
 	bool m_doColorManagement;
 	bool m_doColorPredivide;
+	ImBuf *m_ibuf;
 
-	struct PartialBufferUpdateContext *m_partialBufferUpdate;
 public:
 	bool isOutputOperation(bool rendering) const { return isActiveViewerOutput(); }
 	void initExecution();

Modified: branches/soc-2011-tomato/source/blender/editors/render/render_internal.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/render/render_internal.c	2012-07-20 14:02:51 UTC (rev 49083)
+++ branches/soc-2011-tomato/source/blender/editors/render/render_internal.c	2012-07-20 14:16:25 UTC (rev 49084)
@@ -61,6 +61,7 @@
 #include "ED_object.h"
 
 #include "RE_pipeline.h"
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
@@ -150,6 +151,9 @@
 	IMB_buffer_byte_from_float(rectc, rectf,
 	                           4, ibuf->dither, IB_PROFILE_SRGB, profile_from, predivide,
 	                           xmax, ymax, ibuf->x, rr->rectx);
+
+	IMB_partial_display_buffer_update(ibuf, rectf, rr->rectx, rxmin, rymin,
+	                                  rxmin, rymin, rxmin + xmax - 1, rymin + ymax - 1);
 }
 
 /* ****************************** render invoking ***************** */

Modified: branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h	2012-07-20 14:02:51 UTC (rev 49083)
+++ branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h	2012-07-20 14:16:25 UTC (rev 49084)
@@ -92,8 +92,8 @@
 void IMB_colormanagement_colorspace_items_add(struct EnumPropertyItem **items, int *totitem);
 
 /* Tile-based buffer management */
-struct PartialBufferUpdateContext *IMB_partial_buffer_update_context_new(struct ImBuf *ibuf);
-void IMB_partial_buffer_update_rect(struct PartialBufferUpdateContext *context, const float *linear_buffer, struct rcti *rect);
-void IMB_partial_buffer_update_free(struct PartialBufferUpdateContext *context, struct ImBuf *ibuf);
+void IMB_partial_display_buffer_update(struct ImBuf *ibuf, const float *linear_buffer,
+                                       int stride, int offset_x, int offset_y,
+                                       int xmin, int ymin, int xmax, int ymax);
 
 #endif // IMB_COLORMANAGEMENT_H

Modified: branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-07-20 14:02:51 UTC (rev 49083)
+++ branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-07-20 14:16:25 UTC (rev 49084)
@@ -70,6 +70,8 @@
 /* define this to allow byte buffers be color managed */
 #undef COLORMANAGE_BYTE_BUFFER
 
+#define ACES_ODT_TONECORVE "ACES ODT Tonecurve"
+
 /* ** list of all supported color spaces, displays and views */
 #ifdef WITH_OCIO
 static char global_role_scene_linear[64];
@@ -224,7 +226,7 @@
 static struct MovieCache *colormanage_moviecache_ensure(ImBuf *ibuf)
 {
 	if (!ibuf->colormanage_cache) {
-		ibuf->colormanage_cache = MEM_callocN(sizeof(ColormanageCache), "imbuf colormanage ca cache");
+		ibuf->colormanage_cache = MEM_callocN(sizeof(ColormanageCache), "imbuf colormanage cache");
 	}
 
 	if (!ibuf->colormanage_cache->moviecache) {
@@ -242,7 +244,7 @@
 static void colormanage_cachedata_set(ImBuf *ibuf, ColormnaageCacheData *data)
 {
 	if (!ibuf->colormanage_cache) {
-		ibuf->colormanage_cache = MEM_callocN(sizeof(ColormanageCache), "imbuf colormanage ca cache");
+		ibuf->colormanage_cache = MEM_callocN(sizeof(ColormanageCache), "imbuf colormanage cache");
 	}
 
 	ibuf->colormanage_cache->data = data;
@@ -324,8 +326,10 @@
 		cache_data = colormanage_cachedata_get(cache_ibuf);
 
 		if (cache_data->exposure != view_settings->exposure ||
-			cache_data->gamma != view_settings->gamma)
+		    cache_data->gamma != view_settings->gamma)
 		{
+			*cache_handle = NULL;
+
 			IMB_freeImBuf(cache_ibuf);
 
 			return NULL;
@@ -371,20 +375,12 @@
 	IMB_moviecache_put(moviecache, &key, cache_ibuf);
 }
 
-/* validation function checks whether there's buffer with given display transform
- * in the cache and if so, check whether it matches resolution of source buffer.
- * if resolution is different new buffer would be put into the cache and it'll
- * be returned as a result
- *
- * this function does not check exposure / gamma because currently it's only
- * used by partial buffer update functions which uses the same exposure / gamma
- * settings as cached buffer had
- */
-static unsigned char *colormanage_cache_get_validated(ImBuf *ibuf, const ColormanageCacheViewSettings *view_settings,
-                                                      const ColormanageCacheDisplaySettings *display_settings,
-                                                      void **cache_handle)
+static unsigned char *colormanage_cache_get_cache_data(ImBuf *ibuf, const ColormanageCacheViewSettings *view_settings,
+                                                       const ColormanageCacheDisplaySettings *display_settings,
+                                                       void **cache_handle, float *exposure, float *gamma)
 {
 	ColormanageCacheKey key;
+	ColormnaageCacheData *cache_data;
 	ImBuf *cache_ibuf;
 
 	colormanage_settings_to_key(&key, view_settings, display_settings);
@@ -392,44 +388,16 @@
 	cache_ibuf = colormanage_cache_get_ibuf(ibuf, &key, cache_handle);
 
 	if (cache_ibuf) {
-		if (cache_ibuf->x != ibuf->x || cache_ibuf->y != ibuf->y) {
-			ColormanageCacheViewSettings new_view_settings = *view_settings;
-			ColormnaageCacheData *cache_data;
-			unsigned char *display_buffer;
-			int buffer_size;
+		cache_data = colormanage_cachedata_get(cache_ibuf);
 
-			/* use the same settings as original cached buffer  */
-			cache_data = colormanage_cachedata_get(cache_ibuf);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list