Blender V5.3
trace_values.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_stack.hh"
10
16#include "NOD_trace_values.hh"
17
20
21#include "ED_node.hh"
22
23namespace blender::nodes {
24
26{
27 if (!socket->is_input()) {
28 return false;
29 }
30 if (socket->index() == 0 && socket.owner_node()->is_type("NodeEvaluateClosure"_ustr)) {
31 return true;
32 }
33 if (const SocketDeclaration *decl = socket->runtime->declaration) {
34 if (const auto *closure_decl = dynamic_cast<const decl::Closure *>(decl)) {
35 return bool(closure_decl->create_signature);
36 }
37 }
38 return false;
39}
40
42{
43 return socket->owner_node().is_type("NodeClosureOutput"_ustr) && socket->is_output();
44}
45
46static bool use_link_for_tracing(const bNodeLink &link)
47{
48 if (!link.is_used()) {
49 return false;
50 }
51 const bNodeTree &tree = link.fromnode->owner_tree();
52 if (tree.typeinfo->validate_link &&
53 !tree.typeinfo->validate_link(link.fromsock->type, link.tosock->type))
54 {
55 return false;
56 }
57 return true;
58}
59
61 SocketInContext start_socket,
62 bke::ComputeContextCache &compute_context_cache,
63 FunctionRef<bool(const SocketInContext &)> handle_possible_origin_socket_fn,
64 bool find_all);
65
67 const SocketInContext start_socket,
68 bke::ComputeContextCache &compute_context_cache,
69 const FunctionRef<bool(const SocketInContext &)> handle_possible_target_socket_fn,
70 const bool find_all)
71{
72 using BundlePath = Vector<std::string, 0>;
73
74 struct SocketToCheck {
75 SocketInContext socket;
76 BundlePath bundle_path;
77 };
78
79 Stack<SocketToCheck> sockets_to_check;
80 Set<SocketInContext> added_sockets;
81
82 auto add_if_new = [&](const SocketInContext &socket, BundlePath bundle_path) {
83 if (added_sockets.add(socket)) {
84 sockets_to_check.push({socket, std::move(bundle_path)});
85 }
86 };
87
88 add_if_new(start_socket, {});
89
90 VectorSet<SocketInContext> found_targets;
91
92 while (!sockets_to_check.is_empty()) {
93 const SocketToCheck socket_to_check = sockets_to_check.pop();
94 const SocketInContext socket = socket_to_check.socket;
95 const BundlePath &bundle_path = socket_to_check.bundle_path;
96 const NodeInContext &node = socket.owner_node();
97 if (socket->is_input()) {
98 if (node->is_muted()) {
99 for (const bNodeInternalLink &link : node->internal_links()) {
100 if (link.in == socket.socket) {
101 add_if_new({socket.context, link.out}, bundle_path);
102 }
103 }
104 continue;
105 }
106 if (bundle_path.is_empty() && handle_possible_target_socket_fn(socket)) {
107 found_targets.add(socket);
108 if (!find_all) {
109 break;
110 }
111 continue;
112 }
113 if (node->is_reroute()) {
114 add_if_new(node.output_socket(0), bundle_path);
115 continue;
116 }
117 if (node->is_group()) {
118 if (const bNodeTree *group = reinterpret_cast<const bNodeTree *>(node->id)) {
119 group->ensure_topology_cache();
120 const ComputeContext &group_compute_context = compute_context_cache.for_group_node(
121 socket.context, node->identifier, &node->owner_tree());
122 for (const bNode *input_node : group->group_input_nodes()) {
123 if (const bNodeSocket *group_input_socket = input_node->output_by_identifier(
124 socket->identifier_ustr()))
125 {
126 if (group_input_socket->is_directly_linked()) {
127 add_if_new({&group_compute_context, group_input_socket}, bundle_path);
128 }
129 }
130 }
131 }
132 continue;
133 }
134 if (node->is_group_output()) {
135 if (const auto *group_context = dynamic_cast<const bke::GroupNodeComputeContext *>(
136 socket.context))
137 {
138 const bNodeTree *caller_group = group_context->tree();
139 const bNode *caller_group_node = group_context->node();
140 if (caller_group && caller_group_node) {
141 caller_group->ensure_topology_cache();
142 if (const bNodeSocket *output_socket = caller_group_node->output_by_identifier(
143 socket->identifier_ustr()))
144 {
145 add_if_new({group_context->parent(), output_socket}, bundle_path);
146 }
147 }
148 }
149 continue;
150 }
151 if (node->is_type("NodeCombineBundle"_ustr)) {
152 const auto &storage = *static_cast<const NodeCombineBundle *>(node->storage);
153 BundlePath new_bundle_path = bundle_path;
154 new_bundle_path.append(storage.items[socket->index()].name);
155 add_if_new(node.output_socket(0), std::move(new_bundle_path));
156 continue;
157 }
158 if (node->is_type("NodeSeparateBundle"_ustr)) {
159 if (bundle_path.is_empty()) {
160 continue;
161 }
162 const StringRef last_key = bundle_path.last();
163 const auto &storage = *static_cast<const NodeSeparateBundle *>(node->storage);
164 for (const int output_i : IndexRange(storage.items_num)) {
165 if (last_key == storage.items[output_i].name) {
166 add_if_new(node.output_socket(output_i), bundle_path.as_span().drop_back(1));
167 }
168 }
169 continue;
170 }
171 if (node->is_type("NodeClosureOutput"_ustr)) {
172 const auto &closure_storage = *static_cast<const NodeClosureOutput *>(node->storage);
173 const StringRef key = closure_storage.output_items.items[socket->index()].name;
175 node.output_socket(0), compute_context_cache, target_socket_evaluates_closure, true);
176 for (const auto &target_socket : target_sockets) {
177 const NodeInContext evaluate_node = target_socket.owner_node();
178 if (!evaluate_node->is_type("NodeEvaluateClosure"_ustr)) {
179 continue;
180 }
181 const auto &evaluate_storage = *static_cast<const NodeEvaluateClosure *>(
182 evaluate_node->storage);
183 for (const int i : IndexRange(evaluate_storage.output_items.items_num)) {
184 const NodeEvaluateClosureOutputItem &item = evaluate_storage.output_items.items[i];
185 if (key == item.name) {
186 add_if_new(evaluate_node.output_socket(i), bundle_path);
187 }
188 }
189 }
190 continue;
191 }
192 if (node->is_type("NodeEvaluateClosure"_ustr)) {
193 if (socket->index() == 0) {
194 continue;
195 }
196 const auto &evaluate_storage = *static_cast<const NodeEvaluateClosure *>(node->storage);
197 const StringRef key = evaluate_storage.input_items.items[socket->index() - 1].name;
199 node.input_socket(0), compute_context_cache, is_closure_zone_output_socket, true);
200 for (const SocketInContext origin_socket : origin_sockets) {
201 const bNodeTree &closure_tree = origin_socket->owner_tree();
202 const bke::bNodeTreeZones *closure_tree_zones = closure_tree.zones();
203 if (!closure_tree_zones) {
204 continue;
205 }
206 const auto &closure_output_node = origin_socket.owner_node();
207 const bke::bNodeTreeZone *closure_zone = closure_tree_zones->get_zone_by_node(
208 closure_output_node->identifier);
209 if (!closure_zone) {
210 continue;
211 }
212 const bNode *closure_input_node = closure_zone->input_node();
213 if (!closure_input_node) {
214 continue;
215 }
216 const bke::EvaluateClosureComputeContext &closure_context =
217 compute_context_cache.for_evaluate_closure(
218 node.context,
219 node->identifier,
220 &node->owner_tree(),
221 ClosureSourceLocation{&closure_tree,
222 closure_output_node->identifier,
223 origin_socket.context_hash(),
224 origin_socket.context});
225 if (closure_context.is_recursive()) {
226 continue;
227 }
228 const auto &closure_output_storage = *static_cast<const NodeClosureOutput *>(
229 closure_output_node->storage);
230 for (const int i : IndexRange(closure_output_storage.input_items.items_num)) {
231 const NodeClosureInputItem &item = closure_output_storage.input_items.items[i];
232 if (key == item.name) {
233 add_if_new({&closure_context, &closure_input_node->output_socket(i)}, bundle_path);
234 }
235 }
236 }
237 continue;
238 }
239 if (node->is_type("GeometryNodeSimulationInput"_ustr)) {
240 const ComputeContext &simulation_compute_context =
241 compute_context_cache.for_simulation_zone(socket.context, *node);
242 add_if_new({&simulation_compute_context, &node->output_socket(socket->index() + 1)},
243 bundle_path);
244 continue;
245 }
246 if (node->is_type("GeometryNodeSimulationOutput"_ustr)) {
247 const int output_index = socket->index();
248 if (output_index >= 1) {
249 BLI_assert(dynamic_cast<const bke::SimulationZoneComputeContext *>(socket.context));
250 add_if_new({socket.context->parent(), &node->output_socket(output_index - 1)},
251 bundle_path);
252 }
253 continue;
254 }
255 if (node->is_type("GeometryNodeRepeatInput"_ustr)) {
256 const int index = socket->index();
257 if (index >= 1) {
258 const ComputeContext &repeat_compute_context = compute_context_cache.for_repeat_zone(
259 socket.context, *node, 0);
260 add_if_new({&repeat_compute_context, &node->output_socket(index)}, bundle_path);
261 const auto &storage = *static_cast<NodeGeometryRepeatInput *>(node->storage);
262 if (const bNode *repeat_output_node = node->owner_tree().node_by_id(
263 storage.output_node_id))
264 {
265 add_if_new({socket.context, &repeat_output_node->output_socket(index - 1)},
266 bundle_path);
267 }
268 }
269 continue;
270 }
271 if (node->is_type("GeometryNodeRepeatOutput"_ustr)) {
272 BLI_assert(dynamic_cast<const bke::RepeatZoneComputeContext *>(socket.context));
273 add_if_new({socket.context->parent(), &node->output_socket(socket->index())}, bundle_path);
274 continue;
275 }
276 for (const bNodeSocket *output_socket : node->output_sockets()) {
277 const SocketDeclaration *output_decl = output_socket->runtime->declaration;
278 if (!output_decl) {
279 continue;
280 }
281 if (const decl::Bundle *bundle_decl = dynamic_cast<const decl::Bundle *>(output_decl)) {
282 if (bundle_decl->pass_through_input_index == socket->index()) {
283 add_if_new({socket.context, output_socket}, bundle_path);
284 }
285 }
286 }
287 }
288 else {
289 const bke::bNodeTreeZones *zones = node->owner_tree().zones();
290 if (!zones) {
291 continue;
292 }
293 const bke::bNodeTreeZone *from_zone = zones->get_zone_by_socket(*socket.socket);
294 for (const bNodeLink *link : socket->directly_linked_links()) {
295 if (!use_link_for_tracing(*link)) {
296 continue;
297 }
298 bNodeSocket *to_socket = link->tosock;
299 const bke::bNodeTreeZone *to_zone = zones->get_zone_by_socket(*to_socket);
300 if (!zones->link_between_zones_is_allowed(from_zone, to_zone)) {
301 continue;
302 }
303 const Vector<const bke::bNodeTreeZone *> zones_to_enter = zones->get_zones_to_enter(
304 from_zone, to_zone);
306 zones_to_enter, compute_context_cache, socket.context);
307 if (!compute_context) {
308 continue;
309 }
310 add_if_new({compute_context, to_socket}, bundle_path);
311 }
312 }
313 }
314 return found_targets.extract_vector();
315}
316
318 const ComputeContext *closure_socket_context,
319 const bNodeSocket &closure_socket,
320 bke::ComputeContextCache &compute_context_cache,
321 const std::optional<ClosureSourceLocation> &source_location)
322{
324 {closure_socket_context, &closure_socket},
325 compute_context_cache,
327 false);
328 if (target_sockets.is_empty()) {
329 return nullptr;
330 }
331 const SocketInContext target_socket = target_sockets[0];
332 const NodeInContext target_node = target_socket.owner_node();
333 if (!target_node->is_type("NodeEvaluateClosure"_ustr)) {
334 return nullptr;
335 }
336 return &compute_context_cache.for_evaluate_closure(target_socket.context,
337 target_node->identifier,
338 &target_socket->owner_tree(),
339 source_location);
340}
341
343 const SocketInContext start_socket,
344 bke::ComputeContextCache &compute_context_cache,
345 const FunctionRef<bool(const SocketInContext &)> handle_possible_origin_socket_fn,
346 const bool find_all)
347{
348 using BundlePath = Vector<std::string, 0>;
349
350 struct SocketToCheck {
351 SocketInContext socket;
352 BundlePath bundle_path;
353 };
354
355 Stack<SocketToCheck> sockets_to_check;
356 Set<SocketInContext> added_sockets;
357
358 auto add_if_new = [&](const SocketInContext &socket, BundlePath bundle_path) {
359 if (added_sockets.add(socket)) {
360 sockets_to_check.push({socket, std::move(bundle_path)});
361 }
362 };
363
364 add_if_new(start_socket, {});
365
366 VectorSet<SocketInContext> found_origins;
367
368 while (!sockets_to_check.is_empty()) {
369 const SocketToCheck socket_to_check = sockets_to_check.pop();
370 const SocketInContext socket = socket_to_check.socket;
371 const BundlePath &bundle_path = socket_to_check.bundle_path;
372 const NodeInContext &node = socket.owner_node();
373 const SocketDeclaration *socket_decl = socket->runtime->declaration;
374 if (socket->is_input()) {
375 if (bundle_path.is_empty() && handle_possible_origin_socket_fn(socket)) {
376 found_origins.add(socket);
377 if (!find_all) {
378 break;
379 }
380 continue;
381 }
382 const bke::bNodeTreeZones *zones = node->owner_tree().zones();
383 if (!zones) {
384 continue;
385 }
386 const bke::bNodeTreeZone *to_zone = zones->get_zone_by_socket(*socket.socket);
387 for (const bNodeLink *link : socket->directly_linked_links()) {
388 if (!use_link_for_tracing(*link)) {
389 continue;
390 }
391 const bNodeSocket *from_socket = link->fromsock;
392 const bke::bNodeTreeZone *from_zone = zones->get_zone_by_socket(*from_socket);
393 if (!zones->link_between_zones_is_allowed(from_zone, to_zone)) {
394 continue;
395 }
396 const ComputeContext *compute_context = socket.context;
397 for (const bke::bNodeTreeZone *zone = to_zone; zone != from_zone; zone = zone->parent_zone)
398 {
399 if (const auto *evaluate_closure_context =
400 dynamic_cast<const bke::EvaluateClosureComputeContext *>(compute_context))
401 {
402 const std::optional<nodes::ClosureSourceLocation> &source_location =
403 evaluate_closure_context->closure_source_location();
404 /* This is expected to be available during value tracing. */
405 BLI_assert(source_location);
406 BLI_assert(source_location->compute_context);
407 compute_context = source_location->compute_context;
408 }
409 else {
410 compute_context = compute_context->parent();
411 }
412 }
413 add_if_new({compute_context, from_socket}, bundle_path);
414 }
415 }
416 else {
417 if (node->is_muted()) {
418 for (const bNodeInternalLink &link : node->internal_links()) {
419 if (link.out == socket.socket) {
420 add_if_new({socket.context, link.in}, bundle_path);
421 }
422 }
423 continue;
424 }
425 if (bundle_path.is_empty() && handle_possible_origin_socket_fn(socket)) {
426 found_origins.add(socket);
427 if (!find_all) {
428 break;
429 }
430 continue;
431 }
432 if (node->is_reroute()) {
433 add_if_new(node.input_socket(0), bundle_path);
434 continue;
435 }
436 if (node->is_group()) {
437 if (const bNodeTree *group = reinterpret_cast<const bNodeTree *>(node->id)) {
438 group->ensure_topology_cache();
439 if (const bNode *group_output_node = group->group_output_node()) {
440 const ComputeContext &group_compute_context = compute_context_cache.for_group_node(
441 socket.context, node->identifier, &node->owner_tree());
442 if (const bNodeSocket *group_output_socket = group_output_node->input_by_identifier(
443 socket->identifier_ustr()))
444 {
445 add_if_new({&group_compute_context, group_output_socket}, bundle_path);
446 }
447 }
448 }
449 continue;
450 }
451 if (node->is_group_input()) {
452 if (const auto *group_context = dynamic_cast<const bke::GroupNodeComputeContext *>(
453 socket.context))
454 {
455 const bNodeTree *caller_group = group_context->tree();
456 const bNode *caller_group_node = group_context->node();
457 if (caller_group && caller_group_node) {
458 caller_group->ensure_topology_cache();
459 if (const bNodeSocket *input_socket = caller_group_node->input_by_identifier(
460 socket->identifier_ustr()))
461 {
462 add_if_new({group_context->parent(), input_socket}, bundle_path);
463 }
464 }
465 }
466 continue;
467 }
468 if (node->is_type("NodeJoinBundle"_ustr)) {
469 add_if_new(node.input_socket(0), bundle_path);
470 continue;
471 }
472 if (node->is_type("NodeEvaluateClosure"_ustr)) {
473 const auto &evaluate_storage = *static_cast<const NodeEvaluateClosure *>(node->storage);
474 const StringRef key = evaluate_storage.output_items.items[socket->index()].name;
476 node.input_socket(0), compute_context_cache, is_closure_zone_output_socket, true);
477 for (const SocketInContext origin_socket : origin_sockets) {
478 const bNodeTree &closure_tree = origin_socket->owner_tree();
479 const NodeInContext closure_output_node = origin_socket.owner_node();
480 const auto &closure_storage = *static_cast<const NodeClosureOutput *>(
481 closure_output_node->storage);
482 const bke::EvaluateClosureComputeContext &closure_context =
483 compute_context_cache.for_evaluate_closure(
484 node.context,
485 node->identifier,
486 &node->owner_tree(),
487 ClosureSourceLocation{&closure_tree,
488 closure_output_node->identifier,
489 origin_socket.context_hash(),
490 origin_socket.context});
491 if (closure_context.is_recursive()) {
492 continue;
493 }
494 for (const int i : IndexRange(closure_storage.output_items.items_num)) {
495 const NodeClosureOutputItem &item = closure_storage.output_items.items[i];
496 if (key == item.name) {
497 add_if_new({&closure_context, &closure_output_node->input_socket(i)}, bundle_path);
498 }
499 }
500 }
501 continue;
502 }
503 if (node->is_type("NodeClosureInput"_ustr)) {
504 const auto &input_storage = *static_cast<const NodeClosureInput *>(node->storage);
505 const bNode *closure_output_node = node->owner_tree().node_by_id(
506 input_storage.output_node_id);
507 if (!closure_output_node) {
508 continue;
509 }
510 const auto &output_storage = *static_cast<const NodeClosureOutput *>(
511 closure_output_node->storage);
512 const StringRef key = output_storage.input_items.items[socket->index()].name;
513 const bNodeSocket &closure_output_socket = closure_output_node->output_socket(0);
515 {socket.context, &closure_output_socket},
516 compute_context_cache,
518 true);
519 for (const SocketInContext &target_socket : target_sockets) {
520 const NodeInContext target_node = target_socket.owner_node();
521 if (!target_node->is_type("NodeEvaluateClosure"_ustr)) {
522 continue;
523 }
524 const auto &evaluate_storage = *static_cast<const NodeEvaluateClosure *>(
525 target_node.node->storage);
526 for (const int i : IndexRange(evaluate_storage.input_items.items_num)) {
527 const NodeEvaluateClosureInputItem &item = evaluate_storage.input_items.items[i];
528 if (key == item.name) {
529 add_if_new(target_node.input_socket(i + 1), bundle_path);
530 }
531 }
532 }
533 continue;
534 }
535 if (node->is_type("NodeCombineBundle"_ustr)) {
536 if (bundle_path.is_empty()) {
537 continue;
538 }
539 const StringRef last_key = bundle_path.last();
540 const auto &storage = *static_cast<const NodeCombineBundle *>(node->storage);
541 for (const int input_i : IndexRange(storage.items_num)) {
542 if (last_key == storage.items[input_i].name) {
543 add_if_new(node.input_socket(input_i), bundle_path.as_span().drop_back(1));
544 }
545 }
546 continue;
547 }
548 if (node->is_type("NodeSeparateBundle"_ustr)) {
549 const auto &storage = *static_cast<const NodeSeparateBundle *>(node->storage);
550 BundlePath new_bundle_path = bundle_path;
551 new_bundle_path.append(storage.items[socket->index()].name);
552 add_if_new(node.input_socket(0), std::move(new_bundle_path));
553 continue;
554 }
555 if (node->is_type("GeometryNodeSimulationInput"_ustr)) {
556 const int output_index = socket->index();
557 if (output_index >= 1) {
558 BLI_assert(dynamic_cast<const bke::SimulationZoneComputeContext *>(socket.context));
559 add_if_new({socket.context->parent(), &node->input_socket(output_index - 1)},
560 bundle_path);
561 }
562 continue;
563 }
564 if (node->is_type("GeometryNodeSimulationOutput"_ustr)) {
565 const ComputeContext &simulation_compute_context =
566 compute_context_cache.for_simulation_zone(socket.context, *node);
567 add_if_new({&simulation_compute_context, &node->input_socket(socket->index() + 1)},
568 bundle_path);
569 continue;
570 }
571 if (node->is_type("GeometryNodeRepeatInput"_ustr)) {
572 const int index = socket->index();
573 if (index >= 1) {
574 BLI_assert(dynamic_cast<const bke::RepeatZoneComputeContext *>(socket.context));
575 add_if_new({socket.context->parent(), &node->input_socket(index)}, bundle_path);
576 }
577 continue;
578 }
579 if (node->is_type("GeometryNodeRepeatOutput"_ustr)) {
580 const int index = socket->index();
581 const ComputeContext &repeat_compute_context = compute_context_cache.for_repeat_zone(
582 socket.context, *node, 0);
583 add_if_new({&repeat_compute_context, &node->input_socket(index)}, bundle_path);
584 const bke::bNodeZoneType &zone_type = *bke::zone_type_by_node_type(node->type_legacy);
585 if (const bNode *repeat_input_node = zone_type.get_corresponding_input(node->owner_tree(),
586 *node))
587 {
588 add_if_new({socket.context, &repeat_input_node->input_socket(index + 1)}, bundle_path);
589 }
590 continue;
591 }
592 if (socket_decl) {
593 if (const decl::Bundle *bundle_decl = dynamic_cast<const decl::Bundle *>(socket_decl)) {
594 if (bundle_decl->pass_through_input_index) {
595 const int input_index = *bundle_decl->pass_through_input_index;
596 add_if_new(node.input_socket(input_index), bundle_path);
597 }
598 }
599 }
600 }
601 }
602
603 return found_origins.extract_vector();
604}
605
607 const ComputeContext *bundle_socket_context,
608 const bNodeSocket &bundle_socket,
609 bke::ComputeContextCache &compute_context_cache)
610{
613 {bundle_socket_context, &bundle_socket},
614 compute_context_cache,
615 [&](const SocketInContext &socket) {
616 const bNode &node = socket->owner_node();
617 if (socket->is_input() && node.is_type("NodeSeparateBundle"_ustr)) {
618 const auto &storage = *static_cast<const NodeSeparateBundle *>(node.storage);
621 socket});
622 return true;
623 }
624 return false;
625 },
626 true);
627 return result;
628}
629
631 const ComputeContext *bundle_socket_context,
632 const bNodeSocket &bundle_socket,
633 bke::ComputeContextCache &compute_context_cache)
634{
637 {bundle_socket_context, &bundle_socket},
638 compute_context_cache,
639 [&](const SocketInContext &socket) {
640 const NodeInContext node = socket.owner_node();
641 if (socket->is_output()) {
642 if (node->is_type("NodeCombineBundle"_ustr)) {
643 const auto &storage = *static_cast<const NodeCombineBundle *>(node->storage);
646 socket});
647 return true;
648 }
649 }
650 if (node->is_type("NodeJoinBundle"_ustr)) {
651 const SocketInContext input_socket = node.input_socket(0);
652 BundleSignature joined_signature;
653 bool is_signature_definition = true;
654 for (const bNodeLink *link : input_socket->directly_linked_links()) {
655 if (!link->is_used()) {
656 continue;
657 }
658 const bNodeSocket *socket_from = link->fromsock;
660 node.context, *socket_from, compute_context_cache);
661 for (const LinkedBundleSignatures::Item &sub_signature : sub_signatures.items) {
662 if (!sub_signature.is_signature_definition) {
663 is_signature_definition = false;
664 }
665 for (const BundleSignature::Item &item : sub_signature.signature.items) {
666 joined_signature.items.add(item);
667 }
668 }
669 }
670 result.items.append({joined_signature, is_signature_definition, socket});
671 return true;
672 }
673 return false;
674 },
675 true);
676 return result;
677}
678
680 const ComputeContext *closure_socket_context,
681 const bNodeSocket &closure_socket,
682 bke::ComputeContextCache &compute_context_cache)
683{
686 {closure_socket_context, &closure_socket},
687 compute_context_cache,
688 [&](const SocketInContext &socket) {
689 const bNode &node = socket->owner_node();
690 if (const SocketDeclaration *decl = socket.socket->runtime->declaration) {
691 if (const auto *closure_decl = dynamic_cast<const decl::Closure *>(decl)) {
692 if (closure_decl->create_signature) {
693 bool define_signature = false;
694 if (node.is_type("NodeEvaluateClosure"_ustr)) {
695 const auto &storage = *static_cast<const NodeEvaluateClosure *>(node.storage);
696 define_signature = bool(storage.flag &
698 }
699 else if (node.is_type("GeometryNodeClosureToList"_ustr)) {
700 define_signature = true;
701 }
702 result.items.append(
703 {(*closure_decl->create_signature)(node), define_signature, socket});
704 return true;
705 }
706 }
707 }
708 return false;
709 },
710 true);
711 return result;
712}
713
715 const ComputeContext *closure_socket_context,
716 const bNodeSocket &closure_socket,
717 bke::ComputeContextCache &compute_context_cache)
718{
721 {closure_socket_context, &closure_socket},
722 compute_context_cache,
723 [&](const SocketInContext &socket) {
724 const bNode &node = socket->owner_node();
725 if (is_closure_zone_output_socket(socket)) {
726 const auto &storage = *static_cast<const NodeClosureOutput *>(node.storage);
729 socket});
730 return true;
731 }
732 return false;
733 },
734 true);
735 return result;
736}
737
738std::optional<NodeInContext> find_origin_index_menu_switch(
739 const SocketInContext &src_socket, bke::ComputeContextCache &compute_context_cache)
740{
741 std::optional<NodeInContext> result;
743 src_socket,
744 compute_context_cache,
745 [&](const SocketInContext &socket) {
746 if (socket->is_input()) {
747 return false;
748 }
749 const NodeInContext node = socket.owner_node();
750 if (!node->is_type("GeometryNodeMenuSwitch"_ustr)) {
751 return false;
752 }
753 const auto &storage = *static_cast<const NodeMenuSwitch *>(node->storage);
754 if (storage.data_type != SOCK_INT) {
755 return false;
756 }
757 result = socket.owner_node();
758 return true;
759 },
760 false);
761 return result;
762}
763
764} // namespace blender::nodes
const ComputeContext * parent() const
constexpr IndexRange()=default
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_stack.hh:310
void push(const T &value)
Definition BLI_stack.hh:215
bool is_empty() const
const EvaluateClosureComputeContext & for_evaluate_closure(const ComputeContext *parent, int32_t node_id, const bNodeTree *tree=nullptr, const std::optional< nodes::ClosureSourceLocation > &closure_source_location=std::nullopt)
const GroupNodeComputeContext & for_group_node(const ComputeContext *parent, int32_t node_id, const bNodeTree *tree=nullptr)
const RepeatZoneComputeContext & for_repeat_zone(const ComputeContext *parent, int32_t output_node_id, int iteration)
const SimulationZoneComputeContext & for_simulation_zone(const ComputeContext *parent, int output_node_id)
const nodes::SocketDeclaration * declaration
const bNode * input_node() const
Vector< const bNodeTreeZone * > get_zones_to_enter(const bNodeTreeZone *outer_zone, const bNodeTreeZone *inner_zone) const
bool link_between_zones_is_allowed(const bNodeTreeZone *from_zone, const bNodeTreeZone *to_zone) const
const bNodeTreeZone * get_zone_by_node(const int32_t node_id) const
const bNodeTreeZone * get_zone_by_socket(const bNodeSocket &socket) const
static ClosureSignature from_closure_output_node(const bNode &node, bool allow_auto_structure_type)
#define storage(slot, qualifiers)
const bNodeZoneType * zone_type_by_node_type(const int node_type)
const ComputeContext * compute_context_for_zones(const Span< const bke::bNodeTreeZone * > zones, bke::ComputeContextCache &compute_context_cache, const ComputeContext *parent_compute_context)
static Vector< SocketInContext > find_origin_sockets_through_contexts(SocketInContext start_socket, bke::ComputeContextCache &compute_context_cache, FunctionRef< bool(const SocketInContext &)> handle_possible_origin_socket_fn, bool find_all)
static bool use_link_for_tracing(const bNodeLink &link)
LinkedBundleSignatures gather_linked_target_bundle_signatures(const ComputeContext *bundle_socket_context, const bNodeSocket &bundle_socket, bke::ComputeContextCache &compute_context_cache)
static bool target_socket_evaluates_closure(const SocketInContext &socket)
LinkedClosureSignatures gather_linked_target_closure_signatures(const ComputeContext *closure_socket_context, const bNodeSocket &closure_socket, bke::ComputeContextCache &compute_context_cache)
const ComputeContext * compute_context_for_closure_evaluation(const ComputeContext *closure_socket_context, const bNodeSocket &closure_socket, bke::ComputeContextCache &compute_context_cache, const std::optional< ClosureSourceLocation > &source_location)
LinkedBundleSignatures gather_linked_origin_bundle_signatures(const ComputeContext *bundle_socket_context, const bNodeSocket &bundle_socket, bke::ComputeContextCache &compute_context_cache)
LinkedClosureSignatures gather_linked_origin_closure_signatures(const ComputeContext *closure_socket_context, const bNodeSocket &closure_socket, bke::ComputeContextCache &compute_context_cache)
std::optional< NodeInContext > find_origin_index_menu_switch(const SocketInContext &src_socket, bke::ComputeContextCache &compute_context_cache)
static Vector< SocketInContext > find_target_sockets_through_contexts(const SocketInContext start_socket, bke::ComputeContextCache &compute_context_cache, const FunctionRef< bool(const SocketInContext &)> handle_possible_target_socket_fn, const bool find_all)
static bool is_closure_zone_output_socket(const SocketInContext &socket)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ NODE_CLOSURE_FLAG_DEFINE_SIGNATURE
@ NODE_EVALUATE_CLOSURE_FLAG_DEFINE_SIGNATURE
@ NODE_COMBINE_BUNDLE_FLAG_DEFINE_SIGNATURE
@ NODE_SEPARATE_BUNDLE_FLAG_DEFINE_SIGNATURE
eNodeSocketDatatype type
bke::bNodeSocketRuntime * runtime
bke::bNodeTreeType * typeinfo
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
Definition BKE_node.hh:566
static BundleSignature from_separate_bundle_node(const bNode &node, bool allow_auto_structure_type)
CustomIDVectorSet< Item, ItemKeyGetter > items
static BundleSignature from_combine_bundle_node(const bNode &node, bool allow_auto_structure_type)
SocketInContext input_socket(int index) const
SocketInContext output_socket(int index) const