diff options
author | Julian Eisel <julian@blender.org> | 2021-03-31 23:53:03 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-03-31 23:53:03 +0300 |
commit | c7904d2398fd4d43d15268c792aa15ea8ee538fe (patch) | |
tree | 484fd7f66ac59c82abd4aca18894f991b4935483 /source/blender/compositor/intern/COM_WorkScheduler.cc | |
parent | 91b87d8d7fb8aec62faf00e5e0c3619d2753a92e (diff) | |
parent | 1a100d2d78c75c9a6ac015606cc16698e7775682 (diff) |
Merge branch 'master' into ui-asset-view-templateui-asset-view-template
Diffstat (limited to 'source/blender/compositor/intern/COM_WorkScheduler.cc')
-rw-r--r-- | source/blender/compositor/intern/COM_WorkScheduler.cc | 83 |
1 files changed, 29 insertions, 54 deletions
diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cc b/source/blender/compositor/intern/COM_WorkScheduler.cc index 56956b9d097..55114e6b72a 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; + blender::Vector<CPUDevice> devices; /** \brief list of all thread for every CPUDevice in cpudevices a thread exists. */ ListBase threads; @@ -89,7 +91,7 @@ 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; + blender::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. */ @@ -117,7 +119,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; @@ -130,9 +131,8 @@ static void opencl_start(CompositorContext &context) BLI_threadpool_init(&g_work_scheduler.opencl.threads, thread_execute_gpu, g_work_scheduler.opencl.devices.size()); - for (int index = 0; index < g_work_scheduler.opencl.devices.size(); index++) { - Device *device = g_work_scheduler.opencl.devices[index]; - BLI_threadpool_insert(&g_work_scheduler.opencl.threads, device); + for (Device &device : g_work_scheduler.opencl.devices) { + BLI_threadpool_insert(&g_work_scheduler.opencl.threads, &device); } g_work_scheduler.opencl.active = true; } @@ -143,7 +143,7 @@ static void opencl_start(CompositorContext &context) static bool opencl_schedule(WorkPackage *package) { - if (package->execution_group->isOpenCL() && g_work_scheduler.opencl.active) { + if (package->execution_group->get_flags().open_cl && g_work_scheduler.opencl.active) { BLI_thread_queue_push(g_work_scheduler.opencl.queue, package); return true; } @@ -263,12 +263,10 @@ static void opencl_initialize(const bool use_opencl) if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error2, clewErrorString(error2)); } - OpenCLDevice *clDevice = new OpenCLDevice(g_work_scheduler.opencl.context, - device, - g_work_scheduler.opencl.program, - vendorID); - clDevice->initialize(); - g_work_scheduler.opencl.devices.append(clDevice); + g_work_scheduler.opencl.devices.append(OpenCLDevice(g_work_scheduler.opencl.context, + device, + g_work_scheduler.opencl.program, + vendorID)); } } MEM_freeN(cldevices); @@ -282,26 +280,19 @@ static void opencl_initialize(const bool use_opencl) static void opencl_deinitialize() { - /* Deinitialize OpenCL GPU's. */ - if (g_work_scheduler.opencl.initialized) { - while (!g_work_scheduler.opencl.devices.is_empty()) { - Device *device = g_work_scheduler.opencl.devices.pop_last(); - device->deinitialize(); - delete device; - } - g_work_scheduler.opencl.devices.clear_and_make_inline(); + g_work_scheduler.opencl.devices.clear_and_make_inline(); - if (g_work_scheduler.opencl.program) { - clReleaseProgram(g_work_scheduler.opencl.program); - g_work_scheduler.opencl.program = nullptr; - } - if (g_work_scheduler.opencl.context) { - clReleaseContext(g_work_scheduler.opencl.context); - g_work_scheduler.opencl.context = nullptr; - } + if (g_work_scheduler.opencl.program) { + clReleaseProgram(g_work_scheduler.opencl.program); + g_work_scheduler.opencl.program = nullptr; + } - g_work_scheduler.opencl.initialized = false; + if (g_work_scheduler.opencl.context) { + clReleaseContext(g_work_scheduler.opencl.context); + g_work_scheduler.opencl.context = nullptr; } + + g_work_scheduler.opencl.initialized = false; } /* \} */ @@ -314,7 +305,6 @@ static void threading_model_single_thread_execute(WorkPackage *package) { CPUDevice device(0); device.execute(package); - delete package; } /* \} */ @@ -330,7 +320,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; @@ -347,9 +336,8 @@ static void threading_model_queue_start() BLI_threadpool_init(&g_work_scheduler.queue.threads, threading_model_queue_execute, g_work_scheduler.queue.devices.size()); - for (int index = 0; index < g_work_scheduler.queue.devices.size(); index++) { - Device *device = g_work_scheduler.queue.devices[index]; - BLI_threadpool_insert(&g_work_scheduler.queue.threads, device); + for (Device &device : g_work_scheduler.queue.devices) { + BLI_threadpool_insert(&g_work_scheduler.queue.threads, &device); } } @@ -370,25 +358,17 @@ static void threading_model_queue_initialize(const int num_cpu_threads) { /* Reinitialize if number of threads doesn't match. */ if (g_work_scheduler.queue.devices.size() != num_cpu_threads) { - Device *device; - - while (!g_work_scheduler.queue.devices.is_empty()) { - device = g_work_scheduler.queue.devices.pop_last(); - device->deinitialize(); - delete device; - } + g_work_scheduler.queue.devices.clear(); if (g_work_scheduler.queue.initialized) { BLI_thread_local_delete(g_thread_device); + g_work_scheduler.queue.initialized = false; } - g_work_scheduler.queue.initialized = false; } /* Initialize CPU threads. */ if (!g_work_scheduler.queue.initialized) { for (int index = 0; index < num_cpu_threads; index++) { - CPUDevice *device = new CPUDevice(index); - device->initialize(); - g_work_scheduler.queue.devices.append(device); + g_work_scheduler.queue.devices.append(CPUDevice(index)); } BLI_thread_local_create(g_thread_device); g_work_scheduler.queue.initialized = true; @@ -398,11 +378,6 @@ static void threading_model_queue_deinitialize() { /* deinitialize CPU threads */ if (g_work_scheduler.queue.initialized) { - while (!g_work_scheduler.queue.devices.is_empty()) { - Device *device = g_work_scheduler.queue.devices.pop_last(); - device->deinitialize(); - delete device; - } g_work_scheduler.queue.devices.clear_and_make_inline(); BLI_thread_local_delete(g_thread_device); @@ -455,10 +430,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; @@ -607,3 +580,5 @@ int WorkScheduler::current_thread_id() } /* \} */ + +} // namespace blender::compositor |