Blender V4.3
deg_node_id.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cstdio>
12#include <cstring> /* required for STREQ later on. */
13
14#include "BLI_string.h"
15#include "BLI_utildefines.h"
16
17#include "DNA_ID.h"
18#include "DNA_anim_types.h"
19
20#include "BKE_lib_id.hh"
21
22#include "DEG_depsgraph.hh"
23
28
29namespace blender::deg {
30
32{
33 switch (linked_state) {
35 return "INDIRECTLY";
37 return "VIA_SET";
39 return "DIRECTLY";
40 }
41 BLI_assert_msg(0, "Unhandled linked state, should never happen.");
42 return "UNKNOWN";
43}
44
45IDNode::ComponentIDKey::ComponentIDKey(NodeType type, const char *name) : type(type), name(name) {}
46
48{
49 return type == other.type && STREQ(name, other.name);
50}
51
53{
54 const int type_as_int = int(type);
57}
58
59void IDNode::init(const ID *id, const char * /*subdata*/)
60{
61 BLI_assert(id != nullptr);
62 /* Store ID-pointer. */
63 id_type = GS(id->name);
64 id_orig = (ID *)id;
66 eval_flags = 0;
72 is_enabled_on_eval = true;
74 has_base = false;
75 is_user_modified = false;
77
80}
81
83{
84 /* Create pointer as early as possible, so we can use it for function
85 * bindings. Rest of data we'll be copying to the new datablock when
86 * it is actually needed. */
87 if (id_cow_hint != nullptr) {
88 // BLI_assert(deg_eval_copy_is_needed(id_orig));
90 id_cow = id_cow_hint;
91 }
92 else {
94 }
95 }
99 "Create shallow copy for %s: id_orig=%p id_cow=%p\n", id_orig->name, id_orig, id_cow);
101 }
102 else {
103 id_cow = id_orig;
104 }
105}
106
107/* Free 'id' node. */
109{
110 destroy();
111}
112
114{
115 if (id_orig == nullptr) {
116 return;
117 }
118
119 /* Free memory used by this evaluated ID. */
120 if (!ELEM(id_cow, id_orig, nullptr)) {
123 id_cow = nullptr;
125 "Destroy evaluated ID for %s: id_orig=%p id_cow=%p\n", id_orig->name, id_orig, id_cow);
126 }
127
128 for (ComponentNode *comp_node : components.values()) {
129 delete comp_node;
130 }
131
132 /* Tag that the node is freed. */
133 id_orig = nullptr;
134}
135
136string IDNode::identifier() const
137{
138 char orig_ptr[24], cow_ptr[24];
139 SNPRINTF(orig_ptr, "%p", id_orig);
140 SNPRINTF(cow_ptr, "%p", id_cow);
141 return string(nodeTypeAsString(type)) + " : " + name + " (orig: " + orig_ptr +
142 ", eval: " + cow_ptr + ", is_visible_on_build " +
143 (is_visible_on_build ? "true" : "false") + ")";
144}
145
146ComponentNode *IDNode::find_component(NodeType type, const char *name) const
147{
148 ComponentIDKey key(type, name);
149 return components.lookup_default(key, nullptr);
150}
151
153{
154 ComponentNode *comp_node = find_component(type, name);
155 if (!comp_node) {
156 DepsNodeFactory *factory = type_get_factory(type);
157 BLI_assert(factory);
158 comp_node = (ComponentNode *)factory->create_node(this->id_orig, "", name);
159
160 /* Register. */
161 ComponentIDKey key(type, comp_node->name.c_str());
162 components.add_new(key, comp_node);
163 comp_node->owner = this;
164 }
165 return comp_node;
166}
167
169{
170 for (ComponentNode *comp_node : components.values()) {
171 /* Relations update does explicit animation update when needed. Here we ignore animation
172 * component to avoid loss of possible unkeyed changes. */
173 if (comp_node->type == NodeType::ANIMATION && source == DEG_UPDATE_SOURCE_RELATIONS) {
174 continue;
175 }
176 comp_node->tag_update(graph, source);
177 }
178}
179
181{
182 /* Finalize build of all components. */
183 for (ComponentNode *comp_node : components.values()) {
184 comp_node->finalize_build(graph);
185 }
187}
188
190{
191 IDComponentsMask result = 0;
192 for (ComponentNode *comp_node : components.values()) {
193 if (comp_node->possibly_affects_visible_id) {
194 const int component_type_as_int = int(comp_node->type);
195 BLI_assert(component_type_as_int < 64);
196 result |= (1ULL << component_type_as_int);
197 }
198 }
199 return result;
200}
201
202} // namespace blender::deg
void * BKE_libblock_alloc_notest(short type) ATTR_WARN_UNUSED_RESULT
Definition lib_id.cc:1310
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
size_t BLI_ghashutil_combine_hash(size_t hash_a, size_t hash_b)
unsigned int BLI_ghashutil_uinthash(unsigned int key)
unsigned int BLI_ghashutil_strhash_p(const void *ptr)
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:597
#define ELEM(...)
#define STREQ(a, b)
ID and Library types, which are fundamental for SDNA.
const Depsgraph * depsgraph
#define DEG_COW_PRINT(format,...)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
#define GS(x)
Definition iris.cc:202
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
uint64_t IDComponentsMask
void deg_tag_eval_copy_id(deg::Depsgraph &depsgraph, ID *id_cow, const ID *id_orig)
void deg_free_eval_copy_datablock(ID *id_cow)
const char * linkedStateAsString(eDepsNode_LinkedState_Type linked_state)
bool deg_eval_copy_is_needed(const ID *id_orig)
DepsNodeFactory * type_get_factory(const NodeType type)
@ DEG_ID_LINKED_INDIRECTLY
const char * nodeTypeAsString(NodeType type)
Definition deg_node.cc:40
unsigned __int64 uint64_t
Definition stdint.h:90
Definition DNA_ID.h:413
char name[66]
Definition DNA_ID.h:425
unsigned int session_uid
Definition DNA_ID.h:454
virtual void tag_update(Depsgraph *graph, eUpdateSource source) override
virtual Node * create_node(const ID *id, const char *subdata, const char *name) const =0
bool operator==(const ComponentIDKey &other) const
ComponentIDKey(NodeType type, const char *name="")
IDComponentsMask previously_visible_components_mask
DEGCustomDataMeshMasks customdata_masks
DEGCustomDataMeshMasks previous_customdata_masks
ComponentNode * add_component(NodeType type, const char *name="")
virtual string identifier() const override
IDComponentsMask visible_components_mask
void init_copy_on_write(Depsgraph &depsgraph, ID *id_cow_hint=nullptr)
virtual void init(const ID *id, const char *subdata) override
IDComponentsMask get_visible_components_mask() const
void finalize_build(Depsgraph *graph)
ComponentNode * find_component(NodeType type, const char *name="") const
eDepsNode_LinkedState_Type linked_state
virtual void tag_update(Depsgraph *graph, eUpdateSource source) override
uint32_t previous_eval_flags