[Bf-blender-cvs] [f7fab77f857] master: Cleanup: GPU: Replace multiple checks by GLContext::debug_layer_support

Clément Foucault noreply at git.blender.org
Wed Sep 9 00:28:27 CEST 2020


Commit: f7fab77f85734e49414ea7d063532dbac6c5b6da
Author: Clément Foucault
Date:   Wed Sep 9 00:23:48 2020 +0200
Branches: master
https://developer.blender.org/rBf7fab77f85734e49414ea7d063532dbac6c5b6da

Cleanup: GPU: Replace multiple checks by GLContext::debug_layer_support

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

M	source/blender/gpu/opengl/gl_backend.cc
M	source/blender/gpu/opengl/gl_context.hh
M	source/blender/gpu/opengl/gl_debug.cc
M	source/blender/gpu/opengl/gl_framebuffer.cc
M	source/blender/gpu/opengl/gl_immediate.cc
M	source/blender/gpu/opengl/gl_shader.cc
M	source/blender/gpu/opengl/gl_texture.cc
M	source/blender/gpu/opengl/gl_uniform_buffer.cc

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

diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc
index e55e07d5a0b..c8d57a20a38 100644
--- a/source/blender/gpu/opengl/gl_backend.cc
+++ b/source/blender/gpu/opengl/gl_backend.cc
@@ -330,6 +330,7 @@ GLint GLContext::max_ubo_size;
 GLint GLContext::max_ubo_binds;
 /** Extensions. */
 bool GLContext::base_instance_support = false;
+bool GLContext::debug_layer_support = false;
 bool GLContext::texture_cube_map_array_support = false;
 /** Workarounds. */
 bool GLContext::texture_copy_workaround = false;
@@ -354,6 +355,12 @@ void GLBackend::capabilities_init(void)
   glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &GLContext::max_ubo_size);
   GLContext::base_instance_support = GLEW_ARB_base_instance;
   GLContext::texture_cube_map_array_support = GLEW_ARB_texture_cube_map_array;
+  GLContext::debug_layer_support = (GLEW_VERSION_4_3 || GLEW_KHR_debug);
+
+  if ((G.debug & G_DEBUG_GPU) == 0) {
+    /* Disable this feature entierly when not debugging. */
+    GLContext::debug_layer_support = false;
+  }
 
   detect_workarounds();
 }
diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh
index 8e653a56cd6..10ae396d138 100644
--- a/source/blender/gpu/opengl/gl_context.hh
+++ b/source/blender/gpu/opengl/gl_context.hh
@@ -62,6 +62,7 @@ class GLContext : public Context {
   static GLint max_ubo_binds;
   /** Extensions. */
   static bool base_instance_support;
+  static bool debug_layer_support;
   static bool texture_cube_map_array_support;
   /** Workarounds. */
   static bool texture_copy_workaround;
diff --git a/source/blender/gpu/opengl/gl_debug.cc b/source/blender/gpu/opengl/gl_debug.cc
index 53a71516018..468d1514d60 100644
--- a/source/blender/gpu/opengl/gl_debug.cc
+++ b/source/blender/gpu/opengl/gl_debug.cc
@@ -122,7 +122,7 @@ void init_gl_callbacks(void)
   char msg[256] = "";
   const char format[] = "Successfully hooked OpenGL debug callback using %s";
 
-  if (GLEW_VERSION_4_3 || GLEW_KHR_debug) {
+  if (GLContext::debug_layer_support) {
     SNPRINTF(msg, format, GLEW_VERSION_4_3 ? "OpenGL 4.3" : "KHR_debug extension");
     glEnable(GL_DEBUG_OUTPUT);
     glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc
index 14b7d78c2ff..bfc8a2f74eb 100644
--- a/source/blender/gpu/opengl/gl_framebuffer.cc
+++ b/source/blender/gpu/opengl/gl_framebuffer.cc
@@ -63,13 +63,11 @@ GLFrameBuffer::GLFrameBuffer(
   viewport_[2] = scissor_[2] = w;
   viewport_[3] = scissor_[3] = h;
 
-#ifndef __APPLE__
-  if (fbo_id_ && (G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
+  if (fbo_id_ && GLContext::debug_layer_support) {
     char sh_name[32];
     SNPRINTF(sh_name, "FrameBuffer-%s", name);
     glObjectLabel(GL_FRAMEBUFFER, fbo_id_, -1, sh_name);
   }
-#endif
 }
 
 GLFrameBuffer::~GLFrameBuffer()
@@ -100,15 +98,13 @@ void GLFrameBuffer::init(void)
   state_manager_ = static_cast<GLStateManager *>(context_->state_manager);
   glGenFramebuffers(1, &fbo_id_);
 
-#ifndef __APPLE__
-  if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
+  if (GLContext::debug_layer_support) {
     char sh_name[64];
     SNPRINTF(sh_name, "FrameBuffer-%s", name_);
     /* Binding before setting the label is needed on some drivers. */
     glBindFramebuffer(GL_FRAMEBUFFER, fbo_id_);
     glObjectLabel(GL_FRAMEBUFFER, fbo_id_, -1, sh_name);
   }
-#endif
 }
 
 /** \} */
diff --git a/source/blender/gpu/opengl/gl_immediate.cc b/source/blender/gpu/opengl/gl_immediate.cc
index 26b1df88b64..7afbbf9965c 100644
--- a/source/blender/gpu/opengl/gl_immediate.cc
+++ b/source/blender/gpu/opengl/gl_immediate.cc
@@ -60,13 +60,11 @@ GLImmediate::GLImmediate()
   glBindBuffer(GL_ARRAY_BUFFER, 0);
   glBindVertexArray(0);
 
-#ifndef __APPLE__
-  if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
+  if (GLContext::debug_layer_support) {
     glObjectLabel(GL_VERTEX_ARRAY, vao_id_, -1, "VAO-Immediate");
     glObjectLabel(GL_BUFFER, buffer.vbo_id, -1, "VBO-ImmediateBuffer");
     glObjectLabel(GL_BUFFER, buffer_strict.vbo_id, -1, "VBO-ImmediateBufferStrict");
   }
-#endif
 }
 
 GLImmediate::~GLImmediate()
diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc
index ca38efe37b5..4314ecfa6be 100644
--- a/source/blender/gpu/opengl/gl_shader.cc
+++ b/source/blender/gpu/opengl/gl_shader.cc
@@ -48,13 +48,11 @@ GLShader::GLShader(const char *name) : Shader(name)
 #endif
   shader_program_ = glCreateProgram();
 
-#ifndef __APPLE__
-  if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
+  if (GLContext::debug_layer_support) {
     char sh_name[64];
     SNPRINTF(sh_name, "ShaderProgram-%s", name);
     glObjectLabel(GL_PROGRAM, shader_program_, -1, sh_name);
   }
-#endif
 }
 
 GLShader::~GLShader(void)
@@ -165,8 +163,7 @@ GLuint GLShader::create_shader_stage(GLenum gl_stage, MutableSpan<const char *>
     return 0;
   }
 
-#ifndef __APPLE__
-  if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
+  if (GLContext::debug_layer_support) {
     char sh_name[64];
     switch (gl_stage) {
       case GL_VERTEX_SHADER:
@@ -181,7 +178,6 @@ GLuint GLShader::create_shader_stage(GLenum gl_stage, MutableSpan<const char *>
     }
     glObjectLabel(GL_SHADER, shader, -1, sh_name);
   }
-#endif
 
   glAttachShader(shader_program_, shader);
   return shader;
diff --git a/source/blender/gpu/opengl/gl_texture.cc b/source/blender/gpu/opengl/gl_texture.cc
index e649f73d1c4..ec08b736af2 100644
--- a/source/blender/gpu/opengl/gl_texture.cc
+++ b/source/blender/gpu/opengl/gl_texture.cc
@@ -96,14 +96,12 @@ bool GLTexture::init_internal(void)
     glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   }
 
-#ifndef __APPLE__
-  if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
+  if (GLContext::debug_layer_support) {
     char sh_name[64];
     SNPRINTF(sh_name, "Texture-%s", name_);
     /* Binding before setting the label is needed on some drivers. */
     glObjectLabel(GL_TEXTURE, tex_id_, -1, sh_name);
   }
-#endif
 
   GL_CHECK_ERROR("Post-texture creation");
   return true;
@@ -127,14 +125,12 @@ bool GLTexture::init_internal(GPUVertBuf *vbo)
     glTexBuffer(target_, internal_format, gl_vbo->vbo_id_);
   }
 
-#ifndef __APPLE__
-  if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
+  if (GLContext::debug_layer_support) {
     char sh_name[64];
     SNPRINTF(sh_name, "Texture-%s", name_);
     /* Binding before setting the label is needed on some drivers. */
     glObjectLabel(GL_TEXTURE, tex_id_, -1, sh_name);
   }
-#endif
 
   GL_CHECK_ERROR("Post-texture buffer creation");
   return true;
@@ -514,8 +510,7 @@ void GLTexture::samplers_init(void)
      * - GL_TEXTURE_LOD_BIAS is 0.0f.
      **/
 
-#ifndef __APPLE__
-    if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
+    if (GLContext::debug_layer_support) {
       char sampler_name[128];
       SNPRINTF(sampler_name,
                "Sampler%s%s%s%s%s%s%s%s%s%s",
@@ -531,7 +526,6 @@ void GLTexture::samplers_init(void)
                (state & GPU_SAMPLER_ANISO) ? "_aniso" : "");
       glObjectLabel(GL_SAMPLER, samplers_[i], -1, sampler_name);
     }
-#endif
   }
   samplers_update();
 
@@ -541,11 +535,9 @@ void GLTexture::samplers_init(void)
   glSamplerParameteri(icon_sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glSamplerParameterf(icon_sampler, GL_TEXTURE_LOD_BIAS, -0.5f);
 
-#ifndef __APPLE__
-  if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
+  if (GLContext::debug_layer_support) {
     glObjectLabel(GL_SAMPLER, icon_sampler, -1, "Sampler-icons");
   }
-#endif
 }
 
 void GLTexture::samplers_update(void)
diff --git a/source/blender/gpu/opengl/gl_uniform_buffer.cc b/source/blender/gpu/opengl/gl_uniform_buffer.cc
index 62c590d289f..74453a08bfe 100644
--- a/source/blender/gpu/opengl/gl_uniform_buffer.cc
+++ b/source/blender/gpu/opengl/gl_uniform_buffer.cc
@@ -62,13 +62,11 @@ void GLUniformBuf::init(void)
   glBindBuffer(GL_UNIFORM_BUFFER, ubo_id_);
   glBufferData(GL_UNIFORM_BUFFER, size_in_bytes_, NULL, GL_DYNAMIC_DRAW);
 
-#ifndef __APPLE__
-  if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
+  if (GLContext::debug_layer_support) {
     char sh_name[64];
     SNPRINTF(sh_name, "UBO-%s", name_);
     glObjectLabel(GL_BUFFER, ubo_id_, -1, sh_name);
   }
-#endif
 }
 
 void GLUniformBuf::update(const void *data)



More information about the Bf-blender-cvs mailing list