Blender V4.3
COM_ExecutionSystem.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <functional>
8
9#include "atomic_ops.h"
10
11#include "BLI_index_range.hh"
12#include "BLI_threads.h"
13#include "BLI_vector.hh"
14
17
18#include "DNA_color_types.h"
19#include "DNA_node_types.h"
20#include "DNA_scene_types.h"
21#include "DNA_vec_types.h"
22
24class RenderContext;
25class Profiler;
26} // namespace blender::realtime_compositor
27
28namespace blender::compositor {
29
86/* Forward declarations. */
87class ExecutionModel;
88class NodeOperation;
89
94 private:
99 SharedOperationBuffers active_buffers_;
100
104 CompositorContext context_;
105
109 Vector<NodeOperation *> operations_;
110
114 ExecutionModel *execution_model_;
115
119 int num_work_threads_;
120
121 ThreadMutex work_mutex_;
122 ThreadCondition work_finished_cond_;
123
124 public:
133 Scene *scene,
134 bNodeTree *editingtree,
135 bool rendering,
136 const char *view_name,
139
144
145 void set_operations(Span<NodeOperation *> operations);
146
153 void execute();
154
159 {
160 return context_;
161 }
162
166 void execute_work(const rcti &work_rect, std::function<void(const rcti &split_rect)> work_func);
167
172 template<typename TResult>
173 void execute_work(const rcti &work_rect,
174 std::function<TResult(const rcti &split_rect)> work_func,
175 TResult &join,
176 std::function<void(TResult &join, const TResult &chunk)> reduce_func)
177 {
178 Array<TResult> chunks(num_work_threads_);
179 int num_started = 0;
180 execute_work(work_rect, [&](const rcti &split_rect) {
181 const int current = atomic_fetch_and_add_int32(&num_started, 1);
182 chunks[current] = work_func(split_rect);
183 });
184 for (const int i : IndexRange(num_started)) {
185 reduce_func(join, chunks[i]);
186 }
187 }
188
189 bool is_breaked() const;
190
191 private:
192 /* allow the DebugInfo class to look at internals */
193 friend class DebugInfo;
194
195#ifdef WITH_CXX_GUARDEDALLOC
196 MEM_CXX_CLASS_ALLOC_FUNCS("COM:ExecutionSystem")
197#endif
198};
199
200} // namespace blender::compositor
pthread_cond_t ThreadCondition
pthread_mutex_t ThreadMutex
Definition BLI_threads.h:83
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
ATOMIC_INLINE int32_t atomic_fetch_and_add_int32(int32_t *p, int32_t x)
Overall context of the compositor.
the ExecutionSystem contains the whole compositor tree.
const CompositorContext & get_context() const
get the reference to the compositor context
void set_operations(Span< NodeOperation * > operations)
ExecutionSystem(RenderData *rd, Scene *scene, bNodeTree *editingtree, bool rendering, const char *view_name, realtime_compositor::RenderContext *render_context, realtime_compositor::Profiler *profiler)
Create a new ExecutionSystem and initialize it with the editingtree.
void execute_work(const rcti &work_rect, std::function< TResult(const rcti &split_rect)> work_func, TResult &join, std::function< void(TResult &join, const TResult &chunk)> reduce_func)
void execute_work(const rcti &work_rect, std::function< void(const rcti &split_rect)> work_func)