Blender V5.3
COM_multi_function_procedure_operation.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <memory>
8
9#include "BLI_map.hh"
10#include "BLI_set.hh"
11#include "BLI_vector.hh"
12#include "BLI_vector_set.hh"
13
17
18#include "NOD_multi_function.hh"
19
20#include "COM_context.hh"
23
24namespace blender::compositor {
25
26struct Schedule;
27
28/* ------------------------------------------------------------------------------------------------
29 * Multi-Function Procedure Operation
30 *
31 * A pixel operation that evaluates a multi-function procedure built from the pixel compile unit
32 * using the multi-function procedure builder, see FN_multi_function_procedure_builder.hh for more
33 * information. Also see the PixelOperation class for more information on pixel operations. */
35 private:
36 /* The multi-function procedure, its builder, and executor that are backing the operation. This
37 * is created and compiled during construction. */
38 mf::Procedure procedure_;
39 mf::ProcedureBuilder procedure_builder_;
40 std::unique_ptr<mf::ProcedureExecutor> procedure_executor_;
41 /* A map that associates each node in the compile unit with an instance of its multi-function
42 * builder. */
44 /* A map that associates the output sockets of each node to the variables that were created for
45 * them. */
46 Map<const bNodeSocket *, mf::Variable *> output_to_variable_map_;
47 /* A map that associates implicit inputs to the variables that were created for them. */
48 Map<ImplicitInputType, mf::Variable *> implicit_input_to_variable_map_;
49 /* A vector that stores the intermediate variables that were implicitly created for the procedure
50 * but are not associated with a node output. Those variables are for such multi-functions like
51 * constant inputs and implicit conversion. */
52 Vector<mf::Variable *> implicit_variables_;
53 /* A set that stores the variables that are used as the outputs of the procedure. */
54 Set<mf::Variable *> output_variables_;
55 /* A vector that stores the identifiers of the parameters of the multi-function procedure in
56 * order. The parameters include both inputs and outputs. This is used to retrieve the input and
57 * output results for each of the parameters in the procedure. Note that parameters have no
58 * identifiers and are identified solely by their order. */
59 Vector<std::string> parameter_identifiers_;
60
61 public:
62 /* Build a multi-function procedure as well as an executor for it from the given pixel compile
63 * unit and execution schedule. If the operation is operating on single values, is_single_value
64 * should be true. */
66 NodeTreeEvaluator &node_tree_evaluator,
67 const bool is_single_value,
68 const ComputeContext &compute_context);
69
70 /* Calls the multi-function procedure executor on the domain of the operator passing in the
71 * inputs and outputs as parameters. */
72 void execute() override;
73
74 private:
75 /* Builds the procedure by going over the nodes in the compile unit, calling their
76 * multi-functions and creating any necessary inputs or outputs to the operation/procedure. */
77 void build_procedure();
78
79 /* Get the variables corresponding to the inputs of the given node. The variables can be those
80 * that were returned by a previous call to a multi-function, those that were generated as
81 * constants for unlinked inputs, or those that were added as inputs to the operation/procedure
82 * itself. The variables are implicitly converted to the type expected by the multi-function. */
83 Vector<mf::Variable *> get_input_variables(const bNode &node,
84 const mf::MultiFunction &multi_function);
85
86 /* Returns a constant variable that was created by calling a constant function carrying the value
87 * of the given input socket. */
88 mf::Variable *get_constant_input_variable(const bNodeSocket &input);
89
90 /* Given an unlinked input with an implicit input. Declare an input to the operation/procedure
91 * for that implicit input if not done already and return a variable that represent that implicit
92 * input. */
93 mf::Variable *get_implicit_input_variable(const bNodeSocket &input);
94
95 /* Given an input in a node that is part of the compile unit that is connected to an output that
96 * is in a non that is not part of the compile unit. Declare an input to the operation/procedure
97 * for that output if not done already and return a variable that represent that input. */
98 mf::Variable *get_multi_function_input_variable(const bNodeSocket &input_socket,
99 const bNodeSocket &output_socket);
100
101 /* Given the variables that were returned by calling the multi-function for the given node,
102 * assign the variables to their corresponding outputs. And if an output is connected to a node
103 * outside of the compile unit or is used as the preview of the node, declare an output to the
104 * operation/procedure for it. */
105 void assign_output_variables(const bNode &node, Vector<mf::Variable *> &variables);
106
107 /* Populate an output to the operator/procedure for the given output socket whose value is stored
108 * in the given variable. The variable is implicitly converted to the type expected by the
109 * socket. */
110 void populate_operation_result(const bNodeSocket &output_socket, mf::Variable *variable);
111
112 /* Convert the given variable to the given expected type. This is done by adding an implicit
113 * conversion function whose output variable will be returned. If no conversion is needed, the
114 * given variable is returned as is. If conversion is not possible, a fallback default variable
115 * will b returned. */
116 mf::Variable *convert_variable(mf::Variable *variable, const mf::DataType expected_type);
117
118 /* Creates and returns a variable that carries the default value of the given type. */
119 mf::Variable *get_default_value_variable(const mf::DataType type);
120};
121
122} // namespace blender::compositor
MultiFunctionProcedureOperation(Context &context, NodeTreeEvaluator &node_tree_evaluator, const bool is_single_value, const ComputeContext &compute_context)
Context & context() const
Definition operation.cc:57
PixelOperation(Context &context, NodeTreeEvaluator &node_tree_evaluator, const ComputeContext &compute_context, const bool is_single_value)