Revert r50528: "Performance fix for Cycles: Don't wait in the main UI thread when...
authorLukas Toenne <lukas.toenne@googlemail.com>
Mon, 17 Sep 2012 12:07:06 +0000 (12:07 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Mon, 17 Sep 2012 12:07:06 +0000 (12:07 +0000)
This commit leads to random freezes in Cycles rendering:
https://projects.blender.org/tracker/index.php?func=detail&aid=32545&group_id=9&atid=498

The goal of this commit was to remove UI lag for OSL, but since that is not officially supported yet, better revert it until a proper fix can be implemented in 2.65.

intern/cycles/blender/blender_session.cpp
intern/cycles/device/device.h
intern/cycles/device/device_cpu.cpp
intern/cycles/device/device_cuda.cpp
intern/cycles/device/device_multi.cpp
intern/cycles/device/device_opencl.cpp
intern/cycles/render/session.cpp
intern/cycles/render/session.h
intern/cycles/util/util_task.cpp

index 5930a2800bf7d4b31702e8d2e6684411321cc41e..7b80c520e726131929db67110f6e3cfbd43cc2dc 100644 (file)
@@ -372,12 +372,6 @@ void BlenderSession::synchronize()
                return;
        }
 
-       /* if the session is still resetting the device come back later */
-       if(session->resetting()) {
-               tag_update();
-               return;
-       }
-
        /* increase samples, but never decrease */
        session->set_samples(session_params.samples);
        session->set_pause(BlenderSync::get_session_pause(b_scene, background));
index 8e3bc408399b18f388feba65d3a8b01a63b9e73d..2ee2e044618a03927518083a09ed3e4a370db948 100644 (file)
@@ -115,7 +115,6 @@ public:
        virtual void task_add(DeviceTask& task) = 0;
        virtual void task_wait() = 0;
        virtual void task_cancel() = 0;
-       virtual bool task_cancelled() = 0;
        
        /* opengl drawing */
        virtual void draw_pixels(device_memory& mem, int y, int w, int h,
index e2f612ee2335e4f08f9f4102b14dd84af644d8bd..4c54671b0d0a494bfae406db723ab4d2f7a5393d 100644 (file)
@@ -273,11 +273,6 @@ public:
        {
                task_pool.cancel();
        }
-
-       bool task_cancelled()
-       {
-               return task_pool.cancelled();
-       }
 };
 
 Device *device_cpu_create(DeviceInfo& info, int threads)
index acc1086cc3547e08c3bd41c6e5747d1c8ed74c3c..c8dcfdc2f3d7cc4292d7997e89866f33df5b1a20 100644 (file)
@@ -892,11 +892,6 @@ public:
        {
                task_pool.cancel();
        }
-
-       bool task_cancelled()
-       {
-               return task_pool.cancelled();
-       }
 };
 
 Device *device_cuda_create(DeviceInfo& info, bool background)
index 4923e5c9e6699b625b276887c58baa4b621e7255..546ffe5e4b9651aac25310428db02d85a234affe 100644 (file)
@@ -312,14 +312,6 @@ public:
                foreach(SubDevice& sub, devices)
                        sub.device->task_cancel();
        }
-
-       bool task_cancelled()
-       {
-               foreach(SubDevice& sub, devices)
-                       if (sub.device->task_cancelled())
-                               return true;
-               return false;
-       }
 };
 
 Device *device_multi_create(DeviceInfo& info, bool background)
index ed7229d49da151938040d88c730832462fedc92d..673ffdf79fd8a4fbf6ea1fe495448070242d0661 100644 (file)
@@ -724,11 +724,6 @@ public:
        {
                task_pool.cancel();
        }
-
-       bool task_cancelled()
-       {
-               return task_pool.cancelled();
-       }
 };
 
 Device *device_opencl_create(DeviceInfo& info, bool background)
index b190cdfec96c4b0334921f0e60bf27f012a3a7f2..cd410e4e0118a452e8183298dba5eb33593cbfba 100644 (file)
@@ -140,12 +140,6 @@ void Session::reset_gpu(BufferParams& buffer_params, int samples)
        pause_cond.notify_all();
 }
 
-bool Session::resetting_gpu() const
-{
-       /* no need to wait for gpu device */
-       return false;
-}
-
 bool Session::draw_gpu(BufferParams& buffer_params)
 {
        /* block for buffer access */
@@ -296,11 +290,6 @@ void Session::reset_cpu(BufferParams& buffer_params, int samples)
        pause_cond.notify_all();
 }
 
-bool Session::resetting_cpu() const
-{
-       return device->task_cancelled();
-}
-
 bool Session::draw_cpu(BufferParams& buffer_params)
 {
        thread_scoped_lock display_lock(display_mutex);
@@ -595,14 +584,6 @@ void Session::reset(BufferParams& buffer_params, int samples)
                reset_cpu(buffer_params, samples);
 }
 
-bool Session::resetting() const
-{
-       if(device_use_gl)
-               return resetting_gpu();
-       else
-               return resetting_cpu();
-}
-
 void Session::set_samples(int samples)
 {
        if(samples != params.samples) {
index a3a2751fb23fab221bf08a17a0f3499f8dda7aeb..eda8b3da60e5bbbc2a7b920cb41be0a53d4f1ac4 100644 (file)
@@ -116,7 +116,6 @@ public:
 
        bool ready_to_reset();
        void reset(BufferParams& params, int samples);
-       bool resetting() const;
        void set_samples(int samples);
        void set_pause(bool pause);
 
@@ -140,12 +139,10 @@ protected:
        void run_cpu();
        bool draw_cpu(BufferParams& params);
        void reset_cpu(BufferParams& params, int samples);
-       bool resetting_cpu() const;
 
        void run_gpu();
        bool draw_gpu(BufferParams& params);
        void reset_gpu(BufferParams& params, int samples);
-       bool resetting_gpu() const;
 
        bool acquire_tile(Device *tile_device, RenderTile& tile);
        void update_tile_sample(RenderTile& tile);
index 2b209c135f447802b6be1699c101296e8e30ee9a..ea0abd6f54f31eaf03b741027d86f98f326f58ca 100644 (file)
@@ -38,8 +38,6 @@ TaskPool::~TaskPool()
 
 void TaskPool::push(Task *task, bool front)
 {
-       thread_scoped_lock num_lock(num_mutex);
-
        TaskScheduler::Entry entry;
 
        entry.task = task;
@@ -104,17 +102,22 @@ void TaskPool::wait_work()
 
 void TaskPool::cancel()
 {
-       thread_scoped_lock num_lock(num_mutex);
-
        do_cancel = true;
 
        TaskScheduler::clear(this);
+       
+       {
+               thread_scoped_lock num_lock(num_mutex);
+
+               while(num)
+                       num_cond.wait(num_lock);
+       }
+
+       do_cancel = false;
 }
 
 void TaskPool::stop()
 {
-       thread_scoped_lock num_lock(num_mutex);
-       
        TaskScheduler::clear(this);
 
        assert(num == 0);
@@ -127,20 +130,20 @@ bool TaskPool::cancelled()
 
 void TaskPool::num_decrease(int done)
 {
+       num_mutex.lock();
        num -= done;
+
        assert(num >= 0);
-       
-       if(num == 0) {
-               do_cancel = false;
-               
+       if(num == 0)
                num_cond.notify_all();
-       }
+
+       num_mutex.unlock();
 }
 
 void TaskPool::num_increase()
 {
+       thread_scoped_lock num_lock(num_mutex);
        num++;
-       
        num_cond.notify_all();
 }
 
@@ -236,11 +239,7 @@ void TaskScheduler::thread_run(int thread_id)
                delete entry.task;
 
                /* notify pool task was done */
-               {
-                       /* not called from TaskPool, have to explicitly lock the mutex here */
-                       thread_scoped_lock num_lock(entry.pool->num_mutex);
-                       entry.pool->num_decrease(1);
-               }
+               entry.pool->num_decrease(1);
        }
 }