diff options
author | Marek Olšák <[email protected]> | 2020-02-12 18:02:24 -0500 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2020-03-04 19:54:42 -0500 |
commit | 87085c673d593e6332ca2f3fb6737b77f7087f66 (patch) | |
tree | c54fb454a368b7c309e5f6266ee23a16a66ff57f | |
parent | f38ffa4659aa985f5d1c78bdd5be5064b792b819 (diff) |
mesa: add index_size_shift = log2(index_size) into _mesa_index_buffer
for faster division
Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4052>
-rw-r--r-- | src/mesa/main/draw.c | 43 | ||||
-rw-r--r-- | src/mesa/main/draw.h | 3 | ||||
-rw-r--r-- | src/mesa/tnl/t_rebase.c | 1 | ||||
-rw-r--r-- | src/mesa/tnl/t_split_copy.c | 1 | ||||
-rw-r--r-- | src/mesa/tnl/t_split_inplace.c | 1 |
5 files changed, 30 insertions, 19 deletions
diff --git a/src/mesa/main/draw.c b/src/mesa/main/draw.c index 6877a6b06b6..bcf4384a3a9 100644 --- a/src/mesa/main/draw.c +++ b/src/mesa/main/draw.c @@ -104,20 +104,28 @@ check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao, } -static inline int -sizeof_ib_type(GLenum type) +static inline void +get_index_size(GLenum type, struct _mesa_index_buffer *ib) { switch (type) { case GL_UNSIGNED_INT: - return sizeof(GLuint); + ib->index_size = 4; + ib->index_size_shift = 2; + break; case GL_UNSIGNED_SHORT: - return sizeof(GLushort); + ib->index_size = 2; + ib->index_size_shift = 1; + break; case GL_UNSIGNED_BYTE: - return sizeof(GLubyte); + ib->index_size = 1; + ib->index_size_shift = 0; + break; default: assert(!"unsupported index data type"); /* In case assert is turned off */ - return 0; + ib->index_size = 1; + ib->index_size_shift = 0; + break; } } @@ -790,9 +798,9 @@ _mesa_validated_drawrangeelements(struct gl_context *ctx, GLenum mode, return; ib.count = count; - ib.index_size = sizeof_ib_type(type); ib.obj = ctx->Array.VAO->IndexBufferObj; ib.ptr = indices; + get_index_size(type, &ib); prim.begin = 1; prim.end = 1; @@ -1186,7 +1194,6 @@ _mesa_validated_multidrawelements(struct gl_context *ctx, GLenum mode, GLsizei primcount, const GLint *basevertex) { struct _mesa_index_buffer ib; - unsigned int index_type_size = sizeof_ib_type(type); uintptr_t min_index_ptr, max_index_ptr; GLboolean fallback = GL_FALSE; int i; @@ -1194,12 +1201,14 @@ _mesa_validated_multidrawelements(struct gl_context *ctx, GLenum mode, if (primcount == 0) return; + get_index_size(type, &ib); + min_index_ptr = (uintptr_t) indices[0]; max_index_ptr = 0; for (i = 0; i < primcount; i++) { min_index_ptr = MIN2(min_index_ptr, (uintptr_t) indices[i]); max_index_ptr = MAX2(max_index_ptr, (uintptr_t) indices[i] + - index_type_size * count[i]); + ib.index_size * count[i]); } /* Check if we can handle this thing as a bunch of index offsets from the @@ -1208,9 +1217,9 @@ _mesa_validated_multidrawelements(struct gl_context *ctx, GLenum mode, * Check that the difference between each prim's indexes is a multiple of * the index/element size. */ - if (index_type_size != 1) { + if (ib.index_size != 1) { for (i = 0; i < primcount; i++) { - if ((((uintptr_t) indices[i] - min_index_ptr) % index_type_size) != + if ((((uintptr_t) indices[i] - min_index_ptr) % ib.index_size) != 0) { fallback = GL_TRUE; break; @@ -1230,8 +1239,7 @@ _mesa_validated_multidrawelements(struct gl_context *ctx, GLenum mode, ALLOC_PRIMS(prim, primcount, "glMultiDrawElements"); - ib.count = (max_index_ptr - min_index_ptr) / index_type_size; - ib.index_size = sizeof_ib_type(type); + ib.count = (max_index_ptr - min_index_ptr) / ib.index_size; ib.obj = ctx->Array.VAO->IndexBufferObj; ib.ptr = (void *) min_index_ptr; @@ -1240,7 +1248,7 @@ _mesa_validated_multidrawelements(struct gl_context *ctx, GLenum mode, prim[i].end = 1; prim[i].mode = mode; prim[i].start = - ((uintptr_t) indices[i] - min_index_ptr) / index_type_size; + ((uintptr_t) indices[i] - min_index_ptr) / ib.index_size; prim[i].count = count[i]; prim[i].draw_id = i; if (basevertex != NULL) @@ -1260,7 +1268,6 @@ _mesa_validated_multidrawelements(struct gl_context *ctx, GLenum mode, continue; ib.count = count[i]; - ib.index_size = sizeof_ib_type(type); ib.obj = ctx->Array.VAO->IndexBufferObj; ib.ptr = indices[i]; @@ -1511,9 +1518,9 @@ _mesa_validated_drawelementsindirect(struct gl_context *ctx, struct _mesa_index_buffer ib; ib.count = 0; /* unknown */ - ib.index_size = sizeof_ib_type(type); ib.obj = ctx->Array.VAO->IndexBufferObj; ib.ptr = NULL; + get_index_size(type, &ib); ctx->Driver.DrawIndirect(ctx, mode, ctx->DrawIndirectBuffer, (GLsizeiptr) indirect, @@ -1540,9 +1547,9 @@ _mesa_validated_multidrawelementsindirect(struct gl_context *ctx, /* NOTE: IndexBufferObj is guaranteed to be a VBO. */ ib.count = 0; /* unknown */ - ib.index_size = sizeof_ib_type(type); ib.obj = ctx->Array.VAO->IndexBufferObj; ib.ptr = NULL; + get_index_size(type, &ib); ctx->Driver.DrawIndirect(ctx, mode, ctx->DrawIndirectBuffer, offset, @@ -1853,9 +1860,9 @@ _mesa_validated_multidrawelementsindirectcount(struct gl_context *ctx, /* NOTE: IndexBufferObj is guaranteed to be a VBO. */ ib.count = 0; /* unknown */ - ib.index_size = sizeof_ib_type(type); ib.obj = ctx->Array.VAO->IndexBufferObj; ib.ptr = NULL; + get_index_size(type, &ib); ctx->Driver.DrawIndirect(ctx, mode, ctx->DrawIndirectBuffer, offset, diff --git a/src/mesa/main/draw.h b/src/mesa/main/draw.h index 3a7dedea529..bf9a9ca06b0 100644 --- a/src/mesa/main/draw.h +++ b/src/mesa/main/draw.h @@ -71,7 +71,8 @@ struct _mesa_prim struct _mesa_index_buffer { GLuint count; - unsigned index_size; + uint8_t index_size; + uint8_t index_size_shift; /* logbase2(index_size) */ struct gl_buffer_object *obj; const void *ptr; }; diff --git a/src/mesa/tnl/t_rebase.c b/src/mesa/tnl/t_rebase.c index 06d67620f63..3c2a0e0afcc 100644 --- a/src/mesa/tnl/t_rebase.c +++ b/src/mesa/tnl/t_rebase.c @@ -188,6 +188,7 @@ void t_rebase_prims( struct gl_context *ctx, tmp_ib.ptr = tmp_indices; tmp_ib.count = ib->count; tmp_ib.index_size = ib->index_size; + tmp_ib.index_size_shift = ib->index_size_shift; ib = &tmp_ib; } diff --git a/src/mesa/tnl/t_split_copy.c b/src/mesa/tnl/t_split_copy.c index 45b20fbd49c..f20a97755cb 100644 --- a/src/mesa/tnl/t_split_copy.c +++ b/src/mesa/tnl/t_split_copy.c @@ -551,6 +551,7 @@ replay_init(struct copy_context *copy) */ copy->dstib.count = 0; /* duplicates dstelt_nr */ copy->dstib.index_size = 4; + copy->dstib.index_size_shift = 2; copy->dstib.obj = ctx->Shared->NullBufferObj; copy->dstib.ptr = copy->dstelt; } diff --git a/src/mesa/tnl/t_split_inplace.c b/src/mesa/tnl/t_split_inplace.c index d9ea52dfaf1..ee229b6a97f 100644 --- a/src/mesa/tnl/t_split_inplace.c +++ b/src/mesa/tnl/t_split_inplace.c @@ -228,6 +228,7 @@ split_prims(struct split_context *split) ib.count = count; ib.index_size = 4; + ib.index_size_shift = 2; ib.obj = split->ctx->Shared->NullBufferObj; ib.ptr = elts; |