[Bf-blender-cvs] [d822d4731fb] cycles-x: Fix OpenGL context usage in Cycles X

Sergey Sharybin noreply at git.blender.org
Fri Jul 23 12:09:09 CEST 2021


Commit: d822d4731fbb1575f39912823b59fa4b757a9a71
Author: Sergey Sharybin
Date:   Wed Jul 21 18:08:45 2021 +0200
Branches: cycles-x
https://developer.blender.org/rBd822d4731fbb1575f39912823b59fa4b757a9a71

Fix OpenGL context usage in Cycles X

Activating nullptr context is not a valid way to release the active
context, there is a dedicated function for this.

This also showed a logical error in the buffer mapping: the buffer
unmap is not supposed to release current OpenGL context but should
instead leave it active for a possible subsequent calls to the GPU
update. It worked before because the context as never released due
to wrong API usage.

Would say that the WM OpenGL API should have an assert to catch
such case, but this better to happen in the master branch.

Noticed while doing a further development related to GPUDisplay and
watching return value of GHOST_ActivateOpenGLContext.

Differential Revision: https://developer.blender.org/D11989

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

M	intern/cycles/blender/blender_gpu_display.cpp

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

diff --git a/intern/cycles/blender/blender_gpu_display.cpp b/intern/cycles/blender/blender_gpu_display.cpp
index a02547fb5c6..a76c708c403 100644
--- a/intern/cycles/blender/blender_gpu_display.cpp
+++ b/intern/cycles/blender/blender_gpu_display.cpp
@@ -27,31 +27,11 @@ void DRW_opengl_context_activate(bool drw_state);
 void *WM_opengl_context_create();
 void WM_opengl_context_activate(void *gl_context);
 void WM_opengl_context_dispose(void *gl_context);
+void WM_opengl_context_release(void *context);
 }
 
 CCL_NAMESPACE_BEGIN
 
-namespace {
-
-/* --------------------------------------------------------------------
- * Context helpers.
- */
-
-class GLContextScope {
- public:
-  explicit GLContextScope(void *gl_context)
-  {
-    WM_opengl_context_activate(gl_context);
-  }
-
-  ~GLContextScope()
-  {
-    WM_opengl_context_activate(nullptr);
-  }
-};
-
-} /* namespace */
-
 /* --------------------------------------------------------------------
  * BlenderDisplayShader.
  */
@@ -317,7 +297,7 @@ bool BlenderGPUDisplay::do_update_begin(int texture_width, int texture_height)
   glWaitSync((GLsync)gl_render_sync_, 0, GL_TIMEOUT_IGNORED);
 
   if (!gl_texture_resources_ensure()) {
-    WM_opengl_context_activate(nullptr);
+    WM_opengl_context_release(gl_context_);
     return false;
   }
 
@@ -365,7 +345,7 @@ void BlenderGPUDisplay::do_update_end()
   gl_upload_sync_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
   glFlush();
 
-  WM_opengl_context_activate(nullptr);
+  WM_opengl_context_release(gl_context_);
 }
 
 /* --------------------------------------------------------------------
@@ -426,8 +406,6 @@ void BlenderGPUDisplay::do_unmap_texture_buffer()
   glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
 
   glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
-
-  WM_opengl_context_activate(nullptr);
 }
 
 /* --------------------------------------------------------------------
@@ -559,7 +537,7 @@ void BlenderGPUDisplay::gl_resources_destroy()
   if (gl_context_) {
     const bool drw_state = DRW_opengl_context_release();
 
-    GLContextScope scope(gl_context_);
+    WM_opengl_context_activate(gl_context_);
 
     if (texture_.gl_pbo_id_) {
       glDeleteBuffers(1, &texture_.gl_pbo_id_);



More information about the Bf-blender-cvs mailing list