Blender V4.3
COM_pixel_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 "BLI_map.hh"
8#include "BLI_string_ref.hh"
9#include "BLI_vector_set.hh"
10
12
13#include "COM_context.hh"
14#include "COM_operation.hh"
15#include "COM_scheduler.hh"
16
18
19using namespace nodes::derived_node_tree_types;
20
21/* A type representing a contiguous subset of the node execution schedule that will be compiled
22 * into a Pixel Operation. */
24
25/* ------------------------------------------------------------------------------------------------
26 * Pixel Operation
27 *
28 * An operation that is evaluated pixel-wise and is compiled from a contiguous subset of the node
29 * execution schedule, whose nodes all represent pixel-wise operations. The subset of the node
30 * execution schedule is called a Pixel Compile Unit and contains nodes that are called Pixel
31 * nodes, see the discussion in COM_compile_state.hh for more information. Since the nodes inside
32 * the compile unit are all pixel wise, they can be combined into a single operation that can be
33 * evaluated more efficiently. This is an abstract class that should be implemented to compile and
34 * evaluate the compile unit as needed.
35 *
36 * Consider the following node graph with a node execution schedule denoted by the number on each
37 * node. The compiler may decide to compile a subset of the execution schedule into a pixel
38 * operation if they are all pixel nodes, in this case, the nodes from 3 to 5 were compiled
39 * together into a pixel operation. This subset is called the pixel compile unit. See the
40 * discussion in COM_evaluator.hh for more information on the compilation process. Links that are
41 * internal to the pixel operation are established between the input and outputs of the pixel
42 * nodes, for instance, the links between nodes 3 and 4 as well as those between nodes 4 and 5.
43 * However, links that cross the boundary of the pixel operation needs special handling.
44 *
45 * Pixel Operation
46 * +------------------------------------------------------+
47 * .------------. | .------------. .------------. .------------. | .------------.
48 * | Node 1 | | | Node 3 | | Node 4 | | Node 5 | | | Node 6 |
49 * | |----|--| |--| |------| |--|--| |
50 * | | .-|--| | | | .---| | | | |
51 * '------------' | | '------------' '------------' | '------------' | '------------'
52 * | +----------------------------------|-------------------+
53 * .------------. | |
54 * | Node 2 | | |
55 * | |--'------------------------------------'
56 * | |
57 * '------------'
58 *
59 * Links from nodes that are not part of the pixel operation to nodes that are part of the pixel
60 * operation are considered inputs of the operation itself and are declared as such. For instance,
61 * the link from node 1 to node 3 is declared as an input to the operation, and the same applies
62 * for the links from node 2 to nodes 3 and 5. Note, however, that only one input is declared for
63 * each distinct output socket, so both links from node 2 share the same input of the operation.
64 *
65 * Links from nodes that are part of the pixel operation to nodes that are not part of the pixel
66 * operation are considered outputs of the operation itself and are declared as such. For instance,
67 * the link from node 5 to node 6 is declared as an output to the operation. */
68class PixelOperation : public Operation {
69 protected:
70 /* The compile unit that will be compiled into this pixel operation. */
72 /* A reference to the node execution schedule that is being compiled. */
74 /* A map that associates the identifier of each input of the operation with the output socket it
75 * is linked to. This is needed to help the compiler establish links between operations. */
77 /* A map that associates the output socket that provides the result of an output of the operation
78 * with the identifier of that output. This is needed to help the compiler establish links
79 * between operations. */
81 /* A vector set that stores all output sockets that are used as previews for nodes inside the
82 * pixel operation. */
84
85 public:
86 PixelOperation(Context &context, PixelCompileUnit &compile_unit, const Schedule &schedule);
87
88 /* Compute a node preview for all nodes in the pixel operations if the node requires a preview.
89 *
90 * Previews are computed from results that are populated for outputs that are used to compute
91 * previews even if they are internally linked, and those outputs are stored and tracked in the
92 * preview_outputs_ vector set, see the populate_results_for_node method for more information. */
93 void compute_preview() override;
94
95 /* Get the identifier of the operation output corresponding to the given output socket. This is
96 * called by the compiler to identify the operation output that provides the result for an input
97 * by providing the output socket that the input is linked to. See
98 * output_sockets_to_output_identifiers_map_ for more information. */
99 StringRef get_output_identifier_from_output_socket(DOutputSocket output_socket);
100
101 /* Get a reference to the inputs to linked outputs map of the operation. This is called by the
102 * compiler to identify the output that each input of the operation is linked to for correct
103 * input mapping. See inputs_to_linked_outputs_map_ for more information. */
105
106 /* Compute and set the initial reference counts of all the results of the operation. The
107 * reference counts of the results are the number of operations that use those results, which is
108 * computed as the number of inputs linked to the output corresponding to each of the results of
109 * the operation, but only the linked inputs whose node is part of the schedule but not part of
110 * the pixel operation, since inputs that are part of the pixel operations are internal links.
111 *
112 * Additionally, results that are used as node previews gets an extra reference count because
113 * they are referenced and released by the compute_preview method.
114 *
115 * The node execution schedule is given as an input. */
116 void compute_results_reference_counts(const Schedule &schedule);
117};
118
119} // namespace blender::realtime_compositor
Map< std::string, DOutputSocket > & get_inputs_to_linked_outputs_map()
PixelOperation(Context &context, PixelCompileUnit &compile_unit, const Schedule &schedule)
void compute_results_reference_counts(const Schedule &schedule)
StringRef get_output_identifier_from_output_socket(DOutputSocket output_socket)
Map< DOutputSocket, std::string > output_sockets_to_output_identifiers_map_
Map< std::string, DOutputSocket > inputs_to_linked_outputs_map_