diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-03-24 15:40:52 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-03-24 16:30:22 +0300 |
commit | 31f8d894b99a59ecb3b59f1bf6c558a3944fa988 (patch) | |
tree | be11a2b47f098b13a8ce7bef397691785375180c | |
parent | 0d5cef989803d047696b5f76f0cc95a8cc07a25a (diff) |
Cleanup: replace index based forloops with iterators.
3 files changed, 60 insertions, 67 deletions
diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.cc b/source/blender/compositor/intern/COM_ExecutionGroup.cc index 3cedc5da663..75e5c4d3178 100644 --- a/source/blender/compositor/intern/COM_ExecutionGroup.cc +++ b/source/blender/compositor/intern/COM_ExecutionGroup.cc @@ -130,9 +130,7 @@ void ExecutionGroup::initExecution() if (this->m_chunks_len != 0) { m_chunk_execution_states.resize(this->m_chunks_len); - for (int index = 0; index < this->m_chunks_len; index++) { - m_chunk_execution_states[index] = eChunkExecutionState::NOT_SCHEDULED; - } + m_chunk_execution_states.fill(eChunkExecutionState::NOT_SCHEDULED); } unsigned int max_offset = 0; @@ -185,7 +183,6 @@ void ExecutionGroup::determineNumberOfChunks() blender::Array<unsigned int> ExecutionGroup::determine_chunk_execution_order() const { - int index; blender::Array<unsigned int> chunk_order(m_chunks_len); for (int chunk_index = 0; chunk_index < this->m_chunks_len; chunk_index++) { chunk_order[chunk_index] = chunk_index; @@ -205,7 +202,7 @@ blender::Array<unsigned int> ExecutionGroup::determine_chunk_execution_order() c const int border_width = BLI_rcti_size_x(&this->m_viewerBorder); const int border_height = BLI_rcti_size_y(&this->m_viewerBorder); - + int index; switch (order_type) { case ChunkOrdering::Random: { static blender::RandomNumberGenerator rng; @@ -303,7 +300,6 @@ void ExecutionGroup::execute(ExecutionSystem *graph) this->m_chunks_finished = 0; this->m_bTree = bTree; - unsigned int index; blender::Array<unsigned int> chunk_order = determine_chunk_execution_order(); @@ -320,7 +316,8 @@ void ExecutionGroup::execute(ExecutionSystem *graph) finished = true; int numberEvaluated = 0; - for (index = startIndex; index < this->m_chunks_len && numberEvaluated < maxNumberEvaluated; + for (int index = startIndex; + index < this->m_chunks_len && numberEvaluated < maxNumberEvaluated; index++) { chunk_index = chunk_order[index]; int yChunk = chunk_index / this->m_x_chunks_len; diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.cc b/source/blender/compositor/intern/COM_ExecutionSystem.cc index 993aedf7715..b28ee79c359 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystem.cc +++ b/source/blender/compositor/intern/COM_ExecutionSystem.cc @@ -71,7 +71,6 @@ ExecutionSystem::ExecutionSystem(RenderData *rd, builder.convertToOperations(this); } - unsigned int index; unsigned int resolution[2]; rctf *viewer_border = &editingtree->viewer_border; @@ -81,10 +80,9 @@ ExecutionSystem::ExecutionSystem(RenderData *rd, editingtree->stats_draw(editingtree->sdh, TIP_("Compositing | Determining resolution")); - for (index = 0; index < this->m_groups.size(); index++) { + for (ExecutionGroup *executionGroup : m_groups) { resolution[0] = 0; resolution[1] = 0; - ExecutionGroup *executionGroup = this->m_groups[index]; executionGroup->determineResolution(resolution); if (rendering) { @@ -108,14 +106,12 @@ ExecutionSystem::ExecutionSystem(RenderData *rd, ExecutionSystem::~ExecutionSystem() { - unsigned int index; - for (index = 0; index < this->m_operations.size(); index++) { - NodeOperation *operation = this->m_operations[index]; + for (NodeOperation *operation : m_operations) { delete operation; } this->m_operations.clear(); - for (index = 0; index < this->m_groups.size(); index++) { - ExecutionGroup *group = this->m_groups[index]; + + for (ExecutionGroup *group : m_groups) { delete group; } this->m_groups.clear(); @@ -128,92 +124,98 @@ void ExecutionSystem::set_operations(const blender::Vector<NodeOperation *> &ope m_groups = groups; } -void ExecutionSystem::execute() +static void update_read_buffer_offset(blender::Vector<NodeOperation *> &operations) { - const bNodeTree *editingtree = this->m_context.getbNodeTree(); - editingtree->stats_draw(editingtree->sdh, TIP_("Compositing | Initializing execution")); - - DebugInfo::execute_started(this); - unsigned int order = 0; - for (NodeOperation *operation : m_operations) { + for (NodeOperation *operation : operations) { if (operation->isReadBufferOperation()) { ReadBufferOperation *readOperation = (ReadBufferOperation *)operation; readOperation->setOffset(order); order++; } } - unsigned int index; +} - // First allocale all write buffer - for (index = 0; index < this->m_operations.size(); index++) { - NodeOperation *operation = this->m_operations[index]; +static void init_write_operations_for_execution(blender::Vector<NodeOperation *> &operations, + const bNodeTree *bTree) +{ + for (NodeOperation *operation : operations) { if (operation->isWriteBufferOperation()) { - operation->setbNodeTree(this->m_context.getbNodeTree()); + operation->setbNodeTree(bTree); operation->initExecution(); } } - // Connect read buffers to their write buffers - for (index = 0; index < this->m_operations.size(); index++) { - NodeOperation *operation = this->m_operations[index]; +} + +static void link_write_buffers(blender::Vector<NodeOperation *> &operations) +{ + for (NodeOperation *operation : operations) { if (operation->isReadBufferOperation()) { - ReadBufferOperation *readOperation = (ReadBufferOperation *)operation; + ReadBufferOperation *readOperation = static_cast<ReadBufferOperation *>(operation); readOperation->updateMemoryBuffer(); } } - // initialize other operations - for (index = 0; index < this->m_operations.size(); index++) { - NodeOperation *operation = this->m_operations[index]; +} + +static void init_non_write_operations_for_execution(blender::Vector<NodeOperation *> &operations, + const bNodeTree *bTree) +{ + for (NodeOperation *operation : operations) { if (!operation->isWriteBufferOperation()) { - operation->setbNodeTree(this->m_context.getbNodeTree()); + operation->setbNodeTree(bTree); operation->initExecution(); } } - for (index = 0; index < this->m_groups.size(); index++) { - ExecutionGroup *executionGroup = this->m_groups[index]; - executionGroup->setChunksize(this->m_context.getChunksize()); - executionGroup->initExecution(); +} + +static void init_execution_groups_for_execution(blender::Vector<ExecutionGroup *> &groups, + const int chunk_size) +{ + for (ExecutionGroup *execution_group : groups) { + execution_group->setChunksize(chunk_size); + execution_group->initExecution(); } +} - WorkScheduler::start(this->m_context); +void ExecutionSystem::execute() +{ + const bNodeTree *editingtree = this->m_context.getbNodeTree(); + editingtree->stats_draw(editingtree->sdh, TIP_("Compositing | Initializing execution")); + + DebugInfo::execute_started(this); + update_read_buffer_offset(m_operations); + init_write_operations_for_execution(m_operations, m_context.getbNodeTree()); + link_write_buffers(m_operations); + init_non_write_operations_for_execution(m_operations, m_context.getbNodeTree()); + init_execution_groups_for_execution(m_groups, m_context.getChunksize()); + + WorkScheduler::start(this->m_context); execute_groups(CompositorPriority::High); if (!this->getContext().isFastCalculation()) { execute_groups(CompositorPriority::Medium); execute_groups(CompositorPriority::Low); } - WorkScheduler::finish(); WorkScheduler::stop(); editingtree->stats_draw(editingtree->sdh, TIP_("Compositing | De-initializing execution")); - for (index = 0; index < this->m_operations.size(); index++) { - NodeOperation *operation = this->m_operations[index]; + + for (NodeOperation *operation : m_operations) { operation->deinitExecution(); } - for (index = 0; index < this->m_groups.size(); index++) { - ExecutionGroup *executionGroup = this->m_groups[index]; - executionGroup->deinitExecution(); - } -} -void ExecutionSystem::execute_groups(CompositorPriority priority) -{ - blender::Vector<ExecutionGroup *> execution_groups = find_output_execution_groups(priority); - for (ExecutionGroup *group : execution_groups) { - group->execute(this); + for (ExecutionGroup *execution_group : m_groups) { + execution_group->deinitExecution(); } } -blender::Vector<ExecutionGroup *> ExecutionSystem::find_output_execution_groups( - CompositorPriority priority) const +void ExecutionSystem::execute_groups(CompositorPriority priority) { - blender::Vector<ExecutionGroup *> result; - - for (ExecutionGroup *group : m_groups) { - if (group->isOutputExecutionGroup() && group->getRenderPriotrity() == priority) { - result.append(group); + for (ExecutionGroup *execution_group : m_groups) { + if (execution_group->isOutputExecutionGroup() && + execution_group->getRenderPriotrity() == priority) { + execution_group->execute(this); } } - return result; } diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.h b/source/blender/compositor/intern/COM_ExecutionSystem.h index 6a50cc6906b..c12380fe839 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystem.h +++ b/source/blender/compositor/intern/COM_ExecutionSystem.h @@ -135,12 +135,6 @@ class ExecutionSystem { blender::Vector<ExecutionGroup *> m_groups; private: // methods - /** - * find all execution group with output nodes - */ - blender::Vector<ExecutionGroup *> find_output_execution_groups( - CompositorPriority priority) const; - public: /** * \brief Create a new ExecutionSystem and initialize it with the |