diff options
-rw-r--r-- | intern/cycles/device/cuda/device_cuda_impl.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/device/device_cpu.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/device/device_optix.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/device/opencl/device_opencl.h | 2 | ||||
-rw-r--r-- | intern/cycles/device/opencl/device_opencl_impl.cpp | 17 | ||||
-rw-r--r-- | intern/cycles/util/util_task.cpp | 33 | ||||
-rw-r--r-- | intern/cycles/util/util_task.h | 3 |
7 files changed, 22 insertions, 39 deletions
diff --git a/intern/cycles/device/cuda/device_cuda_impl.cpp b/intern/cycles/device/cuda/device_cuda_impl.cpp index 13f2ec530b0..b9bbeb9a25b 100644 --- a/intern/cycles/device/cuda/device_cuda_impl.cpp +++ b/intern/cycles/device/cuda/device_cuda_impl.cpp @@ -243,7 +243,7 @@ CUDADevice::CUDADevice(DeviceInfo &info, Stats &stats, Profiler &profiler, bool CUDADevice::~CUDADevice() { - task_pool.stop(); + task_pool.cancel(); delete split_kernel; diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index d2914bd519c..bc85d9386ad 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -333,7 +333,7 @@ class CPUDevice : public Device { ~CPUDevice() { - task_pool.stop(); + task_pool.cancel(); texture_info.free(); } diff --git a/intern/cycles/device/device_optix.cpp b/intern/cycles/device/device_optix.cpp index d46a747a2fd..bc2aeb0ae90 100644 --- a/intern/cycles/device/device_optix.cpp +++ b/intern/cycles/device/device_optix.cpp @@ -246,7 +246,7 @@ class OptiXDevice : public CUDADevice { ~OptiXDevice() { // Stop processing any more tasks - task_pool.stop(); + task_pool.cancel(); // Make CUDA context current const CUDAContextScope scope(cuContext); diff --git a/intern/cycles/device/opencl/device_opencl.h b/intern/cycles/device/opencl/device_opencl.h index ec091d12114..e0140996cf0 100644 --- a/intern/cycles/device/opencl/device_opencl.h +++ b/intern/cycles/device/opencl/device_opencl.h @@ -259,6 +259,8 @@ class OpenCLDevice : public Device { TaskPool load_required_kernel_task_pool; /* Task pool for optional kernels (feature kernels during foreground rendering) */ TaskPool load_kernel_task_pool; + std::atomic<int> load_kernel_num_compiling; + cl_context cxContext; cl_command_queue cqCommandQueue; cl_platform_id cpPlatform; diff --git a/intern/cycles/device/opencl/device_opencl_impl.cpp b/intern/cycles/device/opencl/device_opencl_impl.cpp index 368f7bef236..899de2b9d45 100644 --- a/intern/cycles/device/opencl/device_opencl_impl.cpp +++ b/intern/cycles/device/opencl/device_opencl_impl.cpp @@ -610,6 +610,7 @@ void OpenCLDevice::opencl_assert_err(cl_int err, const char *where) OpenCLDevice::OpenCLDevice(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background) : Device(info, stats, profiler, background), + load_kernel_num_compiling(0), kernel_programs(this), preview_programs(this), memory_manager(this), @@ -684,9 +685,9 @@ OpenCLDevice::OpenCLDevice(DeviceInfo &info, Stats &stats, Profiler &profiler, b OpenCLDevice::~OpenCLDevice() { - task_pool.stop(); - load_required_kernel_task_pool.stop(); - load_kernel_task_pool.stop(); + task_pool.cancel(); + load_required_kernel_task_pool.cancel(); + load_kernel_task_pool.cancel(); memory_manager.free(); @@ -798,7 +799,11 @@ bool OpenCLDevice::load_kernels(const DeviceRequestedFeatures &requested_feature * internally within a single process. */ foreach (OpenCLProgram *program, programs) { if (!program->load()) { - load_kernel_task_pool.push(function_bind(&OpenCLProgram::compile, program)); + load_kernel_num_compiling++; + load_kernel_task_pool.push([&] { + program->compile(); + load_kernel_num_compiling--; + }); } } return true; @@ -868,7 +873,7 @@ bool OpenCLDevice::wait_for_availability(const DeviceRequestedFeatures &requeste * Better to check on device level than per kernel as mixing preview and * non-preview kernels does not work due to different data types */ if (use_preview_kernels) { - use_preview_kernels = !load_kernel_task_pool.finished(); + use_preview_kernels = load_kernel_num_compiling.load() > 0; } } return split_kernel->load_kernels(requested_features); @@ -895,7 +900,7 @@ DeviceKernelStatus OpenCLDevice::get_active_kernel_switch_state() return DEVICE_KERNEL_USING_FEATURE_KERNEL; } - bool other_kernels_finished = load_kernel_task_pool.finished(); + bool other_kernels_finished = load_kernel_num_compiling.load() == 0; if (use_preview_kernels) { if (other_kernels_finished) { return DEVICE_KERNEL_FEATURE_KERNEL_AVAILABLE; diff --git a/intern/cycles/util/util_task.cpp b/intern/cycles/util/util_task.cpp index b7a47c73571..eb07ec0bfa0 100644 --- a/intern/cycles/util/util_task.cpp +++ b/intern/cycles/util/util_task.cpp @@ -46,7 +46,7 @@ TaskPool::TaskPool() TaskPool::~TaskPool() { - stop(); + cancel(); } void TaskPool::push(TaskRunFunction &&task, bool front) @@ -135,24 +135,11 @@ void TaskPool::cancel() do_cancel = false; } -void TaskPool::stop() -{ - TaskScheduler::clear(this); - - assert(num == 0); -} - bool TaskPool::canceled() { return do_cancel; } -bool TaskPool::finished() -{ - thread_scoped_lock num_lock(num_mutex); - return num == 0; -} - void TaskPool::num_decrease(int done) { num_mutex.lock(); @@ -453,7 +440,11 @@ DedicatedTaskPool::DedicatedTaskPool() DedicatedTaskPool::~DedicatedTaskPool() { - stop(); + wait(); + + do_exit = true; + queue_cond.notify_all(); + worker_thread->join(); delete worker_thread; } @@ -491,18 +482,6 @@ void DedicatedTaskPool::cancel() do_cancel = false; } -void DedicatedTaskPool::stop() -{ - clear(); - - do_exit = true; - queue_cond.notify_all(); - - wait(); - - assert(num == 0); -} - bool DedicatedTaskPool::canceled() { return do_cancel; diff --git a/intern/cycles/util/util_task.h b/intern/cycles/util/util_task.h index a3d277c8fa6..a7232e68f60 100644 --- a/intern/cycles/util/util_task.h +++ b/intern/cycles/util/util_task.h @@ -66,8 +66,6 @@ class TaskPool { void wait_work(Summary *stats = NULL); /* work and wait until all tasks are done */ void cancel(); /* cancel all tasks, keep worker threads running */ - void stop(); /* stop all worker threads */ - bool finished(); /* check if all work has been completed */ bool canceled(); /* for worker threads, test if canceled */ @@ -155,7 +153,6 @@ class DedicatedTaskPool { void wait(); /* wait until all tasks are done */ void cancel(); /* cancel all tasks, keep worker thread running */ - void stop(); /* stop worker thread */ bool canceled(); /* for worker thread, test if canceled */ |