[gtk/wip/chergert/glproto: 833/920] add split draw API




commit 99d6cedf1af0cb4b4df7f5c66774bdb5c40e29be
Author: Christian Hergert <chergert redhat com>
Date:   Mon Feb 1 10:36:07 2021 -0800

    add split draw API
    
    sometimes we have tight loops that do lots of draws and we want a way to
    begin a new slightly different draw (different uniforms) without having
    to do all the state tracking checks.

 gsk/next/gskglcommandqueue.c        | 40 +++++++++++++++++++++++++++++++++++++
 gsk/next/gskglcommandqueueprivate.h |  1 +
 gsk/next/gskglprogram.c             |  8 --------
 gsk/next/gskglprogramprivate.h      | 13 +++++++++++-
 4 files changed, 53 insertions(+), 9 deletions(-)
---
diff --git a/gsk/next/gskglcommandqueue.c b/gsk/next/gskglcommandqueue.c
index 4c54a7dc19..430aaaee02 100644
--- a/gsk/next/gskglcommandqueue.c
+++ b/gsk/next/gskglcommandqueue.c
@@ -470,6 +470,46 @@ gsk_gl_command_queue_end_draw (GskGLCommandQueue *self)
   self->in_draw = FALSE;
 }
 
+/**
+ * gsk_gl_command_queue_split_draw:
+ * @self a #GskGLCommandQueue
+ *
+ * This function is like calling gsk_gl_command_queue_end_draw() followed by
+ * a gsk_gl_command_queue_begin_draw() with the same parameters as a
+ * previous begin draw (if shared uniforms where not changed further).
+ *
+ * This is useful to avoid comparisons inside of loops where we know shared
+ * uniforms are not changing.
+ *
+ * This generally should just be called from gsk_gl_program_split_draw()
+ * as that is where the begin/end flow happens from the render job.
+ */
+void
+gsk_gl_command_queue_split_draw (GskGLCommandQueue *self)
+{
+  GskGLCommandBatch *batch;
+  graphene_rect_t viewport;
+  guint program;
+
+  g_assert (GSK_IS_GL_COMMAND_QUEUE (self));
+  g_assert (self->batches->len > 0);
+  g_assert (self->in_draw == TRUE);
+
+  batch = &g_array_index (self->batches, GskGLCommandBatch, self->batches->len-1);
+
+  g_assert (batch->any.kind == GSK_GL_COMMAND_KIND_DRAW);
+
+  program = batch->any.program;
+
+  viewport.origin.x = 0;
+  viewport.origin.y = 0;
+  viewport.size.width = batch->any.viewport.width;
+  viewport.size.height = batch->any.viewport.height;
+
+  gsk_gl_command_queue_end_draw (self);
+  gsk_gl_command_queue_begin_draw (self, program, &viewport);
+}
+
 GskGLDrawVertex *
 gsk_gl_command_queue_add_vertices (GskGLCommandQueue     *self,
                                    const GskGLDrawVertex  vertices[GSK_GL_N_VERTICES])
diff --git a/gsk/next/gskglcommandqueueprivate.h b/gsk/next/gskglcommandqueueprivate.h
index 15df41a981..0fa5087c08 100644
--- a/gsk/next/gskglcommandqueueprivate.h
+++ b/gsk/next/gskglcommandqueueprivate.h
@@ -156,6 +156,7 @@ void               gsk_gl_command_queue_begin_draw           (GskGLCommandQueue
                                                               guint                     program,
                                                               const graphene_rect_t    *viewport);
 void               gsk_gl_command_queue_end_draw             (GskGLCommandQueue        *self);
+void               gsk_gl_command_queue_split_draw           (GskGLCommandQueue        *self);
 GskGLDrawVertex   *gsk_gl_command_queue_add_vertices         (GskGLCommandQueue        *self,
                                                               const GskGLDrawVertex     
vertices[GSK_GL_N_VERTICES]);
 
diff --git a/gsk/next/gskglprogram.c b/gsk/next/gskglprogram.c
index 454dc643fd..acdb4d891c 100644
--- a/gsk/next/gskglprogram.c
+++ b/gsk/next/gskglprogram.c
@@ -225,11 +225,3 @@ gsk_gl_program_begin_draw (GskGLProgram            *self,
                                         self->alpha_location,
                                         alpha);
 }
-
-void
-gsk_gl_program_end_draw (GskGLProgram *self)
-{
-  g_assert (GSK_IS_GL_PROGRAM (self));
-
-  gsk_gl_command_queue_end_draw (self->driver->command_queue);
-}
diff --git a/gsk/next/gskglprogramprivate.h b/gsk/next/gskglprogramprivate.h
index 098995f578..6c69f1ad9a 100644
--- a/gsk/next/gskglprogramprivate.h
+++ b/gsk/next/gskglprogramprivate.h
@@ -67,7 +67,18 @@ void          gsk_gl_program_begin_draw  (GskGLProgram            *self,
                                           const graphene_matrix_t *modelview,
                                           const GskRoundedRect    *clip,
                                           float                    alpha);
-void          gsk_gl_program_end_draw    (GskGLProgram            *self);
+
+static inline void
+gsk_gl_program_end_draw (GskGLProgram *self)
+{
+  gsk_gl_command_queue_end_draw (self->driver->command_queue);
+}
+
+static inline void
+gsk_gl_program_split_draw (GskGLProgram *self)
+{
+  gsk_gl_command_queue_split_draw (self->driver->command_queue);
+}
 
 static inline int
 gsk_gl_program_get_uniform_location (GskGLProgram *self,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]