mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-04 05:28:05 +02:00
mesa: add index_size_shift = log2(index_size) into _mesa_index_buffer
for faster division Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Reviewed-by: Ian Romanick <ian.d.romanic@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4052>
This commit is contained in:
parent
f38ffa4659
commit
87085c673d
5 changed files with 30 additions and 19 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue