Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2021-06-21 19:44:40 +0300
committerBrecht Van Lommel <brecht@blender.org>2021-06-21 20:25:12 +0300
commit41af27c582ec21e65ff3f835754c7b0bcf6d3be7 (patch)
treed0b6c01a034876cd36a21c9e3517026b05ba6e0c /source
parent47473bee34897347b8a11d03a29a4efe83246e02 (diff)
Fix deadlocks in mesh modifier evaluation and particles
The recent task isolation changes missed two mutex locks that also need task isolation. Ref D11603, T89194
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.cc13
-rw-r--r--source/blender/blenkernel/intern/particle_system.c11
2 files changed, 19 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index 4cd611d2fa8..3150e096a73 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -42,6 +42,7 @@
#include "BLI_linklist.h"
#include "BLI_math.h"
#include "BLI_task.h"
+#include "BLI_task.hh"
#include "BLI_utildefines.h"
#include "BLI_vector.hh"
@@ -1463,10 +1464,14 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
BLI_assert(runtime->eval_mutex != nullptr);
BLI_mutex_lock((ThreadMutex *)runtime->eval_mutex);
if (runtime->mesh_eval == nullptr) {
- mesh_final = BKE_mesh_copy_for_eval(mesh_input, true);
- mesh_calc_modifier_final_normals(mesh_input, &final_datamask, sculpt_dyntopo, mesh_final);
- mesh_calc_finalize(mesh_input, mesh_final);
- runtime->mesh_eval = mesh_final;
+ /* Isolate since computing normals is multithreaded and we are holding a lock. */
+ blender::threading::isolate_task([&] {
+ mesh_final = BKE_mesh_copy_for_eval(mesh_input, true);
+ mesh_calc_modifier_final_normals(
+ mesh_input, &final_datamask, sculpt_dyntopo, mesh_final);
+ mesh_calc_finalize(mesh_input, mesh_final);
+ runtime->mesh_eval = mesh_final;
+ });
}
BLI_mutex_unlock((ThreadMutex *)runtime->eval_mutex);
}
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 149e345e501..2dc752d57e1 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -1320,6 +1320,14 @@ void psys_get_pointcache_start_end(Scene *scene, ParticleSystem *psys, int *sfra
*efra = min_ii((int)(part->end + part->lifetime + 1.0f), max_ii(scene->r.pefra, scene->r.efra));
}
+/* BVH tree balancing inside a mutex lock must be run in isolation. Balancing
+ * is multithreaded, and we do not want the current thread to start another task
+ * that may involve acquiring the same mutex lock that it is waiting for. */
+static void bvhtree_balance_isolated(void *userdata)
+{
+ BLI_bvhtree_balance((BVHTree *)userdata);
+}
+
/************************************************/
/* Effectors */
/************************************************/
@@ -1356,7 +1364,8 @@ static void psys_update_particle_bvhtree(ParticleSystem *psys, float cfra)
}
}
}
- BLI_bvhtree_balance(psys->bvhtree);
+
+ BLI_task_isolate(bvhtree_balance_isolated, psys->bvhtree);
psys->bvhtree_frame = cfra;