mesa: precompute _mesa_primitive_restart_index during state changes
authorMarek Olšák <marek.olsak@amd.com>
Sun, 22 Mar 2020 20:40:32 +0000 (16:40 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 6 Apr 2020 14:29:16 +0000 (10:29 -0400)
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4466>

src/mesa/drivers/dri/i965/genX_state_upload.c
src/mesa/main/attrib.c
src/mesa/main/enable.c
src/mesa/main/enable.h
src/mesa/main/mtypes.h
src/mesa/main/varray.c
src/mesa/state_tracker/st_draw.c
src/mesa/state_tracker/st_draw_feedback.c
src/mesa/vbo/vbo_minmax_index.c
src/mesa/vbo/vbo_primitive_restart.c
src/mesa/vbo/vbo_save_api.c

index e9d3b614ee36e3feb34e07ff97a923b7fa3b8a52..898d5aa7a43343711fbe2624168936ed9edc1368 100644 (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];
       }
    }
 }
index f84844ccea24e53bddbfa7394cae66cc33baa040..5aa3f7bf067c4b7e21c91f7d29ce00a08dfe3d68 100644 (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 */
 
index 7410b0faddf165071b7be2f5e016fba05afaed74..7e0162b0040c18dd531da3550d8d4a9e0284ede9 100644 (file)
 #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;
 
index 1cd8f675d330b9d229c3876104f6535e18e9644a..78e3170054817a18d2775f821e163a959b7d8cd7 100644 (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 );
 
index 50380c05b141d7d9d1ff4ac33a233a91d404ced9..86b1a7035b886365be900e2aa3e6b8db22d7f0c2 100644 (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 */
index 2190687e10830e38c10018c3809f60a2ec5cc96e..140c84de2b1cab0a578a74aa0ac16f3c7be0cc93 100644 (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);
 }
 
 
index a8ff306e00a4401dd0b6ebf9aaa19fc5cb095530..10374746734a55f914c4b18ebb191cadf30c0424 100644 (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.
index 8d82884ba8d661e281f3c7872e7b65bc932a2b3e..a4a385561992f701f45eb7d93b828f79e5e9e444 100644 (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;
index f66ed3dee392b22fc36701b82418acca3e7b6907..34766642c6a0d8e17d3db5ac74ad003002a2e90f 100644 (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;
index 1349740249f513a47251a3c7d99e4b8129cfddc3..8dd059f165a8ed5476657fd98620fa801934ba38 100644 (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;
index 52ed86cf3b7acd2aeef525fded3497641f53af41..4e96fc79343bd71c6f4016c43e6b8a4df502a12b 100644 (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;
    }