diff --git a/source/blender/blenkernel/BKE_scene_runtime.hh b/source/blender/blenkernel/BKE_scene_runtime.hh index 87b2faf7552..4d52cfe63fc 100644 --- a/source/blender/blenkernel/BKE_scene_runtime.hh +++ b/source/blender/blenkernel/BKE_scene_runtime.hh @@ -8,13 +8,20 @@ #include "BLI_timeit.hh" #include "BLI_utility_mixins.hh" +struct Depsgraph; + namespace blender::bke { /* Runtime data specific to the compositing trees. */ -struct CompositorRuntime { +class CompositorRuntime { + public: /* Per-node instance total execution time for the corresponding node, during the last tree * evaluation. */ Map per_node_execution_time; + + Depsgraph *preview_depsgraph = nullptr; + + ~CompositorRuntime(); }; class SceneRuntime : NonCopyable, NonMovable { diff --git a/source/blender/blenkernel/intern/scene.cc b/source/blender/blenkernel/intern/scene.cc index c79ba46b9a1..3032e076591 100644 --- a/source/blender/blenkernel/intern/scene.cc +++ b/source/blender/blenkernel/intern/scene.cc @@ -107,8 +107,16 @@ #include "bmesh.hh" +using blender::bke::CompositorRuntime; using blender::bke::SceneRuntime; +CompositorRuntime::~CompositorRuntime() +{ + if (preview_depsgraph) { + DEG_graph_free(preview_depsgraph); + } +} + CurveMapping *BKE_sculpt_default_cavity_curve() { diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc index 2f947089d39..d862d0fa231 100644 --- a/source/blender/editors/space_node/node_edit.cc +++ b/source/blender/editors/space_node/node_edit.cc @@ -219,9 +219,6 @@ static void compo_freejob(void *cjv) bke::ntreeFreeTree(cj->localtree); MEM_freeN(cj->localtree); } - if (cj->compositor_depsgraph != nullptr) { - DEG_graph_free(cj->compositor_depsgraph); - } MEM_delete(cj); } @@ -235,8 +232,15 @@ static void compo_initjob(void *cjv) Scene *scene = cj->scene; ViewLayer *view_layer = cj->view_layer; - cj->compositor_depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_RENDER); - DEG_debug_name_set(cj->compositor_depsgraph, "COMPOSITOR"); + bke::CompositorRuntime &compositor_runtime = scene->runtime->compositor; + + if (!compositor_runtime.preview_depsgraph) { + compositor_runtime.preview_depsgraph = DEG_graph_new( + bmain, scene, view_layer, DAG_EVAL_RENDER); + DEG_debug_name_set(compositor_runtime.preview_depsgraph, "COMPOSITOR"); + } + + cj->compositor_depsgraph = compositor_runtime.preview_depsgraph; DEG_graph_build_for_compositor_preview(cj->compositor_depsgraph, cj->ntree); /* NOTE: Don't update animation to preserve unkeyed changes, this means can not use