74 struct SocketToCheck {
76 BundlePath bundle_path;
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)});
88 add_if_new(start_socket, {});
92 while (!sockets_to_check.
is_empty()) {
93 const SocketToCheck socket_to_check = sockets_to_check.
pop();
95 const BundlePath &bundle_path = socket_to_check.bundle_path;
97 if (socket->is_input()) {
98 if (
node->is_muted()) {
100 if (link.in == socket.
socket) {
101 add_if_new({socket.
context, link.out}, bundle_path);
106 if (bundle_path.is_empty() && handle_possible_target_socket_fn(socket)) {
107 found_targets.add(socket);
113 if (
node->is_reroute()) {
114 add_if_new(
node.output_socket(0), bundle_path);
117 if (
node->is_group()) {
119 group->ensure_topology_cache();
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()))
126 if (group_input_socket->is_directly_linked()) {
127 add_if_new({&group_compute_context, group_input_socket}, bundle_path);
134 if (
node->is_group_output()) {
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()))
145 add_if_new({group_context->parent(), output_socket}, bundle_path);
151 if (
node->is_type(
"NodeCombineBundle"_ustr)) {
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));
158 if (
node->is_type(
"NodeSeparateBundle"_ustr)) {
159 if (bundle_path.is_empty()) {
162 const StringRef last_key = bundle_path.last();
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));
171 if (
node->is_type(
"NodeClosureOutput"_ustr)) {
173 const StringRef key = closure_storage.output_items.items[socket->index()].name;
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)) {
183 for (
const int i :
IndexRange(evaluate_storage.output_items.items_num)) {
185 if (key == item.
name) {
192 if (
node->is_type(
"NodeEvaluateClosure"_ustr)) {
193 if (socket->index() == 0) {
197 const StringRef key = evaluate_storage.input_items.items[socket->index() - 1].name;
201 const bNodeTree &closure_tree = origin_socket->owner_tree();
203 if (!closure_tree_zones) {
206 const auto &closure_output_node = origin_socket.owner_node();
208 closure_output_node->identifier);
213 if (!closure_input_node) {
222 closure_output_node->identifier,
223 origin_socket.context_hash(),
224 origin_socket.context});
229 closure_output_node->storage);
230 for (
const int i :
IndexRange(closure_output_storage.input_items.items_num)) {
232 if (key == item.
name) {
233 add_if_new({&closure_context, &closure_input_node->output_socket(i)}, bundle_path);
239 if (
node->is_type(
"GeometryNodeSimulationInput"_ustr)) {
242 add_if_new({&simulation_compute_context, &
node->output_socket(socket->index() + 1)},
246 if (
node->is_type(
"GeometryNodeSimulationOutput"_ustr)) {
247 const int output_index = socket->index();
248 if (output_index >= 1) {
255 if (
node->is_type(
"GeometryNodeRepeatInput"_ustr)) {
256 const int index = socket->index();
260 add_if_new({&repeat_compute_context, &
node->output_socket(
index)}, bundle_path);
262 if (
const bNode *repeat_output_node =
node->owner_tree().node_by_id(
265 add_if_new({socket.
context, &repeat_output_node->output_socket(
index - 1)},
271 if (
node->is_type(
"GeometryNodeRepeatOutput"_ustr)) {
273 add_if_new({socket.
context->
parent(), &
node->output_socket(socket->index())}, bundle_path);
282 if (bundle_decl->pass_through_input_index == socket->index()) {
283 add_if_new({socket.
context, output_socket}, bundle_path);
294 for (
const bNodeLink *link : socket->directly_linked_links()) {
306 zones_to_enter, compute_context_cache, socket.
context);
307 if (!compute_context) {
310 add_if_new({compute_context, to_socket}, bundle_path);
350 struct SocketToCheck {
352 BundlePath bundle_path;
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)});
364 add_if_new(start_socket, {});
368 while (!sockets_to_check.
is_empty()) {
369 const SocketToCheck socket_to_check = sockets_to_check.
pop();
371 const BundlePath &bundle_path = socket_to_check.bundle_path;
374 if (socket->is_input()) {
375 if (bundle_path.is_empty() && handle_possible_origin_socket_fn(socket)) {
376 found_origins.add(socket);
387 for (
const bNodeLink *link : socket->directly_linked_links()) {
399 if (
const auto *evaluate_closure_context =
402 const std::optional<nodes::ClosureSourceLocation> &source_location =
403 evaluate_closure_context->closure_source_location();
407 compute_context = source_location->compute_context;
410 compute_context = compute_context->
parent();
413 add_if_new({compute_context, from_socket}, bundle_path);
417 if (
node->is_muted()) {
419 if (link.out == socket.
socket) {
420 add_if_new({socket.
context, link.in}, bundle_path);
425 if (bundle_path.is_empty() && handle_possible_origin_socket_fn(socket)) {
426 found_origins.add(socket);
432 if (
node->is_reroute()) {
433 add_if_new(
node.input_socket(0), bundle_path);
436 if (
node->is_group()) {
438 group->ensure_topology_cache();
439 if (
const bNode *group_output_node = group->group_output_node()) {
442 if (
const bNodeSocket *group_output_socket = group_output_node->input_by_identifier(
443 socket->identifier_ustr()))
445 add_if_new({&group_compute_context, group_output_socket}, bundle_path);
451 if (
node->is_group_input()) {
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()))
462 add_if_new({group_context->parent(), input_socket}, bundle_path);
468 if (
node->is_type(
"NodeJoinBundle"_ustr)) {
469 add_if_new(
node.input_socket(0), bundle_path);
472 if (
node->is_type(
"NodeEvaluateClosure"_ustr)) {
474 const StringRef key = evaluate_storage.output_items.items[socket->index()].name;
478 const bNodeTree &closure_tree = origin_socket->owner_tree();
479 const NodeInContext closure_output_node = origin_socket.owner_node();
488 closure_output_node->identifier,
489 origin_socket.context_hash(),
490 origin_socket.context});
494 for (
const int i :
IndexRange(closure_storage.output_items.items_num)) {
496 if (key == item.
name) {
497 add_if_new({&closure_context, &closure_output_node->input_socket(i)}, bundle_path);
503 if (
node->is_type(
"NodeClosureInput"_ustr)) {
505 const bNode *closure_output_node =
node->owner_tree().node_by_id(
506 input_storage.output_node_id);
507 if (!closure_output_node) {
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,
520 const NodeInContext target_node = target_socket.owner_node();
521 if (!target_node->is_type(
"NodeEvaluateClosure"_ustr)) {
526 for (
const int i :
IndexRange(evaluate_storage.input_items.items_num)) {
528 if (key == item.
name) {
529 add_if_new(target_node.
input_socket(i + 1), bundle_path);
535 if (
node->is_type(
"NodeCombineBundle"_ustr)) {
536 if (bundle_path.is_empty()) {
539 const StringRef last_key = bundle_path.last();
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));
548 if (
node->is_type(
"NodeSeparateBundle"_ustr)) {
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));
555 if (
node->is_type(
"GeometryNodeSimulationInput"_ustr)) {
556 const int output_index = socket->index();
557 if (output_index >= 1) {
564 if (
node->is_type(
"GeometryNodeSimulationOutput"_ustr)) {
567 add_if_new({&simulation_compute_context, &
node->input_socket(socket->index() + 1)},
571 if (
node->is_type(
"GeometryNodeRepeatInput"_ustr)) {
572 const int index = socket->index();
579 if (
node->is_type(
"GeometryNodeRepeatOutput"_ustr)) {
580 const int index = socket->index();
583 add_if_new({&repeat_compute_context, &
node->input_socket(
index)}, bundle_path);
585 if (
const bNode *repeat_input_node = zone_type.get_corresponding_input(
node->owner_tree(),
588 add_if_new({socket.
context, &repeat_input_node->input_socket(
index + 1)}, bundle_path);
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);
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)