Depsgraph: Fix missing updates when changing node tree topology
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 29 Aug 2017 09:26:57 +0000 (11:26 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 29 Aug 2017 09:32:25 +0000 (11:32 +0200)
There were two issues here:

1. material_update did not do anything, because DEG_id_tag_update was storing
   update tags in original IDs, which had nothing evaluated. Even more, material
   update should have been called with evaluated version of material, Solved
   this by copying update tag from original ID to a copied one.

   However, perhaps DEG_id_tag_update should tag both original and copied ID,
   so updates are never gets lots if some depsgraph is not visible.

2. Tagging material for update should ensure it's copied version of node tree is
   up to date, otherwise material will still use old node tree.

This solves missing material updates when changing topology. Tweaking values is
still broken, because of GPUMaterial using pointer to original node's socket
value, which gets broken after copy-on-write of the node tree (pointers of nodes
are changing).

source/blender/depsgraph/intern/depsgraph_tag.cc
source/blender/depsgraph/intern/eval/deg_eval_flush.cc

index 46557b93aa52294771914100d14eb04ce99a6b68..9f2081c816903a88b2be87273ad8c64deec48c71 100644 (file)
@@ -95,6 +95,8 @@ void lib_id_recalc_data_tag(Main *bmain, ID *id)
 
 namespace {
 
+void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag);
+
 void lib_id_recalc_tag_flag(Main *bmain, ID *id, int flag)
 {
        /* This bit of code ensures legacy object->recalc flags are still filled in
@@ -270,6 +272,25 @@ void id_tag_update_copy_on_write(Depsgraph *graph, IDDepsNode *id_node)
 }
 #endif
 
+void id_tag_update_ntree_special(Main *bmain, Depsgraph *graph, ID *id, int flag)
+{
+       bNodeTree *ntree = NULL;
+       switch (GS(id->name)) {
+               case ID_MA:
+                       ntree = ((Material *)id)->nodetree;
+                       break;
+               default:
+                       break;
+       }
+       if (ntree == NULL) {
+               return;
+       }
+       IDDepsNode *id_node = graph->find_id_node(&ntree->id);
+       if (id_node != NULL) {
+               deg_graph_id_tag_update(bmain, graph, id_node->id_orig, flag);
+       }
+}
+
 void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag)
 {
        Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
@@ -283,6 +304,7 @@ void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag)
        /* Tag components based on flags. */
        if (flag == 0) {
                id_tag_update_special_zero_flag(graph, id_node);
+               id_tag_update_ntree_special(bmain, graph, id, flag);
                return;
        }
        if (flag & OB_RECALC_OB) {
@@ -315,6 +337,7 @@ void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag)
                id_tag_update_copy_on_write(graph, id_node);
        }
 #endif
+       id_tag_update_ntree_special(bmain, graph, id, flag);
 }
 
 void deg_id_tag_update(Main *bmain, ID *id, int flag)
index 861e7ec2650c4db18b439711748861261c1649d8..3eaa9cdaa173d04fa3d33335ba0f3f94d6a8febf 100644 (file)
@@ -50,6 +50,7 @@ extern "C" {
 #include "intern/nodes/deg_node_operation.h"
 
 #include "intern/depsgraph_intern.h"
+#include "intern/eval/deg_eval_copy_on_write.h"
 #include "util/deg_util_foreach.h"
 
 namespace DEG {
@@ -122,12 +123,20 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph)
                        IDDepsNode *id_node = comp_node->owner;
 
                        /* TODO(sergey): Do we need to pass original or evaluated ID here? */
-                       ID *id = id_node->id_orig;
+                       ID *id_orig = id_node->id_orig;
+                       ID *id_cow = id_node->id_cow;
                        if (id_node->done == 0) {
-                               deg_editors_id_update(bmain, id);
-                               lib_id_recalc_tag(bmain, id);
+                               /* Copy tag from original data to CoW storage.
+                                * This is because DEG_id_tag_update() sets tags on original
+                                * data.
+                                */
+                               id_cow->tag |= (id_orig->tag & LIB_TAG_ID_RECALC_ALL);
+                               if (deg_copy_on_write_is_expanded(id_cow)) {
+                                       deg_editors_id_update(bmain, id_cow);
+                               }
+                               lib_id_recalc_tag(bmain, id_orig);
                                /* TODO(sergey): For until we've got proper data nodes in the graph. */
-                               lib_id_recalc_data_tag(bmain, id);
+                               lib_id_recalc_data_tag(bmain, id_orig);
 
 #ifdef WITH_COPY_ON_WRITE
                                /* Currently this is needed to get ob->mesh to be replaced with
@@ -143,8 +152,8 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph)
 
                        if (comp_node->done == 0) {
                                Object *object = NULL;
-                               if (GS(id->name) == ID_OB) {
-                                       object = (Object *)id;
+                               if (GS(id_orig->name) == ID_OB) {
+                                       object = (Object *)id_orig;
                                        if (id_node->done == 0) {
                                                ++num_flushed_objects;
                                        }