Blender V5.3
COM_utilities.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 <optional>
8
9#include "BLI_index_range.hh"
11#include "BLI_task.hh"
12
13#include "DNA_node_types.h"
14
15#include "GPU_shader.hh"
16
18#include "COM_result.hh"
19
20namespace blender::compositor {
21
22/* Returns true if the socket is available and not virtual. Returns false otherwise. */
23bool is_socket_available(const bNodeSocket *socket);
24
25/* Get the output socket linked to the given node input. If the input is not linked to an output,
26 * a null output is returned. */
27const bNodeSocket *get_output_linked_to_input(const bNodeSocket &input);
28
29/* Get the result type that corresponds to the given socket data type. For vector sockets, the
30 * dimensions of the socket can be provided, but if not provided, 3 will be assumed. */
32 const std::optional<int> dimensions = std::nullopt);
33
34/* Get the result type that corresponds to the type of the given socket. */
35ResultType get_node_socket_result_type(const bNodeSocket *socket);
36
37/* Get the result type that corresponds to the type of the given interface socket. */
38ResultType get_node_interface_socket_result_type(const bNodeTreeInterfaceSocket &socket);
39
40/* Returns true if any of the inputs linked to the given output satisfies the given condition,
41 * and false otherwise. */
42bool is_output_linked_to_input_conditioned(const bNodeSocket &output,
43 FunctionRef<bool(const bNodeSocket &)> condition);
44
45/* A node is a pixel node if it defines a method to get a pixel node operation. */
46bool is_pixel_node(const bNode &node);
47
48/* Get the input descriptor of the given input socket. */
50
51/* Get the input descriptor of the given interface input of the given node group. */
53 const bNodeTreeInterfaceSocket &socket);
54
55/* Dispatch the given compute shader in a 2D compute space such that the number of threads in both
56 * dimensions is as small as possible but at least covers the entirety of threads_range assuming
57 * the shader has a local group size given by local_size. That means that the number of threads
58 * might be a bit larger than threads_range, so shaders has to put that into consideration. A
59 * default local size of 16x16 is assumed, which is the optimal local size for many image
60 * processing shaders. */
61void compute_dispatch_threads_at_least(gpu::Shader *shader,
62 int2 threads_range,
63 int2 local_size = int2(16));
64
65/* Returns true if a node preview needs to be computed for the give node. */
66bool is_node_preview_needed(const bNode &node);
67
68/* Returns the node output that will be used to generate previews. */
69const bNodeSocket *find_preview_output_socket(const bNode &node);
70
71/* -------------------------------------------------------------------- */
72/* Inline Functions.
73 */
74
75/* Executes the given function in parallel over the given 2D range. The given function gets the
76 * texel coordinates of the element of the range as an argument. */
77template<typename Function> inline void parallel_for(const int2 range, const Function &function)
78{
79 threading::parallel_for(IndexRange(range.y), 1, [&](const IndexRange sub_y_range) {
80 for (const int64_t y : sub_y_range) {
81 for (const int64_t x : IndexRange(range.x)) {
82 function(int2(x, y));
83 }
84 }
85 });
86}
87
88} // namespace blender::compositor
#define output
constexpr IndexRange()=default
#define condition(cond)
#define local_size(...)
ResultType socket_data_type_to_result_type(const eNodeSocketDatatype data_type, const std::optional< int > dimensions=std::nullopt)
Definition utilities.cc:39
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
Definition utilities.cc:235
const bNodeSocket * find_preview_output_socket(const bNode &node)
Definition utilities.cc:258
bool is_node_preview_needed(const bNode &node)
Definition utilities.cc:245
ResultType get_node_interface_socket_result_type(const bNodeTreeInterfaceSocket &socket)
Definition utilities.cc:123
const bNodeSocket * get_output_linked_to_input(const bNodeSocket &input)
Definition utilities.cc:31
bool is_output_linked_to_input_conditioned(const bNodeSocket &output, FunctionRef< bool(const bNodeSocket &)> condition)
Definition utilities.cc:143
InputDescriptor input_descriptor_from_interface_input(const bNodeTree &node_group, const bNodeTreeInterfaceSocket &socket)
Definition utilities.cc:221
ResultType get_node_socket_result_type(const bNodeSocket *socket)
Definition utilities.cc:103
bool is_pixel_node(const bNode &node)
Definition utilities.cc:154
InputDescriptor input_descriptor_from_input_socket(const bNodeSocket *socket)
Definition utilities.cc:195
void parallel_for(const int2 range, const Function &function)
bool is_socket_available(const bNodeSocket *socket)
Definition utilities.cc:26
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69