diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-11-23 18:03:44 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-11-24 12:19:48 +0300 |
commit | a5d763a11ee46fff12d53e8cb21b3ab45fa2c64d (patch) | |
tree | 075d6fa83432ca1e5b6c56b6773756cd7ea71301 | |
parent | 0f5ef668daa041514376a98e2957248626e5649d (diff) |
Depsgraph: Use depsgraph to handle edit mode selection
This is crucial bit since batch cache is stored in the evaluated object,
meaning we can't tag it's hatch cache dirty from the notifier system.
Not easily at least. Better to leave this job to depsgraph, it knows
all the copies of data.
13 files changed, 90 insertions, 30 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 0826a5fa5eb..eb1c99e9d6a 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -206,6 +206,8 @@ void BKE_object_eval_cloth(const struct EvaluationContext *eval_ctx, void BKE_object_eval_update_shading(const struct EvaluationContext *eval_ctx, struct Object *object); +void BKE_object_data_select_update(const struct EvaluationContext *eval_ctx, + struct ID *object_data); void BKE_object_handle_data_update( const struct EvaluationContext *eval_ctx, diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c index 76b72f7a308..8da3e8136b3 100644 --- a/source/blender/blenkernel/intern/object_update.c +++ b/source/blender/blenkernel/intern/object_update.c @@ -396,3 +396,25 @@ void BKE_object_eval_update_shading(const EvaluationContext *UNUSED(eval_ctx), O BKE_mesh_batch_cache_dirty(object->data, BKE_MESH_BATCH_DIRTY_SHADING); } } + +void BKE_object_data_select_update(const EvaluationContext *UNUSED(eval_ctx), + struct ID *object_data) +{ + DEBUG_PRINT("%s on %s (%p)\n", __func__, object_data->name, object_data); + switch (GS(object_data->name)) { + case ID_ME: + BKE_mesh_batch_cache_dirty((Mesh *)object_data, + BKE_CURVE_BATCH_DIRTY_SELECT); + break; + case ID_CU: + BKE_curve_batch_cache_dirty((Curve *)object_data, + BKE_CURVE_BATCH_DIRTY_SELECT); + break; + case ID_LT: + BKE_lattice_batch_cache_dirty((struct Lattice *)object_data, + BKE_CURVE_BATCH_DIRTY_SELECT); + break; + default: + break; + } +} diff --git a/source/blender/depsgraph/DEG_depsgraph.h b/source/blender/depsgraph/DEG_depsgraph.h index b224303fb84..f007ceeed9e 100644 --- a/source/blender/depsgraph/DEG_depsgraph.h +++ b/source/blender/depsgraph/DEG_depsgraph.h @@ -165,6 +165,7 @@ enum { * Only parameters of material changed). */ DEG_TAG_SHADING_UPDATE = (1 << 9), + DEG_TAG_SELECT_UPDATE = (1 << 10), }; void DEG_id_tag_update(struct ID *id, int flag); void DEG_id_tag_update_ex(struct Main *bmain, struct ID *id, int flag); diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index 948e1410df5..0f68f317984 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -1060,6 +1060,14 @@ void DepsgraphNodeBuilder::build_obdata_geom(Object *object) DEG_NODE_TYPE_PARAMETERS, NULL, DEG_OPCODE_PARAMETERS_EVAL); + + /* Batch cache. */ + add_operation_node(obdata, + DEG_NODE_TYPE_BATCH_CACHE, + function_bind(BKE_object_data_select_update, + _1, + obdata_cow), + DEG_OPCODE_GEOMETRY_SELECT_UPDATE); } /* Cameras */ diff --git a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc index 618f4ced295..5111db08e03 100644 --- a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc +++ b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc @@ -383,6 +383,7 @@ static void deg_debug_graphviz_node(const DebugContext &ctx, case DEG_NODE_TYPE_LAYER_COLLECTIONS: case DEG_NODE_TYPE_EVAL_PARTICLES: case DEG_NODE_TYPE_COPY_ON_WRITE: + case DEG_NODE_TYPE_BATCH_CACHE: { ComponentDepsNode *comp_node = (ComponentDepsNode *)node; if (!comp_node->operations.empty()) { diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc index 58bae1f5cc6..968be5269c4 100644 --- a/source/blender/depsgraph/intern/depsgraph_tag.cc +++ b/source/blender/depsgraph/intern/depsgraph_tag.cc @@ -282,6 +282,18 @@ void id_tag_update_copy_on_write(Depsgraph *graph, IDDepsNode *id_node) cow_node->tag_update(graph); } +void id_tag_update_select_update(Depsgraph *graph, IDDepsNode *id_node) +{ + ComponentDepsNode *batch_cache_comp = + id_node->find_component(DEG_NODE_TYPE_BATCH_CACHE); + OperationDepsNode *select_update_node = + batch_cache_comp->find_operation(DEG_OPCODE_GEOMETRY_SELECT_UPDATE, + "", -1); + if (select_update_node != NULL) { + select_update_node->tag_update(graph); + } +} + void id_tag_update_ntree_special(Main *bmain, Depsgraph *graph, ID *id, int flag) { bNodeTree *ntree = NULL; @@ -345,6 +357,9 @@ void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag) if (flag & DEG_TAG_COPY_ON_WRITE) { id_tag_update_copy_on_write(graph, id_node); } + if (flag & DEG_TAG_SELECT_UPDATE) { + id_tag_update_select_update(graph, id_node); + } id_tag_update_ntree_special(bmain, graph, id, flag); } diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cc b/source/blender/depsgraph/intern/depsgraph_type_defines.cc index f5f1980557f..b6e58b13186 100644 --- a/source/blender/depsgraph/intern/depsgraph_type_defines.cc +++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cc @@ -136,6 +136,8 @@ static const char *stringify_opcode(eDepsOperation_Code opcode) STRINGIFY_OPCODE(PARTICLE_SYSTEM_EVAL); STRINGIFY_OPCODE(PARTICLE_SETTINGS_EVAL); STRINGIFY_OPCODE(PARTICLE_SETTINGS_RECALC_CLEAR); + /* Batch cache. */ + STRINGIFY_OPCODE(GEOMETRY_SELECT_UPDATE); /* Masks. */ STRINGIFY_OPCODE(MASK_ANIMATION); STRINGIFY_OPCODE(MASK_EVAL); diff --git a/source/blender/depsgraph/intern/depsgraph_types.h b/source/blender/depsgraph/intern/depsgraph_types.h index d7084a38a94..c73488bd434 100644 --- a/source/blender/depsgraph/intern/depsgraph_types.h +++ b/source/blender/depsgraph/intern/depsgraph_types.h @@ -147,6 +147,8 @@ typedef enum eDepsNode_Type { DEG_NODE_TYPE_SHADING_PARAMETERS, /* Cache Component */ DEG_NODE_TYPE_CACHE, + /* Batch Cache Component */ + DEG_NODE_TYPE_BATCH_CACHE, } eDepsNode_Type; /* Identifiers for common operations (as an enum). */ @@ -245,6 +247,9 @@ typedef enum eDepsOperation_Code { DEG_OPCODE_MATERIAL_UPDATE, DEG_OPCODE_WORLD_UPDATE, + /* Batch caches. -------------------------------------- */ + DEG_OPCODE_GEOMETRY_SELECT_UPDATE, + /* Masks. ------------------------------------------ */ DEG_OPCODE_MASK_ANIMATION, DEG_OPCODE_MASK_EVAL, diff --git a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc index cbe00a98719..832d7339904 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc @@ -209,6 +209,7 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph) case DEG_NODE_TYPE_PROXY: object->recalc |= OB_RECALC_DATA; break; + case DEG_NODE_TYPE_BATCH_CACHE: case DEG_NODE_TYPE_SHADING_PARAMETERS: break; } diff --git a/source/blender/depsgraph/intern/nodes/deg_node.cc b/source/blender/depsgraph/intern/nodes/deg_node.cc index 05138d90a7b..5f83d02082b 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node.cc @@ -291,6 +291,9 @@ void IDDepsNode::tag_update(Depsgraph *graph) /* Only do explicit particle settings tagging. */ do_component_tag = false; } + else if (comp_node->type == DEG_NODE_TYPE_BATCH_CACHE) { + do_component_tag = false; + } if (do_component_tag) { comp_node->tag_update(graph); } diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.cc b/source/blender/depsgraph/intern/nodes/deg_node_component.cc index aca25acd7c3..bba16316288 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_component.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node_component.cc @@ -161,7 +161,22 @@ string ComponentDepsNode::identifier() const OperationDepsNode *ComponentDepsNode::find_operation(OperationIDKey key) const { - OperationDepsNode *node = reinterpret_cast<OperationDepsNode *>(BLI_ghash_lookup(operations_map, &key)); + OperationDepsNode *node = NULL; + if (operations_map != NULL) { + node = (OperationDepsNode *)BLI_ghash_lookup(operations_map, &key); + } + else { + BLI_assert(key.name_tag == -1); + foreach (OperationDepsNode *op_node, operations) { + if (op_node->opcode == key.opcode && + STREQ(op_node->name, key.name)) + { + node = op_node; + break; + } + } + } + if (node != NULL) { return node; } @@ -339,6 +354,7 @@ static DepsNodeFactoryImpl<name ## ComponentDepsNode> DNTI_ ## NAME DEG_COMPONENT_DEFINE(Animation, ANIMATION); +DEG_COMPONENT_DEFINE(BatchCache, BATCH_CACHE); DEG_COMPONENT_DEFINE(Cache, CACHE); DEG_COMPONENT_DEFINE(CopyOnWrite, COPY_ON_WRITE); DEG_COMPONENT_DEFINE(Geometry, GEOMETRY); @@ -377,26 +393,21 @@ DEG_COMPONENT_DEFINE(Bone, BONE); void deg_register_component_depsnodes() { - deg_register_node_typeinfo(&DNTI_PARAMETERS); - deg_register_node_typeinfo(&DNTI_PROXY); deg_register_node_typeinfo(&DNTI_ANIMATION); - deg_register_node_typeinfo(&DNTI_TRANSFORM); - deg_register_node_typeinfo(&DNTI_GEOMETRY); - deg_register_node_typeinfo(&DNTI_SEQUENCER); - - deg_register_node_typeinfo(&DNTI_EVAL_POSE); deg_register_node_typeinfo(&DNTI_BONE); - + deg_register_node_typeinfo(&DNTI_CACHE); + deg_register_node_typeinfo(&DNTI_BATCH_CACHE); + deg_register_node_typeinfo(&DNTI_COPY_ON_WRITE); + deg_register_node_typeinfo(&DNTI_GEOMETRY); + deg_register_node_typeinfo(&DNTI_LAYER_COLLECTIONS); + deg_register_node_typeinfo(&DNTI_PARAMETERS); deg_register_node_typeinfo(&DNTI_EVAL_PARTICLES); - + deg_register_node_typeinfo(&DNTI_PROXY); + deg_register_node_typeinfo(&DNTI_EVAL_POSE); + deg_register_node_typeinfo(&DNTI_SEQUENCER); deg_register_node_typeinfo(&DNTI_SHADING); deg_register_node_typeinfo(&DNTI_SHADING_PARAMETERS); - - deg_register_node_typeinfo(&DNTI_CACHE); - - deg_register_node_typeinfo(&DNTI_LAYER_COLLECTIONS); - - deg_register_node_typeinfo(&DNTI_COPY_ON_WRITE); + deg_register_node_typeinfo(&DNTI_TRANSFORM); } } // namespace DEG diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.h b/source/blender/depsgraph/intern/nodes/deg_node_component.h index 3fef313b1e4..9be5388e69f 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_component.h +++ b/source/blender/depsgraph/intern/nodes/deg_node_component.h @@ -162,6 +162,7 @@ struct ComponentDepsNode : public DepsNode { } DEG_COMPONENT_DECLARE_GENERIC(Animation); +DEG_COMPONENT_DECLARE_GENERIC(BatchCache); DEG_COMPONENT_DECLARE_GENERIC(Cache); DEG_COMPONENT_DECLARE_GENERIC(CopyOnWrite); DEG_COMPONENT_DECLARE_GENERIC(Geometry); diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index c01eadce0fb..0dffab3511e 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -915,22 +915,10 @@ static void view3d_main_region_listener( case ND_SELECT: { WM_manipulatormap_tag_refresh(mmap); - if (scene->obedit) { Object *ob = scene->obedit; - switch (ob->type) { - case OB_MESH: - BKE_mesh_batch_cache_dirty(ob->data, BKE_CURVE_BATCH_DIRTY_SELECT); - break; - // case OB_FONT: /* handled by text_update_edited */ - case OB_CURVE: - case OB_SURF: - BKE_curve_batch_cache_dirty(ob->data, BKE_CURVE_BATCH_DIRTY_SELECT); - break; - case OB_LATTICE: - BKE_lattice_batch_cache_dirty(ob->data, BKE_CURVE_BATCH_DIRTY_SELECT); - break; - } + /* TODO(sergey): Notifiers shouldn't really be doing DEG tags. */ + DEG_id_tag_update((ID *)ob->data, DEG_TAG_SELECT_UPDATE); } ATTR_FALLTHROUGH; } |