[Bf-blender-cvs] [2895c670865] master: Fix T103408: Cycles deadlock during GPU viewport rendering

Lukas Stockner noreply at git.blender.org
Sat Jan 7 20:41:41 CET 2023


Commit: 2895c6708656b749b76331a907b539654ca125e1
Author: Lukas Stockner
Date:   Sat Jan 7 20:27:23 2023 +0100
Branches: master
https://developer.blender.org/rB2895c6708656b749b76331a907b539654ca125e1

Fix T103408: Cycles deadlock during GPU viewport rendering

This was caused by rB0d73d5c1a2, which releases the scene mutex during kernel
loading. However, the reset mutex was still held, which can cause a deadlock
if another thread tries to reset the session, since it will acquire the
released scene mutex and then wait for the reset mutex.

Turns out there's no point in keeping the reset mutex locked after the delayed
reset section, so now we just release it earlier, which resolves the deadlock.

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

M	intern/cycles/session/session.cpp

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

diff --git a/intern/cycles/session/session.cpp b/intern/cycles/session/session.cpp
index 9fa7f5da296..9e7e0e6e2a4 100644
--- a/intern/cycles/session/session.cpp
+++ b/intern/cycles/session/session.cpp
@@ -289,19 +289,24 @@ RenderWork Session::run_update_for_next_iteration()
   RenderWork render_work;
 
   thread_scoped_lock scene_lock(scene->mutex);
-  thread_scoped_lock reset_lock(delayed_reset_.mutex);
 
   bool have_tiles = true;
   bool switched_to_new_tile = false;
+  bool did_reset = false;
 
-  const bool did_reset = delayed_reset_.do_reset;
-  if (delayed_reset_.do_reset) {
-    thread_scoped_lock buffers_lock(buffers_mutex_);
-    do_delayed_reset();
+  /* Perform delayed reset if requested. */
+  {
+    thread_scoped_lock reset_lock(delayed_reset_.mutex);
+    if (delayed_reset_.do_reset) {
+      did_reset = true;
 
-    /* After reset make sure the tile manager is at the first big tile. */
-    have_tiles = tile_manager_.next();
-    switched_to_new_tile = true;
+      thread_scoped_lock buffers_lock(buffers_mutex_);
+      do_delayed_reset();
+
+      /* After reset make sure the tile manager is at the first big tile. */
+      have_tiles = tile_manager_.next();
+      switched_to_new_tile = true;
+    }
   }
 
   /* Update number of samples in the integrator.



More information about the Bf-blender-cvs mailing list