[Bf-blender-cvs] [71f6898] master: Fix deadlock happening when using Save Buffers for render

Sergey Sharybin noreply at git.blender.org
Wed Jan 1 17:37:52 CET 2014


Commit: 71f689843d13b86fad26ab07867ea70fed80c1e7
Author: Sergey Sharybin
Date:   Wed Jan 1 16:59:38 2014 +0600
https://developer.blender.org/rB71f689843d13b86fad26ab07867ea70fed80c1e7

Fix deadlock happening when using Save Buffers for render

Summary:
Issue was caused by the same tile being written twice to
the EXR file. This was happening because of partial update
of work-in-progress tiles was merging result to the final
render result in order to make color management pipeline
happy.

We need to avoid such a merges and keep memory usage as
low as possible when Save Buffers is enabled.

Now render pipeline will allocate special display buffer
in render layer which will contain combined pass in the
display space. This keeps memory usage as low as we can
do at this moment.

There's one weak thing which is changing color management
settings during rendering would lead to lossy conversion.
This is because render result's display buffer uses color
space from the time when rendering was invoked.

This is actually what was happening in previous release
already actually so not a big issue.

Reviewers: brecht

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D162

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

M	source/blender/blenkernel/intern/image.c
M	source/blender/compositor/operations/COM_ViewerOperation.cpp
M	source/blender/editors/render/render_internal.c
M	source/blender/imbuf/IMB_colormanagement.h
M	source/blender/imbuf/intern/colormanagement.c
M	source/blender/render/extern/include/RE_pipeline.h
M	source/blender/render/intern/source/external_engine.c
M	source/blender/render/intern/source/render_result.c

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

diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 3d59b71..288443d 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -2773,6 +2773,7 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
 	int channels, layer, pass;
 	ImBuf *ibuf;
 	int from_render = (ima->render_slot == ima->last_render_slot);
+	bool byte_buffer_in_display_space = false;
 
 	if (!(iuser && iuser->scene))
 		return NULL;
@@ -2835,6 +2836,13 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
 			/* there's no combined pass, is in renderlayer itself */
 			if (pass == 0) {
 				rectf = rl->rectf;
+				if (rectf == NULL) {
+					/* Happens when Save Buffers is enabled.
+					 * Use display buffer stored in the render layer.
+					 */
+					rect = (unsigned int *) rl->display_buffer;
+					byte_buffer_in_display_space = true;
+				}
 			}
 			else {
 				rpass = BLI_findlink(&rl->passes, pass - 1);
@@ -2859,6 +2867,27 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
 		image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
 	}
 
+	/* Set color space settings for a byte buffer.
+	 *
+	 * This is mainly to make it so color management treats byte buffer
+	 * from render result with Save Buffers enabled as final display buffer
+	 * and doesnt' apply any color management on it.
+	 *
+	 * For other cases we need to be sure it stays to default byte buffer space.
+	 */
+	if (ibuf->rect != rect) {
+		if (byte_buffer_in_display_space) {
+			const char *colorspace =
+				IMB_colormanagement_get_display_colorspace_name(&iuser->scene->view_settings,
+			                                                    &iuser->scene->display_settings);
+			IMB_colormanagement_assign_rect_colorspace(ibuf, colorspace);
+		}
+		else {
+			const char *colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE);
+			IMB_colormanagement_assign_rect_colorspace(ibuf, colorspace);
+		}
+	}
+
 	/* invalidate color managed buffers if render result changed */
 	BLI_lock_thread(LOCK_COLORMANAGE);
 	if (ibuf->x != rres.rectx || ibuf->y != rres.recty || ibuf->rect_float != rectf) {
diff --git a/source/blender/compositor/operations/COM_ViewerOperation.cpp b/source/blender/compositor/operations/COM_ViewerOperation.cpp
index aa08069..f53f2b8 100644
--- a/source/blender/compositor/operations/COM_ViewerOperation.cpp
+++ b/source/blender/compositor/operations/COM_ViewerOperation.cpp
@@ -171,7 +171,7 @@ void ViewerOperation::updateImage(rcti *rect)
 {
 	IMB_partial_display_buffer_update(this->m_ibuf, this->m_outputBuffer, NULL, getWidth(), 0, 0,
 	                                  this->m_viewSettings, this->m_displaySettings,
-	                                  rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+	                                  rect->xmin, rect->ymin, rect->xmax, rect->ymax, false);
 
 	this->updateDraw();
 }
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c
index b4414cf..deec422 100644
--- a/source/blender/editors/render/render_internal.c
+++ b/source/blender/editors/render/render_internal.c
@@ -49,6 +49,7 @@
 
 #include "BKE_blender.h"
 #include "BKE_context.h"
+#include "BKE_colortools.h"
 #include "BKE_depsgraph.h"
 #include "BKE_freestyle.h"
 #include "BKE_global.h"
@@ -93,13 +94,39 @@
 /* Render Callbacks */
 static int render_break(void *rjv);
 
+typedef struct RenderJob {
+	Main *main;
+	Scene *scene;
+	Render *re;
+	SceneRenderLayer *srl;
+	struct Object *camera_override;
+	int lay_override;
+	bool v3d_override;
+	short anim, write_still;
+	Image *image;
+	ImageUser iuser;
+	bool image_outdated;
+	short *stop;
+	short *do_update;
+	float *progress;
+	ReportList *reports;
+	int orig_layer;
+	int last_layer;
+	ScrArea *sa;
+	ColorManagedViewSettings view_settings;
+	ColorManagedDisplaySettings display_settings;
+} RenderJob;
+
 /* called inside thread! */
-static void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, ImageUser *iuser, volatile rcti *renrect)
+static void image_buffer_rect_update(RenderJob *rj, RenderResult *rr, ImBuf *ibuf, ImageUser *iuser, volatile rcti *renrect)
 {
+	Scene *scene = rj->scene;
 	float *rectf = NULL;
 	int ymin, ymax, xmin, xmax;
 	int rymin, rxmin;
 	int linear_stride, linear_offset_x, linear_offset_y;
+	ColorManagedViewSettings *view_settings;
+	ColorManagedDisplaySettings *display_settings;
 
 	if (ibuf->userflags & IB_DISPLAY_BUFFER_INVALID) {
 		/* The whole image buffer it so be color managed again anyway. */
@@ -189,10 +216,23 @@ static void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf
 		linear_offset_y = 0;
 	}
 
+	if (rr->do_exr_tile) {
+		/* We don't support changing color management settings during rendering
+		 * when using Save Buffers option.
+		 */
+		view_settings = &rj->view_settings;
+		display_settings = &rj->display_settings;
+	}
+	else {
+		view_settings = &scene->view_settings;
+		display_settings = &scene->display_settings;
+	}
+
 	IMB_partial_display_buffer_update(ibuf, rectf, NULL,
 	                                  linear_stride, linear_offset_x, linear_offset_y,
-	                                  &scene->view_settings, &scene->display_settings,
-	                                  rxmin, rymin, rxmin + xmax, rymin + ymax);
+	                                  view_settings, display_settings,
+	                                  rxmin, rymin, rxmin + xmax, rymin + ymax,
+	                                  rr->do_exr_tile);
 }
 
 /* ****************************** render invoking ***************** */
@@ -286,31 +326,11 @@ static int screen_render_exec(bContext *C, wmOperator *op)
 	return OPERATOR_FINISHED;
 }
 
-typedef struct RenderJob {
-	Main *main;
-	Scene *scene;
-	Render *re;
-	SceneRenderLayer *srl;
-	struct Object *camera_override;
-	int lay_override;
-	bool v3d_override;
-	short anim, write_still;
-	Image *image;
-	ImageUser iuser;
-	bool image_outdated;
-	short *stop;
-	short *do_update;
-	float *progress;
-	ReportList *reports;
-	int orig_layer;
-	int last_layer;
-	ScrArea *sa;
-} RenderJob;
-
 static void render_freejob(void *rjv)
 {
 	RenderJob *rj = rjv;
 
+	BKE_color_managed_view_settings_free(&rj->view_settings);
 	MEM_freeN(rj);
 }
 
@@ -516,11 +536,16 @@ static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrec
 	if (ibuf) {
 		/* Don't waste time on CPU side color management if
 		 * image will be displayed using GLSL.
+		 *
+		 * Need to update rect if Save Buffers enabled because in
+		 * this case GLSL doesn't have original float buffer to
+		 * operate with.
 		 */
-		if (ibuf->channels == 1 ||
+		if (rr->do_exr_tile ||
+		    ibuf->channels == 1 ||
 		    U.image_draw_method != IMAGE_DRAW_METHOD_GLSL)
 		{
-			image_buffer_rect_update(rj->scene, rr, ibuf, &rj->iuser, renrect);
+			image_buffer_rect_update(rj, rr, ibuf, &rj->iuser, renrect);
 		}
 
 		/* make jobs timer to send notifier */
@@ -793,6 +818,9 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
 	rj->last_layer = 0;
 	rj->sa = sa;
 
+	BKE_color_managed_display_settings_copy(&rj->display_settings, &scene->display_settings);
+	BKE_color_managed_view_settings_copy(&rj->view_settings, &scene->view_settings);
+
 	if (sa) {
 		SpaceImage *sima = sa->spacedata.first;
 		rj->orig_layer = sima->iuser.layer;
diff --git a/source/blender/imbuf/IMB_colormanagement.h b/source/blender/imbuf/IMB_colormanagement.h
index 263216c..262e87b 100644
--- a/source/blender/imbuf/IMB_colormanagement.h
+++ b/source/blender/imbuf/IMB_colormanagement.h
@@ -113,6 +113,9 @@ void IMB_colormanagement_display_settings_from_ctx(const struct bContext *C,
                                                    struct ColorManagedViewSettings **view_settings_r,
                                                    struct ColorManagedDisplaySettings **display_settings_r);
 
+const char *IMB_colormanagement_get_display_colorspace_name(const struct ColorManagedViewSettings *view_settings,
+                                                            const struct ColorManagedDisplaySettings *display_settings);
+
 unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
                                           const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
 unsigned char *IMB_display_buffer_acquire_ctx(const struct bContext *C, struct ImBuf *ibuf, void **cache_handle);
@@ -153,9 +156,11 @@ void IMB_colormanagement_colorspace_items_add(struct EnumPropertyItem **items, i
 
 /* ** Tile-based buffer management ** */
 void IMB_partial_display_buffer_update(struct ImBuf *ibuf, const float *linear_buffer, const unsigned char *buffer_byte,
-                                       int stride, int offset_x, int offset_y, const struct ColorManagedViewSettings *view_settings,
+                                       int stride, int offset_x, int offset_y,
+                                       const struct ColorManagedViewSettings *view_settings,
                                        const struct ColorManagedDisplaySettings *display_settings,
-                                       int xmin, int ymin, int xmax, int ymax);
+                                       int xmin, int ymin, int xmax, int ymax,
+                                       bool copy_display_to_byte_buffer);
 
 void IMB_partial_display_buffer_update_delayed(struct ImBuf *ibuf, int xmin, int ymin, int xmax, int ymax);
 
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
index 6ca3e1a..e5884f7 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -745,8 +745,8 @@ void IMB_colormanagement_display_settings_from_ctx(const bContext *C,
 	}
 }
 
-static const char *display_transform_get_colorspace_name(const ColorManagedViewSettings *view_settings,
-                                                         const ColorManagedDisplaySettings *display_settings)
+const char *IMB_colorman

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list