Depsgraph: Use BLI::Map in more places
Reviewers: sergey Differential Revision: https://developer.blender.org/D7519
This commit is contained in:
parent
9c2715ffda
commit
b21a3e7702
Notes:
blender-bot
2024-04-29 13:07:32 +02:00
Referenced by commit 5461c7526a
, Depsgraph: Fix memory leak
|
@ -157,10 +157,9 @@ void deg_graph_build_flush_visibility(Depsgraph *graph)
|
|||
|
||||
BLI_Stack *stack = BLI_stack_new(sizeof(OperationNode *), "DEG flush layers stack");
|
||||
for (IDNode *id_node : graph->id_nodes) {
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, id_node->components) {
|
||||
for (ComponentNode *comp_node : id_node->components.values()) {
|
||||
comp_node->affects_directly_visible |= id_node->is_directly_visible;
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
}
|
||||
for (OperationNode *op_node : graph->operations) {
|
||||
op_node->custom_flags = 0;
|
||||
|
|
|
@ -120,20 +120,6 @@ extern "C" {
|
|||
|
||||
namespace DEG {
|
||||
|
||||
namespace {
|
||||
|
||||
void free_copy_on_write_datablock(void *id_info_v)
|
||||
{
|
||||
DepsgraphNodeBuilder::IDInfo *id_info = (DepsgraphNodeBuilder::IDInfo *)id_info_v;
|
||||
if (id_info->id_cow != nullptr) {
|
||||
deg_free_copy_on_write_datablock(id_info->id_cow);
|
||||
MEM_freeN(id_info->id_cow);
|
||||
}
|
||||
MEM_freeN(id_info);
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* ************ */
|
||||
/* Node Builder */
|
||||
|
||||
|
@ -147,15 +133,18 @@ DepsgraphNodeBuilder::DepsgraphNodeBuilder(Main *bmain,
|
|||
view_layer_(nullptr),
|
||||
view_layer_index_(-1),
|
||||
collection_(nullptr),
|
||||
is_parent_collection_visible_(true),
|
||||
id_info_hash_(nullptr)
|
||||
is_parent_collection_visible_(true)
|
||||
{
|
||||
}
|
||||
|
||||
DepsgraphNodeBuilder::~DepsgraphNodeBuilder()
|
||||
{
|
||||
if (id_info_hash_ != nullptr) {
|
||||
BLI_ghash_free(id_info_hash_, nullptr, free_copy_on_write_datablock);
|
||||
for (IDInfo *id_info : id_info_hash_.values()) {
|
||||
if (id_info->id_cow != nullptr) {
|
||||
deg_free_copy_on_write_datablock(id_info->id_cow);
|
||||
MEM_freeN(id_info->id_cow);
|
||||
}
|
||||
MEM_freeN(id_info);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,7 +155,7 @@ IDNode *DepsgraphNodeBuilder::add_id_node(ID *id)
|
|||
IDComponentsMask previously_visible_components_mask = 0;
|
||||
uint32_t previous_eval_flags = 0;
|
||||
DEGCustomDataMeshMasks previous_customdata_masks;
|
||||
IDInfo *id_info = (IDInfo *)BLI_ghash_lookup(id_info_hash_, id);
|
||||
IDInfo *id_info = id_info_hash_.lookup_default(id, nullptr);
|
||||
if (id_info != nullptr) {
|
||||
id_cow = id_info->id_cow;
|
||||
previously_visible_components_mask = id_info->previously_visible_components_mask;
|
||||
|
@ -182,7 +171,7 @@ IDNode *DepsgraphNodeBuilder::add_id_node(ID *id)
|
|||
/* Currently all ID nodes are supposed to have copy-on-write logic.
|
||||
*
|
||||
* NOTE: Zero number of components indicates that ID node was just created. */
|
||||
if (BLI_ghash_len(id_node->components) == 0) {
|
||||
if (id_node->components.is_empty()) {
|
||||
ComponentNode *comp_cow = id_node->add_component(NodeType::COPY_ON_WRITE);
|
||||
OperationNode *op_cow = comp_cow->add_operation(
|
||||
function_bind(deg_evaluate_copy_on_write, _1, id_node),
|
||||
|
@ -320,7 +309,6 @@ void DepsgraphNodeBuilder::begin_build()
|
|||
{
|
||||
/* Store existing copy-on-write versions of datablock, so we can re-use
|
||||
* them for new ID nodes. */
|
||||
id_info_hash_ = BLI_ghash_ptr_new("Depsgraph id hash");
|
||||
for (IDNode *id_node : graph_->id_nodes) {
|
||||
/* It is possible that the ID does not need to have CoW version in which case id_cow is the
|
||||
* same as id_orig. Additionally, such ID might have been removed, which makes the check
|
||||
|
@ -344,7 +332,7 @@ void DepsgraphNodeBuilder::begin_build()
|
|||
id_info->previously_visible_components_mask = id_node->visible_components_mask;
|
||||
id_info->previous_eval_flags = id_node->eval_flags;
|
||||
id_info->previous_customdata_masks = id_node->customdata_masks;
|
||||
BLI_ghash_insert(id_info_hash_, id_node->id_orig, id_info);
|
||||
id_info_hash_.add_new(id_node->id_orig, id_info);
|
||||
id_node->id_cow = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -277,7 +277,7 @@ class DepsgraphNodeBuilder : public DepsgraphBuilder {
|
|||
bool is_parent_collection_visible_;
|
||||
|
||||
/* Indexed by original ID, values are IDInfo. */
|
||||
GHash *id_info_hash_;
|
||||
Map<const ID *, IDInfo *> id_info_hash_;
|
||||
|
||||
/* Set of IDs which were already build. Makes it easier to keep track of
|
||||
* what was already built and what was not. */
|
||||
|
|
|
@ -2632,7 +2632,7 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDNode *id_node)
|
|||
Node *node_cow = find_node(copy_on_write_key);
|
||||
OperationNode *op_cow = node_cow->get_exit_operation();
|
||||
/* Plug any other components to this one. */
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, id_node->components) {
|
||||
for (ComponentNode *comp_node : id_node->components.values()) {
|
||||
if (comp_node->type == NodeType::COPY_ON_WRITE) {
|
||||
/* Copy-on-write component never depends on itself. */
|
||||
continue;
|
||||
|
@ -2709,7 +2709,6 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDNode *id_node)
|
|||
* evaluation step needs geometry, it will have transitive dependency
|
||||
* to Mesh copy-on-write already. */
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
/* TODO(sergey): This solves crash for now, but causes too many
|
||||
* updates potentially. */
|
||||
if (GS(id_orig->name) == ID_OB) {
|
||||
|
|
|
@ -407,15 +407,14 @@ static void deg_debug_graphviz_node(const DebugContext &ctx, const Node *node)
|
|||
switch (node->type) {
|
||||
case NodeType::ID_REF: {
|
||||
const IDNode *id_node = (const IDNode *)node;
|
||||
if (BLI_ghash_len(id_node->components) == 0) {
|
||||
if (id_node->components.is_empty()) {
|
||||
deg_debug_graphviz_node_single(ctx, node);
|
||||
}
|
||||
else {
|
||||
deg_debug_graphviz_node_cluster_begin(ctx, node);
|
||||
GHASH_FOREACH_BEGIN (const ComponentNode *, comp, id_node->components) {
|
||||
for (const ComponentNode *comp : id_node->components.values()) {
|
||||
deg_debug_graphviz_node(ctx, comp);
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
deg_debug_graphviz_node_cluster_end(ctx);
|
||||
}
|
||||
break;
|
||||
|
@ -472,7 +471,7 @@ static bool deg_debug_graphviz_is_cluster(const Node *node)
|
|||
switch (node->type) {
|
||||
case NodeType::ID_REF: {
|
||||
const IDNode *id_node = (const IDNode *)node;
|
||||
return BLI_ghash_len(id_node->components) > 0;
|
||||
return !id_node->components.is_empty();
|
||||
}
|
||||
case NodeType::PARAMETERS:
|
||||
case NodeType::ANIMATION:
|
||||
|
@ -568,12 +567,11 @@ static void deg_debug_graphviz_graph_nodes(const DebugContext &ctx, const Depsgr
|
|||
static void deg_debug_graphviz_graph_relations(const DebugContext &ctx, const Depsgraph *graph)
|
||||
{
|
||||
for (IDNode *id_node : graph->id_nodes) {
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, id_node->components) {
|
||||
for (ComponentNode *comp_node : id_node->components.values()) {
|
||||
for (OperationNode *op_node : comp_node->operations) {
|
||||
deg_debug_graphviz_node_relations(ctx, op_node);
|
||||
}
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
}
|
||||
|
||||
TimeSourceNode *time_source = graph->find_time_source();
|
||||
|
|
|
@ -81,7 +81,6 @@ Depsgraph::Depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluati
|
|||
is_render_pipeline_depsgraph(false)
|
||||
{
|
||||
BLI_spin_init(&lock);
|
||||
id_hash = BLI_ghash_ptr_new("Depsgraph id hash");
|
||||
entry_tags = BLI_gset_ptr_new("Depsgraph entry_tags");
|
||||
memset(id_type_updated, 0, sizeof(id_type_updated));
|
||||
memset(id_type_exist, 0, sizeof(id_type_exist));
|
||||
|
@ -91,7 +90,6 @@ Depsgraph::Depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluati
|
|||
Depsgraph::~Depsgraph()
|
||||
{
|
||||
clear_id_nodes();
|
||||
BLI_ghash_free(id_hash, nullptr, nullptr);
|
||||
BLI_gset_free(entry_tags, nullptr);
|
||||
if (time_source != nullptr) {
|
||||
OBJECT_GUARDED_DELETE(time_source, TimeSourceNode);
|
||||
|
@ -117,7 +115,7 @@ TimeSourceNode *Depsgraph::find_time_source() const
|
|||
|
||||
IDNode *Depsgraph::find_id_node(const ID *id) const
|
||||
{
|
||||
return reinterpret_cast<IDNode *>(BLI_ghash_lookup(id_hash, id));
|
||||
return id_hash.lookup_default(id, nullptr);
|
||||
}
|
||||
|
||||
IDNode *Depsgraph::add_id_node(ID *id, ID *id_cow_hint)
|
||||
|
@ -132,7 +130,7 @@ IDNode *Depsgraph::add_id_node(ID *id, ID *id_cow_hint)
|
|||
*
|
||||
* NOTE: We address ID nodes by the original ID pointer they are
|
||||
* referencing to. */
|
||||
BLI_ghash_insert(id_hash, id, id_node);
|
||||
id_hash.add_new(id, id_node);
|
||||
id_nodes.push_back(id_node);
|
||||
|
||||
id_type_exist[BKE_idtype_idcode_to_index(GS(id->name))] = 1;
|
||||
|
@ -170,7 +168,7 @@ void Depsgraph::clear_id_nodes()
|
|||
OBJECT_GUARDED_DELETE(id_node, IDNode);
|
||||
}
|
||||
/* Clear containers. */
|
||||
BLI_ghash_clear(id_hash, nullptr, nullptr);
|
||||
id_hash.clear();
|
||||
id_nodes.clear();
|
||||
/* Clear physics relation caches. */
|
||||
clear_physics_relations(this);
|
||||
|
|
|
@ -97,7 +97,7 @@ struct Depsgraph {
|
|||
|
||||
/* <ID : IDNode> mapping from ID blocks to nodes representing these
|
||||
* blocks, used for quick lookups. */
|
||||
GHash *id_hash;
|
||||
Map<const ID *, IDNode *> id_hash;
|
||||
|
||||
/* Ordered list of ID nodes, order matches ID allocation order.
|
||||
* Used for faster iteration, especially for areas which are critical to
|
||||
|
@ -169,7 +169,7 @@ struct Depsgraph {
|
|||
|
||||
/* Cached list of colliders/effectors for collections and the scene
|
||||
* created along with relations, for fast lookup during evaluation. */
|
||||
GHash *physics_relations[DEG_PHYSICS_RELATIONS_NUM];
|
||||
Map<const ID *, ListBase *> *physics_relations[DEG_PHYSICS_RELATIONS_NUM];
|
||||
};
|
||||
|
||||
} // namespace DEG
|
||||
|
|
|
@ -224,13 +224,12 @@ void DEG_stats_simple(const Depsgraph *graph,
|
|||
|
||||
for (DEG::IDNode *id_node : deg_graph->id_nodes) {
|
||||
tot_outer++;
|
||||
GHASH_FOREACH_BEGIN (DEG::ComponentNode *, comp_node, id_node->components) {
|
||||
for (DEG::ComponentNode *comp_node : id_node->components.values()) {
|
||||
tot_outer++;
|
||||
for (DEG::OperationNode *op_node : comp_node->operations) {
|
||||
tot_rels += op_node->inlinks.size();
|
||||
}
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
}
|
||||
|
||||
DEG::TimeSourceNode *time_source = deg_graph->find_time_source();
|
||||
|
|
|
@ -72,8 +72,8 @@ ListBase *DEG_get_effector_relations(const Depsgraph *graph, Collection *collect
|
|||
}
|
||||
|
||||
ID *collection_orig = DEG_get_original_id(&collection->id);
|
||||
return (ListBase *)BLI_ghash_lookup(deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR],
|
||||
collection_orig);
|
||||
return deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR]->lookup_default(collection_orig,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
ListBase *DEG_get_collision_relations(const Depsgraph *graph,
|
||||
|
@ -86,7 +86,7 @@ ListBase *DEG_get_collision_relations(const Depsgraph *graph,
|
|||
return nullptr;
|
||||
}
|
||||
ID *collection_orig = DEG_get_original_id(&collection->id);
|
||||
return (ListBase *)BLI_ghash_lookup(deg_graph->physics_relations[type], collection_orig);
|
||||
return deg_graph->physics_relations[type]->lookup_default(collection_orig, nullptr);
|
||||
}
|
||||
|
||||
/********************** Depsgraph Building API ************************/
|
||||
|
@ -165,19 +165,15 @@ namespace DEG {
|
|||
|
||||
ListBase *build_effector_relations(Depsgraph *graph, Collection *collection)
|
||||
{
|
||||
GHash *hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR];
|
||||
Map<const ID *, ListBase *> *hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR];
|
||||
if (hash == nullptr) {
|
||||
graph->physics_relations[DEG_PHYSICS_EFFECTOR] = BLI_ghash_ptr_new(
|
||||
"Depsgraph physics relations hash");
|
||||
graph->physics_relations[DEG_PHYSICS_EFFECTOR] = new Map<const ID *, ListBase *>();
|
||||
hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR];
|
||||
}
|
||||
ListBase *relations = reinterpret_cast<ListBase *>(BLI_ghash_lookup(hash, collection));
|
||||
if (relations == nullptr) {
|
||||
return hash->lookup_or_add(&collection->id, [&]() {
|
||||
::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph *>(graph);
|
||||
relations = BKE_effector_relations_create(depsgraph, graph->view_layer, collection);
|
||||
BLI_ghash_insert(hash, &collection->id, relations);
|
||||
}
|
||||
return relations;
|
||||
return BKE_effector_relations_create(depsgraph, graph->view_layer, collection);
|
||||
});
|
||||
}
|
||||
|
||||
ListBase *build_collision_relations(Depsgraph *graph,
|
||||
|
@ -185,48 +181,38 @@ ListBase *build_collision_relations(Depsgraph *graph,
|
|||
unsigned int modifier_type)
|
||||
{
|
||||
const ePhysicsRelationType type = modifier_to_relation_type(modifier_type);
|
||||
GHash *hash = graph->physics_relations[type];
|
||||
Map<const ID *, ListBase *> *hash = graph->physics_relations[type];
|
||||
if (hash == nullptr) {
|
||||
graph->physics_relations[type] = BLI_ghash_ptr_new("Depsgraph physics relations hash");
|
||||
graph->physics_relations[type] = new Map<const ID *, ListBase *>();
|
||||
hash = graph->physics_relations[type];
|
||||
}
|
||||
ListBase *relations = reinterpret_cast<ListBase *>(BLI_ghash_lookup(hash, collection));
|
||||
if (relations == nullptr) {
|
||||
return hash->lookup_or_add(&collection->id, [&]() {
|
||||
::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph *>(graph);
|
||||
relations = BKE_collision_relations_create(depsgraph, collection, modifier_type);
|
||||
BLI_ghash_insert(hash, &collection->id, relations);
|
||||
}
|
||||
return relations;
|
||||
return BKE_collision_relations_create(depsgraph, collection, modifier_type);
|
||||
});
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void free_effector_relations(void *value)
|
||||
{
|
||||
BKE_effector_relations_free(reinterpret_cast<ListBase *>(value));
|
||||
}
|
||||
|
||||
void free_collision_relations(void *value)
|
||||
{
|
||||
BKE_collision_relations_free(reinterpret_cast<ListBase *>(value));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void clear_physics_relations(Depsgraph *graph)
|
||||
{
|
||||
for (int i = 0; i < DEG_PHYSICS_RELATIONS_NUM; i++) {
|
||||
if (graph->physics_relations[i]) {
|
||||
Map<const ID *, ListBase *> *hash = graph->physics_relations[i];
|
||||
if (hash) {
|
||||
const ePhysicsRelationType type = (ePhysicsRelationType)i;
|
||||
|
||||
switch (type) {
|
||||
case DEG_PHYSICS_EFFECTOR:
|
||||
BLI_ghash_free(graph->physics_relations[i], nullptr, free_effector_relations);
|
||||
for (ListBase *list : hash->values()) {
|
||||
BKE_effector_relations_free(list);
|
||||
}
|
||||
hash->clear();
|
||||
break;
|
||||
case DEG_PHYSICS_COLLISION:
|
||||
case DEG_PHYSICS_SMOKE_COLLISION:
|
||||
case DEG_PHYSICS_DYNAMIC_BRUSH:
|
||||
BLI_ghash_free(graph->physics_relations[i], nullptr, free_collision_relations);
|
||||
for (ListBase *list : hash->values()) {
|
||||
BKE_collision_relations_free(list);
|
||||
}
|
||||
hash->clear();
|
||||
break;
|
||||
case DEG_PHYSICS_RELATIONS_NUM:
|
||||
break;
|
||||
|
|
|
@ -75,7 +75,7 @@ void deg_foreach_dependent_operation(const Depsgraph *UNUSED(graph),
|
|||
/* Start with scheduling all operations from ID node. */
|
||||
TraversalQueue queue;
|
||||
Set<OperationNode *> scheduled;
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, target_id_node->components) {
|
||||
for (ComponentNode *comp_node : target_id_node->components.values()) {
|
||||
if (source_component_type != DEG_OB_COMP_ANY &&
|
||||
nodeTypeToObjectComponent(comp_node->type) != source_component_type) {
|
||||
continue;
|
||||
|
@ -88,7 +88,6 @@ void deg_foreach_dependent_operation(const Depsgraph *UNUSED(graph),
|
|||
scheduled.add(op_node);
|
||||
}
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
/* Process the queue. */
|
||||
while (!queue.empty()) {
|
||||
/* get next operation node to process. */
|
||||
|
@ -205,13 +204,12 @@ void deg_foreach_ancestor_ID(const Depsgraph *graph,
|
|||
/* Start with scheduling all operations from ID node. */
|
||||
TraversalQueue queue;
|
||||
Set<OperationNode *> scheduled;
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, target_id_node->components) {
|
||||
for (ComponentNode *comp_node : target_id_node->components.values()) {
|
||||
for (OperationNode *op_node : comp_node->operations) {
|
||||
queue.push_back(op_node);
|
||||
scheduled.add(op_node);
|
||||
}
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
Set<IDNode *> visited;
|
||||
visited.add_new(target_id_node);
|
||||
/* Process the queue. */
|
||||
|
|
|
@ -495,13 +495,13 @@ void deg_graph_node_tag_zero(Main *bmain,
|
|||
ID *id = id_node->id_orig;
|
||||
/* TODO(sergey): Which recalc flags to set here? */
|
||||
id_node->id_cow->recalc |= deg_recalc_flags_for_legacy_zero();
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, id_node->components) {
|
||||
|
||||
for (ComponentNode *comp_node : id_node->components.values()) {
|
||||
if (comp_node->type == NodeType::ANIMATION) {
|
||||
continue;
|
||||
}
|
||||
comp_node->tag_update(graph, update_source);
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
deg_graph_id_tag_legacy_compat(bmain, graph, id, (IDRecalcFlag)0, update_source);
|
||||
}
|
||||
|
||||
|
|
|
@ -94,9 +94,9 @@ void flush_init_id_node_func(void *__restrict data_v,
|
|||
Depsgraph *graph = (Depsgraph *)data_v;
|
||||
IDNode *id_node = graph->id_nodes[i];
|
||||
id_node->custom_flags = ID_STATE_NONE;
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, id_node->components)
|
||||
for (ComponentNode *comp_node : id_node->components.values()) {
|
||||
comp_node->custom_flags = COMPONENT_STATE_NONE;
|
||||
GHASH_FOREACH_END();
|
||||
}
|
||||
}
|
||||
|
||||
BLI_INLINE void flush_prepare(Depsgraph *graph)
|
||||
|
@ -231,7 +231,7 @@ void flush_editors_id_update(Depsgraph *graph, const DEGEditorUpdateContext *upd
|
|||
ID *id_orig = id_node->id_orig;
|
||||
ID *id_cow = id_node->id_cow;
|
||||
/* Gather recalc flags from all changed components. */
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, id_node->components) {
|
||||
for (DEG::ComponentNode *comp_node : id_node->components.values()) {
|
||||
if (comp_node->custom_flags != COMPONENT_STATE_DONE) {
|
||||
continue;
|
||||
}
|
||||
|
@ -239,7 +239,6 @@ void flush_editors_id_update(Depsgraph *graph, const DEGEditorUpdateContext *upd
|
|||
BLI_assert(factory != nullptr);
|
||||
id_cow->recalc |= factory->id_recalc_tag();
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
DEG_DEBUG_PRINTF((::Depsgraph *)graph,
|
||||
EVAL,
|
||||
"Accumulated recalc bits for %s: %u\n",
|
||||
|
@ -307,7 +306,7 @@ void invalidate_tagged_evaluated_data(Depsgraph *graph)
|
|||
if (!deg_copy_on_write_is_expanded(id_cow)) {
|
||||
continue;
|
||||
}
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, id_node->components) {
|
||||
for (ComponentNode *comp_node : id_node->components.values()) {
|
||||
if (comp_node->custom_flags != COMPONENT_STATE_DONE) {
|
||||
continue;
|
||||
}
|
||||
|
@ -322,7 +321,6 @@ void invalidate_tagged_evaluated_data(Depsgraph *graph)
|
|||
break;
|
||||
}
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
}
|
||||
#else
|
||||
(void)graph;
|
||||
|
|
|
@ -41,10 +41,9 @@ void deg_eval_stats_aggregate(Depsgraph *graph)
|
|||
* Those are not filled in by the evaluation engine. */
|
||||
for (Node *node : graph->id_nodes) {
|
||||
IDNode *id_node = (IDNode *)node;
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, id_node->components) {
|
||||
for (ComponentNode *comp_node : id_node->components.values()) {
|
||||
comp_node->stats.reset_current();
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
id_node->stats.reset_current();
|
||||
}
|
||||
/* Now accumulate operation timings to components and IDs. */
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "BLI_string.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
struct GHash;
|
||||
struct ID;
|
||||
struct bPoseChannel;
|
||||
|
||||
|
|
|
@ -69,34 +69,6 @@ bool IDNode::ComponentIDKey::operator==(const ComponentIDKey &other) const
|
|||
return type == other.type && STREQ(name, other.name);
|
||||
}
|
||||
|
||||
static unsigned int id_deps_node_hash_key(const void *key_v)
|
||||
{
|
||||
const IDNode::ComponentIDKey *key = reinterpret_cast<const IDNode::ComponentIDKey *>(key_v);
|
||||
const int type_as_int = static_cast<int>(key->type);
|
||||
return BLI_ghashutil_combine_hash(BLI_ghashutil_uinthash(type_as_int),
|
||||
BLI_ghashutil_strhash_p(key->name));
|
||||
}
|
||||
|
||||
static bool id_deps_node_hash_key_cmp(const void *a, const void *b)
|
||||
{
|
||||
const IDNode::ComponentIDKey *key_a = reinterpret_cast<const IDNode::ComponentIDKey *>(a);
|
||||
const IDNode::ComponentIDKey *key_b = reinterpret_cast<const IDNode::ComponentIDKey *>(b);
|
||||
return !(*key_a == *key_b);
|
||||
}
|
||||
|
||||
static void id_deps_node_hash_key_free(void *key_v)
|
||||
{
|
||||
typedef IDNode::ComponentIDKey ComponentIDKey;
|
||||
ComponentIDKey *key = reinterpret_cast<ComponentIDKey *>(key_v);
|
||||
OBJECT_GUARDED_DELETE(key, ComponentIDKey);
|
||||
}
|
||||
|
||||
static void id_deps_node_hash_value_free(void *value_v)
|
||||
{
|
||||
ComponentNode *comp_node = reinterpret_cast<ComponentNode *>(value_v);
|
||||
OBJECT_GUARDED_DELETE(comp_node, ComponentNode);
|
||||
}
|
||||
|
||||
/* Initialize 'id' node - from pointer data given. */
|
||||
void IDNode::init(const ID *id, const char *UNUSED(subdata))
|
||||
{
|
||||
|
@ -116,9 +88,6 @@ void IDNode::init(const ID *id, const char *UNUSED(subdata))
|
|||
|
||||
visible_components_mask = 0;
|
||||
previously_visible_components_mask = 0;
|
||||
|
||||
components = BLI_ghash_new(
|
||||
id_deps_node_hash_key, id_deps_node_hash_key_cmp, "Depsgraph id components hash");
|
||||
}
|
||||
|
||||
void IDNode::init_copy_on_write(ID *id_cow_hint)
|
||||
|
@ -158,7 +127,9 @@ void IDNode::destroy()
|
|||
return;
|
||||
}
|
||||
|
||||
BLI_ghash_free(components, id_deps_node_hash_key_free, id_deps_node_hash_value_free);
|
||||
for (ComponentNode *comp_node : components.values()) {
|
||||
OBJECT_GUARDED_DELETE(comp_node, ComponentNode);
|
||||
}
|
||||
|
||||
/* Free memory used by this CoW ID. */
|
||||
if (id_cow != id_orig && id_cow != nullptr) {
|
||||
|
@ -185,7 +156,7 @@ string IDNode::identifier() const
|
|||
ComponentNode *IDNode::find_component(NodeType type, const char *name) const
|
||||
{
|
||||
ComponentIDKey key(type, name);
|
||||
return reinterpret_cast<ComponentNode *>(BLI_ghash_lookup(components, &key));
|
||||
return components.lookup_default(key, nullptr);
|
||||
}
|
||||
|
||||
ComponentNode *IDNode::add_component(NodeType type, const char *name)
|
||||
|
@ -196,8 +167,8 @@ ComponentNode *IDNode::add_component(NodeType type, const char *name)
|
|||
comp_node = (ComponentNode *)factory->create_node(this->id_orig, "", name);
|
||||
|
||||
/* Register. */
|
||||
ComponentIDKey *key = OBJECT_GUARDED_NEW(ComponentIDKey, type, name);
|
||||
BLI_ghash_insert(components, key, comp_node);
|
||||
ComponentIDKey key(type, name);
|
||||
components.add_new(key, comp_node);
|
||||
comp_node->owner = this;
|
||||
}
|
||||
return comp_node;
|
||||
|
@ -205,7 +176,7 @@ ComponentNode *IDNode::add_component(NodeType type, const char *name)
|
|||
|
||||
void IDNode::tag_update(Depsgraph *graph, eUpdateSource source)
|
||||
{
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, components) {
|
||||
for (ComponentNode *comp_node : components.values()) {
|
||||
/* Relations update does explicit animation update when needed. Here we ignore animation
|
||||
* component to avoid loss of possible unkeyed changes. */
|
||||
if (comp_node->type == NodeType::ANIMATION && source == DEG_UPDATE_SOURCE_RELATIONS) {
|
||||
|
@ -213,30 +184,27 @@ void IDNode::tag_update(Depsgraph *graph, eUpdateSource source)
|
|||
}
|
||||
comp_node->tag_update(graph, source);
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
}
|
||||
|
||||
void IDNode::finalize_build(Depsgraph *graph)
|
||||
{
|
||||
/* Finalize build of all components. */
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, components) {
|
||||
for (ComponentNode *comp_node : components.values()) {
|
||||
comp_node->finalize_build(graph);
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
visible_components_mask = get_visible_components_mask();
|
||||
}
|
||||
|
||||
IDComponentsMask IDNode::get_visible_components_mask() const
|
||||
{
|
||||
IDComponentsMask result = 0;
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, components) {
|
||||
for (ComponentNode *comp_node : components.values()) {
|
||||
if (comp_node->affects_directly_visible) {
|
||||
const int component_type_as_int = static_cast<int>(comp_node->type);
|
||||
BLI_assert(component_type_as_int < 64);
|
||||
result |= (1ULL << component_type_as_int);
|
||||
}
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "BLI_ghash.h"
|
||||
#include "BLI_sys_types.h"
|
||||
#include "DNA_ID.h"
|
||||
#include "intern/node/deg_node.h"
|
||||
|
||||
struct GHash;
|
||||
|
||||
namespace DEG {
|
||||
|
||||
struct ComponentNode;
|
||||
|
@ -82,7 +81,7 @@ struct IDNode : public Node {
|
|||
ID *id_cow;
|
||||
|
||||
/* Hash to make it faster to look up components. */
|
||||
GHash *components;
|
||||
Map<ComponentIDKey, ComponentNode *> components;
|
||||
|
||||
/* Additional flags needed for scene evaluation.
|
||||
* TODO(sergey): Only needed for until really granular updates
|
||||
|
@ -116,3 +115,16 @@ struct IDNode : public Node {
|
|||
};
|
||||
|
||||
} // namespace DEG
|
||||
|
||||
namespace BLI {
|
||||
|
||||
template<> struct DefaultHash<DEG::IDNode::ComponentIDKey> {
|
||||
uint32_t operator()(const DEG::IDNode::ComponentIDKey &key) const
|
||||
{
|
||||
const int type_as_int = static_cast<int>(key.type);
|
||||
return BLI_ghashutil_combine_hash(BLI_ghashutil_uinthash(type_as_int),
|
||||
BLI_ghashutil_strhash_p(key.name));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace BLI
|
||||
|
|
Loading…
Reference in New Issue