Fix T65447: Mask doesn't update in compositor unless there's motion blur on
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 3 Jun 2019 12:47:44 +0000 (14:47 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 4 Jun 2019 07:41:33 +0000 (09:41 +0200)
This is probably just one of the related issues.

Root of the problem was that compositor job was using original scene and node
tree for compositing. It is not guaranteed to have all the evaluated data.

Switched compositor job to use it's own render-pipeline-like dependency graph
which has everything evaluated in it.

Reviewers: brecht

Reviewed By: brecht

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

source/blender/depsgraph/DEG_depsgraph_build.h
source/blender/depsgraph/intern/depsgraph_build.cc
source/blender/editors/space_node/node_edit.c

index 15abc0c0a641795cc9cf60194e1b454c075a9820..effcece6e00ee2b1177acd108cf6f348d8d6d5d3 100644 (file)
@@ -33,6 +33,7 @@ struct Depsgraph;
 
 /* ------------------------------------------------ */
 
+struct bNodeTree;
 struct CacheFile;
 struct Collection;
 struct CustomData_MeshMasks;
@@ -65,6 +66,17 @@ void DEG_graph_build_for_render_pipeline(struct Depsgraph *graph,
                                          struct Scene *scene,
                                          struct ViewLayer *view_layer);
 
+/* Builds minimal dependency graph for compositor preview.
+ *
+ * Note that compositor editor might have pinned node tree, which is different from scene's node
+ * tree.
+ */
+void DEG_graph_build_for_compositor_preview(struct Depsgraph *graph,
+                                            struct Main *bmain,
+                                            struct Scene *scene,
+                                            struct ViewLayer *view_layer,
+                                            struct bNodeTree *nodetree);
+
 /* Tag relations from the given graph for update. */
 void DEG_graph_tag_relations_update(struct Depsgraph *graph);
 
index 138b23888b4d41e825b440dfd5443155daff44c4..cf1ebccc6c6af14971c1105a6b97cf30200a9033 100644 (file)
@@ -315,6 +315,42 @@ void DEG_graph_build_for_render_pipeline(Depsgraph *graph,
   }
 }
 
+void DEG_graph_build_for_compositor_preview(Depsgraph *graph,
+                                            Main *bmain,
+                                            Scene *scene,
+                                            struct ViewLayer * /*view_layer*/,
+                                            bNodeTree *nodetree)
+{
+  double start_time = 0.0;
+  if (G.debug & (G_DEBUG_DEPSGRAPH_BUILD | G_DEBUG_DEPSGRAPH_TIME)) {
+    start_time = PIL_check_seconds_timer();
+  }
+  DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
+  /* Perform sanity checks. */
+  BLI_assert(deg_graph->scene == scene);
+  deg_graph->is_render_pipeline_depsgraph = true;
+  DEG::DepsgraphBuilderCache builder_cache;
+  /* Generate all the nodes in the graph first */
+  DEG::DepsgraphNodeBuilder node_builder(bmain, deg_graph, &builder_cache);
+  node_builder.begin_build();
+  node_builder.build_scene_render(scene);
+  node_builder.build_nodetree(nodetree);
+  node_builder.end_build();
+  /* Hook up relationships between operations - to determine evaluation
+   * order. */
+  DEG::DepsgraphRelationBuilder relation_builder(bmain, deg_graph, &builder_cache);
+  relation_builder.begin_build();
+  relation_builder.build_scene_render(scene);
+  relation_builder.build_nodetree(nodetree);
+  relation_builder.build_copy_on_write_relations();
+  /* Finalize building. */
+  graph_build_finalize_common(deg_graph, bmain);
+  /* Finish statistics. */
+  if (G.debug & (G_DEBUG_DEPSGRAPH_BUILD | G_DEBUG_DEPSGRAPH_TIME)) {
+    printf("Depsgraph built in %f seconds.\n", PIL_check_seconds_timer() - start_time);
+  }
+}
+
 /* Tag graph relations for update. */
 void DEG_graph_tag_relations_update(Depsgraph *graph)
 {
index d54a30047e6f6a722a641665e0b0783bfd25d932..7a6e37bfd4d296b02804d445afd258f0e493abca 100644 (file)
@@ -42,6 +42,8 @@
 #include "BKE_scene.h"
 
 #include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
 
 #include "RE_engine.h"
 #include "RE_pipeline.h"
@@ -79,14 +81,19 @@ enum {
 };
 
 typedef struct CompoJob {
+  /* Input parameters. */
   Main *bmain;
   Scene *scene;
+  ViewLayer *view_layer;
   bNodeTree *ntree;
+  int recalc_flags;
+  /* Evaluated state/ */
+  Depsgraph *compositor_depsgraph;
   bNodeTree *localtree;
+  /* Jon system integration. */
   const short *stop;
   short *do_update;
   float *progress;
-  int recalc_flags;
 } CompoJob;
 
 static void compo_tag_output_nodes(bNodeTree *nodetree, int recalc_flags)
@@ -182,6 +189,9 @@ static void compo_freejob(void *cjv)
   if (cj->localtree) {
     ntreeLocalMerge(cj->bmain, cj->localtree, cj->ntree);
   }
+  if (cj->compositor_depsgraph != NULL) {
+    DEG_graph_free(cj->compositor_depsgraph);
+  }
   MEM_freeN(cj);
 }
 
@@ -190,8 +200,19 @@ static void compo_freejob(void *cjv)
 static void compo_initjob(void *cjv)
 {
   CompoJob *cj = cjv;
+  Main *bmain = cj->bmain;
+  Scene *scene = cj->scene;
+  ViewLayer *view_layer = cj->view_layer;
+
+  cj->compositor_depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER);
+  DEG_graph_build_for_compositor_preview(
+      cj->compositor_depsgraph, bmain, scene, view_layer, cj->ntree);
+  DEG_evaluate_on_framechange(bmain, cj->compositor_depsgraph, CFRA);
+
+  bNodeTree *ntree_eval = (bNodeTree *)DEG_get_evaluated_id(cj->compositor_depsgraph,
+                                                            &cj->ntree->id);
 
-  cj->localtree = ntreeLocalize(cj->ntree);
+  cj->localtree = ntreeLocalize(ntree_eval);
 
   if (cj->recalc_flags) {
     compo_tag_output_nodes(cj->localtree, cj->recalc_flags);
@@ -283,6 +304,7 @@ void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, Scene
   CompoJob *cj;
   Main *bmain = CTX_data_main(C);
   Scene *scene = CTX_data_scene(C);
+  ViewLayer *view_layer = CTX_data_view_layer(C);
 
   /* to fix bug: [#32272] */
   if (G.is_rendering) {
@@ -307,6 +329,7 @@ void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, Scene
   /* customdata for preview thread */
   cj->bmain = bmain;
   cj->scene = scene;
+  cj->view_layer = view_layer;
   cj->ntree = nodetree;
   cj->recalc_flags = compo_get_recalc_flags(C);