Blender V5.3
node_group_operation.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
6#include "BLI_string_ref.hh"
7
8#include "DNA_node_types.h"
9
10#include "BKE_node.hh"
11#include "BKE_node_runtime.hh"
12
13#include "NOD_eval_log.hh"
14
15#include "COM_context.hh"
19#include "COM_operation.hh"
20#include "COM_scheduler.hh"
21#include "COM_utilities.hh"
22
23namespace blender::compositor {
24
26 const bNodeTree &node_group,
27 const ComputeContext &compute_context)
28 : Operation(context), node_group_(node_group), compute_context_(compute_context)
29{
30 node_group.ensure_interface_cache();
31 for (const bNodeTreeInterfaceSocket *input : node_group.interface_inputs()) {
32 const InputDescriptor input_descriptor = input_descriptor_from_interface_input(node_group,
33 *input);
34 this->declare_input_descriptor(input->identifier, input_descriptor);
35 }
36
37 for (const bNodeTreeInterfaceSocket *output : node_group.interface_outputs()) {
38 this->populate_result(output->identifier, get_node_interface_socket_result_type(*output));
39 }
40}
41
43 private:
44 const ComputeContext &compute_context_;
46
48
49 public:
51 : compute_context_(compute_context), log_(log)
52 {
53 start_ = nodes::eval_log::Clock::now();
54 }
55
57 {
58 if (!log_) {
59 return;
60 }
61 const nodes::eval_log::TimePoint end = nodes::eval_log::Clock::now();
62 nodes::eval_log::NodeTreeLogger &tree_logger = log_->get_local_tree_logger(compute_context_);
63 tree_logger.execution_time = end - start_;
64 }
65};
66
67/* Get the results associated with sockets in the node group prior to its evaluation. */
69 const bNodeSocket &socket)
70{
71 if (socket.owner_node().is_group_input()) {
72 return &operation.get_input(socket.identifier);
73 }
74 if (socket.owner_node().is_group_output()) {
75 return &operation.get_result(socket.identifier);
76 }
77 return nullptr;
78}
79
81{
82 const ScopedNodeGroupTimer node_group_timer{compute_context_,
84 auto socket_result_fn = [&](const bNodeSocket &socket) {
85 return get_node_group_result_for_socket(*this, socket);
86 };
87 const Schedule schedule = compute_schedule(
88 this->context(), this->node_group(), compute_context_, socket_result_fn);
89 NodeTreeEvaluator node_tree_evaluator(this->context(), schedule, *this, compute_context_);
90 node_tree_evaluator.evaluate();
91
92 /* Some of the needed outputs might not be allocated even after execution. This could happen for
93 * instance when no Group Output node exist or when the evaluation gets canceled before the
94 * output is written. */
96}
97
99{
100 return node_group_;
101}
102
103} // namespace blender::compositor
#define output
virtual nodes::eval_log::NodesEvalLog * nodes_evaluation_log() const
NodeGroupOperation(Context &context, const bNodeTree &node_group, const ComputeContext &compute_context)
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
ScopedNodeGroupTimer(const ComputeContext &compute_context, nodes::eval_log::NodesEvalLog *log)
std::chrono::nanoseconds execution_time
#define log
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_node_group_result_for_socket(NodeGroupOperation &operation, const bNodeSocket &socket)
Clock::time_point TimePoint