[Bf-blender-cvs] [8507336e769] master: Fix T92423: Blender freeze rendering animation with Mantaflow

Sergey Sharybin noreply at git.blender.org
Wed Oct 27 14:53:05 CEST 2021


Commit: 8507336e76902604a2128b23a4d8e52094031ab0
Author: Sergey Sharybin
Date:   Wed Oct 27 14:40:18 2021 +0200
Branches: master
https://developer.blender.org/rB8507336e76902604a2128b23a4d8e52094031ab0

Fix T92423: Blender freeze rendering animation with Mantaflow

Mantaflow could steal tasks from dependency graph, which under
certain conditions causes a recursive lock involving GIL.

Isolate threading done in mantaflow when it is interfaced form
the dependency graph.

Isolation done from the modifier, since the deeper calls are
branching out quite quickly.

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

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

M	source/blender/modifiers/intern/MOD_fluid.c

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

diff --git a/source/blender/modifiers/intern/MOD_fluid.c b/source/blender/modifiers/intern/MOD_fluid.c
index a14d582063a..acc92fde766 100644
--- a/source/blender/modifiers/intern/MOD_fluid.c
+++ b/source/blender/modifiers/intern/MOD_fluid.c
@@ -25,6 +25,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_task.h"
 #include "BLI_utildefines.h"
 
 #include "BLT_translation.h"
@@ -112,6 +113,29 @@ static void requiredDataMask(Object *UNUSED(ob),
   }
 }
 
+typedef struct FluidIsolationData {
+  Depsgraph *depsgraph;
+  Object *object;
+  Mesh *mesh;
+  FluidModifierData *fmd;
+
+  Mesh *result;
+} FluidIsolationData;
+
+static void fluid_modifier_do_isolated(void *userdata)
+{
+  FluidIsolationData *isolation_data = (FluidIsolationData *)userdata;
+
+  Scene *scene = DEG_get_evaluated_scene(isolation_data->depsgraph);
+
+  Mesh *result = BKE_fluid_modifier_do(isolation_data->fmd,
+                                       isolation_data->depsgraph,
+                                       scene,
+                                       isolation_data->object,
+                                       isolation_data->mesh);
+  isolation_data->result = result ? result : isolation_data->mesh;
+}
+
 static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *me)
 {
 #ifndef WITH_FLUID
@@ -125,10 +149,19 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
     return me;
   }
 
-  Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
-
-  result = BKE_fluid_modifier_do(fmd, ctx->depsgraph, scene, ctx->object, me);
-  return result ? result : me;
+  /* Isolate execution of Mantaflow when running from dependency graph. The reason for this is
+   * because Mantaflow uses TBB to parallel its own computation which without isolation will start
+   * stealing tasks from dependency graph. Stealing tasks from the dependency graph might cause
+   * a recursive lock when Python drivers are used (because Mantaflow is interfaced via Python as
+   * well. */
+  FluidIsolationData isolation_data;
+  isolation_data.depsgraph = ctx->depsgraph;
+  isolation_data.object = ctx->object;
+  isolation_data.mesh = me;
+  isolation_data.fmd = fmd;
+  BLI_task_isolate(fluid_modifier_do_isolated, &isolation_data);
+
+  return isolation_data.result;
 #endif /* WITH_FLUID */
 }



More information about the Bf-blender-cvs mailing list