From: Marek Olšák Date: Tue, 2 Feb 2021 01:01:13 +0000 (-0500) Subject: vbo: optimize copy_to_current functions X-Git-Tag: upstream/21.2.3~7158 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c0a893543d42b85a1f2614d82f4f5b1fcb7a55a1;p=platform%2Fupstream%2Fmesa.git vbo: optimize copy_to_current functions - 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 Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c index 7e8bb33..8504e1f 100644 --- a/src/mesa/vbo/vbo_exec_api.c +++ b/src/mesa/vbo/vbo_exec_api.c @@ -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. diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c index d6ec968..f0a520c 100644 --- a/src/mesa/vbo/vbo_save_draw.c +++ b/src/mesa/vbo/vbo_save_draw.c @@ -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; } }