[Bf-blender-cvs] [8d59f060ca7] master: GL: Wrap extension support inside GLContext

Clément Foucault noreply at git.blender.org
Thu Sep 10 14:19:12 CEST 2020


Commit: 8d59f060ca73247b2265db04655eef9db0f1c06a
Author: Clément Foucault
Date:   Thu Sep 10 14:18:19 2020 +0200
Branches: master
https://developer.blender.org/rB8d59f060ca73247b2265db04655eef9db0f1c06a

GL: Wrap extension support inside GLContext

This makes it possible to disable all the extensions when forcing
workarounds.

Also it will allow future options to selectively disable each extension
to know which one is buggy.

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

M	source/blender/gpu/opengl/gl_backend.cc
M	source/blender/gpu/opengl/gl_batch.cc
M	source/blender/gpu/opengl/gl_context.hh
M	source/blender/gpu/opengl/gl_drawlist.cc
M	source/blender/gpu/opengl/gl_shader.cc
M	source/blender/gpu/opengl/gl_state.cc
M	source/blender/gpu/opengl/gl_texture.cc
M	source/blender/gpu/opengl/gl_vertex_array.cc

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

diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc
index 7285b9ad35c..edaa84cdcf8 100644
--- a/source/blender/gpu/opengl/gl_backend.cc
+++ b/source/blender/gpu/opengl/gl_backend.cc
@@ -209,11 +209,20 @@ static void detect_workarounds(void)
     GCaps.mip_render_workaround = true;
     GLContext::debug_layer_workaround = true;
     GLContext::unused_fb_slot_workaround = true;
-    GLContext::texture_copy_workaround = true;
     /* Turn off extensions. */
     GLContext::base_instance_support = false;
+    GLContext::clear_texture_support = false;
+    GLContext::copy_image_support = false;
     GLContext::debug_layer_support = false;
+    GLContext::direct_state_access_support = false;
+    GLContext::fixed_restart_index_support = false;
+    GLContext::multi_bind_support = false;
+    GLContext::multi_draw_indirect_support = false;
+    GLContext::shader_draw_parameters_support = false;
     GLContext::texture_cube_map_array_support = false;
+    GLContext::texture_filter_anisotropic_support = false;
+    GLContext::texture_gather_support = false;
+    GLContext::vertex_attrib_binding_support = false;
     return;
   }
 
@@ -268,7 +277,7 @@ static void detect_workarounds(void)
    * covered since they only support GL 4.4 on windows.
    * This fixes some issues with workbench anti-aliasing on Win + Intel GPU. (see T76273) */
   if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_WIN, GPU_DRIVER_OFFICIAL) && !GLEW_VERSION_4_5) {
-    GLContext::texture_copy_workaround = true;
+    GLContext::copy_image_support = false;
   }
   /* Special fix for theses specific GPUs.
    * Without this workaround, blender crashes on startup. (see T72098) */
@@ -305,6 +314,11 @@ static void detect_workarounds(void)
        strstr(version, "Mesa 19.1") || strstr(version, "Mesa 19.2"))) {
     GLContext::unused_fb_slot_workaround = true;
   }
+  /* There is a bug on older Nvidia GPU where GL_ARB_texture_gather
+   * is reported to be supported but yield a compile error (see T55802). */
+  if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY) && !GLEW_VERSION_4_0) {
+    GLContext::texture_gather_support = false;
+  }
 
   /* dFdx/dFdy calculation factors, those are dependent on driver. */
   if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY) &&
@@ -323,6 +337,11 @@ static void detect_workarounds(void)
       GLContext::derivative_signs[1] = 1.0;
     }
   }
+
+  /* Disable multidraw if the base instance cannot be read. */
+  if (GLContext::shader_draw_parameters_support == false) {
+    GLContext::multi_draw_indirect_support = false;
+  }
   /* Enable our own incomplete debug layer if no other is available. */
   if (GLContext::debug_layer_support == false) {
     GLContext::debug_layer_workaround = true;
@@ -336,11 +355,20 @@ GLint GLContext::max_ubo_size;
 GLint GLContext::max_ubo_binds;
 /** Extensions. */
 bool GLContext::base_instance_support = false;
+bool GLContext::clear_texture_support = false;
+bool GLContext::copy_image_support = false;
 bool GLContext::debug_layer_support = false;
+bool GLContext::direct_state_access_support = false;
+bool GLContext::fixed_restart_index_support = false;
+bool GLContext::multi_bind_support = false;
+bool GLContext::multi_draw_indirect_support = false;
+bool GLContext::shader_draw_parameters_support = false;
 bool GLContext::texture_cube_map_array_support = false;
+bool GLContext::texture_filter_anisotropic_support = false;
+bool GLContext::texture_gather_support = false;
+bool GLContext::vertex_attrib_binding_support = false;
 /** Workarounds. */
 bool GLContext::debug_layer_workaround = false;
-bool GLContext::texture_copy_workaround = false;
 bool GLContext::unused_fb_slot_workaround = false;
 float GLContext::derivative_signs[2] = {1.0f, 1.0f};
 
@@ -361,8 +389,18 @@ void GLBackend::capabilities_init(void)
   glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &GLContext::max_ubo_binds);
   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::clear_texture_support = GLEW_ARB_clear_texture;
+  GLContext::copy_image_support = GLEW_ARB_copy_image;
   GLContext::debug_layer_support = GLEW_VERSION_4_3 || GLEW_KHR_debug || GLEW_ARB_debug_output;
+  GLContext::direct_state_access_support = GLEW_ARB_direct_state_access;
+  GLContext::fixed_restart_index_support = GLEW_ARB_ES3_compatibility;
+  GLContext::multi_bind_support = GLEW_ARB_multi_bind;
+  GLContext::multi_draw_indirect_support = GLEW_ARB_multi_draw_indirect;
+  GLContext::shader_draw_parameters_support = GLEW_ARB_shader_draw_parameters;
+  GLContext::texture_cube_map_array_support = GLEW_ARB_texture_cube_map_array;
+  GLContext::texture_filter_anisotropic_support = GLEW_EXT_texture_filter_anisotropic;
+  GLContext::texture_gather_support = GLEW_ARB_texture_gather;
+  GLContext::vertex_attrib_binding_support = GLEW_ARB_vertex_attrib_binding;
 
   detect_workarounds();
 
diff --git a/source/blender/gpu/opengl/gl_batch.cc b/source/blender/gpu/opengl/gl_batch.cc
index 17bc1013a78..ca627775e1f 100644
--- a/source/blender/gpu/opengl/gl_batch.cc
+++ b/source/blender/gpu/opengl/gl_batch.cc
@@ -307,7 +307,7 @@ void GLBatch::bind(int i_first)
 
 #if GPU_TRACK_INDEX_RANGE
   /* Can be removed if GL 4.3 is required. */
-  if (!GLEW_ARB_ES3_compatibility && (elem != NULL)) {
+  if (!GLContext::fixed_restart_index_support && (elem != NULL)) {
     glPrimitiveRestartIndex(this->elem_()->restart_index());
   }
 #endif
diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh
index 1cef6e61425..9822c842ce7 100644
--- a/source/blender/gpu/opengl/gl_context.hh
+++ b/source/blender/gpu/opengl/gl_context.hh
@@ -62,11 +62,20 @@ class GLContext : public Context {
   static GLint max_ubo_binds;
   /** Extensions. */
   static bool base_instance_support;
+  static bool clear_texture_support;
+  static bool copy_image_support;
   static bool debug_layer_support;
+  static bool direct_state_access_support;
+  static bool fixed_restart_index_support;
+  static bool multi_bind_support;
+  static bool multi_draw_indirect_support;
+  static bool shader_draw_parameters_support;
   static bool texture_cube_map_array_support;
+  static bool texture_filter_anisotropic_support;
+  static bool texture_gather_support;
+  static bool vertex_attrib_binding_support;
   /** Workarounds. */
   static bool debug_layer_workaround;
-  static bool texture_copy_workaround;
   static bool unused_fb_slot_workaround;
   static float derivative_signs[2];
 
diff --git a/source/blender/gpu/opengl/gl_drawlist.cc b/source/blender/gpu/opengl/gl_drawlist.cc
index 6e3b1107b9c..990e1a8014b 100644
--- a/source/blender/gpu/opengl/gl_drawlist.cc
+++ b/source/blender/gpu/opengl/gl_drawlist.cc
@@ -41,8 +41,6 @@
 
 #include <limits.h>
 
-#define USE_MULTI_DRAW_INDIRECT 1
-
 using namespace blender::gpu;
 
 typedef struct GLDrawCommand {
@@ -75,8 +73,7 @@ GLDrawList::GLDrawList(int length)
   data_size_ = 0;
   data_ = NULL;
 
-  if (USE_MULTI_DRAW_INDIRECT && GLEW_ARB_multi_draw_indirect &&
-      GLContext::base_instance_support) {
+  if (GLContext::multi_draw_indirect_support) {
     /* Alloc the biggest possible command list, which is indexed. */
     buffer_size_ = sizeof(GLDrawCommandIndexed) * length;
   }
diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc
index 7b3a071bf63..c400f218f5a 100644
--- a/source/blender/gpu/opengl/gl_shader.cc
+++ b/source/blender/gpu/opengl/gl_shader.cc
@@ -85,25 +85,15 @@ char *GLShader::glsl_patch_get(void)
 
   /* Enable extensions for features that are not part of our base GLSL version
    * don't use an extension for something already available! */
-  if (GLEW_ARB_texture_gather) {
-    /* There is a bug on older Nvidia GPU where GL_ARB_texture_gather
-     * is reported to be supported but yield a compile error (see T55802). */
-    if (!GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY) || GLEW_VERSION_4_0) {
-      STR_CONCAT(patch, slen, "#extension GL_ARB_texture_gather: enable\n");
-
-      /* Some drivers don't agree on GLEW_ARB_texture_gather and the actual support in the
-       * shader so double check the preprocessor define (see T56544). */
-      if (!GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY) && !GLEW_VERSION_4_0) {
-        STR_CONCAT(patch, slen, "#ifdef GL_ARB_texture_gather\n");
-        STR_CONCAT(patch, slen, "#  define GPU_ARB_texture_gather\n");
-        STR_CONCAT(patch, slen, "#endif\n");
-      }
-      else {
-        STR_CONCAT(patch, slen, "#define GPU_ARB_texture_gather\n");
-      }
-    }
+  if (GLContext::texture_gather_support) {
+    STR_CONCAT(patch, slen, "#extension GL_ARB_texture_gather: enable\n");
+    /* Some drivers don't agree on GLEW_ARB_texture_gather and the actual support in the
+     * shader so double check the preprocessor define (see T56544). */
+    STR_CONCAT(patch, slen, "#ifdef GL_ARB_texture_gather\n");
+    STR_CONCAT(patch, slen, "#  define GPU_ARB_texture_gather\n");
+    STR_CONCAT(patch, slen, "#endif\n");
   }
-  if (GLEW_ARB_shader_draw_parameters) {
+  if (GLContext::shader_draw_parameters_support) {
     STR_CONCAT(patch, slen, "#extension GL_ARB_shader_draw_parameters : enable\n");
     STR_CONCAT(patch, slen, "#define GPU_ARB_shader_draw_parameters\n");
   }
diff --git a/source/blender/gpu/opengl/gl_state.cc b/source/blender/gpu/opengl/gl_state.cc
index 970a4d45a88..03762edac93 100644
--- a/source/blender/gpu/opengl/gl_state.cc
+++ b/source/blender/gpu/opengl/gl_state.cc
@@ -56,7 +56,7 @@ GLStateManager::GLStateManager(void) : GPUStateManager()
 
   glPrimitiveRestartIndex((GLuint)0xFFFFFFFF);
   /* TODO: Should become default. But needs at least GL 4.3 */
-  if (GLEW_ARB_ES3_compatibility) {
+  if (GLContext::fixed_restart_index_support) {
     /* Takes precedence over #GL_PRIMITIVE_RESTART. */
     glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
   }
@@ -454,7 +454,6 @@ void GLStateManager::texture_bind(Texture *tex_, eGPUSamplerState sampler_type,
 /* Bind the texture to slot 0 for editing

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list