Blender V5.3
zone_tree_operation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "DNA_node_types.h"
6
8#include "BKE_node.hh"
9#include "BKE_node_runtime.hh"
11
13#include "COM_operation.hh"
14#include "COM_result.hh"
15#include "COM_scheduler.hh"
16#include "COM_utilities.hh"
18
19namespace blender::compositor {
20
22 const bke::bNodeTreeZone &zone,
23 const ComputeContext &compute_context)
24 : Operation(context), zone_(zone), compute_context_(compute_context)
25{
26 /* Declare inputs. */
27 for (const bNodeSocket *output : zone_.input_node()->output_sockets()) {
28 if (!is_socket_available(output)) {
29 continue;
30 }
31
32 const InputDescriptor input_descriptor = InputDescriptor{get_node_socket_result_type(output),
33 InputRealizationMode::None};
34 this->declare_input_descriptor(output->identifier, input_descriptor);
35 }
36
37 /* Declare inputs for border links. */
38 Set<const bNodeSocket *> outputs_already_considered;
39 for (const bNodeLink *link : zone_.border_links) {
40 const bNodeSocket *output = get_output_linked_to_input(*link->tosock);
41 if (!output) {
42 continue;
43 }
44
45 if (outputs_already_considered.contains(output)) {
46 continue;
47 }
48 outputs_already_considered.add_new(output);
49
50 const InputDescriptor input_descriptor = InputDescriptor{get_node_socket_result_type(output),
51 InputRealizationMode::None};
52 const std::string input_identifier = ZoneTreeOperation::get_external_input_identifier(*output);
53 this->declare_input_descriptor(input_identifier, input_descriptor);
54 }
55
56 /* Declare outputs. */
57 for (const bNodeSocket *input : zone_.output_node()->input_sockets()) {
58 if (!is_socket_available(input)) {
59 continue;
60 }
61
62 this->populate_result(input->identifier, get_node_socket_result_type(input));
63 }
64}
65
66/* Get the results associated with sockets in the zone prior to its evaluation. */
68 const bke::bNodeTreeZone &zone,
69 const bNodeSocket &socket)
70{
71 if (zone.input_node() == &socket.owner_node()) {
72 return &operation.get_input(socket.identifier);
73 }
74 if (zone.output_node() == &socket.owner_node()) {
75 return &operation.get_result(socket.identifier);
76 }
77 return nullptr;
78}
79
81{
82 auto socket_result_fn = [&](const bNodeSocket &socket) {
83 return get_zone_result_for_socket(*this, zone_, socket);
84 };
85 const Schedule schedule = compute_schedule(
86 this->context(), *zone_.owner->tree, compute_context_, socket_result_fn, &zone_);
87 NodeTreeEvaluator node_tree_evaluator(this->context(), schedule, *this, compute_context_);
88 node_tree_evaluator.evaluate();
89
90 /* Some of the needed outputs might not be allocated even after execution. This could happen for
91 * instance when the evaluation gets canceled before the output is written. */
93}
94
96{
97 return std::string("External Input: ") + output.owner_node().name + ":" + output.identifier;
98}
99
100} // namespace blender::compositor
#define output
bool contains(const Key &key) const
Definition BLI_set.hh:310
void add_new(const Key &key)
Definition BLI_set.hh:233
const bNode * output_node() const
const bNode * input_node() const
Result & get_result(StringRef identifier)
Definition operation.cc:40
Operation(Context &context)
Definition operation.cc:22
Context & context() const
Definition operation.cc:57
Result & get_input(StringRef identifier) const
Definition operation.cc:35
static std::string get_external_input_identifier(const bNodeSocket &output)
ZoneTreeOperation(Context &context, const bke::bNodeTreeZone &zone, const ComputeContext &compute_context)
Schedule compute_schedule(const Context &context, const bNodeTree &node_group, const ComputeContext &compute_context, SocketResultFn socket_result_fn, const bke::bNodeTreeZone *zone=nullptr)
Definition scheduler.cc:720
static Result * get_zone_result_for_socket(ZoneTreeOperation &operation, const bke::bNodeTreeZone &zone, const bNodeSocket &socket)