vbo: optimize copy_to_current functions
authorMarek Olšák <marek.olsak@amd.com>
Tue, 2 Feb 2021 01:01:13 +0000 (20:01 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 26 Feb 2021 23:38:02 +0000 (23:38 +0000)
- execute vbo_set_vertex_format in a separate skipable conditional block
- replace dmul with dmul_shift
- don't check <= VBO_ATTRIB_MAT_BACK_INDEXES because there is no attrib
  above that

Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8850>

src/mesa/vbo/vbo_exec_api.c
src/mesa/vbo/vbo_save_draw.c

index 7e8bb33..8504e1f 100644 (file)
@@ -187,11 +187,7 @@ vbo_exec_copy_to_current(struct vbo_exec_context *exec)
        */
       GLfloat *current = (GLfloat *)vbo->current[i].Ptr;
       fi_type tmp[8]; /* space for doubles */
-      int dmul = 1;
-
-      if (exec->vtx.attr[i].type == GL_DOUBLE ||
-          exec->vtx.attr[i].type == GL_UNSIGNED_INT64_ARB)
-         dmul = 2;
+      int dmul_shift = 0;
 
       assert(exec->vtx.attr[i].size);
 
@@ -199,6 +195,7 @@ vbo_exec_copy_to_current(struct vbo_exec_context *exec)
           exec->vtx.attr[i].type == GL_UNSIGNED_INT64_ARB) {
          memset(tmp, 0, sizeof(tmp));
          memcpy(tmp, exec->vtx.attrptr[i], exec->vtx.attr[i].size * sizeof(GLfloat));
+         dmul_shift = 1;
       } else {
          COPY_CLEAN_4V_TYPE_AS_UNION(tmp,
                                      exec->vtx.attr[i].size,
@@ -206,22 +203,10 @@ vbo_exec_copy_to_current(struct vbo_exec_context *exec)
                                      exec->vtx.attr[i].type);
       }
 
-      if (exec->vtx.attr[i].type != vbo->current[i].Format.Type ||
-          memcmp(current, tmp, 4 * sizeof(GLfloat) * dmul) != 0) {
-         memcpy(current, tmp, 4 * sizeof(GLfloat) * dmul);
-
-         /* Given that we explicitly state size here, there is no need
-          * for the COPY_CLEAN above, could just copy 16 bytes and be
-          * done.  The only problem is when Mesa accesses ctx->Current
-          * directly.
-          */
-         /* Size here is in components - not bytes */
-         vbo_set_vertex_format(&vbo->current[i].Format,
-                               exec->vtx.attr[i].size / dmul,
-                               exec->vtx.attr[i].type);
+      if (memcmp(current, tmp, 4 * sizeof(GLfloat) << dmul_shift) != 0) {
+         memcpy(current, tmp, 4 * sizeof(GLfloat) << dmul_shift);
 
-         if (i >= VBO_ATTRIB_MAT_FRONT_AMBIENT &&
-             i <= VBO_ATTRIB_MAT_BACK_INDEXES) {
+         if (i >= VBO_ATTRIB_MAT_FRONT_AMBIENT) {
             ctx->NewState |= _NEW_MATERIAL;
             ctx->PopAttribState |= GL_LIGHTING_BIT;
 
@@ -234,6 +219,19 @@ vbo_exec_copy_to_current(struct vbo_exec_context *exec)
          ctx->NewState |= _NEW_CURRENT_ATTRIB;
          ctx->PopAttribState |= GL_CURRENT_BIT;
       }
+
+      /* Given that we explicitly state size here, there is no need
+       * for the COPY_CLEAN above, could just copy 16 bytes and be
+       * done.  The only problem is when Mesa accesses ctx->Current
+       * directly.
+       */
+      /* Size here is in components - not bytes */
+      if (exec->vtx.attr[i].type != vbo->current[i].Format.Type ||
+          (exec->vtx.attr[i].size >> dmul_shift) != vbo->current[i].Format.Size) {
+         vbo_set_vertex_format(&vbo->current[i].Format,
+                               exec->vtx.attr[i].size >> dmul_shift,
+                               exec->vtx.attr[i].type);
+      }
    }
 
    /* Colormaterial -- this kindof sucks.
index d6ec968..f0a520c 100644 (file)
@@ -58,22 +58,18 @@ copy_vao(struct gl_context *ctx, const struct gl_vertex_array_object *vao,
       const GLubyte size = attrib->Format.Size;
       const GLenum16 type = attrib->Format.Type;
       fi_type tmp[8];
-      int dmul = 1;
+      int dmul_shift = 0;
 
       if (type == GL_DOUBLE ||
-          type == GL_UNSIGNED_INT64_ARB)
-         dmul = 2;
-
-      if (dmul == 2)
-         memcpy(tmp, *data, size * dmul * sizeof(GLfloat));
-      else
+          type == GL_UNSIGNED_INT64_ARB) {
+         dmul_shift = 1;
+         memcpy(tmp, *data, size * 2 * sizeof(GLfloat));
+      } else {
          COPY_CLEAN_4V_TYPE_AS_UNION(tmp, size, *data, type);
+      }
 
-      if (type != currval->Format.Type ||
-          memcmp(currval->Ptr, tmp, 4 * sizeof(GLfloat) * dmul) != 0) {
-         memcpy((fi_type*)currval->Ptr, tmp, 4 * sizeof(GLfloat) * dmul);
-
-         vbo_set_vertex_format(&currval->Format, size, type);
+      if (memcmp(currval->Ptr, tmp, 4 * sizeof(GLfloat) << dmul_shift) != 0) {
+         memcpy((fi_type*)currval->Ptr, tmp, 4 * sizeof(GLfloat) << dmul_shift);
 
          /* The fixed-func vertex program uses this. */
          if (current_index == VBO_ATTRIB_MAT_FRONT_SHININESS ||
@@ -84,6 +80,10 @@ copy_vao(struct gl_context *ctx, const struct gl_vertex_array_object *vao,
          ctx->PopAttribState |= pop_state;
       }
 
+      if (type != currval->Format.Type ||
+          (size >> dmul_shift) != currval->Format.Size)
+         vbo_set_vertex_format(&currval->Format, size >> dmul_shift, type);
+
       *data += size;
    }
 }