[Bf-blender-cvs] [558e1158e7b] master: GLState: Add texture multibind and remove redundant binds

Clément Foucault noreply at git.blender.org
Sat Sep 5 17:50:10 CEST 2020


Commit: 558e1158e7b07e2a1b2fd239cd662282828990f0
Author: Clément Foucault
Date:   Sat Sep 5 17:35:38 2020 +0200
Branches: master
https://developer.blender.org/rB558e1158e7b07e2a1b2fd239cd662282828990f0

GLState: Add texture multibind and remove redundant binds

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

M	source/blender/gpu/opengl/gl_state.cc

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

diff --git a/source/blender/gpu/opengl/gl_state.cc b/source/blender/gpu/opengl/gl_state.cc
index 4831185307f..20d6d608f78 100644
--- a/source/blender/gpu/opengl/gl_state.cc
+++ b/source/blender/gpu/opengl/gl_state.cc
@@ -20,7 +20,10 @@
  * \ingroup gpu
  */
 
+#include "BKE_global.h"
+
 #include "BLI_math_base.h"
+#include "BLI_math_bits.h"
 
 #include "GPU_extensions.h"
 
@@ -431,6 +434,11 @@ void GLStateManager::texture_bind(Texture *tex_, eGPUSamplerState sampler_type,
 {
   BLI_assert(unit < GPU_max_textures());
   GLTexture *tex = static_cast<GLTexture *>(tex_);
+  /* Eliminate redundant binds. */
+  if ((textures_[unit] == tex->tex_id_) &&
+      (samplers_[unit] == GLTexture::samplers_[sampler_type])) {
+    return;
+  }
   targets_[unit] = tex->target_;
   textures_[unit] = tex->tex_id_;
   samplers_[unit] = GLTexture::samplers_[sampler_type];
@@ -486,20 +494,25 @@ void GLStateManager::texture_bind_apply(void)
   if (dirty_texture_binds_ == 0) {
     return;
   }
+  uint64_t dirty_bind = dirty_texture_binds_;
+  dirty_texture_binds_ = 0;
+
+  int first = bitscan_forward_uint64(dirty_bind);
+  int last = 64 - bitscan_reverse_uint64(dirty_bind);
+  int count = last - first;
 
-  if (false) {
-    /* TODO multibind */
+  if (GLEW_ARB_multi_bind) {
+    glBindTextures(first, count, textures_ + first);
+    glBindSamplers(first, count, samplers_ + first);
   }
   else {
-    uint64_t dirty_bind = dirty_texture_binds_;
-    for (int unit = 0; dirty_bind != 0; dirty_bind >>= 1, unit++) {
-      if (dirty_bind & 1) {
+    for (int unit = first; unit < last; unit++) {
+      if ((dirty_bind >> unit) & 1UL) {
         glActiveTexture(GL_TEXTURE0 + unit);
         glBindTexture(targets_[unit], textures_[unit]);
         glBindSampler(unit, samplers_[unit]);
       }
     }
-    dirty_texture_binds_ = 0;
   }
 }



More information about the Bf-blender-cvs mailing list