mesa: precompute _mesa_primitive_restart_index during state changes

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4466>
This commit is contained in:
Marek Olšák 2020-03-22 16:40:32 -04:00
parent 10beee8a77
commit e6bc1702f4
11 changed files with 22 additions and 16 deletions

View file

@ -904,7 +904,7 @@ genX(upload_cut_index)(struct brw_context *brw)
brw_batch_emit(brw, GENX(3DSTATE_VF), vf) {
if (ctx->Array._PrimitiveRestart && brw->ib.ib) {
vf.IndexedDrawCutIndexEnable = true;
vf.CutIndex = _mesa_primitive_restart_index(ctx, brw->ib.index_size);
vf.CutIndex = ctx->Array._RestartIndex[brw->ib.index_size - 1];
}
}
}

View file

@ -1607,6 +1607,7 @@ copy_array_attrib(struct gl_context *ctx,
dest->PrimitiveRestartFixedIndex = src->PrimitiveRestartFixedIndex;
dest->_PrimitiveRestart = src->_PrimitiveRestart;
dest->RestartIndex = src->RestartIndex;
memcpy(dest->_RestartIndex, src->_RestartIndex, sizeof(src->_RestartIndex));
/* skip NewState */
/* skip RebindArrays */

View file

@ -44,13 +44,14 @@
#include "varray.h"
static void
update_derived_primitive_restart_state(struct gl_context *ctx)
void
_mesa_update_derived_primitive_restart_state(struct gl_context *ctx)
{
/* Update derived primitive restart state.
*/
ctx->Array._PrimitiveRestart = ctx->Array.PrimitiveRestart
|| ctx->Array.PrimitiveRestartFixedIndex;
ctx->Array._PrimitiveRestart = ctx->Array.PrimitiveRestart ||
ctx->Array.PrimitiveRestartFixedIndex;
ctx->Array._RestartIndex[0] = _mesa_primitive_restart_index(ctx, 1);
ctx->Array._RestartIndex[1] = _mesa_primitive_restart_index(ctx, 2);
ctx->Array._RestartIndex[3] = _mesa_primitive_restart_index(ctx, 4);
}
@ -118,7 +119,7 @@ client_state(struct gl_context *ctx, struct gl_vertex_array_object* vao,
FLUSH_VERTICES(ctx, 0);
ctx->Array.PrimitiveRestart = state;
update_derived_primitive_restart_state(ctx);
_mesa_update_derived_primitive_restart_state(ctx);
return;
default:
@ -1200,7 +1201,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
if (ctx->Array.PrimitiveRestart != state) {
FLUSH_VERTICES(ctx, 0);
ctx->Array.PrimitiveRestart = state;
update_derived_primitive_restart_state(ctx);
_mesa_update_derived_primitive_restart_state(ctx);
}
break;
@ -1210,7 +1211,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
if (ctx->Array.PrimitiveRestartFixedIndex != state) {
FLUSH_VERTICES(ctx, 0);
ctx->Array.PrimitiveRestartFixedIndex = state;
update_derived_primitive_restart_state(ctx);
_mesa_update_derived_primitive_restart_state(ctx);
}
break;

View file

@ -37,6 +37,9 @@
struct gl_context;
extern void
_mesa_update_derived_primitive_restart_state(struct gl_context *ctx);
extern void
_mesa_set_enable( struct gl_context* ctx, GLenum cap, GLboolean state );

View file

@ -1612,6 +1612,7 @@ struct gl_array_attrib
GLboolean PrimitiveRestartFixedIndex;
GLboolean _PrimitiveRestart;
GLuint RestartIndex;
GLuint _RestartIndex[4]; /**< Restart indices for index_size - 1. */
/*@}*/
/* GL_ARB_vertex_buffer_object */

View file

@ -2747,6 +2747,7 @@ static void
primitive_restart_index(struct gl_context *ctx, GLuint index)
{
ctx->Array.RestartIndex = index;
_mesa_update_derived_primitive_restart_state(ctx);
}

View file

@ -85,8 +85,7 @@ setup_primitive_restart(struct gl_context *ctx, struct pipe_draw_info *info)
if (ctx->Array._PrimitiveRestart) {
unsigned index_size = info->index_size;
info->restart_index =
_mesa_primitive_restart_index(ctx, index_size);
info->restart_index = ctx->Array._RestartIndex[index_size - 1];
/* Enable primitive restart only when the restart index can have an
* effect. This is required for correctness in radeonsi GFX8 support.

View file

@ -216,7 +216,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
if (ctx->Array._PrimitiveRestart) {
info.primitive_restart = true;
info.restart_index = _mesa_primitive_restart_index(ctx, info.index_size);
info.restart_index = ctx->Array._RestartIndex[index_size - 1];
}
} else {
info.index_size = 0;

View file

@ -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, 1 << ib->index_size_shift);
ctx->Array._RestartIndex[(1 << ib->index_size_shift) - 1];
const char *indices;
GLuint i;
GLintptr offset = 0;

View file

@ -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, 1 << ib->index_size_shift);
GLuint restart_index = ctx->Array._RestartIndex[(1 << ib->index_size_shift) - 1];
struct _mesa_prim temp_prim;
GLboolean map_ib = ib->obj && !ib->obj->Mappings[MAP_INTERNAL].Pointer;
const void *ptr;

View file

@ -1329,7 +1329,7 @@ array_element(struct gl_context *ctx,
* then we call PrimitiveRestartNV and return.
*/
if (ctx->Array._PrimitiveRestart &&
elt == _mesa_primitive_restart_index(ctx, index_size)) {
elt == ctx->Array._RestartIndex[index_size - 1]) {
CALL_PrimitiveRestartNV(GET_DISPATCH(), ());
return;
}