Mesa (master): glthread: track all matrix stack depths

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jan 21 00:30:49 UTC 2021


Module: Mesa
Branch: master
Commit: 6febe2b880e79ac2b5347412ffdf6502ac47e5be
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6febe2b880e79ac2b5347412ffdf6502ac47e5be

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Fri Oct  2 23:12:52 2020 -0400

glthread: track all matrix stack depths

This just tracks matrix stack depths in MatrixStackDepth and everything
else here is needed to make it correct.

Matrix stack depths will be returned by glGetIntegerv without synchronizing.

Display lists will be handled by a separate commit.

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8297>

---

 src/mapi/glapi/gen/EXT_direct_state_access.xml |  6 +-
 src/mapi/glapi/gen/gl_API.xml                  | 18 ++++--
 src/mesa/main/glthread.h                       | 26 ++++++++
 src/mesa/main/glthread_get.c                   |  0
 src/mesa/main/glthread_marshal.h               | 88 ++++++++++++++++++++++++++
 5 files changed, 130 insertions(+), 8 deletions(-)

diff --git a/src/mapi/glapi/gen/EXT_direct_state_access.xml b/src/mapi/glapi/gen/EXT_direct_state_access.xml
index 4314973cc01..1a7ba6b2393 100644
--- a/src/mapi/glapi/gen/EXT_direct_state_access.xml
+++ b/src/mapi/glapi/gen/EXT_direct_state_access.xml
@@ -93,10 +93,12 @@
       <param name="n" type="GLdouble" />
       <param name="f" type="GLdouble" />
    </function>
-   <function name="MatrixPushEXT" offset="assign">
+   <function name="MatrixPushEXT" offset="assign"
+             marshal_call_after="_mesa_glthread_MatrixPushEXT(ctx, matrixMode);">
       <param name="matrixMode" type="GLenum" />
    </function>
-   <function name="MatrixPopEXT" offset="assign">
+   <function name="MatrixPopEXT" offset="assign"
+             marshal_call_after="_mesa_glthread_MatrixPopEXT(ctx, matrixMode);">
       <param name="matrixMode" type="GLenum" />
    </function>
 
diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
index 7aab5c5d828..bd39ce3e20d 100644
--- a/src/mapi/glapi/gen/gl_API.xml
+++ b/src/mapi/glapi/gen/gl_API.xml
@@ -2402,11 +2402,13 @@
         <glx sop="142" handcode="true"/>
     </function>
 
-    <function name="PopAttrib" deprecated="3.1">
+    <function name="PopAttrib" deprecated="3.1"
+              marshal_call_after="_mesa_glthread_PopAttrib(ctx);">
         <glx rop="141"/>
     </function>
 
-    <function name="PushAttrib" deprecated="3.1">
+    <function name="PushAttrib" deprecated="3.1"
+              marshal_call_after="_mesa_glthread_PushAttrib(ctx, mask);">
         <param name="mask" type="GLbitfield"/>
         <glx rop="142"/>
     </function>
@@ -2910,7 +2912,8 @@
         <glx rop="178"/>
     </function>
 
-    <function name="MatrixMode" es1="1.0" deprecated="3.1">
+    <function name="MatrixMode" es1="1.0" deprecated="3.1"
+              marshal_call_after="_mesa_glthread_MatrixMode(ctx, mode);">
         <param name="mode" type="GLenum"/>
         <glx rop="179"/>
     </function>
@@ -2935,11 +2938,13 @@
         <glx rop="182"/>
     </function>
 
-    <function name="PopMatrix" es1="1.0" deprecated="3.1">
+    <function name="PopMatrix" es1="1.0" deprecated="3.1"
+              marshal_call_after="_mesa_glthread_PopMatrix(ctx);">
         <glx rop="183"/>
     </function>
 
-    <function name="PushMatrix" es1="1.0" deprecated="3.1">
+    <function name="PushMatrix" es1="1.0" deprecated="3.1"
+              marshal_call_after="_mesa_glthread_PushMatrix(ctx);">
         <glx rop="184"/>
     </function>
 
@@ -4292,7 +4297,8 @@
     <enum name="DOT3_RGB"                                 value="0x86AE"/>
     <enum name="DOT3_RGBA"                                value="0x86AF"/>
 
-    <function name="ActiveTexture" es1="1.0" es2="2.0" no_error="true">
+    <function name="ActiveTexture" es1="1.0" es2="2.0" no_error="true"
+              marshal_call_after="ctx->GLThread.ActiveTexture = texture - GL_TEXTURE0; if (ctx->GLThread.MatrixMode == GL_TEXTURE) ctx->GLThread.MatrixIndex = _mesa_get_matrix_index(ctx, texture);">
         <param name="texture" type="GLenum"/>
         <glx rop="197"/>
     </function>
diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h
index 177737f5be2..62367abbfad 100644
--- a/src/mesa/main/glthread.h
+++ b/src/mesa/main/glthread.h
@@ -124,6 +124,24 @@ struct glthread_client_attrib {
    bool Valid;
 };
 
+/* For glPushAttrib / glPopAttrib. */
+struct glthread_attrib_node {
+   GLbitfield Mask;
+   int ActiveTexture;
+   GLenum MatrixMode;
+};
+
+typedef enum {
+   M_MODELVIEW,
+   M_PROJECTION,
+   M_PROGRAM0,
+   M_PROGRAM_LAST = M_PROGRAM0 + MAX_PROGRAM_MATRICES - 1,
+   M_TEXTURE0,
+   M_TEXTURE_LAST = M_TEXTURE0 + MAX_TEXTURE_UNITS - 1,
+   M_DUMMY, /* used instead of reporting errors */
+   M_NUM_MATRIX_STACKS,
+} gl_matrix_index;
+
 struct glthread_state
 {
    /** Multithreaded queue. */
@@ -191,6 +209,14 @@ struct glthread_state
     * glDeleteProgram or -1 if there is no such enqueued call.
     */
    int LastProgramChangeBatch;
+
+   /** Basic matrix state tracking. */
+   int ActiveTexture;
+   GLenum MatrixMode;
+   gl_matrix_index MatrixIndex;
+   struct glthread_attrib_node AttribStack[MAX_ATTRIB_STACK_DEPTH];
+   int AttribStackDepth;
+   int MatrixStackDepth[M_NUM_MATRIX_STACKS];
 };
 
 void _mesa_glthread_init(struct gl_context *ctx);
diff --git a/src/mesa/main/glthread_get.c b/src/mesa/main/glthread_get.c
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/src/mesa/main/glthread_marshal.h b/src/mesa/main/glthread_marshal.h
index 2680530a10f..0607dc4397a 100644
--- a/src/mesa/main/glthread_marshal.h
+++ b/src/mesa/main/glthread_marshal.h
@@ -405,4 +405,92 @@ _mesa_array_to_attrib(struct gl_context *ctx, GLenum array)
    }
 }
 
+static inline gl_matrix_index
+_mesa_get_matrix_index(struct gl_context *ctx, GLenum mode)
+{
+   if (mode == GL_MODELVIEW || mode == GL_PROJECTION)
+      return M_MODELVIEW + (mode - GL_MODELVIEW);
+
+   if (mode == GL_TEXTURE)
+      return M_TEXTURE0 + ctx->GLThread.ActiveTexture;
+
+   if (mode >= GL_TEXTURE0 && mode <= GL_TEXTURE0 + MAX_TEXTURE_UNITS - 1)
+      return M_TEXTURE0 + (mode - GL_TEXTURE0);
+
+   if (mode >= GL_MATRIX0_ARB && mode <= GL_MATRIX0_ARB + MAX_PROGRAM_MATRICES - 1)
+      return M_PROGRAM0 + (mode - GL_MATRIX0_ARB);
+
+   return M_DUMMY;
+}
+
+static inline void
+_mesa_glthread_PushAttrib(struct gl_context *ctx, GLbitfield mask)
+{
+   struct glthread_attrib_node *attr =
+      &ctx->GLThread.AttribStack[ctx->GLThread.AttribStackDepth++];
+
+   attr->Mask = mask;
+
+   if (mask & GL_TEXTURE_BIT)
+      attr->ActiveTexture = ctx->GLThread.ActiveTexture;
+
+   if (mask & GL_TRANSFORM_BIT)
+      attr->MatrixMode = ctx->GLThread.MatrixMode;
+}
+
+static inline void
+_mesa_glthread_PopAttrib(struct gl_context *ctx)
+{
+   struct glthread_attrib_node *attr =
+      &ctx->GLThread.AttribStack[--ctx->GLThread.AttribStackDepth];
+   unsigned mask = attr->Mask;
+
+   if (mask & GL_TEXTURE_BIT)
+      ctx->GLThread.ActiveTexture = attr->ActiveTexture;
+
+   if (mask & GL_TRANSFORM_BIT) {
+      ctx->GLThread.MatrixMode = attr->MatrixMode;
+      ctx->GLThread.MatrixIndex = _mesa_get_matrix_index(ctx, attr->MatrixMode);
+   }
+}
+
+static inline void
+_mesa_glthread_MatrixPushEXT(struct gl_context *ctx, GLenum matrixMode)
+{
+   ctx->GLThread.MatrixStackDepth[_mesa_get_matrix_index(ctx, matrixMode)]++;
+}
+
+static inline void
+_mesa_glthread_MatrixPopEXT(struct gl_context *ctx, GLenum matrixMode)
+{
+   ctx->GLThread.MatrixStackDepth[_mesa_get_matrix_index(ctx, matrixMode)]--;
+}
+
+static inline void
+_mesa_glthread_ActiveTexture(struct gl_context *ctx, GLenum texture)
+{
+   ctx->GLThread.ActiveTexture = texture - GL_TEXTURE0;
+   if (ctx->GLThread.MatrixMode == GL_TEXTURE)
+      ctx->GLThread.MatrixIndex = _mesa_get_matrix_index(ctx, texture);
+}
+
+static inline void
+_mesa_glthread_PushMatrix(struct gl_context *ctx)
+{
+   ctx->GLThread.MatrixStackDepth[ctx->GLThread.MatrixIndex]++;
+}
+
+static inline void
+_mesa_glthread_PopMatrix(struct gl_context *ctx)
+{
+   ctx->GLThread.MatrixStackDepth[ctx->GLThread.MatrixIndex]--;
+}
+
+static inline void
+_mesa_glthread_MatrixMode(struct gl_context *ctx, GLenum mode)
+{
+   ctx->GLThread.MatrixIndex = _mesa_get_matrix_index(ctx, mode);
+   ctx->GLThread.MatrixMode = mode;
+}
+
 #endif /* MARSHAL_H */



More information about the mesa-commit mailing list