glthread: track primitive restart state
authorMarek Olšák <marek.olsak@amd.com>
Sat, 7 Mar 2020 00:00:03 +0000 (19:00 -0500)
committerMarge Bot <eric+marge@anholt.net>
Thu, 30 Apr 2020 22:01:55 +0000 (22:01 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4314>

src/mapi/glapi/gen/GL3x.xml
src/mapi/glapi/gen/gl_API.xml
src/mesa/main/glthread.h
src/mesa/main/glthread_marshal.h
src/mesa/main/glthread_varray.c

index ced4e10f101f64831d0f34d1bf42a8bc9bd5e730..6c256922fe8890d74f1a92a60d41bcb9787e3e0a 100644 (file)
     <param name="buffer" type="GLuint"/>
   </function>
 
-  <function name="PrimitiveRestartIndex" no_error="true">
+  <function name="PrimitiveRestartIndex" no_error="true"
+            marshal_call_after="_mesa_glthread_PrimitiveRestartIndex(ctx, index);">
     <param name="index" type="GLuint"/>
   </function>
 
index 74aeb2f1c315705c06f8dde94cf5cb0bc55527f7..2ee1c7f9edac3d308d52ae0c59d129bd1f268eef 100644 (file)
         <glx rop="137"/>
     </function>
 
-    <function name="Disable" es1="1.0" es2="2.0">
+    <function name="Disable" es1="1.0" es2="2.0"
+              marshal_call_after="if (cap == GL_PRIMITIVE_RESTART || cap == GL_PRIMITIVE_RESTART_FIXED_INDEX) _mesa_glthread_set_prim_restart(ctx, cap, false);">
         <param name="cap" type="GLenum"/>
         <glx rop="138" handcode="client"/>
     </function>
 
     <function name="Enable" es1="1.0" es2="2.0"
-              marshal_call_after='if (cap == GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB) _mesa_glthread_disable(ctx, "Enable(DEBUG_OUTPUT_SYNCHRONOUS)");'>
+              marshal_call_after='if (cap == GL_PRIMITIVE_RESTART || cap == GL_PRIMITIVE_RESTART_FIXED_INDEX) { _mesa_glthread_set_prim_restart(ctx, cap, true); } else if (cap == GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB) { _mesa_glthread_disable(ctx, "Enable(DEBUG_OUTPUT_SYNCHRONOUS)"); }'>
         <param name="cap" type="GLenum"/>
         <glx rop="139" handcode="client"/>
     </function>
index c13ca9e823695ce89ea666bbeeb0299d94b42947..2c6e59adac9c4208e2d56f058dba17205a2d2f42 100644 (file)
@@ -43,6 +43,9 @@
  */
 #define MARSHAL_MAX_BATCHES 8
 
+/* Special value for glEnableClientState(GL_PRIMITIVE_RESTART_NV). */
+#define VERT_ATTRIB_PRIMITIVE_RESTART_NV -1
+
 #include <inttypes.h>
 #include <stdbool.h>
 #include "util/u_queue.h"
@@ -127,6 +130,13 @@ struct glthread_state
    /** Caps. */
    GLboolean SupportsBufferUploads;
 
+   /** Primitive restart state. */
+   bool PrimitiveRestart;
+   bool PrimitiveRestartFixedIndex;
+   bool _PrimitiveRestart;
+   GLuint RestartIndex;
+   GLuint _RestartIndex[4]; /**< Restart index for index_size = 1,2,4. */
+
    /** Vertex Array objects tracked by glthread independently of Mesa. */
    struct _mesa_HashTable *VAOs;
    struct glthread_vao *CurrentVAO;
@@ -162,6 +172,9 @@ void _mesa_glthread_DeleteVertexArrays(struct gl_context *ctx,
                                        GLsizei n, const GLuint *ids);
 void _mesa_glthread_GenVertexArrays(struct gl_context *ctx,
                                     GLsizei n, GLuint *arrays);
+void _mesa_glthread_set_prim_restart(struct gl_context *ctx, GLenum cap,
+                                     bool value);
+void _mesa_glthread_PrimitiveRestartIndex(struct gl_context *ctx, GLuint index);
 void _mesa_glthread_ClientState(struct gl_context *ctx, GLuint *vaobj,
                                 gl_vert_attrib attrib, bool enable);
 void _mesa_glthread_AttribDivisor(struct gl_context *ctx, const GLuint *vaobj,
index a519ff0c5cf9d3f5b3d1e6bc9a8cc0575545cecc..c8cf733f9ce34af3a7c96310c1e81d29564f971b 100644 (file)
@@ -399,6 +399,8 @@ _mesa_array_to_attrib(struct gl_context *ctx, GLenum array)
       return VERT_ATTRIB_COLOR1;
    case GL_POINT_SIZE_ARRAY_OES:
       return VERT_ATTRIB_POINT_SIZE;
+   case GL_PRIMITIVE_RESTART_NV:
+      return VERT_ATTRIB_PRIMITIVE_RESTART_NV;
    default:
       if (array >= GL_TEXTURE0 && array <= GL_TEXTURE7)
          return VERT_ATTRIB_TEX(array - GL_TEXTURE0);
index bcbd229320b2dd9bb448387d63eace56ca4e8793..2aa4a6d65fbc3124fd4084457a7ce4a6c7e545f0 100644 (file)
@@ -31,6 +31,7 @@
 #include "main/mtypes.h"
 #include "main/hash.h"
 #include "main/dispatch.h"
+#include "main/varray.h"
 
 /* TODO:
  *   - Handle ARB_vertex_attrib_binding (incl. EXT_dsa and ARB_dsa)
@@ -140,10 +141,57 @@ get_vao(struct gl_context *ctx, const GLuint *vaobj)
    return ctx->GLThread.CurrentVAO;
 }
 
+static void
+update_primitive_restart(struct gl_context *ctx)
+{
+   struct glthread_state *glthread = &ctx->GLThread;
+
+   glthread->_PrimitiveRestart = glthread->PrimitiveRestart ||
+                                 glthread->PrimitiveRestartFixedIndex;
+   glthread->_RestartIndex[0] =
+      _mesa_get_prim_restart_index(glthread->PrimitiveRestartFixedIndex,
+                                   glthread->RestartIndex, 1);
+   glthread->_RestartIndex[1] =
+      _mesa_get_prim_restart_index(glthread->PrimitiveRestartFixedIndex,
+                                   glthread->RestartIndex, 2);
+   glthread->_RestartIndex[3] =
+      _mesa_get_prim_restart_index(glthread->PrimitiveRestartFixedIndex,
+                                   glthread->RestartIndex, 4);
+}
+
+void
+_mesa_glthread_set_prim_restart(struct gl_context *ctx, GLenum cap, bool value)
+{
+   switch (cap) {
+   case GL_PRIMITIVE_RESTART:
+      ctx->GLThread.PrimitiveRestart = value;
+      break;
+   case GL_PRIMITIVE_RESTART_FIXED_INDEX:
+      ctx->GLThread.PrimitiveRestartFixedIndex = value;
+      break;
+   }
+
+   update_primitive_restart(ctx);
+}
+
+void
+_mesa_glthread_PrimitiveRestartIndex(struct gl_context *ctx, GLuint index)
+{
+   ctx->GLThread.RestartIndex = index;
+   update_primitive_restart(ctx);
+}
+
 void
 _mesa_glthread_ClientState(struct gl_context *ctx, GLuint *vaobj,
                            gl_vert_attrib attrib, bool enable)
 {
+   /* The primitive restart client state uses a special value. */
+   if (attrib == VERT_ATTRIB_PRIMITIVE_RESTART_NV) {
+      ctx->GLThread.PrimitiveRestart = enable;
+      update_primitive_restart(ctx);
+      return;
+   }
+
    if (attrib >= VERT_ATTRIB_MAX)
       return;