[Bf-blender-cvs] [a3deef6fff7] master: Fix Cycles CPU + GPU render not using CPU after recent changes

Brecht Van Lommel noreply at git.blender.org
Thu Jan 13 10:50:43 CET 2022


Commit: a3deef6fff7c395512cf56a64d6e026f84d95db2
Author: Brecht Van Lommel
Date:   Wed Jan 12 23:40:05 2022 +0100
Branches: master
https://developer.blender.org/rBa3deef6fff7c395512cf56a64d6e026f84d95db2

Fix Cycles CPU + GPU render not using CPU after recent changes

In some places the task scheduler was not initialized in time.

===================================================================

M	intern/cycles/device/cpu/device_impl.cpp
M	intern/cycles/device/device.cpp
M	intern/cycles/util/task.cpp
M	intern/cycles/util/task.h

===================================================================

diff --git a/intern/cycles/device/cpu/device_impl.cpp b/intern/cycles/device/cpu/device_impl.cpp
index 6f3c8b42124..0ca24c241f0 100644
--- a/intern/cycles/device/cpu/device_impl.cpp
+++ b/intern/cycles/device/cpu/device_impl.cpp
@@ -72,7 +72,7 @@ CPUDevice::CPUDevice(const DeviceInfo &info_, Stats &stats_, Profiler &profiler_
           << " CPU kernels.";
 
   if (info.cpu_threads == 0) {
-    info.cpu_threads = TaskScheduler::num_threads();
+    info.cpu_threads = TaskScheduler::max_concurrency();
   }
 
 #ifdef WITH_OSL
diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp
index d3de6c54a17..14c97affb76 100644
--- a/intern/cycles/device/device.cpp
+++ b/intern/cycles/device/device.cpp
@@ -334,7 +334,7 @@ DeviceInfo Device::get_multi_device(const vector<DeviceInfo> &subdevices,
     /* Ensure CPU device does not slow down GPU. */
     if (device.type == DEVICE_CPU && subdevices.size() > 1) {
       if (background) {
-        int orig_cpu_threads = (threads) ? threads : TaskScheduler::num_threads();
+        int orig_cpu_threads = (threads) ? threads : TaskScheduler::max_concurrency();
         int cpu_threads = max(orig_cpu_threads - (subdevices.size() - 1), 0);
 
         VLOG(1) << "CPU render threads reduced from " << orig_cpu_threads << " to " << cpu_threads
diff --git a/intern/cycles/util/task.cpp b/intern/cycles/util/task.cpp
index eeccbaf1c44..174befce571 100644
--- a/intern/cycles/util/task.cpp
+++ b/intern/cycles/util/task.cpp
@@ -109,9 +109,10 @@ void TaskScheduler::free_memory()
   assert(users == 0);
 }
 
-int TaskScheduler::num_threads()
+int TaskScheduler::max_concurrency()
 {
-  return active_num_threads;
+  thread_scoped_lock lock(mutex);
+  return (users > 0) ? active_num_threads : tbb::this_task_arena::max_concurrency();
 }
 
 /* Dedicated Task Pool */
diff --git a/intern/cycles/util/task.h b/intern/cycles/util/task.h
index 1a8f512b83a..0117c51d05c 100644
--- a/intern/cycles/util/task.h
+++ b/intern/cycles/util/task.h
@@ -86,10 +86,9 @@ class TaskScheduler {
   static void exit();
   static void free_memory();
 
-  /* Approximate number of threads that will work on task, which may be lower
-   * or higher than the actual number of threads. Use as little as possible and
-   * leave splitting up tasks to the scheduler. */
-  static int num_threads();
+  /* Maximum number of threads that will work on task. Use as little as
+   * possible and leave scheduling and splitting up tasks to the scheduler. */
+  static int max_concurrency();
 
  protected:
   static thread_mutex mutex;



More information about the Bf-blender-cvs mailing list