Commit: 83ea224a7fa2261ded92b5a341c9237855148963
Author: Sergey Sharybin
Date:   Tue Aug 29 11:26:57 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB83ea224a7fa2261ded92b5a341c9237855148963

Depsgraph: Fix missing updates when changing node tree topology

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).

===================================================================

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

===================================================================

diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc 
b/source/blender/depsgraph/intern/depsgraph_tag.cc
index 46557b93aa5..9f2081c8169 100644
--- a/source/blender/depsgraph/intern/depsgraph_tag.cc
+++ b/source/blender/depsgraph/intern/depsgraph_tag.cc
@@ -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)
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc 
b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
index 861e7ec2650..3eaa9cdaa17 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
@@ -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;
                                        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to