Blender V5.0
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
14
15#include "GPU_shader.hh"
16
18#include "COM_result.hh"
19
20namespace blender::compositor {
21
22using namespace nodes::derived_node_tree_types;
23
24/* Returns true if the socket is available and not virtual. Returns false otherwise. */
25bool is_socket_available(const bNodeSocket *socket);
26
34
40
44 const std::optional<int> dimensions = std::nullopt);
45
48
54 FunctionRef<bool(DNode)> condition);
55
58 FunctionRef<bool(DInputSocket)> condition);
59
61bool is_pixel_node(DNode node);
62
65
74void compute_dispatch_threads_at_least(gpu::Shader *shader,
75 int2 threads_range,
76 int2 local_size = int2(16));
77
78/* Returns true if a node preview needs to be computed for the give node. */
79bool is_node_preview_needed(const DNode &node);
80
81/* Returns the node output that will be used to generate previews. */
83
84/* -------------------------------------------------------------------- */
85/* Inline Functions.
86 */
87
88/* Executes the given function in parallel over the given 2D range. The given function gets the
89 * texel coordinates of the element of the range as an argument. */
90template<typename Function> inline void parallel_for(const int2 range, const Function &function)
91{
92 threading::parallel_for(IndexRange(range.y), 1, [&](const IndexRange sub_y_range) {
93 for (const int64_t y : sub_y_range) {
94 for (const int64_t x : IndexRange(range.x)) {
95 function(int2(x, y));
96 }
97 }
98 });
99}
100
101} // namespace blender::compositor
eNodeSocketDatatype
struct bNodeSocket bNodeSocket
#define input
#define output
int number_of_inputs_linked_to_output_conditioned(DOutputSocket output, FunctionRef< bool(DInputSocket)> condition)
Definition utilities.cc:126
ResultType socket_data_type_to_result_type(const eNodeSocketDatatype data_type, const std::optional< int > dimensions=std::nullopt)
Definition utilities.cc:68
bool is_output_linked_to_node_conditioned(DOutputSocket output, FunctionRef< bool(DNode)> condition)
Definition utilities.cc:113
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
Definition utilities.cc:196
DSocket get_input_origin_socket(DInputSocket input)
Definition utilities.cc:32
DOutputSocket find_preview_output_socket(const DNode &node)
Definition utilities.cc:226
ResultType get_node_socket_result_type(const bNodeSocket *socket)
Definition utilities.cc:102
DOutputSocket get_output_linked_to_input(DInputSocket input)
Definition utilities.cc:52
InputDescriptor input_descriptor_from_input_socket(const bNodeSocket *socket)
Definition utilities.cc:169
void parallel_for(const int2 range, const Function &function)
bool is_pixel_node(DNode node)
Definition utilities.cc:143
bool is_socket_available(const bNodeSocket *socket)
Definition utilities.cc:27
bool is_node_preview_needed(const DNode &node)
Definition utilities.cc:206
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:93
VecBase< int32_t, 2 > int2