diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-07-20 17:13:08 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-07-20 18:48:36 +0300 |
commit | dfcb568c165913a15679f6b55b0b76e49a747a2e (patch) | |
tree | 548a0e39e6e22020be213a7fa6311e0d5f3d1901 | |
parent | 177a8f6dab191db2756cc247565458b07d5b6005 (diff) |
Fix T51925: Eevee: Animated Eevee values slowdown
Move material update from RNA callback to dependency graph.
-rw-r--r-- | source/blender/blenkernel/BKE_material.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_world.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/world.c | 11 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/builder/deg_builder_nodes.cc | 9 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/builder/deg_builder_relations.cc | 2 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/depsgraph_type_defines.cc | 1 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/depsgraph_types.h | 1 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/nodes/deg_node.cc | 4 | ||||
-rw-r--r-- | source/blender/editors/render/render_update.c | 11 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 28 |
11 files changed, 53 insertions, 36 deletions
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index 85c649bbd3d..14820587200 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -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 diff --git a/source/blender/blenkernel/BKE_world.h b/source/blender/blenkernel/BKE_world.h index 18ae61f7653..5175edcd3d6 100644 --- a/source/blender/blenkernel/BKE_world.h +++ b/source/blender/blenkernel/BKE_world.h @@ -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 diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index e7232322a36..7038fb0ddcf 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -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); + } +} diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index 363c36e644d..2adbdc83a36 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -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); + } +} diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index b7678bbd9a3..5a552414cd3 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -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 */ diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 1bfb3bbb71d..03cae598d24 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -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"); } } diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cc b/source/blender/depsgraph/intern/depsgraph_type_defines.cc index b757d4ba37e..be2630384ea 100644 --- a/source/blender/depsgraph/intern/depsgraph_type_defines.cc +++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cc @@ -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 diff --git a/source/blender/depsgraph/intern/depsgraph_types.h b/source/blender/depsgraph/intern/depsgraph_types.h index 4371483193b..af18abdb684 100644 --- a/source/blender/depsgraph/intern/depsgraph_types.h +++ b/source/blender/depsgraph/intern/depsgraph_types.h @@ -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; diff --git a/source/blender/depsgraph/intern/nodes/deg_node.cc b/source/blender/depsgraph/intern/nodes/deg_node.cc index f53f3c96800..29f0a3a05ba 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node.cc @@ -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; } } diff --git a/source/blender/editors/render/render_update.c b/source/blender/editors/render/render_update.c index 42d914b1a71..07b445fa6eb 100644 --- a/source/blender/editors/render/render_update.c +++ b/source/blender/editors/render/render_update.c @@ -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) diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 5ecfc495cd4..3c5989c79cd 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -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 } |