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 <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>
This commit is contained in:
Marek Olšák
2021-02-01 20:01:13 -05:00
committed by Marge Bot
parent e29a466bc2
commit c0a893543d
2 changed files with 30 additions and 32 deletions
+18 -20
View 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);
if (memcmp(current, tmp, 4 * sizeof(GLfloat) << dmul_shift) != 0) {
memcpy(current, tmp, 4 * sizeof(GLfloat) << dmul_shift);
/* 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 (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.
+12 -12
View 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;
}
}