mesa: remove _mesa_index_buffer::index_size in favor of index_size_shift
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Suggested-by: Ian Romanick <ian.d.romanick@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4052>
This commit is contained in:
parent
df3891e74a
commit
450152f8d8
|
@ -736,7 +736,7 @@ brw_upload_indices(struct brw_context *brw)
|
|||
if (index_buffer == NULL)
|
||||
return;
|
||||
|
||||
ib_type_size = index_buffer->index_size;
|
||||
ib_type_size = 1 << index_buffer->index_size_shift;
|
||||
ib_size = index_buffer->count ? ib_type_size * index_buffer->count :
|
||||
index_buffer->obj->Size;
|
||||
bufferobj = index_buffer->obj;
|
||||
|
@ -772,8 +772,9 @@ brw_upload_indices(struct brw_context *brw)
|
|||
if (brw->ib.bo != old_bo)
|
||||
brw->ctx.NewDriverState |= BRW_NEW_INDEX_BUFFER;
|
||||
|
||||
if (index_buffer->index_size != brw->ib.index_size) {
|
||||
brw->ib.index_size = index_buffer->index_size;
|
||||
unsigned index_size = 1 << index_buffer->index_size_shift;
|
||||
if (index_size != brw->ib.index_size) {
|
||||
brw->ib.index_size = index_size;
|
||||
brw->ctx.NewDriverState |= BRW_NEW_INDEX_BUFFER;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,14 +52,14 @@ can_cut_index_handle_restart_index(struct gl_context *ctx,
|
|||
|
||||
bool cut_index_will_work;
|
||||
|
||||
switch (ib->index_size) {
|
||||
case 1:
|
||||
switch (ib->index_size_shift) {
|
||||
case 0:
|
||||
cut_index_will_work = ctx->Array.RestartIndex == 0xff;
|
||||
break;
|
||||
case 2:
|
||||
case 1:
|
||||
cut_index_will_work = ctx->Array.RestartIndex == 0xffff;
|
||||
break;
|
||||
case 4:
|
||||
case 2:
|
||||
cut_index_will_work = ctx->Array.RestartIndex == 0xffffffff;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -868,7 +868,7 @@ genX(emit_index_buffer)(struct brw_context *brw)
|
|||
assert(brw->ib.enable_cut_index == brw->prim_restart.enable_cut_index);
|
||||
ib.CutIndexEnable = brw->ib.enable_cut_index;
|
||||
#endif
|
||||
ib.IndexFormat = brw_get_index_type(index_buffer->index_size);
|
||||
ib.IndexFormat = brw_get_index_type(1 << index_buffer->index_size_shift);
|
||||
|
||||
/* The VF cache designers apparently cut corners, and made the cache
|
||||
* only consider the bottom 32 bits of memory addresses. If you happen
|
||||
|
|
|
@ -158,16 +158,16 @@ get_max_vertices(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
|
|||
unsigned max_out;
|
||||
|
||||
if (ib) {
|
||||
switch (ib->index_size) {
|
||||
case 4:
|
||||
switch (ib->index_size_shift) {
|
||||
case 2:
|
||||
max_out = MAX_OUT_I32;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 1:
|
||||
max_out = MAX_OUT_I16;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case 0:
|
||||
max_out = MAX_OUT_I16;
|
||||
break;
|
||||
|
||||
|
|
|
@ -66,9 +66,9 @@ vbo_init_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
|
|||
if (ib) {
|
||||
GLenum ib_type;
|
||||
|
||||
if (ib->index_size == 4)
|
||||
if (ib->index_size_shift == 2)
|
||||
ib_type = GL_UNSIGNED_INT;
|
||||
else if (ib->index_size == 2)
|
||||
else if (ib->index_size_shift == 1)
|
||||
ib_type = GL_UNSIGNED_SHORT;
|
||||
else
|
||||
ib_type = GL_UNSIGNED_BYTE;
|
||||
|
|
|
@ -109,21 +109,17 @@ get_index_size(GLenum type, struct _mesa_index_buffer *ib)
|
|||
{
|
||||
switch (type) {
|
||||
case GL_UNSIGNED_INT:
|
||||
ib->index_size = 4;
|
||||
ib->index_size_shift = 2;
|
||||
break;
|
||||
case GL_UNSIGNED_SHORT:
|
||||
ib->index_size = 2;
|
||||
ib->index_size_shift = 1;
|
||||
break;
|
||||
case GL_UNSIGNED_BYTE:
|
||||
ib->index_size = 1;
|
||||
ib->index_size_shift = 0;
|
||||
break;
|
||||
default:
|
||||
assert(!"unsupported index data type");
|
||||
/* In case assert is turned off */
|
||||
ib->index_size = 1;
|
||||
ib->index_size_shift = 0;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@ struct _mesa_prim
|
|||
struct _mesa_index_buffer
|
||||
{
|
||||
GLuint count;
|
||||
uint8_t index_size;
|
||||
uint8_t index_size_shift; /* logbase2(index_size) */
|
||||
struct gl_buffer_object *obj;
|
||||
const void *ptr;
|
||||
|
|
|
@ -202,7 +202,7 @@ st_draw_vbo(struct gl_context *ctx,
|
|||
nr_prims);
|
||||
}
|
||||
|
||||
info.index_size = ib->index_size;
|
||||
info.index_size = 1 << ib->index_size_shift;
|
||||
info.min_index = min_index;
|
||||
info.max_index = max_index;
|
||||
|
||||
|
@ -297,7 +297,7 @@ st_indirect_draw_vbo(struct gl_context *ctx,
|
|||
/* indices are always in a real VBO */
|
||||
assert(_mesa_is_bufferobj(bufobj));
|
||||
|
||||
info.index_size = ib->index_size;
|
||||
info.index_size = 1 << ib->index_size_shift;
|
||||
info.index.resource = st_buffer_object(bufobj)->buffer;
|
||||
info.start = pointer_to_offset(ib->ptr) >> ib->index_size_shift;
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
|
|||
|
||||
if (ib) {
|
||||
struct gl_buffer_object *bufobj = ib->obj;
|
||||
unsigned index_size = ib->index_size;
|
||||
unsigned index_size = 1 << ib->index_size_shift;
|
||||
|
||||
if (index_size == 0)
|
||||
goto out_unref_vertex;
|
||||
|
|
|
@ -368,7 +368,7 @@ static void bind_indices( struct gl_context *ctx,
|
|||
bo[*nr_bo] = ib->obj;
|
||||
(*nr_bo)++;
|
||||
ptr = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr,
|
||||
ib->count * ib->index_size,
|
||||
ib->count << ib->index_size_shift,
|
||||
GL_MAP_READ_BIT, ib->obj,
|
||||
MAP_INTERNAL);
|
||||
assert(ib->obj->Mappings[MAP_INTERNAL].Pointer);
|
||||
|
@ -377,19 +377,19 @@ static void bind_indices( struct gl_context *ctx,
|
|||
ptr = ADD_POINTERS(ib->obj->Mappings[MAP_INTERNAL].Pointer, ib->ptr);
|
||||
}
|
||||
|
||||
if (ib->index_size == 4 && VB->Primitive[0].basevertex == 0) {
|
||||
if (ib->index_size_shift == 2 && VB->Primitive[0].basevertex == 0) {
|
||||
VB->Elts = (GLuint *) ptr;
|
||||
}
|
||||
else {
|
||||
GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint));
|
||||
VB->Elts = elts;
|
||||
|
||||
if (ib->index_size == 4) {
|
||||
if (ib->index_size_shift == 2) {
|
||||
const GLuint *in = (GLuint *)ptr;
|
||||
for (i = 0; i < ib->count; i++)
|
||||
*elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
|
||||
}
|
||||
else if (ib->index_size == 2) {
|
||||
else if (ib->index_size_shift == 1) {
|
||||
const GLushort *in = (GLushort *)ptr;
|
||||
for (i = 0; i < ib->count; i++)
|
||||
*elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
|
||||
|
|
|
@ -165,14 +165,14 @@ void t_rebase_prims( struct gl_context *ctx,
|
|||
/* Some users might prefer it if we translated elements to
|
||||
* GLuints here. Others wouldn't...
|
||||
*/
|
||||
switch (ib->index_size) {
|
||||
case 4:
|
||||
switch (ib->index_size_shift) {
|
||||
case 2:
|
||||
tmp_indices = rebase_GLuint( ptr, ib->count, min_index );
|
||||
break;
|
||||
case 2:
|
||||
case 1:
|
||||
tmp_indices = rebase_GLushort( ptr, ib->count, min_index );
|
||||
break;
|
||||
case 1:
|
||||
case 0:
|
||||
tmp_indices = rebase_GLubyte( ptr, ib->count, min_index );
|
||||
break;
|
||||
}
|
||||
|
@ -187,7 +187,6 @@ void t_rebase_prims( struct gl_context *ctx,
|
|||
tmp_ib.obj = ctx->Shared->NullBufferObj;
|
||||
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;
|
||||
|
|
|
@ -481,8 +481,8 @@ replay_init(struct copy_context *copy)
|
|||
ADD_POINTERS(copy->ib->obj->Mappings[MAP_INTERNAL].Pointer,
|
||||
copy->ib->ptr);
|
||||
|
||||
switch (copy->ib->index_size) {
|
||||
case 1:
|
||||
switch (copy->ib->index_size_shift) {
|
||||
case 0:
|
||||
copy->translated_elt_buf = malloc(sizeof(GLuint) * copy->ib->count);
|
||||
copy->srcelt = copy->translated_elt_buf;
|
||||
|
||||
|
@ -490,7 +490,7 @@ replay_init(struct copy_context *copy)
|
|||
copy->translated_elt_buf[i] = ((const GLubyte *)srcptr)[i];
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 1:
|
||||
copy->translated_elt_buf = malloc(sizeof(GLuint) * copy->ib->count);
|
||||
copy->srcelt = copy->translated_elt_buf;
|
||||
|
||||
|
@ -498,7 +498,7 @@ replay_init(struct copy_context *copy)
|
|||
copy->translated_elt_buf[i] = ((const GLushort *)srcptr)[i];
|
||||
break;
|
||||
|
||||
case 4:
|
||||
case 2:
|
||||
copy->translated_elt_buf = NULL;
|
||||
copy->srcelt = (const GLuint *)srcptr;
|
||||
break;
|
||||
|
@ -550,7 +550,6 @@ replay_init(struct copy_context *copy)
|
|||
* list:
|
||||
*/
|
||||
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;
|
||||
|
|
|
@ -78,7 +78,7 @@ flush_vertex( struct split_context *split)
|
|||
|
||||
ib.count = split->max_index - split->min_index + 1;
|
||||
ib.ptr = (const void *)((const char *)ib.ptr +
|
||||
split->min_index * ib.index_size);
|
||||
(split->min_index << ib.index_size_shift));
|
||||
|
||||
/* Rebase the primitives to save index buffer entries. */
|
||||
for (i = 0; i < split->dstprim_nr; i++)
|
||||
|
@ -227,7 +227,6 @@ split_prims(struct split_context *split)
|
|||
elts[j] = prim->start + j;
|
||||
|
||||
ib.count = count;
|
||||
ib.index_size = 4;
|
||||
ib.index_size_shift = 2;
|
||||
ib.obj = split->ctx->Shared->NullBufferObj;
|
||||
ib.ptr = elts;
|
||||
|
|
|
@ -242,7 +242,7 @@ vbo_get_minmax_index(struct gl_context *ctx,
|
|||
{
|
||||
const GLboolean restart = ctx->Array._PrimitiveRestart;
|
||||
const GLuint restartIndex =
|
||||
_mesa_primitive_restart_index(ctx, ib->index_size);
|
||||
_mesa_primitive_restart_index(ctx, 1 << ib->index_size_shift);
|
||||
const char *indices;
|
||||
GLuint i;
|
||||
GLintptr offset = 0;
|
||||
|
@ -251,7 +251,7 @@ vbo_get_minmax_index(struct gl_context *ctx,
|
|||
if (_mesa_is_bufferobj(ib->obj)) {
|
||||
GLsizeiptr size = MIN2(count << ib->index_size_shift, ib->obj->Size);
|
||||
|
||||
if (vbo_get_minmax_cached(ib->obj, ib->index_size, (GLintptr) indices,
|
||||
if (vbo_get_minmax_cached(ib->obj, 1 << ib->index_size_shift, (GLintptr) indices,
|
||||
count, min_index, max_index))
|
||||
return;
|
||||
|
||||
|
@ -261,8 +261,8 @@ vbo_get_minmax_index(struct gl_context *ctx,
|
|||
MAP_INTERNAL);
|
||||
}
|
||||
|
||||
switch (ib->index_size) {
|
||||
case 4: {
|
||||
switch (ib->index_size_shift) {
|
||||
case 2: {
|
||||
const GLuint *ui_indices = (const GLuint *)indices;
|
||||
GLuint max_ui = 0;
|
||||
GLuint min_ui = ~0U;
|
||||
|
@ -290,7 +290,7 @@ vbo_get_minmax_index(struct gl_context *ctx,
|
|||
*max_index = max_ui;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
case 1: {
|
||||
const GLushort *us_indices = (const GLushort *)indices;
|
||||
GLuint max_us = 0;
|
||||
GLuint min_us = ~0U;
|
||||
|
@ -312,7 +312,7 @@ vbo_get_minmax_index(struct gl_context *ctx,
|
|||
*max_index = max_us;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
case 0: {
|
||||
const GLubyte *ub_indices = (const GLubyte *)indices;
|
||||
GLuint max_ub = 0;
|
||||
GLuint min_ub = ~0U;
|
||||
|
@ -339,7 +339,7 @@ vbo_get_minmax_index(struct gl_context *ctx,
|
|||
}
|
||||
|
||||
if (_mesa_is_bufferobj(ib->obj)) {
|
||||
vbo_minmax_cache_store(ctx, ib->obj, ib->index_size, offset,
|
||||
vbo_minmax_cache_store(ctx, ib->obj, 1 << ib->index_size_shift, offset,
|
||||
count, *min_index, *max_index);
|
||||
ctx->Driver.UnmapBuffer(ctx, ib->obj, MAP_INTERNAL);
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ vbo_sw_primitive_restart(struct gl_context *ctx,
|
|||
GLuint sub_prim_num;
|
||||
GLuint end_index;
|
||||
GLuint sub_end_index;
|
||||
GLuint restart_index = _mesa_primitive_restart_index(ctx, ib->index_size);
|
||||
GLuint restart_index = _mesa_primitive_restart_index(ctx, 1 << ib->index_size_shift);
|
||||
struct _mesa_prim temp_prim;
|
||||
GLboolean map_ib = ib->obj->Name && !ib->obj->Mappings[MAP_INTERNAL].Pointer;
|
||||
void *ptr;
|
||||
|
@ -226,7 +226,7 @@ vbo_sw_primitive_restart(struct gl_context *ctx,
|
|||
|
||||
ptr = ADD_POINTERS(ib->obj->Mappings[MAP_INTERNAL].Pointer, ib->ptr);
|
||||
|
||||
sub_prims = find_sub_primitives(ptr, ib->index_size,
|
||||
sub_prims = find_sub_primitives(ptr, 1 << ib->index_size_shift,
|
||||
0, ib->count, restart_index,
|
||||
&num_sub_prims);
|
||||
|
||||
|
|
Loading…
Reference in New Issue