Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/compositor/intern/COM_ExecutionSystem.h')
-rw-r--r--source/blender/compositor/intern/COM_ExecutionSystem.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.h b/source/blender/compositor/intern/COM_ExecutionSystem.h
index 38c3432a8ec..bce96db52c7 100644
--- a/source/blender/compositor/intern/COM_ExecutionSystem.h
+++ b/source/blender/compositor/intern/COM_ExecutionSystem.h
@@ -31,6 +31,7 @@ class ExecutionGroup;
#include "DNA_node_types.h"
#include "BLI_vector.hh"
+#include "atomic_ops.h"
namespace blender::compositor {
@@ -150,6 +151,11 @@ class ExecutionSystem {
*/
ExecutionModel *execution_model_;
+ /**
+ * Number of cpu threads available for work execution.
+ */
+ int num_work_threads_;
+
ThreadMutex work_mutex_;
ThreadCondition work_finished_cond_;
@@ -201,6 +207,27 @@ class ExecutionSystem {
void execute_work(const rcti &work_rect, std::function<void(const rcti &split_rect)> work_func);
+ /**
+ * Multi-threaded execution of given work function passing work_rect splits as argument.
+ * Once finished, caller thread will call reduce_func for each thread result.
+ */
+ template<typename TResult>
+ 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)
+ {
+ Array<TResult> chunks(num_work_threads_);
+ int num_started = 0;
+ execute_work(work_rect, [&](const rcti &split_rect) {
+ const int current = atomic_fetch_and_add_int32(&num_started, 1);
+ chunks[current] = work_func(split_rect);
+ });
+ for (const int i : IndexRange(num_started)) {
+ reduce_func(join, chunks[i]);
+ }
+ }
+
bool is_breaked() const;
private: