Mesa (main): glthread: don't sync for glIsEnabled with a few enums

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Oct 27 01:46:56 UTC 2021


Module: Mesa
Branch: main
Commit: f4348ef60d51b07ee40ebfd4215118de281bd7e4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f4348ef60d51b07ee40ebfd4215118de281bd7e4

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Sun Oct 17 23:10:31 2021 -0400

glthread: don't sync for glIsEnabled with a few enums

viewperf benefits

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

---

 src/mapi/glapi/gen/gl_API.dtd     |  3 +++
 src/mapi/glapi/gen/gl_API.xml     |  3 ++-
 src/mapi/glapi/gen/gl_XML.py      |  1 +
 src/mapi/glapi/gen/gl_marshal.py  |  5 +++++
 src/mapi/glapi/gen/marshal_XML.py |  1 +
 src/mesa/main/glthread.h          |  3 +++
 src/mesa/main/glthread_marshal.h  | 43 ++++++++++++++++++++++++++++++++++-----
 7 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/src/mapi/glapi/gen/gl_API.dtd b/src/mapi/glapi/gen/gl_API.dtd
index 3d1801ad2b5..714120b1db3 100644
--- a/src/mapi/glapi/gen/gl_API.dtd
+++ b/src/mapi/glapi/gen/gl_API.dtd
@@ -42,6 +42,7 @@
                    marshal             NMTOKEN #IMPLIED
                    marshal_sync        CDATA #IMPLIED>
                    marshal_count       CDATA #IMPLIED>
+                   marshal_call_before CDATA #IMPLIED>
                    marshal_call_after  CDATA #IMPLIED>
 <!ATTLIST size     name                NMTOKEN #REQUIRED
                    count               NMTOKEN #IMPLIED
@@ -134,6 +135,8 @@ param:
         to sync and execute the call directly.
      marshal_count - same as count, but variable_param is ignored. Used by
         glthread.
+     marshal_call_before - insert the string at the beginning of the marshal
+        function
      marshal_call_after - insert the string at the end of the marshal function
 
 glx:
diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
index 54506e9ecb3..4a92a208a9a 100644
--- a/src/mapi/glapi/gen/gl_API.xml
+++ b/src/mapi/glapi/gen/gl_API.xml
@@ -2881,7 +2881,8 @@
         <glx sop="139"/>
     </function>
 
-    <function name="IsEnabled" es1="1.1" es2="2.0">
+    <function name="IsEnabled" es1="1.1" es2="2.0"
+              marshal_call_before="int result = _mesa_glthread_IsEnabled(ctx, cap); if (result >= 0) return result;">
         <param name="cap" type="GLenum"/>
         <return type="GLboolean"/>
         <glx sop="140" handcode="client"/>
diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py
index 3488000840e..cafe0870037 100644
--- a/src/mapi/glapi/gen/gl_XML.py
+++ b/src/mapi/glapi/gen/gl_XML.py
@@ -655,6 +655,7 @@ class gl_function( gl_item ):
         assert not alias or not element.get('marshal')
         assert not alias or not element.get('marshal_count')
         assert not alias or not element.get('marshal_sync')
+        assert not alias or not element.get('marshal_call_before')
         assert not alias or not element.get('marshal_call_after')
 
         if name in static_data.functions:
diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py
index 39b5aa2015a..72f62a61df6 100644
--- a/src/mapi/glapi/gen/gl_marshal.py
+++ b/src/mapi/glapi/gen/gl_marshal.py
@@ -97,6 +97,8 @@ class PrintCode(gl_XML.gl_print_base):
         out('{')
         with indent():
             out('GET_CURRENT_CONTEXT(ctx);')
+            if func.marshal_call_before:
+                out(func.marshal_call_before);
             out('_mesa_glthread_finish_before(ctx, "{0}");'.format(func.name))
             self.print_sync_call(func)
         out('}')
@@ -317,6 +319,9 @@ class PrintCode(gl_XML.gl_print_base):
         out('{')
         with indent():
             out('GET_CURRENT_CONTEXT(ctx);')
+            if func.marshal_call_before:
+                out(func.marshal_call_before);
+
             if not func.marshal_sync:
                 for p in func.variable_params:
                     out('int {0}_size = {1};'.format(p.name, p.size_string(marshal = 1)))
diff --git a/src/mapi/glapi/gen/marshal_XML.py b/src/mapi/glapi/gen/marshal_XML.py
index d1c0bca7938..7323b9d5e75 100644
--- a/src/mapi/glapi/gen/marshal_XML.py
+++ b/src/mapi/glapi/gen/marshal_XML.py
@@ -58,6 +58,7 @@ class marshal_function(gl_XML.gl_function):
         # Store the "marshal" attribute, if present.
         self.marshal = element.get('marshal')
         self.marshal_sync = element.get('marshal_sync')
+        self.marshal_call_before = element.get('marshal_call_before')
         self.marshal_call_after = element.get('marshal_call_after')
 
     def marshal_flavor(self):
diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h
index 6388baeaf61..cf10bf9be33 100644
--- a/src/mesa/main/glthread.h
+++ b/src/mesa/main/glthread.h
@@ -227,6 +227,9 @@ struct glthread_state
    struct glthread_attrib_node AttribStack[MAX_ATTRIB_STACK_DEPTH];
    int AttribStackDepth;
    int MatrixStackDepth[M_NUM_MATRIX_STACKS];
+
+   /** Enable states. */
+   bool CullFace;
 };
 
 void _mesa_glthread_init(struct gl_context *ctx);
diff --git a/src/mesa/main/glthread_marshal.h b/src/mesa/main/glthread_marshal.h
index b7f5cc91a10..03700dbdd95 100644
--- a/src/mesa/main/glthread_marshal.h
+++ b/src/mesa/main/glthread_marshal.h
@@ -442,11 +442,18 @@ _mesa_glthread_Enable(struct gl_context *ctx, GLenum cap)
    if (ctx->GLThread.ListMode == GL_COMPILE)
       return;
 
-   if (cap == GL_PRIMITIVE_RESTART ||
-       cap == GL_PRIMITIVE_RESTART_FIXED_INDEX)
+   switch (cap) {
+   case GL_PRIMITIVE_RESTART:
+   case GL_PRIMITIVE_RESTART_FIXED_INDEX:
       _mesa_glthread_set_prim_restart(ctx, cap, true);
-   else if (cap == GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB)
+      break;
+   case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
       _mesa_glthread_disable(ctx, "Enable(DEBUG_OUTPUT_SYNCHRONOUS)");
+      break;
+   case GL_CULL_FACE:
+      ctx->GLThread.CullFace = true;
+      break;
+   }
 }
 
 static inline void
@@ -455,9 +462,35 @@ _mesa_glthread_Disable(struct gl_context *ctx, GLenum cap)
    if (ctx->GLThread.ListMode == GL_COMPILE)
       return;
 
-   if (cap == GL_PRIMITIVE_RESTART ||
-       cap == GL_PRIMITIVE_RESTART_FIXED_INDEX)
+   switch (cap) {
+   case GL_PRIMITIVE_RESTART:
+   case GL_PRIMITIVE_RESTART_FIXED_INDEX:
       _mesa_glthread_set_prim_restart(ctx, cap, false);
+      break;
+   case GL_CULL_FACE:
+      ctx->GLThread.CullFace = false;
+      break;
+   }
+}
+
+static inline int
+_mesa_glthread_IsEnabled(struct gl_context *ctx, GLenum cap)
+{
+   switch (cap) {
+   case GL_CULL_FACE:
+      return ctx->GLThread.CullFace;
+   case GL_VERTEX_ARRAY:
+      return !!(ctx->GLThread.CurrentVAO->UserEnabled & VERT_BIT_POS);
+   case GL_NORMAL_ARRAY:
+      return !!(ctx->GLThread.CurrentVAO->UserEnabled & VERT_BIT_NORMAL);
+   case GL_COLOR_ARRAY:
+      return !!(ctx->GLThread.CurrentVAO->UserEnabled & VERT_BIT_COLOR0);
+   case GL_TEXTURE_COORD_ARRAY:
+      return !!(ctx->GLThread.CurrentVAO->UserEnabled &
+                (1 << VERT_ATTRIB_TEX(ctx->GLThread.ClientActiveTexture)));
+   default:
+      return -1; /* sync and call _mesa_IsEnabled. */
+   }
 }
 
 static inline void



More information about the mesa-commit mailing list