Fix T51925: Eevee: Animated Eevee values slowdown
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 20 Jul 2017 14:13:08 +0000 (16:13 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 20 Jul 2017 15:48:36 +0000 (17:48 +0200)
Move material update from RNA callback to dependency graph.

source/blender/blenkernel/BKE_material.h
source/blender/blenkernel/BKE_world.h
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/world.c
source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
source/blender/depsgraph/intern/builder/deg_builder_relations.cc
source/blender/depsgraph/intern/depsgraph_type_defines.cc
source/blender/depsgraph/intern/depsgraph_types.h
source/blender/depsgraph/intern/nodes/deg_node.cc
source/blender/editors/render/render_update.c
source/blender/makesrna/intern/rna_nodetree.c

index 85c649bbd3de6f8f16b32f0f79085644062c0f2f..14820587200c8c3f48993de6e34d38fbb93e5d37 100644 (file)
@@ -118,6 +118,12 @@ void free_matcopybuf(void);
 void copy_matcopybuf(struct Material *ma);
 void paste_matcopybuf(struct Material *ma);
 
+/* Evaluation. */
+
+struct EvaluationContext;
+
+void BKE_material_eval(struct EvaluationContext *eval_ctx, struct Material *material);
+
 #ifdef __cplusplus
 }
 #endif
index 18ae61f76536d7cd305d1a25f125380499539d36..5175edcd3d6fc74bbc4e70d18efc91956550dd52 100644 (file)
@@ -43,5 +43,11 @@ struct World *BKE_world_copy(struct Main *bmain, const struct World *wrld);
 struct World *localize_world(struct World *wrld);
 void BKE_world_make_local(struct Main *bmain, struct World *wrld, const bool lib_local);
 
+/* Evaluation. */
+
+struct EvaluationContext;
+
+void BKE_world_eval(struct EvaluationContext *eval_ctx, struct World *world);
+
 #endif
 
index e7232322a3602d82dcd6b738d682a056ca258f9d..7038fb0ddcfe99d173904c363aff6c641dcc3d10 100644 (file)
@@ -1797,3 +1797,13 @@ bool BKE_object_material_edit_image_set(Object *ob, short mat_nr, Image *image)
        }
        return false;
 }
+
+void BKE_material_eval(struct EvaluationContext *UNUSED(eval_ctx), Material *material)
+{
+       if (G.debug & G_DEBUG_DEPSGRAPH) {
+               printf("%s on %s (%p)\n", __func__, material->id.name, material);
+       }
+       if ((BLI_listbase_is_empty(&material->gpumaterial) == false)) {
+               GPU_material_uniform_buffer_tag_dirty(&material->gpumaterial);
+       }
+}
index 363c36e644d318750d4c6eab4657975ab0734314..2adbdc83a36d60d62ba65067346fef05b62f1467 100644 (file)
@@ -175,3 +175,14 @@ void BKE_world_make_local(Main *bmain, World *wrld, const bool lib_local)
 {
        BKE_id_make_local_generic(bmain, &wrld->id, true, lib_local);
 }
+
+void BKE_world_eval(struct EvaluationContext *UNUSED(eval_ctx), World *world)
+{
+       if (G.debug & G_DEBUG_DEPSGRAPH) {
+               printf("%s on %s (%p)\n", __func__, world->id.name, world);
+       }
+       if (!BLI_listbase_is_empty(&world->gpumaterial)) {
+               world->update_flag = 1;
+               GPU_material_uniform_buffer_tag_dirty(&world->gpumaterial);
+       }
+}
index b7678bbd9a30d2c4f51b6e43715a0223a85e9e3d..5a552414cd321c1aadcc6cff1588d922b2a958f6 100644 (file)
@@ -604,11 +604,10 @@ void DepsgraphNodeBuilder::build_world(World *world)
        build_animdata(world_id);
 
        /* world itself */
-       add_component_node(world_id, DEG_NODE_TYPE_PARAMETERS);
        add_operation_node(world_id,
-                          DEG_NODE_TYPE_PARAMETERS,
-                          NULL,
-                          DEG_OPCODE_PARAMETERS_EVAL);
+                          DEG_NODE_TYPE_SHADING,
+                          function_bind(BKE_world_eval, _1, world),
+                          DEG_OPCODE_WORLD_UPDATE);
 
        /* textures */
        build_texture_stack(world->mtex);
@@ -1099,7 +1098,7 @@ void DepsgraphNodeBuilder::build_material(Material *ma)
 
        add_operation_node(ma_id,
                           DEG_NODE_TYPE_SHADING,
-                          NULL,
+                          function_bind(BKE_material_eval, _1, ma),
                           DEG_OPCODE_MATERIAL_UPDATE);
 
        /* material animation */
index 1bfb3bbb71d531434a34948eda62eabeccfae5ca..03cae598d245ee34da3a2153c8ac311094f393bf 100644 (file)
@@ -1136,7 +1136,7 @@ void DepsgraphRelationBuilder::build_world(World *world)
        if (world->nodetree != NULL) {
                build_nodetree(world->nodetree);
                ComponentKey ntree_key(&world->nodetree->id, DEG_NODE_TYPE_PARAMETERS);
-               ComponentKey world_key(world_id, DEG_NODE_TYPE_PARAMETERS);
+               ComponentKey world_key(world_id, DEG_NODE_TYPE_SHADING);
                add_relation(ntree_key, world_key, "NTree->World Parameters");
        }
 }
index b757d4ba37e5a57860d2655a9ddd5fc33aa2068d..be2630384ea838f835708267f0d58d72aab10324 100644 (file)
@@ -142,6 +142,7 @@ static const char *stringify_opcode(eDepsOperation_Code opcode)
                /* Shading. */
                STRINGIFY_OPCODE(SHADING);
                STRINGIFY_OPCODE(MATERIAL_UPDATE);
+               STRINGIFY_OPCODE(WORLD_UPDATE);
 
                case DEG_NUM_OPCODES: return "SpecialCase";
 #undef STRINGIFY_OPCODE
index 4371483193bfa6725495e5285152d770851deafc..af18abdb6845838ad070c9d0d4483c7592b56f25 100644 (file)
@@ -225,6 +225,7 @@ typedef enum eDepsOperation_Code {
        /* Shading. ------------------------------------------- */
        DEG_OPCODE_SHADING,
        DEG_OPCODE_MATERIAL_UPDATE,
+       DEG_OPCODE_WORLD_UPDATE,
 
        DEG_NUM_OPCODES,
 } eDepsOperation_Code;
index f53f3c96800a60d696245f19843b92f2c4a57be7..29f0a3a05baee647457ad4443fdc4d7cb34a52d3 100644 (file)
@@ -255,7 +255,9 @@ void IDDepsNode::tag_update(Depsgraph *graph)
                        /* TODO(sergey): For until we properly handle granular flags for DEG_id_tag_update()
                         * we skip flushing here to keep Luca happy.
                         */
-                       if (GS(id_orig->name) != ID_MA) {
+                       if (GS(id_orig->name) != ID_MA &&
+                           GS(id_orig->name) != ID_WO)
+                       {
                                do_component_tag = false;
                        }
                }
index 42d914b1a71bcf70153e8d60f48fe86a00d17656..07b445fa6eb9f3b01d10cfe17ae53ddd53c965e6 100644 (file)
@@ -298,10 +298,6 @@ static void material_changed(Main *bmain, Material *ma)
        /* icons */
        BKE_icon_changed(BKE_icon_id_ensure(&ma->id));
 
-       /* glsl */
-       if (ma->gpumaterial.first)
-               GPU_material_free(&ma->gpumaterial);
-
        /* find node materials using this */
        for (parent = bmain->mat.first; parent; parent = parent->id.next) {
                if (parent->use_nodes && parent->nodetree && nodes_use_material(parent->nodetree, ma)) {
@@ -478,13 +474,6 @@ static void world_changed(Main *UNUSED(bmain), World *wo)
 
        /* XXX temporary flag waiting for depsgraph proper tagging */
        wo->update_flag = 1;
-       
-       /* glsl */
-       if (defmaterial.gpumaterial.first)
-               GPU_material_free(&defmaterial.gpumaterial);
-       
-       if (wo->gpumaterial.first)
-               GPU_material_free(&wo->gpumaterial);
 }
 
 static void image_changed(Main *bmain, Image *ima)
index 5ecfc495cd42689f3f0615dedf96873c16918bf2..3c5989c79cdf03c04a08b625141a32959b28148d 100644 (file)
@@ -66,6 +66,8 @@
 
 #include "NOD_composite.h"
 
+#include "DEG_depsgraph.h"
+
 EnumPropertyItem rna_enum_node_socket_in_out_items[] = {
        { SOCK_IN, "IN", 0, "Input", "" },
        { SOCK_OUT, "OUT", 0, "Output", "" },
@@ -2277,28 +2279,18 @@ static void rna_NodeSocketStandard_vector_range(PointerRNA *ptr, float *min, flo
 
 static void rna_NodeSocket_value_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
-       /* XXX: TODO (sergey/dalai) move this to depsgraph. */
        bNodeTree *ntree = (bNodeTree *)ptr->id.data;
        if (ntree->type == NTREE_SHADER) {
                FOREACH_NODETREE(bmain, tntree, id) {
-                       if (GS(id->name) == ID_WO) {
-                               World *wo = (World *)id;
-                               if ((BLI_listbase_is_empty(&wo->gpumaterial) == false) &&
-                                   ntreeHasTree(tntree, ntree))
-                               {
-                                       wo->update_flag = 1;
-                                       GPU_material_uniform_buffer_tag_dirty(&wo->gpumaterial);
+                       switch (GS(id->name)) {
+                               case ID_WO:
+                                       DEG_id_tag_update_ex(bmain, id, 0);
                                        WM_main_add_notifier(NC_MATERIAL | ND_SHADING, NULL);
-                               }
-                       }
-                       else if (GS(id->name) == ID_MA) {
-                               Material *ma = (Material *)id;
-                               if ((BLI_listbase_is_empty(&ma->gpumaterial) == false) &&
-                                   ntreeHasTree(tntree, ntree))
-                               {
-                                       GPU_material_uniform_buffer_tag_dirty(&ma->gpumaterial);
-                                       WM_main_add_notifier(NC_MATERIAL | ND_SHADING, ma);
-                               }
+                                       break;
+                               case ID_MA:
+                                       DEG_id_tag_update_ex(bmain, id, 0);
+                                       WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id);
+                                       break;
                        }
                } FOREACH_NODETREE_END
        }