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
This commit is contained in:
parent
82cf25dfbf
commit
8507336e76
Notes:
blender-bot
2023-02-14 08:42:53 +01:00
Referenced by issue #88449: Blender LTS: Maintenance Task 2.93 Referenced by issue #88449, Blender LTS: Maintenance Task 2.93 Referenced by issue #92423, Blender freeze rendering animation with Mantaflow
|
@ -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);
|
||||
/* 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);
|
||||
|
||||
result = BKE_fluid_modifier_do(fmd, ctx->depsgraph, scene, ctx->object, me);
|
||||
return result ? result : me;
|
||||
return isolation_data.result;
|
||||
#endif /* WITH_FLUID */
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue