glthread: don't upload for glDraw inside a display list and always sync
authorMarek Olšák <marek.olsak@amd.com>
Thu, 28 May 2020 20:21:39 +0000 (16:21 -0400)
committerMarge Bot <eric+marge@anholt.net>
Sat, 30 May 2020 01:42:56 +0000 (01:42 +0000)
Let the vbo module handle it, not glthread.

This handles functions set in vbo_initialize_save_dispatch.

Fixes: 2840bc3065b ("glthread: upload non-VBO vertices and indices for non-Indirect non-IBM draws")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3001
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5246>

src/mapi/glapi/gen/gl_API.xml
src/mesa/main/glthread.h
src/mesa/main/glthread_draw.c

index 2c97c6dcedf66ffe0b57115dc400a9216fa6927d..b3511665280d4cc80d42c12a271454722143b5f6 100644 (file)
     <type name="DEBUGPROCARB" size="4" pointer="true"/>
     <type name="DEBUGPROC" size="4" pointer="true"/>
 
-    <function name="NewList" deprecated="3.1">
+    <function name="NewList" deprecated="3.1"
+              marshal_call_after="if (COMPAT) ctx->GLThread.inside_dlist = true;">
         <param name="list" type="GLuint"/>
         <param name="mode" type="GLenum"/>
         <glx sop="101"/>
     </function>
 
-    <function name="EndList" deprecated="3.1">
+    <function name="EndList" deprecated="3.1"
+              marshal_call_after="if (COMPAT) ctx->GLThread.inside_dlist = false;">
         <glx sop="102"/>
     </function>
 
index d09abb8e28f1b0a22d16e9e6cc6de8ac4aad2ab0..34a5443a6daff75f3affb53b0fe1cd3835461df3 100644 (file)
@@ -123,6 +123,9 @@ struct glthread_state
    /** Whether GLThread is enabled. */
    bool enabled;
 
+   /** Whether GLThread is inside a display list generation. */
+   bool inside_dlist;
+
    /** The ring of batches in memory. */
    struct glthread_batch batches[MARSHAL_MAX_BATCHES];
 
index 5607ced412589f815ca538a72f2f891a802f4676..7c41496e4e0b3ed721a9bb8030c869ea975d09f7 100644 (file)
@@ -226,16 +226,22 @@ draw_arrays_async(struct gl_context *ctx, GLenum mode, GLint first,
       memcpy(cmd + 1, attribs, attribs_size);
 }
 
-void GLAPIENTRY
-_mesa_marshal_DrawArraysInstancedBaseInstance(GLenum mode, GLint first,
-                                              GLsizei count, GLsizei instance_count,
-                                              GLuint baseinstance)
+static ALWAYS_INLINE void
+draw_arrays(GLenum mode, GLint first, GLsizei count, GLsizei instance_count,
+            GLuint baseinstance, bool compiled_into_dlist)
 {
    GET_CURRENT_CONTEXT(ctx);
 
    struct glthread_vao *vao = ctx->GLThread.CurrentVAO;
    unsigned non_vbo_attrib_mask = vao->UserPointerMask & vao->Enabled;
 
+   if (compiled_into_dlist && ctx->GLThread.inside_dlist) {
+      _mesa_glthread_finish_before(ctx, "DrawArrays");
+      /* Use the function that's compiled into a display list. */
+      CALL_DrawArrays(ctx->CurrentServerDispatch, (mode, first, count));
+      return;
+   }
+
    /* Fast path when nothing needs to be done.
     *
     * This is also an error path. Zero counts should still call the driver
@@ -343,6 +349,9 @@ _mesa_marshal_MultiDrawArrays(GLenum mode, const GLint *first,
    struct glthread_vao *vao = ctx->GLThread.CurrentVAO;
    unsigned non_vbo_attrib_mask = vao->UserPointerMask & vao->Enabled;
 
+   if (ctx->GLThread.inside_dlist)
+      goto sync;
+
    if (draw_count >= 0 &&
        (ctx->API == API_OPENGL_CORE || !non_vbo_attrib_mask)) {
       multi_draw_arrays_async(ctx, mode, first, count, draw_count, 0, NULL);
@@ -496,7 +505,8 @@ draw_elements_async(struct gl_context *ctx, GLenum mode, GLsizei count,
 static void
 draw_elements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
               GLsizei instance_count, GLint basevertex, GLuint baseinstance,
-              bool index_bounds_valid, GLuint min_index, GLuint max_index)
+              bool index_bounds_valid, GLuint min_index, GLuint max_index,
+              bool compiled_into_dlist)
 {
    GET_CURRENT_CONTEXT(ctx);
 
@@ -504,6 +514,9 @@ draw_elements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
    unsigned non_vbo_attrib_mask = vao->UserPointerMask & vao->Enabled;
    bool has_user_indices = vao->CurrentElementBufferName == 0;
 
+   if (compiled_into_dlist && ctx->GLThread.inside_dlist)
+      goto sync;
+
    /* Fast path when nothing needs to be done.
     *
     * This is also an error path. Zero counts should still call the driver
@@ -574,7 +587,18 @@ draw_elements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
 sync:
    _mesa_glthread_finish_before(ctx, "DrawElements");
 
-   if (index_bounds_valid && instance_count == 1 && baseinstance == 0) {
+   if (compiled_into_dlist && ctx->GLThread.inside_dlist) {
+      /* Only use the ones that are compiled into display lists. */
+      if (basevertex) {
+         CALL_DrawElementsBaseVertex(ctx->CurrentServerDispatch,
+                                     (mode, count, type, indices, basevertex));
+      } else if (index_bounds_valid) {
+         CALL_DrawRangeElements(ctx->CurrentServerDispatch,
+                                (mode, min_index, max_index, count, type, indices));
+      } else {
+         CALL_DrawElements(ctx->CurrentServerDispatch, (mode, count, type, indices));
+      }
+   } else if (index_bounds_valid && instance_count == 1 && baseinstance == 0) {
       CALL_DrawRangeElementsBaseVertex(ctx->CurrentServerDispatch,
                                        (mode, min_index, max_index, count,
                                         type, indices, basevertex));
@@ -703,6 +727,9 @@ _mesa_marshal_MultiDrawElementsBaseVertex(GLenum mode, const GLsizei *count,
    unsigned non_vbo_attrib_mask = vao->UserPointerMask & vao->Enabled;
    bool has_user_indices = vao->CurrentElementBufferName == 0;
 
+   if (ctx->GLThread.inside_dlist)
+      goto sync;
+
    /* Fast path when nothing needs to be done. */
    if (draw_count >= 0 &&
        (ctx->API == API_OPENGL_CORE ||
@@ -841,22 +868,29 @@ sync:
 void GLAPIENTRY
 _mesa_marshal_DrawArrays(GLenum mode, GLint first, GLsizei count)
 {
-   _mesa_marshal_DrawArraysInstancedBaseInstance(mode, first, count, 1, 0);
+   draw_arrays(mode, first, count, 1, 0, true);
 }
 
 void GLAPIENTRY
 _mesa_marshal_DrawArraysInstancedARB(GLenum mode, GLint first, GLsizei count,
                                      GLsizei instance_count)
 {
-   _mesa_marshal_DrawArraysInstancedBaseInstance(mode, first, count,
-                                                 instance_count, 0);
+   draw_arrays(mode, first, count, instance_count, 0, false);
+}
+
+void GLAPIENTRY
+_mesa_marshal_DrawArraysInstancedBaseInstance(GLenum mode, GLint first,
+                                              GLsizei count, GLsizei instance_count,
+                                              GLuint baseinstance)
+{
+   draw_arrays(mode, first, count, instance_count, baseinstance, false);
 }
 
 void GLAPIENTRY
 _mesa_marshal_DrawElements(GLenum mode, GLsizei count, GLenum type,
                            const GLvoid *indices)
 {
-   draw_elements(mode, count, type, indices, 1, 0, 0, false, 0, 0);
+   draw_elements(mode, count, type, indices, 1, 0, 0, false, 0, 0, true);
 }
 
 void GLAPIENTRY
@@ -864,21 +898,21 @@ _mesa_marshal_DrawRangeElements(GLenum mode, GLuint start, GLuint end,
                                 GLsizei count, GLenum type,
                                 const GLvoid *indices)
 {
-   draw_elements(mode, count, type, indices, 1, 0, 0, true, start, end);
+   draw_elements(mode, count, type, indices, 1, 0, 0, true, start, end, true);
 }
 
 void GLAPIENTRY
 _mesa_marshal_DrawElementsInstancedARB(GLenum mode, GLsizei count, GLenum type,
                                        const GLvoid *indices, GLsizei instance_count)
 {
-   draw_elements(mode, count, type, indices, instance_count, 0, 0, false, 0, 0);
+   draw_elements(mode, count, type, indices, instance_count, 0, 0, false, 0, 0, false);
 }
 
 void GLAPIENTRY
 _mesa_marshal_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
                                      const GLvoid *indices, GLint basevertex)
 {
-   draw_elements(mode, count, type, indices, 1, basevertex, 0, false, 0, 0);
+   draw_elements(mode, count, type, indices, 1, basevertex, 0, false, 0, 0, true);
 }
 
 void GLAPIENTRY
@@ -886,7 +920,7 @@ _mesa_marshal_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end,
                                           GLsizei count, GLenum type,
                                           const GLvoid *indices, GLint basevertex)
 {
-   draw_elements(mode, count, type, indices, 1, basevertex, 0, true, start, end);
+   draw_elements(mode, count, type, indices, 1, basevertex, 0, true, start, end, false);
 }
 
 void GLAPIENTRY
@@ -894,7 +928,7 @@ _mesa_marshal_DrawElementsInstancedBaseVertex(GLenum mode, GLsizei count,
                                               GLenum type, const GLvoid *indices,
                                               GLsizei instance_count, GLint basevertex)
 {
-   draw_elements(mode, count, type, indices, instance_count, basevertex, 0, false, 0, 0);
+   draw_elements(mode, count, type, indices, instance_count, basevertex, 0, false, 0, 0, false);
 }
 
 void GLAPIENTRY
@@ -902,7 +936,7 @@ _mesa_marshal_DrawElementsInstancedBaseInstance(GLenum mode, GLsizei count,
                                                 GLenum type, const GLvoid *indices,
                                                 GLsizei instance_count, GLuint baseinstance)
 {
-   draw_elements(mode, count, type, indices, instance_count, 0, baseinstance, false, 0, 0);
+   draw_elements(mode, count, type, indices, instance_count, 0, baseinstance, false, 0, 0, false);
 }
 
 void GLAPIENTRY
@@ -911,7 +945,7 @@ _mesa_marshal_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode, GLsizei c
                                                           GLsizei instance_count, GLint basevertex,
                                                           GLuint baseinstance)
 {
-   draw_elements(mode, count, type, indices, instance_count, basevertex, baseinstance, false, 0, 0);
+   draw_elements(mode, count, type, indices, instance_count, basevertex, baseinstance, false, 0, 0, false);
 }
 
 void GLAPIENTRY