Fix #33107: cycles fixed threads 1 was still having two cores do work,
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 7 Nov 2012 21:00:49 +0000 (21:00 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 7 Nov 2012 21:00:49 +0000 (21:00 +0000)
because main thread works as well.

intern/cycles/blender/blender_sync.cpp
intern/cycles/device/device.cpp
intern/cycles/device/device.h
intern/cycles/device/device_cpu.cpp
intern/cycles/device/device_intern.h
intern/cycles/render/session.cpp
intern/cycles/util/util_task.cpp
intern/cycles/util/util_task.h

index c63f72c68c67b8790fc3f28b1e778c229a357692..024cb1685d0eab188968d88412bd67c72cbcbea1 100644 (file)
@@ -379,7 +379,10 @@ SessionParams BlenderSync::get_session_params(BL::RenderEngine b_engine, BL::Use
        params.start_resolution = get_int(cscene, "preview_start_resolution");
 
        /* other parameters */
-       params.threads = b_scene.render().threads();
+       if(b_scene.render().threads_mode() == BL::RenderSettings::threads_mode_FIXED)
+               params.threads = b_scene.render().threads();
+       else
+               params.threads = 0;
 
        params.cancel_timeout = get_float(cscene, "debug_cancel_timeout");
        params.reset_timeout = get_float(cscene, "debug_reset_timeout");
index 550da2982a369b39547f50b9cc6425ec917aff0b..c6a2c678bacc48a806f0ab5e256f2c1e9534fc02 100644 (file)
@@ -78,13 +78,13 @@ void Device::draw_pixels(device_memory& rgba, int y, int w, int h, int dy, int w
                glDisable(GL_BLEND);
 }
 
-Device *Device::create(DeviceInfo& info, Stats &stats, bool background, int threads)
+Device *Device::create(DeviceInfo& info, Stats &stats, bool background)
 {
        Device *device;
 
        switch(info.type) {
                case DEVICE_CPU:
-                       device = device_cpu_create(info, stats, threads);
+                       device = device_cpu_create(info, stats);
                        break;
 #ifdef WITH_CUDA
                case DEVICE_CUDA:
index 95da0a89833ba7cc63f5873ae34bf060753dfc06..9840687b76a238aef031a6e5078b9246a55c876b 100644 (file)
@@ -134,7 +134,7 @@ public:
        virtual int device_number(Device *sub_device) { return 0; }
 
        /* static */
-       static Device *create(DeviceInfo& info, Stats &stats, bool background = true, int threads = 0);
+       static Device *create(DeviceInfo& info, Stats &stats, bool background = true);
 
        static DeviceType type_from_string(const char *name);
        static string string_from_type(DeviceType type);
index 519c458ffdf990118dd26f7de63b1dd462bd96ca..bc28061661553bc5df2c1d3970cf67bd3ca45043 100644 (file)
@@ -45,7 +45,7 @@ public:
        TaskPool task_pool;
        KernelGlobals *kg;
        
-       CPUDevice(Stats &stats, int threads_num) : Device(stats)
+       CPUDevice(Stats &stats) : Device(stats)
        {
                kg = kernel_globals_create();
 
@@ -274,7 +274,7 @@ public:
                /* split task into smaller ones, more than number of threads for uneven
                 * workloads where some parts of the image render slower than others */
                list<DeviceTask> tasks;
-               task.split(tasks, TaskScheduler::num_threads()+1);
+               task.split(tasks, TaskScheduler::num_threads());
 
                foreach(DeviceTask& task, tasks)
                        task_pool.push(new CPUDeviceTask(this, task));
@@ -291,9 +291,9 @@ public:
        }
 };
 
-Device *device_cpu_create(DeviceInfo& info, Stats &stats, int threads)
+Device *device_cpu_create(DeviceInfo& info, Stats &stats)
 {
-       return new CPUDevice(stats, threads);
+       return new CPUDevice(stats);
 }
 
 void device_cpu_info(vector<DeviceInfo>& devices)
index 02fbac6860e55c983c8ca9b2958e8b7845ebc110..b49ebba3e8b1f51bb24fc0f4589dc61c19967684 100644 (file)
@@ -23,7 +23,7 @@ CCL_NAMESPACE_BEGIN
 
 class Device;
 
-Device *device_cpu_create(DeviceInfo& info, Stats &stats, int threads);
+Device *device_cpu_create(DeviceInfo& info, Stats &stats);
 Device *device_opencl_create(DeviceInfo& info, Stats &stats, bool background);
 Device *device_cuda_create(DeviceInfo& info, Stats &stats, bool background);
 Device *device_network_create(DeviceInfo& info, Stats &stats, const char *address);
index 7303cb52ad82b4e95b4535fc8011213316e3470b..024af8dede8d08d3cc3774f424fe5b24a3f5b62b 100644 (file)
@@ -49,7 +49,7 @@ Session::Session(const SessionParams& params_)
 
        TaskScheduler::init(params.threads);
 
-       device = Device::create(params.device, stats, params.background, params.threads);
+       device = Device::create(params.device, stats, params.background);
 
        if(params.background) {
                buffers = NULL;
index ea0abd6f54f31eaf03b741027d86f98f326f58ca..8c4ec312256d94da575480024a83dcf9844bea51 100644 (file)
@@ -168,10 +168,16 @@ void TaskScheduler::init(int num_threads)
        if(users == 0) {
                do_exit = false;
 
-               /* launch threads that will be waiting for work */
-               if(num_threads == 0)
+               if(num_threads == 0) {
+                       /* automatic number of threads will be main thread + num cores */
                        num_threads = system_cpu_thread_count();
+               }
+               else {
+                       /* main thread will also work, for fixed threads we count it too */
+                       num_threads -= 1;
+               }
 
+               /* launch threads that will be waiting for work */
                threads.resize(num_threads);
                thread_level.resize(num_threads);
 
index a2f284479c77e3bb5e56eb609a9e3ba4b5185c3c..b795ca7524b47961c7c7c222bbdabb31b8de4629 100644 (file)
@@ -94,7 +94,10 @@ public:
        static void init(int num_threads = 0);
        static void exit();
 
-       static int num_threads() { return threads.size(); }
+       /* number of threads that can work on tasks, main thread counts too */
+       static int num_threads() { return threads.size() + 1; }
+
+       /* test if any session is using the scheduler */
        static bool active() { return users != 0; }
 
 protected: