Blender V5.3
COM_scheduler.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "BLI_function_ref.hh"
8#include "BLI_set.hh"
9#include "BLI_vector_set.hh"
10
11namespace blender {
12struct bNodeTree;
13struct bNode;
14struct bNodeSocket;
16class ComputeContext;
17
18namespace bke {
19class bNodeTreeZone;
20}
21
22} // namespace blender
23
24namespace blender::compositor {
25
26class Context;
27class Result;
28
29struct Schedule {
30 /* The node group the schedule is for. */
32 /* The zone that the schedule is for, if nullptr, the schedule is for the root node tree. */
33 const bke::bNodeTreeZone *zone = nullptr;
34 /* The node execution schedule. */
36 /* Holds the set of all inputs sockets that needn't be computed because the node does not need
37 * them, for instance, the unneeded inputs of a Switch node. */
39};
40
41/* A function that returns the result associated with the given socket if it is known statically
42 * and nullptr otherwise. For instance, the results associated with the sockets of the Group Input
43 * and Group Output nodes are known statically because they are those of the node group operation
44 * itself, not a node that is yet to be compiled and evaluated. */
46
47/* Computes the execution schedule of the given node group in the given compute context. If the
48 * results associated with some of the sockets are known, the socket_result_fn callback should
49 * provide them. Only output types and node group outputs that are needed are computed. If a zone
50 * is provided, then only nodes in the zone are scheduled. The execution schedule only includes the
51 * zone output node of child zones, the caller will have to recursively schedule zones to fully
52 * schedule the node tree.
53 *
54 * This is essentially a post-order depth first traversal of the node tree from the needed output
55 * nodes to the leaf input nodes, with informed order of traversal of dependencies based on a
56 * heuristic estimation of the number of needed buffers. */
57Schedule compute_schedule(const Context &context,
58 const bNodeTree &node_group,
59 const ComputeContext &compute_context,
60 SocketResultFn socket_result_fn,
61 const bke::bNodeTreeZone *zone = nullptr);
62
63/* Computes how many times the given output is referenced in the given schedule, ignoring outgoing
64 * links to the given ignored nodes if not nullptr. */
66 const Schedule &schedule,
67 const VectorSet<const bNode *> *ignored_nodes = nullptr);
68
69} // namespace blender::compositor
#define output
int compute_output_reference_count(const bNodeSocket &output, const Schedule &schedule, const VectorSet< const bNode * > *ignored_nodes=nullptr)
Definition scheduler.cc:780
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
FunctionRef< Result *(const bNodeSocket &)> SocketResultFn
BMesh Iterators.
Set< const bNodeSocket * > unneeded_inputs
const bke::bNodeTreeZone * zone
VectorSet< const bNode * > nodes