Blender V5.3
deg_eval_visibility.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "DNA_layer_types.h"
12#include "DNA_modifier_types.h"
13#include "DNA_object_types.h"
14
15#include "BLI_assert.hh"
16#include "BLI_listbase.hh"
17#include "BLI_stack.hh"
18
19#include "DEG_depsgraph.hh"
20
21#include "intern/depsgraph.hh"
27
28namespace blender::deg {
29
30void deg_evaluate_object_node_visibility(blender::Depsgraph *depsgraph, IDNode *id_node)
31{
32 BLI_assert(GS(id_node->id_cow->name) == ID_OB);
33
34 Depsgraph *graph = reinterpret_cast<Depsgraph *>(depsgraph);
35 const Object *object = reinterpret_cast<const Object *>(id_node->id_cow);
36
37 DEG_debug_print_eval(depsgraph, __func__, object->id.name, &object->id);
38
39 const int required_flags = (graph->mode == DAG_EVAL_VIEWPORT) ? BASE_ENABLED_VIEWPORT :
41
42 const bool is_enabled = !graph->use_visibility_optimization ||
43 object->base_flag & required_flags;
44
45 if (id_node->is_enabled_on_eval != is_enabled) {
46 id_node->is_enabled_on_eval = is_enabled;
47
48 /* Tag dependency graph for changed visibility, so that it is updated on all dependencies prior
49 * to a pass of an actual evaluation. */
50 graph->need_update_nodes_visibility = true;
51 }
52}
53
54void deg_evaluate_object_modifiers_mode_node_visibility(blender::Depsgraph *depsgraph,
55 IDNode *id_node)
56{
57 BLI_assert(GS(id_node->id_cow->name) == ID_OB);
58
59 Depsgraph *graph = reinterpret_cast<Depsgraph *>(depsgraph);
60 const Object *object = reinterpret_cast<const Object *>(id_node->id_cow);
61
62 DEG_debug_print_eval(depsgraph, __func__, object->id.name, &object->id);
63
64 if (object->modifiers.is_empty()) {
65 return;
66 }
67
68 const ModifierMode modifier_mode = (graph->mode == DAG_EVAL_VIEWPORT) ? eModifierMode_Realtime :
70
71 const ComponentNode *geometry_component = id_node->find_component(NodeType::GEOMETRY);
72 for (ModifierData &modifier : object->modifiers) {
73 OperationNode *modifier_node = geometry_component->find_operation(OperationCode::MODIFIER,
74 modifier.name);
75
76 BLI_assert_msg(modifier_node != nullptr,
77 "Modifier node in depsgraph is not found. Likely due to missing "
78 "DEG_relations_tag_update().");
79
80 const bool modifier_enabled = !graph->use_visibility_optimization ||
81 (modifier.mode & modifier_mode);
82 const int mute_flag = modifier_enabled ? 0 : DEPSOP_FLAG_MUTE;
83 if ((modifier_node->flag & DEPSOP_FLAG_MUTE) != mute_flag) {
84 modifier_node->flag &= ~DEPSOP_FLAG_MUTE;
85 modifier_node->flag |= mute_flag;
86
87 graph->need_update_nodes_visibility = true;
88 }
89 }
90}
91
93{
94 enum {
95 DEG_NODE_VISITED = (1 << 0),
96 };
97
98 for (IDNode *id_node : graph->id_nodes) {
99 for (ComponentNode *comp_node : id_node->components.values()) {
100 comp_node->possibly_affects_visible_id = id_node->is_visible_on_build;
101 comp_node->affects_visible_id = id_node->is_visible_on_build && id_node->is_enabled_on_eval;
102
103 /* Visibility component is always to be considered to have the same visibility as the
104 * `id_node->is_visible_on_build`. This is because the visibility is to be evaluated
105 * regardless of its current state as it might get changed due to animation. */
106 if (comp_node->type == NodeType::VISIBILITY) {
107 comp_node->affects_visible_id = id_node->is_visible_on_build;
108 }
109
110 /* Enforce "visibility" of the synchronization component.
111 *
112 * This component is never connected to other ID nodes, and hence can not be handled in the
113 * same way as other components needed for evaluation. It is only needed for proper
114 * evaluation of the ID node it belongs to.
115 *
116 * The design is such that the synchronization is supposed to happen whenever any part of the
117 * ID changed/evaluated. Here we mark the component as "visible" so that genetic recalc flag
118 * flushing and scheduling will handle the component in a generic manner. */
119 if (comp_node->type == NodeType::SYNCHRONIZATION) {
120 comp_node->possibly_affects_visible_id = true;
121 comp_node->affects_visible_id = true;
122 }
123 }
124 }
125
127
128 for (OperationNode *op_node : graph->operations) {
129 op_node->custom_flags = 0;
130 op_node->num_links_pending = 0;
131 for (Relation *rel : op_node->outlinks) {
132 if ((rel->to->type == NodeType::OPERATION) && (rel->flag & RELATION_FLAG_CYCLIC) == 0) {
133 ++op_node->num_links_pending;
134 }
135 }
136 if (op_node->num_links_pending == 0) {
137 stack.push(op_node);
138 op_node->custom_flags |= DEG_NODE_VISITED;
139 }
140 }
141
142 while (!stack.is_empty()) {
143 OperationNode *op_node = stack.pop();
144
145 /* Flush flags to parents. */
146 for (Relation *rel : op_node->inlinks) {
147 if (rel->from->type == NodeType::OPERATION) {
148 const OperationNode *op_to = reinterpret_cast<const OperationNode *>(rel->to);
149 const ComponentNode *comp_to = op_to->owner;
150
151 /* Ignore the synchronization target.
152 * It is always visible and should not affect on other components. */
153 if (comp_to->type == NodeType::SYNCHRONIZATION) {
154 continue;
155 }
156
157 OperationNode *op_from = reinterpret_cast<OperationNode *>(rel->from);
158 ComponentNode *comp_from = op_from->owner;
159
161
163 continue;
164 }
165
166 const bool target_possibly_affects_visible_id = comp_to->possibly_affects_visible_id;
167
168 bool target_affects_visible_id = comp_to->affects_visible_id;
169
170 /* This is a bit arbitrary but the idea here is following:
171 *
172 * - When another object is used by a disabled modifier we do not want that object to
173 * be considered needed for evaluation.
174 *
175 * - However, we do not want to take mute flag during visibility propagation within the
176 * same object. Otherwise drivers and transform dependencies of the geometry component
177 * entry component might not be properly handled.
178 *
179 * This code works fine for muting modifiers, but might need tweaks when mute is used for
180 * something else. */
181 if (comp_from != comp_to && (op_to->flag & DEPSOP_FLAG_MUTE)) {
182 target_affects_visible_id = false;
183 }
184
185 /* Visibility component forces all components of the current ID to be considered as
186 * affecting directly visible. */
187 if (comp_from->type == NodeType::VISIBILITY) {
188 const IDNode *id_node_from = comp_from->owner;
189 if (target_possibly_affects_visible_id) {
190 for (ComponentNode *comp_node : id_node_from->components.values()) {
191 comp_node->possibly_affects_visible_id |= target_possibly_affects_visible_id;
192 }
193 }
194 if (target_affects_visible_id) {
195 for (ComponentNode *comp_node : id_node_from->components.values()) {
196 comp_node->affects_visible_id |= target_affects_visible_id;
197 }
198 }
199 }
200 else {
201 comp_from->possibly_affects_visible_id |= target_possibly_affects_visible_id;
202 comp_from->affects_visible_id |= target_affects_visible_id;
203 }
204 }
205 }
206
207 /* Schedule parent nodes. */
208 for (Relation *rel : op_node->inlinks) {
209 if (rel->from->type == NodeType::OPERATION) {
210 OperationNode *op_from = static_cast<OperationNode *>(rel->from);
211 if ((rel->flag & RELATION_FLAG_CYCLIC) == 0) {
212 BLI_assert(op_from->num_links_pending > 0);
213 --op_from->num_links_pending;
214 }
215 if ((op_from->num_links_pending == 0) && (op_from->custom_flags & DEG_NODE_VISITED) == 0) {
216 stack.push(op_from);
217 op_from->custom_flags |= DEG_NODE_VISITED;
218 }
219 }
220 }
221 }
222
223 graph->need_update_nodes_visibility = false;
224}
225
227{
228 if (!graph->need_update_nodes_visibility) {
229 return;
230 }
231
233}
234
235} // namespace blender::deg
Object is a sort of wrapper for general info.
#define BLI_assert_msg(a, msg)
bool is_empty() const
Definition BLI_stack.hh:310
void push(const T &value)
Definition BLI_stack.hh:215
void deg_evaluate_object_modifiers_mode_node_visibility(blender::Depsgraph *depsgraph, IDNode *id_node)
void deg_graph_flush_visibility_flags(Depsgraph *graph)
void deg_evaluate_object_node_visibility(blender::Depsgraph *depsgraph, IDNode *id_node)
void deg_graph_flush_visibility_flags_if_needed(Depsgraph *graph)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ BASE_ENABLED_VIEWPORT
void DEG_debug_print_eval(Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address)
@ DAG_EVAL_VIEWPORT
ID_Type GS(const char *name)
Definition DNA_ID.h:410
char name[258]
Definition DNA_ID.h:433
OperationNode * find_operation(OperationIDKey key) const
OperationNodes operations
Definition depsgraph.hh:135
eEvaluationMode mode
Definition depsgraph.hh:145
Map< ComponentIDKey, ComponentNode * > components
ComponentNode * find_component(NodeType type, StringRef name="") const
Relations inlinks
Definition deg_node.hh:188
Relations outlinks
Definition deg_node.hh:189