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
diff options
context:
space:
mode:
authorJeroen Bakker <jbakker>2020-06-15 16:22:40 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2020-06-15 16:22:57 +0300
commit3c717a631b56244f4a6c6dc30e8c353f318b35fe (patch)
tree2e014da09bcec7e02059c50b768a36ab57e7d633 /source/blender
parentec25084f5a404cbca4ceffd659d46b21c758522a (diff)
Fix Memory Leak introduced by Draw Manager Threading
The memory leak is noticeable when using custom bone shapes. When using custom bone shapes objects could be extracted twice. Where the second extraction can overwrite data created by the first extraction what causes the memory leak. Options that have been checked: 1. Use two task graphs phases. One for normal extraction (DST.task_graph) and the other one will handle extractions that require blocking threads. 2. Keep a list of all objects that needs extraction and only start extraction when all objects have been populated. The second would slow performance as the extraction only happens when all objects have been populated. In the future we might want to go for the second option when we have the capability to render multiple viewports with a single populate. As this design isn't clear this patch will implement the first option. Reviewed By: Clément Foucault Differential Revision: https://developer.blender.org/D7969
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/draw/engines/overlay/overlay_armature.c6
-rw-r--r--source/blender/draw/intern/draw_cache.c5
-rw-r--r--source/blender/draw/intern/draw_manager.c12
-rw-r--r--source/blender/draw/intern/draw_manager.h3
4 files changed, 20 insertions, 6 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_armature.c b/source/blender/draw/engines/overlay/overlay_armature.c
index 95fd918f8c1..481dec340ba 100644
--- a/source/blender/draw/engines/overlay/overlay_armature.c
+++ b/source/blender/draw/engines/overlay/overlay_armature.c
@@ -510,7 +510,7 @@ static void drw_shgroup_bone_envelope(ArmatureDrawContext *ctx,
/* Custom (geometry) */
extern void drw_batch_cache_validate(Object *custom);
-extern void drw_batch_cache_generate_requested(Object *custom);
+extern void drw_batch_cache_generate_requested_delayed(Object *custom);
BLI_INLINE DRWCallBuffer *custom_bone_instance_shgroup(ArmatureDrawContext *ctx,
DRWShadingGroup *grp,
@@ -567,7 +567,7 @@ static void drw_shgroup_bone_custom_solid(ArmatureDrawContext *ctx,
}
/* TODO(fclem) needs to be moved elsewhere. */
- drw_batch_cache_generate_requested(custom);
+ drw_batch_cache_generate_requested_delayed(custom);
}
static void drw_shgroup_bone_custom_wire(ArmatureDrawContext *ctx,
@@ -591,7 +591,7 @@ static void drw_shgroup_bone_custom_wire(ArmatureDrawContext *ctx,
}
/* TODO(fclem) needs to be moved elsewhere. */
- drw_batch_cache_generate_requested(custom);
+ drw_batch_cache_generate_requested_delayed(custom);
}
static void drw_shgroup_bone_custom_empty(ArmatureDrawContext *ctx,
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index c23ea3d7c82..af5b9cd05dd 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -3552,6 +3552,11 @@ void drw_batch_cache_generate_requested(Object *ob)
}
}
+void drw_batch_cache_generate_requested_delayed(Object *ob)
+{
+ BLI_gset_add(DST.delayed_extraction, ob);
+}
+
void DRW_batch_cache_free_old(Object *ob, int ctime)
{
struct Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob);
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 2ba766f4729..10ef8d9c4c8 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -132,11 +132,17 @@ static void drw_task_graph_init(void)
{
BLI_assert(DST.task_graph == NULL);
DST.task_graph = BLI_task_graph_create();
+ DST.delayed_extraction = BLI_gset_ptr_new(__func__);
}
static void drw_task_graph_deinit(void)
{
BLI_task_graph_work_and_wait(DST.task_graph);
+
+ BLI_gset_free(DST.delayed_extraction, (void (*)(void *key))drw_batch_cache_generate_requested);
+ DST.delayed_extraction = NULL;
+ BLI_task_graph_work_and_wait(DST.task_graph);
+
BLI_task_graph_free(DST.task_graph);
DST.task_graph = NULL;
}
@@ -1486,6 +1492,7 @@ void DRW_draw_render_loop_ex(struct Depsgraph *depsgraph,
drw_duplidata_free();
drw_engines_cache_finish();
+ drw_task_graph_deinit();
DRW_render_instance_buffer_finish();
#ifdef USE_PROFILE
@@ -1494,7 +1501,6 @@ void DRW_draw_render_loop_ex(struct Depsgraph *depsgraph,
#endif
}
- drw_task_graph_deinit();
DRW_stats_begin();
GPU_framebuffer_bind(DST.default_framebuffer);
@@ -2292,9 +2298,9 @@ static void drw_draw_depth_loop_imp(struct Depsgraph *depsgraph,
drw_duplidata_free();
drw_engines_cache_finish();
+ drw_task_graph_deinit();
DRW_render_instance_buffer_finish();
}
- drw_task_graph_deinit();
/* Start Drawing */
DRW_state_reset();
@@ -2411,6 +2417,7 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons
drw_engines_cache_finish();
+ drw_task_graph_deinit();
#if 0 /* This is a workaround to a nasty bug that seems to be a nasty driver bug. (See T69377) */
DRW_render_instance_buffer_finish();
#else
@@ -2419,7 +2426,6 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons
drw_resource_buffer_finish(DST.vmempool);
#endif
}
- drw_task_graph_deinit();
/* Start Drawing */
DRW_state_reset();
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index 6cae2a4f9f6..31a2dd7f0fe 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -548,6 +548,8 @@ typedef struct DRWManager {
#endif
struct TaskGraph *task_graph;
+ /* Contains list of objects that needs to be extracted from other objects. */
+ struct GSet *delayed_extraction;
/* ---------- Nothing after this point is cleared after use ----------- */
@@ -585,6 +587,7 @@ eDRWCommandType command_type_get(uint64_t *command_type_bits, int index);
void drw_batch_cache_validate(Object *ob);
void drw_batch_cache_generate_requested(struct Object *ob);
+void drw_batch_cache_generate_requested_delayed(Object *ob);
void drw_resource_buffer_finish(ViewportMemoryPool *vmempool);