[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58801] branches/soc-2013-depsgraph_mt/ source/blender: Hack to workaround scene update lock caused by GIL

Sergey Sharybin sergey.vfx at gmail.com
Thu Aug 1 05:58:23 CEST 2013


Revision: 58801
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58801
Author:   nazgul
Date:     2013-08-01 03:58:22 +0000 (Thu, 01 Aug 2013)
Log Message:
-----------
Hack to workaround scene update lock caused by GIL

Couple of RNA callbacks would imply scene update routines
to trigger. This works fine for until some objects does have
drivers.

If some object does have driver, it'll try to lock GIL
when evaluating this driver, and GIL is already locked by
a python API, which causes deadlock.

For now made it so RNA callbacks doesn't do threaded update.
This is not so much nice, especially since Cycles might
use the same API for motion blur, but for now don't see
better way to solve the deadlock.

Modified Paths:
--------------
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_scene.h
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c
    branches/soc-2013-depsgraph_mt/source/blender/makesrna/intern/rna_scene_api.c

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_scene.h
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_scene.h	2013-08-01 01:41:25 UTC (rev 58800)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_scene.h	2013-08-01 03:58:22 UTC (rev 58801)
@@ -111,8 +111,10 @@
 float BKE_scene_frame_get_from_ctime(struct Scene *scene, const float frame);
 void  BKE_scene_frame_set(struct Scene *scene, double cfra);
 
+void BKE_scene_update_tagged_ex(struct Main *bmain, struct Scene *scene, bool use_threads);
 void BKE_scene_update_tagged(struct Main *bmain, struct Scene *sce);
 
+void BKE_scene_update_for_newframe_ex(struct Main *bmain, struct Scene *sce, unsigned int lay, bool use_threads);
 void BKE_scene_update_for_newframe(struct Main *bmain, struct Scene *sce, unsigned int lay);
 
 struct SceneRenderLayer *BKE_scene_add_render_layer(struct Scene *sce, const char *name);

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c	2013-08-01 01:41:25 UTC (rev 58800)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c	2013-08-01 03:58:22 UTC (rev 58801)
@@ -1180,6 +1180,25 @@
 
 static void scene_update_object_add_task(void *node, void *user_data);
 
+static void scene_update_all_bases(Scene *scene, Scene *scene_parent)
+{
+	Base *base;
+
+	for (base = scene->base.first; base; base = base->next) {
+		Object *object = base->object;
+
+		BKE_object_handle_update_ex(scene_parent, object, scene->rigidbody_world);
+
+		if (object->dup_group && (object->transflag & OB_DUPLIGROUP))
+			BKE_group_handle_recalc_and_update(scene_parent, object, object->dup_group);
+
+		/* always update layer, so that animating layers works (joshua july 2010) */
+		/* XXX commented out, this has depsgraph issues anyway - and this breaks setting scenes
+		 * (on scene-set, the base-lay is copied to ob-lay (ton nov 2012) */
+		// base->lay = ob->lay;
+	}
+}
+
 static void scene_update_object_func(TaskPool *pool, void *taskdata, int threadid)
 {
 /* Disable print for now in favor of summary statistics at the end of update. */
@@ -1280,12 +1299,17 @@
 	}
 }
 
-static void scene_update_objects(Scene *scene, Scene *scene_parent)
+static void scene_update_objects(Scene *scene, Scene *scene_parent, bool use_threads)
 {
 	TaskScheduler *task_scheduler = BLI_task_scheduler_get();
 	TaskPool *task_pool;
 	ThreadedObjectUpdateState state;
 
+	if (use_threads == false) {
+		scene_update_all_bases(scene, scene_parent);
+		return;
+	}
+
 	/* Ensure malloc will go go fine from threads,
 	 * this is needed because we could be in main thread here
 	 * and malloc could be non-threda safe at this point because
@@ -1373,17 +1397,17 @@
 	}
 }
 
-static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scene_parent)
+static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scene_parent, bool use_threads)
 {
 	scene->customdata_mask = scene_parent->customdata_mask;
 
 	/* sets first, we allow per definition current scene to have
 	 * dependencies on sets, but not the other way around. */
 	if (scene->set)
-		scene_update_tagged_recursive(bmain, scene->set, scene_parent);
+		scene_update_tagged_recursive(bmain, scene->set, scene_parent, use_threads);
 
 	/* scene objects */
-	scene_update_objects(scene, scene_parent);
+	scene_update_objects(scene, scene_parent, use_threads);
 
 	/* scene drivers... */
 	scene_update_drivers(bmain, scene);
@@ -1397,7 +1421,7 @@
 }
 
 /* this is called in main loop, doing tagged updates before redraw */
-void BKE_scene_update_tagged(Main *bmain, Scene *scene)
+void BKE_scene_update_tagged_ex(Main *bmain, Scene *scene, bool use_threads)
 {
 	Scene *sce_iter;
 	
@@ -1424,7 +1448,7 @@
 	 *
 	 * in the future this should handle updates for all datablocks, not
 	 * only objects and scenes. - brecht */
-	scene_update_tagged_recursive(bmain, scene, scene);
+	scene_update_tagged_recursive(bmain, scene, scene, use_threads);
 
 	/* extra call here to recalc scene animation (for sequencer) */
 	{
@@ -1443,8 +1467,13 @@
 	DAG_ids_clear_recalc(bmain);
 }
 
+void BKE_scene_update_tagged(Main *bmain, Scene *scene)
+{
+	BKE_scene_update_tagged_ex(bmain, scene, true);
+}
+
 /* applies changes right away, does all sets too */
-void BKE_scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay)
+void BKE_scene_update_for_newframe_ex(Main *bmain, Scene *sce, unsigned int lay, bool use_threads)
 {
 	float ctime = BKE_scene_frame_get(sce);
 	Scene *sce_iter;
@@ -1502,7 +1531,7 @@
 	scene_do_rb_simulation_recursive(sce, ctime);
 
 	/* BKE_object_handle_update() on all objects, groups and sets */
-	scene_update_tagged_recursive(bmain, sce, sce);
+	scene_update_tagged_recursive(bmain, sce, sce, use_threads);
 
 	scene_depsgraph_hack(sce, sce);
 
@@ -1516,6 +1545,11 @@
 	DAG_ids_clear_recalc(bmain);
 }
 
+void BKE_scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay)
+{
+	BKE_scene_update_for_newframe_ex(bmain, sce, lay, true);
+}
+
 /* return default layer, also used to patch old files */
 SceneRenderLayer *BKE_scene_add_render_layer(Scene *sce, const char *name)
 {

Modified: branches/soc-2013-depsgraph_mt/source/blender/makesrna/intern/rna_scene_api.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/makesrna/intern/rna_scene_api.c	2013-08-01 01:41:25 UTC (rev 58800)
+++ branches/soc-2013-depsgraph_mt/source/blender/makesrna/intern/rna_scene_api.c	2013-08-01 03:58:22 UTC (rev 58801)
@@ -61,7 +61,7 @@
 	CLAMP(cfra, MINAFRAME, MAXFRAME);
 	BKE_scene_frame_set(scene, cfra);
 
-	BKE_scene_update_for_newframe(G.main, scene, (1 << 20) - 1);
+	BKE_scene_update_for_newframe_ex(G.main, scene, (1 << 20) - 1, false);
 	BKE_scene_camera_switch_update(scene);
 
 	/* don't do notifier when we're rendering, avoid some viewport crashes
@@ -78,7 +78,7 @@
 
 static void rna_Scene_update_tagged(Scene *scene)
 {
-	BKE_scene_update_tagged(G.main, scene);
+	BKE_scene_update_tagged_ex(G.main, scene, false);
 }
 
 static void rna_SceneRender_get_frame_path(RenderData *rd, int frame, char *name)




More information about the Bf-blender-cvs mailing list