Blender  V2.93
COM_ExecutionGroup.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #pragma once
20 
21 #ifdef WITH_CXX_GUARDEDALLOC
22 # include "MEM_guardedalloc.h"
23 #endif
24 
25 #include "BLI_array.hh"
26 #include "BLI_rect.h"
27 #include "BLI_vector.hh"
28 
29 #include "COM_CompositorContext.h"
30 #include "COM_Device.h"
31 #include "COM_MemoryProxy.h"
32 #include "COM_Node.h"
33 #include "COM_NodeOperation.h"
34 #include "COM_WorkPackage.h"
35 #include <vector>
36 
37 namespace blender::compositor {
38 
39 class ExecutionSystem;
40 class MemoryProxy;
41 class MemoryBuffer;
42 class ReadBufferOperation;
43 class Device;
44 
46  bool initialized : 1;
52  bool is_output : 1;
53  bool complex : 1;
54 
58  bool open_cl : 1;
59 
64  bool single_threaded : 1;
65 
67  {
68  initialized = false;
69  is_output = false;
70  complex = false;
71  open_cl = false;
72  single_threaded = false;
73  }
74 };
75 
76 std::ostream &operator<<(std::ostream &os, const ExecutionGroupFlags &flags);
77 
85  private:
86  // fields
90  int m_id;
91 
95  Vector<NodeOperation *> m_operations;
96 
97  ExecutionGroupFlags m_flags;
98 
102  unsigned int m_width;
103 
107  unsigned int m_height;
108 
113  unsigned int m_chunkSize;
114 
118  unsigned int m_x_chunks_len;
119 
123  unsigned int m_y_chunks_len;
124 
128  unsigned int m_chunks_len;
129 
134  unsigned int m_max_read_buffer_offset;
135 
139  Vector<ReadBufferOperation *> m_read_operations;
140 
146  const bNodeTree *m_bTree;
147 
151  unsigned int m_chunks_finished;
152 
156  Vector<WorkPackage> m_work_packages;
157 
162  rcti m_viewerBorder;
163 
167  double m_executionStartTime;
168 
169  // methods
174  bool can_contain(NodeOperation &operation);
175 
179  void determineChunkRect(rcti *r_rect,
180  const unsigned int xChunk,
181  const unsigned int yChunk) const;
182 
187  void init_number_of_chunks();
188 
200  bool scheduleChunkWhenPossible(ExecutionSystem *graph, const int chunk_x, const int chunk_y);
201 
212  bool scheduleAreaWhenPossible(ExecutionSystem *graph, rcti *area);
213 
218  bool scheduleChunk(unsigned int chunkNumber);
219 
227  void determineDependingAreaOfInterest(rcti *input,
228  ReadBufferOperation *readOperation,
229  rcti *output);
230 
234  blender::Array<unsigned int> get_execution_order() const;
235 
236  void init_read_buffer_operations();
237  void init_work_packages();
238 
239  public:
240  // constructors
241  ExecutionGroup(int id);
242 
243  int get_id() const
244  {
245  return m_id;
246  }
247 
249  {
250  return m_flags;
251  }
252 
253  // methods
262  bool addOperation(NodeOperation *operation);
263 
268  void setOutputExecutionGroup(bool is_output)
269  {
270  this->m_flags.is_output = is_output;
271  }
272 
277  void determineResolution(unsigned int resolution[2]);
278 
283  void setResolution(unsigned int resolution[2])
284  {
285  this->m_width = resolution[0];
286  this->m_height = resolution[1];
287  }
288 
292  unsigned int getWidth() const
293  {
294  return m_width;
295  }
296 
300  unsigned int getHeight() const
301  {
302  return m_height;
303  }
304 
310 
316 
321  void initExecution();
322 
330 
337  MemoryBuffer **getInputBuffersOpenCL(int chunkNumber);
338 
346 
352  void finalizeChunkExecution(int chunkNumber, MemoryBuffer **memoryBuffers);
353 
358  void deinitExecution();
359 
377 
381  void determineChunkRect(rcti *r_rect, const unsigned int chunkNumber) const;
382 
383  void setChunksize(int chunksize)
384  {
385  this->m_chunkSize = chunksize;
386  }
387 
393 
398  void setViewerBorder(float xmin, float xmax, float ymin, float ymax);
399 
400  void setRenderBorder(float xmin, float xmax, float ymin, float ymax);
401 
402  /* allow the DebugInfo class to look at internals */
403  friend class DebugInfo;
404 
405 #ifdef WITH_CXX_GUARDEDALLOC
406  MEM_CXX_CLASS_ALLOC_FUNCS("COM:ExecutionGroup")
407 #endif
408 };
409 
410 std::ostream &operator<<(std::ostream &os, const ExecutionGroup &execution_group);
411 
412 } // namespace blender::compositor
Read Guarded memory(de)allocation.
btScalar m_height
Definition: btConeShape.h:29
int m_flags
btScalar m_width
#define output
Definition: device.h:293
Class ExecutionGroup is a group of Operations that are executed as one. This grouping is used to comb...
unsigned int getWidth() const
get the width of this execution group
MemoryBuffer ** getInputBuffersCPU()
get all inputbuffers needed to calculate an chunk
eCompositorPriority getRenderPriority()
get the Render priority of this ExecutionGroup
void execute(ExecutionSystem *graph)
schedule an ExecutionGroup
void setViewerBorder(float xmin, float xmax, float ymin, float ymax)
set border for viewer operation
MemoryBuffer * constructConsolidatedMemoryBuffer(MemoryProxy &memoryProxy, rcti &rect)
compose multiple chunks into a single chunk
MemoryBuffer * allocateOutputBuffer(rcti &rect)
allocate the outputbuffer of a chunk
const ExecutionGroupFlags get_flags() const
MemoryBuffer ** getInputBuffersOpenCL(int chunkNumber)
get all inputbuffers needed to calculate an chunk
void setOutputExecutionGroup(bool is_output)
set whether this ExecutionGroup is an output
void deinitExecution()
deinitExecution is called just after execution the whole graph.
NodeOperation * getOutputOperation() const
get the output operation of this ExecutionGroup
bool addOperation(NodeOperation *operation)
add an operation to this ExecutionGroup
void initExecution()
initExecution is called just before the execution of the whole graph will be done.
void setResolution(unsigned int resolution[2])
set the resolution of this executiongroup
void setRenderBorder(float xmin, float xmax, float ymin, float ymax)
void finalizeChunkExecution(int chunkNumber, MemoryBuffer **memoryBuffers)
after a chunk is executed the needed resources can be freed or unlocked.
unsigned int getHeight() const
get the height of this execution group
void determineResolution(unsigned int resolution[2])
determine the resolution of this ExecutionGroup
the ExecutionSystem contains the whole compositor tree.
a MemoryBuffer contains access to the data of a chunk
A MemoryProxy is a unique identifier for a memory buffer. A single MemoryProxy is used among all chun...
NodeOperation contains calculation logic.
Depsgraph * graph
eCompositorPriority
Possible priority settings.
Definition: COM_Enums.h:45
static void area(int d1, int d2, int e1, int e2, float weights[2])
std::ostream & operator<<(std::ostream &os, const eCompositorPriority &priority)
Definition: COM_Enums.cc:23