Blender  V3.3
COM_ExecutionSystem.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #pragma once
5 
6 #include <functional>
7 
8 #include "atomic_ops.h"
9 
10 #include "BLI_index_range.hh"
11 #include "BLI_threads.h"
12 #include "BLI_vector.hh"
13 
14 #include "COM_CompositorContext.h"
16 
17 #include "DNA_color_types.h"
18 #include "DNA_node_types.h"
19 #include "DNA_scene_types.h"
20 #include "DNA_vec_types.h"
21 
22 namespace blender::compositor {
23 
106 /* Forward declarations. */
107 class ExecutionGroup;
108 class ExecutionModel;
109 class NodeOperation;
110 
115  private:
120  SharedOperationBuffers active_buffers_;
121 
125  CompositorContext context_;
126 
130  Vector<NodeOperation *> operations_;
131 
135  Vector<ExecutionGroup *> groups_;
136 
140  ExecutionModel *execution_model_;
141 
145  int num_work_threads_;
146 
147  ThreadMutex work_mutex_;
148  ThreadCondition work_finished_cond_;
149 
150  public:
159  Scene *scene,
160  bNodeTree *editingtree,
161  bool rendering,
162  bool fastcalculation,
163  const char *view_name);
164 
169 
170  void set_operations(const Vector<NodeOperation *> &operations,
171  const Vector<ExecutionGroup *> &groups);
172 
179  void execute();
180 
185  {
186  return context_;
187  }
188 
190  {
191  return active_buffers_;
192  }
193 
197  void execute_work(const rcti &work_rect, std::function<void(const rcti &split_rect)> work_func);
198 
203  template<typename TResult>
204  void execute_work(const rcti &work_rect,
205  std::function<TResult(const rcti &split_rect)> work_func,
206  TResult &join,
207  std::function<void(TResult &join, const TResult &chunk)> reduce_func)
208  {
209  Array<TResult> chunks(num_work_threads_);
210  int num_started = 0;
211  execute_work(work_rect, [&](const rcti &split_rect) {
212  const int current = atomic_fetch_and_add_int32(&num_started, 1);
213  chunks[current] = work_func(split_rect);
214  });
215  for (const int i : IndexRange(num_started)) {
216  reduce_func(join, chunks[i]);
217  }
218  }
219 
220  bool is_breaked() const;
221 
222  private:
223  /* allow the DebugInfo class to look at internals */
224  friend class DebugInfo;
225 
226 #ifdef WITH_CXX_GUARDEDALLOC
227  MEM_CXX_CLASS_ALLOC_FUNCS("COM:ExecutionSystem")
228 #endif
229 };
230 
231 } // namespace blender::compositor
pthread_cond_t ThreadCondition
Definition: BLI_threads.h:150
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:82
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.
SharedOperationBuffers & get_active_buffers()
void set_operations(const Vector< NodeOperation * > &operations, const Vector< ExecutionGroup * > &groups)
ExecutionSystem(RenderData *rd, Scene *scene, bNodeTree *editingtree, bool rendering, bool fastcalculation, const char *view_name)
Create a new ExecutionSystem and initialize it with the editingtree.
const CompositorContext & get_context() const
get the reference to the compositor context
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)
Scene scene