diff options
Diffstat (limited to 'source/blender/compositor/intern/COM_WorkScheduler.cc')
-rw-r--r-- | source/blender/compositor/intern/COM_WorkScheduler.cc | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cc b/source/blender/compositor/intern/COM_WorkScheduler.cc index 7d9dd502762..cd0139fd18e 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.cc +++ b/source/blender/compositor/intern/COM_WorkScheduler.cc @@ -37,6 +37,8 @@ #include "BKE_global.h" +namespace blender::compositor { + enum class ThreadingModel { /** Everything is executed in the caller thread. easy for debugging. */ SingleThreaded, @@ -70,7 +72,7 @@ static struct { /** \brief list of all CPUDevices. for every hardware thread an instance of CPUDevice is * created */ - blender::Vector<CPUDevice> devices; + Vector<CPUDevice> devices; /** \brief list of all thread for every CPUDevice in cpudevices a thread exists. */ ListBase threads; @@ -89,13 +91,15 @@ static struct { cl_program program; /** \brief list of all OpenCLDevices. for every OpenCL GPU device an instance of OpenCLDevice * is created. */ - blender::Vector<OpenCLDevice> devices; + Vector<OpenCLDevice> devices; /** \brief list of all thread for every GPUDevice in cpudevices a thread exists. */ ListBase threads; /** \brief all scheduled work for the GPU. */ bool active = false; bool initialized = false; } opencl; + + int num_cpu_threads; } g_work_scheduler; /* -------------------------------------------------------------------- */ @@ -117,7 +121,6 @@ static void *thread_execute_gpu(void *data) while ((work = (WorkPackage *)BLI_thread_queue_pop(g_work_scheduler.opencl.queue))) { device->execute(work); - delete work; } return nullptr; @@ -142,7 +145,8 @@ static void opencl_start(CompositorContext &context) static bool opencl_schedule(WorkPackage *package) { - if (package->execution_group->isOpenCL() && g_work_scheduler.opencl.active) { + if (package->type == eWorkPackageType::Tile && package->execution_group->get_flags().open_cl && + g_work_scheduler.opencl.active) { BLI_thread_queue_push(g_work_scheduler.opencl.queue, package); return true; } @@ -262,10 +266,10 @@ static void opencl_initialize(const bool use_opencl) if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error2, clewErrorString(error2)); } - g_work_scheduler.opencl.devices.append(OpenCLDevice(g_work_scheduler.opencl.context, - device, - g_work_scheduler.opencl.program, - vendorID)); + g_work_scheduler.opencl.devices.append_as(g_work_scheduler.opencl.context, + device, + g_work_scheduler.opencl.program, + vendorID); } } MEM_freeN(cldevices); @@ -304,7 +308,6 @@ static void threading_model_single_thread_execute(WorkPackage *package) { CPUDevice device(0); device.execute(package); - delete package; } /* \} */ @@ -320,7 +323,6 @@ static void *threading_model_queue_execute(void *data) BLI_thread_local_set(g_thread_device, device); while ((work = (WorkPackage *)BLI_thread_queue_pop(g_work_scheduler.queue.queue))) { device->execute(work); - delete work; } return nullptr; @@ -369,7 +371,7 @@ static void threading_model_queue_initialize(const int num_cpu_threads) /* Initialize CPU threads. */ if (!g_work_scheduler.queue.initialized) { for (int index = 0; index < num_cpu_threads; index++) { - g_work_scheduler.queue.devices.append(CPUDevice(index)); + g_work_scheduler.queue.devices.append_as(index); } BLI_thread_local_create(g_thread_device); g_work_scheduler.queue.initialized = true; @@ -398,7 +400,6 @@ static void threading_model_task_execute(TaskPool *__restrict UNUSED(pool), void CPUDevice device(BLI_task_parallel_thread_id(nullptr)); BLI_thread_local_set(g_thread_device, &device); device.execute(package); - delete package; } static void threading_model_task_schedule(WorkPackage *package) @@ -410,7 +411,8 @@ static void threading_model_task_schedule(WorkPackage *package) static void threading_model_task_start() { BLI_thread_local_create(g_thread_device); - g_work_scheduler.task.pool = BLI_task_pool_create(nullptr, TASK_PRIORITY_HIGH); + g_work_scheduler.task.pool = BLI_task_pool_create( + nullptr, TASK_PRIORITY_HIGH, TASK_ISOLATION_ON); } static void threading_model_task_finish() @@ -431,10 +433,8 @@ static void threading_model_task_stop() /** \name Public API * \{ */ -void WorkScheduler::schedule(ExecutionGroup *group, int chunkNumber) +void WorkScheduler::schedule(WorkPackage *package) { - WorkPackage *package = new WorkPackage(group, chunkNumber); - if (COM_is_opencl_enabled()) { if (opencl_schedule(package)) { return; @@ -536,11 +536,12 @@ void WorkScheduler::initialize(bool use_opencl, int num_cpu_threads) opencl_initialize(use_opencl); } + g_work_scheduler.num_cpu_threads = num_cpu_threads; switch (COM_threading_model()) { case ThreadingModel::SingleThreaded: + g_work_scheduler.num_cpu_threads = 1; /* Nothing to do. */ break; - case ThreadingModel::Queue: threading_model_queue_initialize(num_cpu_threads); break; @@ -572,6 +573,11 @@ void WorkScheduler::deinitialize() } } +int WorkScheduler::get_num_cpu_threads() +{ + return g_work_scheduler.num_cpu_threads; +} + int WorkScheduler::current_thread_id() { if (COM_threading_model() == ThreadingModel::SingleThreaded) { @@ -583,3 +589,5 @@ int WorkScheduler::current_thread_id() } /* \} */ + +} // namespace blender::compositor |