glthread: track pointers and strides for Pointer & EXT_dsa attrib functions
authorMarek Olšák <marek.olsak@amd.com>
Fri, 28 Feb 2020 02:58:35 +0000 (21:58 -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/ARB_vertex_attrib_64bit.xml
src/mapi/glapi/gen/EXT_direct_state_access.xml
src/mapi/glapi/gen/GL3x.xml
src/mapi/glapi/gen/es_EXT.xml
src/mapi/glapi/gen/gl_API.xml
src/mesa/main/glthread.h
src/mesa/main/glthread_varray.c

index fcbb167397110f9cd81e61bf39dd3f16c32748bd..90144944715eb4c14d2a3631a91a91c26b6d4103 100644 (file)
@@ -52,7 +52,7 @@
     </function>
 
     <function name="VertexAttribLPointer" no_error="true" marshal="async"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_GENERIC(index));">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_GENERIC(index), size, type, stride, pointer);">
         <param name="index" type="GLuint"/>
         <param name="size" type="GLint"/>
         <param name="type" type="GLenum"/>
@@ -66,7 +66,8 @@
         <param name="params" type="GLdouble *"/>
     </function>
 
-    <function name="VertexArrayVertexAttribLOffsetEXT">
+    <function name="VertexArrayVertexAttribLOffsetEXT"
+              marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_GENERIC(index), size, type, stride, offset);">
         <param name="vaobj" type="GLuint" />
         <param name="buffer" type="GLuint" />
         <param name="index" type="GLuint" />
index 5c52573a17276e7ffbc40c4ec9a2ac18b44a3ead..d570f688e53b330cd661550fa4ab857d8add5662 100644 (file)
    </function>
 
    <function name="MultiTexCoordPointerEXT" marshal="async"
-             marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_TEX(texunit - GL_TEXTURE0));">
+             marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_TEX(texunit - GL_TEXTURE0), size, type, stride,  pointer);">
       <param name="texunit" type="GLenum" />
       <param name="size" type="GLint" />
       <param name="type" type="GLenum" />
       <param name="size" type="GLsizeiptr" />
    </function>
 
-   <function name="VertexArrayVertexOffsetEXT">
+   <function name="VertexArrayVertexOffsetEXT"
+             marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_POS, size, type, stride, offset);">
       <param name="vaobj" type="GLuint" />
       <param name="buffer" type="GLuint" />
       <param name="size" type="GLint" />
       <param name="offset" type="GLintptr" />
    </function>
 
-   <function name="VertexArrayColorOffsetEXT">
+   <function name="VertexArrayColorOffsetEXT"
+             marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_COLOR0, size, type, stride, offset);">
       <param name="vaobj" type="GLuint" />
       <param name="buffer" type="GLuint" />
       <param name="size" type="GLint" />
       <param name="offset" type="GLintptr" />
    </function>
 
-   <function name="VertexArrayEdgeFlagOffsetEXT">
+   <function name="VertexArrayEdgeFlagOffsetEXT"
+             marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_EDGEFLAG, 1, GL_UNSIGNED_BYTE, stride, offset);">
       <param name="vaobj" type="GLuint" />
       <param name="buffer" type="GLuint" />
       <param name="stride" type="GLsizei" />
       <param name="offset" type="GLintptr" />
    </function>
 
-   <function name="VertexArrayIndexOffsetEXT">
+   <function name="VertexArrayIndexOffsetEXT"
+             marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_COLOR_INDEX, 1, type, stride, offset);">
       <param name="vaobj" type="GLuint" />
       <param name="buffer" type="GLuint" />
       <param name="type" type="GLenum" />
       <param name="offset" type="GLintptr" />
    </function>
 
-   <function name="VertexArrayNormalOffsetEXT">
+   <function name="VertexArrayNormalOffsetEXT"
+             marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_NORMAL, 3, type, stride, offset);">
       <param name="vaobj" type="GLuint" />
       <param name="buffer" type="GLuint" />
       <param name="type" type="GLenum" />
       <param name="offset" type="GLintptr" />
    </function>
 
-   <function name="VertexArrayTexCoordOffsetEXT">
+   <function name="VertexArrayTexCoordOffsetEXT"
+             marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_TEX(ctx->GLThread.ClientActiveTexture), size, type, stride, offset);">
       <param name="vaobj" type="GLuint" />
       <param name="buffer" type="GLuint" />
       <param name="size" type="GLint" />
       <param name="offset" type="GLintptr" />
    </function>
 
-   <function name="VertexArrayMultiTexCoordOffsetEXT">
+   <function name="VertexArrayMultiTexCoordOffsetEXT"
+             marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_TEX(texunit - GL_TEXTURE0), size, type, stride, offset);">
       <param name="vaobj" type="GLuint" />
       <param name="buffer" type="GLuint" />
       <param name="texunit" type="GLenum" />
       <param name="offset" type="GLintptr" />
    </function>
 
-   <function name="VertexArrayFogCoordOffsetEXT">
+   <function name="VertexArrayFogCoordOffsetEXT"
+             marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_FOG, 1, type, stride, offset);">
       <param name="vaobj" type="GLuint" />
       <param name="buffer" type="GLuint" />
       <param name="type" type="GLenum" />
       <param name="offset" type="GLintptr" />
    </function>
 
-   <function name="VertexArraySecondaryColorOffsetEXT">
+   <function name="VertexArraySecondaryColorOffsetEXT"
+             marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_COLOR1, size, type, stride, offset);">
       <param name="vaobj" type="GLuint" />
       <param name="buffer" type="GLuint" />
       <param name="size" type="GLint" />
       <param name="offset" type="GLintptr" />
    </function>
 
-   <function name="VertexArrayVertexAttribOffsetEXT">
+   <function name="VertexArrayVertexAttribOffsetEXT"
+             marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_GENERIC(index), size, type, stride, offset);">
       <param name="vaobj" type="GLuint" />
       <param name="buffer" type="GLuint" />
       <param name="index" type="GLuint" />
       <param name="offset" type="GLintptr" />
    </function>
 
-   <function name="VertexArrayVertexAttribIOffsetEXT">
+   <function name="VertexArrayVertexAttribIOffsetEXT"
+             marshal_call_after="if (COMPAT) _mesa_glthread_DSAAttribPointer(ctx, vaobj, buffer, VERT_ATTRIB_GENERIC(index), size, type, stride, offset);">
       <param name="vaobj" type="GLuint" />
       <param name="buffer" type="GLuint" />
       <param name="index" type="GLuint" />
index 19875bc9505ae0d2370336d4942866efc8c6ea3d..ced4e10f101f64831d0f34d1bf42a8bc9bd5e730 100644 (file)
 
   <function name="VertexAttribIPointer" es2="3.0" marshal="async"
             no_error="true"
-            marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_GENERIC(index));">
+            marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_GENERIC(index), size, type, stride, pointer);">
     <param name="index" type="GLuint"/>
     <param name="size" type="GLint"/>
     <param name="type" type="GLenum"/>
index de3c14dafede65e540aabd2751f3283c1f3f864b..dd987b8dc8f75a99748ecc4f43ad11bb72a12774 100644 (file)
 
     <function name="PointSizePointerOES" es1="1.0" desktop="false"
               no_error="true" marshal="async"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_POINT_SIZE);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_POINT_SIZE, 1, type, stride, pointer);">
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
         <param name="pointer" type="const GLvoid *"/>
index 4477f5833e34fdb1a266132cee3d0dcc1ee9899e..74aeb2f1c315705c06f8dde94cf5cb0bc55527f7 100644 (file)
 
     <function name="ColorPointer" es1="1.0" deprecated="3.1" marshal="async"
               no_error="true"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_COLOR0);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_COLOR0, size, type, stride, pointer);">
         <param name="size" type="GLint"/>
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
 
     <function name="EdgeFlagPointer" deprecated="3.1" marshal="async"
               no_error="true"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_EDGEFLAG);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_EDGEFLAG, 1, GL_UNSIGNED_BYTE, stride, pointer);">
         <param name="stride" type="GLsizei"/>
         <param name="pointer" type="const GLvoid *"/>
         <glx handcode="true"/>
 
     <function name="IndexPointer" deprecated="3.1" marshal="async"
               no_error="true"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_COLOR_INDEX);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_COLOR_INDEX, 1, type, stride, pointer);">
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
         <param name="pointer" type="const GLvoid *"/>
 
     <function name="NormalPointer" es1="1.0" deprecated="3.1" marshal="async"
               no_error="true"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_NORMAL);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_NORMAL, 3, type, stride, pointer);">
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
         <param name="pointer" type="const GLvoid *"/>
 
     <function name="TexCoordPointer" es1="1.0" deprecated="3.1" marshal="async"
               no_error="true"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_TEX(ctx->GLThread.ClientActiveTexture));">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_TEX(ctx->GLThread.ClientActiveTexture), size, type, stride, pointer);">
         <param name="size" type="GLint"/>
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
 
     <function name="VertexPointer" es1="1.0" deprecated="3.1" marshal="async"
               no_error="true"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_POS);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_POS, size, type, stride, pointer);">
         <param name="size" type="GLint"/>
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
 
     <function name="FogCoordPointer" deprecated="3.1" marshal="async"
               no_error="true"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_FOG);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_FOG, 1, type, stride, pointer);">
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
         <param name="pointer" type="const GLvoid *"/>
 
     <function name="SecondaryColorPointer" deprecated="3.1" marshal="async"
               no_error="true"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_COLOR1);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_COLOR1, size, type, stride, pointer);">
         <param name="size" type="GLint"/>
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
 
     <function name="VertexAttribPointer" es2="2.0" marshal="async"
               no_error="true"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_GENERIC(index));">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_GENERIC(index), size, type, stride, pointer);">
         <param name="index" type="GLuint"/>
         <param name="size" type="GLint"/>
         <param name="type" type="GLenum"/>
     </function>
 
     <function name="ColorPointerEXT" deprecated="3.1" marshal="async"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_COLOR0);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_COLOR0, size, type, stride, pointer);">
         <param name="size" type="GLint"/>
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
     </function>
 
     <function name="EdgeFlagPointerEXT" deprecated="3.1" marshal="async"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_EDGEFLAG);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_EDGEFLAG, 1, GL_UNSIGNED_BYTE, stride, pointer);">
         <param name="stride" type="GLsizei"/>
         <param name="count" type="GLsizei"/>
         <param name="pointer" type="const GLboolean *"/>
     </function>
 
     <function name="IndexPointerEXT" deprecated="3.1" marshal="async"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_COLOR_INDEX);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_COLOR_INDEX, 1, type, stride, pointer);">
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
         <param name="count" type="GLsizei"/>
     </function>
 
     <function name="NormalPointerEXT" deprecated="3.1" marshal="async"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_NORMAL);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_NORMAL, 3, type, stride, pointer);">
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
         <param name="count" type="GLsizei"/>
     </function>
 
     <function name="TexCoordPointerEXT" deprecated="3.1" marshal="async"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_TEX(ctx->GLThread.ClientActiveTexture));">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_TEX(ctx->GLThread.ClientActiveTexture), size, type, stride, pointer);">
         <param name="size" type="GLint"/>
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
     </function>
 
     <function name="VertexPointerEXT" deprecated="3.1" marshal="async"
-              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_POS);">
+              marshal_call_after="if (COMPAT) _mesa_glthread_AttribPointer(ctx, VERT_ATTRIB_POS, size, type, stride, pointer);">
         <param name="size" type="GLint"/>
         <param name="type" type="GLenum"/>
         <param name="stride" type="GLsizei"/>
index 64b82ac131740ff3e66035fe78aafce3ea1e00c1..c1117872dc8aab3ba653f70c40a79a711673467b 100644 (file)
@@ -64,6 +64,12 @@ struct glthread_vao {
    GLuint CurrentElementBufferName;
    GLbitfield Enabled;
    GLbitfield UserPointerMask;
+
+   struct {
+      GLuint ElementSize;
+      GLsizei Stride;
+      const void *Pointer;
+   } Attrib[VERT_ATTRIB_MAX];
 };
 
 /** A single batch of commands queued up for execution. */
@@ -156,7 +162,12 @@ void _mesa_glthread_GenVertexArrays(struct gl_context *ctx,
                                     GLsizei n, GLuint *arrays);
 void _mesa_glthread_ClientState(struct gl_context *ctx, GLuint *vaobj,
                                 gl_vert_attrib attrib, bool enable);
-void _mesa_glthread_AttribPointer(struct gl_context *ctx,
-                                  gl_vert_attrib attrib);
+void _mesa_glthread_AttribPointer(struct gl_context *ctx, gl_vert_attrib attrib,
+                                  GLint size, GLenum type, GLsizei stride,
+                                  const void *pointer);
+void _mesa_glthread_DSAAttribPointer(struct gl_context *ctx, GLuint vao,
+                                     GLuint buffer, gl_vert_attrib attrib,
+                                     GLint size, GLenum type, GLsizei stride,
+                                     GLintptr offset);
 
 #endif /* _GLTHREAD_H*/
index fbd08f41e5a94f9626a3f8557a48053f0f86cffd..53a973600a6fd1d4bda5df0be806c568c2dd4403 100644 (file)
  */
 
 #include "main/glthread.h"
+#include "main/glformats.h"
 #include "main/mtypes.h"
 #include "main/hash.h"
 #include "main/dispatch.h"
 
 /* TODO:
- *   - Implement better tracking of user pointers
- *   - These can unbind user pointers:
- *       ARB_vertex_attrib_binding
- *       ARB_direct_state_access
- *       EXT_direct_state_access
+ *   - Handle GL_ARB_instanced_arrays (incl. EXT_dsa)
+ *   - Handle ARB_vertex_attrib_binding (incl. EXT_dsa and ARB_dsa)
  */
 
 static struct glthread_vao *
@@ -157,14 +155,52 @@ _mesa_glthread_ClientState(struct gl_context *ctx, GLuint *vaobj,
       vao->Enabled &= ~(1u << attrib);
 }
 
-void
-_mesa_glthread_AttribPointer(struct gl_context *ctx, gl_vert_attrib attrib)
+static void
+attrib_pointer(struct glthread_state *glthread, struct glthread_vao *vao,
+               GLuint buffer, gl_vert_attrib attrib,
+               GLint size, GLenum type, GLsizei stride,
+               const void *pointer)
 {
-   struct glthread_state *glthread = &ctx->GLThread;
-   struct glthread_vao *vao = glthread->CurrentVAO;
+   if (attrib >= VERT_ATTRIB_MAX)
+      return;
+
+   unsigned elem_size = _mesa_bytes_per_vertex_attrib(size, type);
+
+   vao->Attrib[attrib].ElementSize = elem_size;
+   vao->Attrib[attrib].Stride = stride ? stride : elem_size;
+   vao->Attrib[attrib].Pointer = pointer;
 
-   if (glthread->CurrentArrayBufferName != 0)
+   if (buffer != 0)
       vao->UserPointerMask &= ~(1u << attrib);
    else
       vao->UserPointerMask |= 1u << attrib;
 }
+
+void
+_mesa_glthread_AttribPointer(struct gl_context *ctx, gl_vert_attrib attrib,
+                             GLint size, GLenum type, GLsizei stride,
+                             const void *pointer)
+{
+   struct glthread_state *glthread = &ctx->GLThread;
+
+   attrib_pointer(glthread, glthread->CurrentVAO,
+                  glthread->CurrentArrayBufferName,
+                  attrib, size, type, stride, pointer);
+}
+
+void
+_mesa_glthread_DSAAttribPointer(struct gl_context *ctx, GLuint vaobj,
+                                GLuint buffer, gl_vert_attrib attrib,
+                                GLint size, GLenum type, GLsizei stride,
+                                GLintptr offset)
+{
+   struct glthread_state *glthread = &ctx->GLThread;
+   struct glthread_vao *vao;
+
+   vao = lookup_vao(ctx, vaobj);
+   if (!vao)
+      return;
+
+   attrib_pointer(glthread, vao, buffer, attrib, size, type, stride,
+                  (const void*)offset);
+}