Blender  V2.93
COM_ExecutionSystem.cc
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 #include "COM_ExecutionSystem.h"
20 
21 #include "BLI_utildefines.h"
22 #include "PIL_time.h"
23 
24 #include "BKE_node.h"
25 
26 #include "BLT_translation.h"
27 
28 #include "COM_Converter.h"
29 #include "COM_Debug.h"
30 #include "COM_ExecutionGroup.h"
31 #include "COM_NodeOperation.h"
34 #include "COM_WorkScheduler.h"
35 
36 #ifdef WITH_CXX_GUARDEDALLOC
37 # include "MEM_guardedalloc.h"
38 #endif
39 
40 namespace blender::compositor {
41 
43  Scene *scene,
44  bNodeTree *editingtree,
45  bool rendering,
46  bool fastcalculation,
47  const ColorManagedViewSettings *viewSettings,
48  const ColorManagedDisplaySettings *displaySettings,
49  const char *viewName)
50 {
51  this->m_context.setViewName(viewName);
52  this->m_context.setScene(scene);
53  this->m_context.setbNodeTree(editingtree);
54  this->m_context.setPreviewHash(editingtree->previews);
55  this->m_context.setFastCalculation(fastcalculation);
56  /* initialize the CompositorContext */
57  if (rendering) {
58  this->m_context.setQuality((eCompositorQuality)editingtree->render_quality);
59  }
60  else {
61  this->m_context.setQuality((eCompositorQuality)editingtree->edit_quality);
62  }
63  this->m_context.setRendering(rendering);
65  (editingtree->flag & NTREE_COM_OPENCL));
66 
67  this->m_context.setRenderData(rd);
68  this->m_context.setViewSettings(viewSettings);
69  this->m_context.setDisplaySettings(displaySettings);
70 
71  {
72  NodeOperationBuilder builder(&m_context, editingtree);
73  builder.convertToOperations(this);
74  }
75 
76  unsigned int resolution[2];
77 
78  rctf *viewer_border = &editingtree->viewer_border;
79  bool use_viewer_border = (editingtree->flag & NTREE_VIEWER_BORDER) &&
80  viewer_border->xmin < viewer_border->xmax &&
81  viewer_border->ymin < viewer_border->ymax;
82 
83  editingtree->stats_draw(editingtree->sdh, TIP_("Compositing | Determining resolution"));
84 
85  for (ExecutionGroup *executionGroup : m_groups) {
86  resolution[0] = 0;
87  resolution[1] = 0;
88  executionGroup->determineResolution(resolution);
89 
90  if (rendering) {
91  /* case when cropping to render border happens is handled in
92  * compositor output and render layer nodes
93  */
94  if ((rd->mode & R_BORDER) && !(rd->mode & R_CROP)) {
95  executionGroup->setRenderBorder(
96  rd->border.xmin, rd->border.xmax, rd->border.ymin, rd->border.ymax);
97  }
98  }
99 
100  if (use_viewer_border) {
101  executionGroup->setViewerBorder(
102  viewer_border->xmin, viewer_border->xmax, viewer_border->ymin, viewer_border->ymax);
103  }
104  }
105 
106  // DebugInfo::graphviz(this);
107 }
108 
110 {
111  for (NodeOperation *operation : m_operations) {
112  delete operation;
113  }
114  this->m_operations.clear();
115 
116  for (ExecutionGroup *group : m_groups) {
117  delete group;
118  }
119  this->m_groups.clear();
120 }
121 
123  const Vector<ExecutionGroup *> &groups)
124 {
125  m_operations = operations;
126  m_groups = groups;
127 }
128 
130 {
131  unsigned int order = 0;
132  for (NodeOperation *operation : operations) {
133  if (operation->get_flags().is_read_buffer_operation) {
134  ReadBufferOperation *readOperation = (ReadBufferOperation *)operation;
135  readOperation->setOffset(order);
136  order++;
137  }
138  }
139 }
140 
142  const bNodeTree *bTree)
143 {
144  for (NodeOperation *operation : operations) {
145  if (operation->get_flags().is_write_buffer_operation) {
146  operation->setbNodeTree(bTree);
147  operation->initExecution();
148  }
149  }
150 }
151 
153 {
154  for (NodeOperation *operation : operations) {
155  if (operation->get_flags().is_read_buffer_operation) {
156  ReadBufferOperation *readOperation = static_cast<ReadBufferOperation *>(operation);
157  readOperation->updateMemoryBuffer();
158  }
159  }
160 }
161 
163  const bNodeTree *bTree)
164 {
165  for (NodeOperation *operation : operations) {
166  if (!operation->get_flags().is_write_buffer_operation) {
167  operation->setbNodeTree(bTree);
168  operation->initExecution();
169  }
170  }
171 }
172 
174  const int chunk_size)
175 {
176  for (ExecutionGroup *execution_group : groups) {
177  execution_group->setChunksize(chunk_size);
178  execution_group->initExecution();
179  }
180 }
181 
183 {
184  const bNodeTree *editingtree = this->m_context.getbNodeTree();
185  editingtree->stats_draw(editingtree->sdh, TIP_("Compositing | Initializing execution"));
186 
188  update_read_buffer_offset(m_operations);
189 
190  init_write_operations_for_execution(m_operations, m_context.getbNodeTree());
191  link_write_buffers(m_operations);
192  init_non_write_operations_for_execution(m_operations, m_context.getbNodeTree());
193  init_execution_groups_for_execution(m_groups, m_context.getChunksize());
194 
195  WorkScheduler::start(this->m_context);
196  execute_groups(eCompositorPriority::High);
197  if (!this->getContext().isFastCalculation()) {
198  execute_groups(eCompositorPriority::Medium);
199  execute_groups(eCompositorPriority::Low);
200  }
203 
204  editingtree->stats_draw(editingtree->sdh, TIP_("Compositing | De-initializing execution"));
205 
206  for (NodeOperation *operation : m_operations) {
207  operation->deinitExecution();
208  }
209 
210  for (ExecutionGroup *execution_group : m_groups) {
211  execution_group->deinitExecution();
212  }
213 }
214 
215 void ExecutionSystem::execute_groups(eCompositorPriority priority)
216 {
217  for (ExecutionGroup *execution_group : m_groups) {
218  if (execution_group->get_flags().is_output &&
219  execution_group->getRenderPriority() == priority) {
220  execution_group->execute(this);
221  }
222  }
223 }
224 
225 } // namespace blender::compositor
#define TIP_(msgid)
#define NTREE_VIEWER_BORDER
#define NTREE_COM_OPENCL
#define R_BORDER
#define R_CROP
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint order
Read Guarded memory(de)allocation.
Platform independent time functions.
void setFastCalculation(bool fastCalculation)
void setViewSettings(const ColorManagedViewSettings *viewSettings)
set view settings of color color management
void setbNodeTree(bNodeTree *bnodetree)
set the bnodetree of the context
void setDisplaySettings(const ColorManagedDisplaySettings *displaySettings)
set display settings of color color management
const bNodeTree * getbNodeTree() const
get the bnodetree of the context
void setHasActiveOpenCLDevices(bool hasAvtiveOpenCLDevices)
set has this system active openclDevices?
void setPreviewHash(bNodeInstanceHash *previews)
set the preview image hash table
void setQuality(eCompositorQuality quality)
set the quality
void setViewName(const char *viewName)
set the active rendering view
void setRendering(bool rendering)
set the rendering field of the context
void setRenderData(RenderData *rd)
set the scene of the context
static void execute_started(const ExecutionSystem *system)
Definition: COM_Debug.cc:475
Class ExecutionGroup is a group of Operations that are executed as one. This grouping is used to comb...
const CompositorContext & getContext() const
get the reference to the compositor context
void set_operations(const Vector< NodeOperation * > &operations, const Vector< ExecutionGroup * > &groups)
ExecutionSystem(RenderData *rd, Scene *scene, bNodeTree *editingtree, bool rendering, bool fastcalculation, const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings, const char *viewName)
Create a new ExecutionSystem and initialize it with the editingtree.
NodeOperation contains calculation logic.
Scene scene
eCompositorPriority
Possible priority settings.
Definition: COM_Enums.h:45
eCompositorQuality
Possible quality settings.
Definition: COM_Enums.h:32
static void init_execution_groups_for_execution(Vector< ExecutionGroup * > &groups, const int chunk_size)
static void link_write_buffers(Vector< NodeOperation * > &operations)
static void init_write_operations_for_execution(Vector< NodeOperation * > &operations, const bNodeTree *bTree)
static void update_read_buffer_offset(Vector< NodeOperation * > &operations)
static void init_non_write_operations_for_execution(Vector< NodeOperation * > &operations, const bNodeTree *bTree)
short render_quality
struct bNodeInstanceHash * previews
short edit_quality
void(* stats_draw)(void *, const char *str)
rctf viewer_border
static bool has_gpu_devices()
Are there OpenCL capable GPU devices initialized? the result of this method is stored in the Composit...
static void finish()
wait for all work to be completed.
static void stop()
stop the execution All created thread by the start method are destroyed.
static void start(CompositorContext &context)
Start the execution this methods will start the WorkScheduler. Inside this method all threads are ini...
float xmax
Definition: DNA_vec_types.h:85
float xmin
Definition: DNA_vec_types.h:85
float ymax
Definition: DNA_vec_types.h:86
float ymin
Definition: DNA_vec_types.h:86