[gtk/wip/chergert/glproto] make program uniform setting passthrough



commit d9d7eee96094d5055857f0b40e0511a7efa86781
Author: Christian Hergert <chergert redhat com>
Date:   Wed Dec 30 10:06:21 2020 -0800

    make program uniform setting passthrough
    
    we want to avoid the extra function call here, so use inlines to go
    straight to the command queue in optimized code.

 gsk/next/gskglprogram.c        | 196 --------------------------------
 gsk/next/gskglprogramprivate.h | 251 ++++++++++++++++++++++++++++++++---------
 2 files changed, 198 insertions(+), 249 deletions(-)
---
diff --git a/gsk/next/gskglprogram.c b/gsk/next/gskglprogram.c
index 916d4ff8a3..823164274b 100644
--- a/gsk/next/gskglprogram.c
+++ b/gsk/next/gskglprogram.c
@@ -25,19 +25,6 @@
 #include "gskglprogramprivate.h"
 #include "gskgluniformstateprivate.h"
 
-struct _GskGLProgram
-{
-  GObject            parent_instance;
-  int                id;
-  char              *name;
-  GArray            *uniform_locations;
-  GskGLCommandQueue *command_queue;
-  int                projection_location;
-  int                modelview_location;
-  int                viewport_location;
-  int                clip_rect_location;
-};
-
 G_DEFINE_TYPE (GskGLProgram, gsk_gl_program, G_TYPE_OBJECT)
 
 GskGLProgram *
@@ -167,16 +154,6 @@ gsk_gl_program_add_uniform (GskGLProgram *self,
   return TRUE;
 }
 
-static inline GLint
-get_uniform_location (GskGLProgram *self,
-                      guint         key)
-{
-  if G_LIKELY (key < self->uniform_locations->len)
-    return g_array_index (self->uniform_locations, GLint, key);
-  else
-    return -1;
-}
-
 /**
  * gsk_gl_program_delete:
  * @self: a #GskGLProgram
@@ -196,179 +173,6 @@ gsk_gl_program_delete (GskGLProgram *self)
   self->id = -1;
 }
 
-void
-gsk_gl_program_set_uniform1i (GskGLProgram *self,
-                              guint         key,
-                              int           value0)
-{
-  gsk_gl_command_queue_set_uniform1i (self->command_queue,
-                                      self->id,
-                                      get_uniform_location (self, key),
-                                      value0);
-}
-
-void
-gsk_gl_program_set_uniform2i (GskGLProgram *self,
-                              guint         key,
-                              int           value0,
-                              int           value1)
-{
-  gsk_gl_command_queue_set_uniform2i (self->command_queue,
-                                      self->id,
-                                      get_uniform_location (self, key),
-                                      value0,
-                                      value1);
-}
-
-void
-gsk_gl_program_set_uniform3i (GskGLProgram *self,
-                              guint         key,
-                              int           value0,
-                              int           value1,
-                              int           value2)
-{
-  gsk_gl_command_queue_set_uniform3i (self->command_queue,
-                                      self->id,
-                                      get_uniform_location (self, key),
-                                      value0,
-                                      value1,
-                                      value2);
-}
-
-void
-gsk_gl_program_set_uniform4i (GskGLProgram *self,
-                              guint         key,
-                              int           value0,
-                              int           value1,
-                              int           value2,
-                              int           value3)
-{
-  gsk_gl_command_queue_set_uniform4i (self->command_queue,
-                                      self->id,
-                                      get_uniform_location (self, key),
-                                      value0,
-                                      value1,
-                                      value2,
-                                      value3);
-}
-
-void
-gsk_gl_program_set_uniform1f (GskGLProgram *self,
-                              guint         key,
-                              float         value0)
-{
-  gsk_gl_command_queue_set_uniform1f (self->command_queue,
-                                      self->id,
-                                      get_uniform_location (self, key),
-                                      value0);
-}
-
-void
-gsk_gl_program_set_uniform2f (GskGLProgram *self,
-                              guint         key,
-                              float         value0,
-                              float         value1)
-{
-  gsk_gl_command_queue_set_uniform2f (self->command_queue,
-                                      self->id,
-                                      get_uniform_location (self, key),
-                                      value0,
-                                      value1);
-}
-
-void
-gsk_gl_program_set_uniform3f (GskGLProgram *self,
-                              guint         key,
-                              float         value0,
-                              float         value1,
-                              float         value2)
-{
-  gsk_gl_command_queue_set_uniform3f (self->command_queue,
-                                      self->id,
-                                      get_uniform_location (self, key),
-                                      value0,
-                                      value1,
-                                      value2);
-}
-
-void
-gsk_gl_program_set_uniform4f (GskGLProgram *self,
-                              guint         key,
-                              float         value0,
-                              float         value1,
-                              float         value2,
-                              float         value3)
-{
-  gsk_gl_command_queue_set_uniform4f (self->command_queue,
-                                      self->id,
-                                      get_uniform_location (self, key),
-                                      value0,
-                                      value1,
-                                      value2,
-                                      value3);
-}
-
-void
-gsk_gl_program_set_uniform_color (GskGLProgram  *self,
-                                  guint          key,
-                                  const GdkRGBA *color)
-{
-  g_assert (GSK_IS_GL_PROGRAM (self));
-
-  gsk_gl_command_queue_set_uniform_color (self->command_queue,
-                                          self->id,
-                                          get_uniform_location (self, key),
-                                          color);
-}
-
-void
-gsk_gl_program_set_uniform_texture (GskGLProgram *self,
-                                    guint         key,
-                                    GLenum        texture_target,
-                                    GLenum        texture_slot,
-                                    guint         texture_id)
-{
-  g_assert (GSK_IS_GL_PROGRAM (self));
-  g_assert (texture_target == GL_TEXTURE_1D ||
-            texture_target == GL_TEXTURE_2D ||
-            texture_target == GL_TEXTURE_3D);
-  g_assert (texture_slot >= GL_TEXTURE0);
-  g_assert (texture_slot <= GL_TEXTURE16);
-
-  gsk_gl_command_queue_set_uniform_texture (self->command_queue,
-                                            self->id,
-                                            get_uniform_location (self, key),
-                                            texture_target,
-                                            texture_slot,
-                                            texture_id);
-}
-
-void
-gsk_gl_program_set_uniform_rounded_rect (GskGLProgram         *self,
-                                         guint                 key,
-                                         const GskRoundedRect *rounded_rect)
-{
-  g_assert (GSK_IS_GL_PROGRAM (self));
-
-  gsk_gl_command_queue_set_uniform_rounded_rect (self->command_queue,
-                                                 self->id,
-                                                 get_uniform_location (self, key),
-                                                 rounded_rect);
-}
-
-void
-gsk_gl_program_set_uniform_matrix (GskGLProgram            *self,
-                                   guint                    key,
-                                   const graphene_matrix_t *matrix)
-{
-  g_assert (GSK_IS_GL_PROGRAM (self));
-
-  gsk_gl_command_queue_set_uniform_matrix (self->command_queue,
-                                           self->id,
-                                           get_uniform_location (self, key),
-                                           matrix);
-}
-
 void
 gsk_gl_program_begin_draw (GskGLProgram            *self,
                            const graphene_rect_t   *viewport,
diff --git a/gsk/next/gskglprogramprivate.h b/gsk/next/gskglprogramprivate.h
index b42d337265..6061ccdbe8 100644
--- a/gsk/next/gskglprogramprivate.h
+++ b/gsk/next/gskglprogramprivate.h
@@ -18,17 +18,32 @@
  * SPDX-License-Identifier: LGPL-2.1-or-later
  */
 
-#ifndef __GSK_GL_PROGRAM_H__
-#define __GSK_GL_PROGRAM_H__
+#ifndef __GSK_GL_PROGRAM_PRIVATE_H__
+#define __GSK_GL_PROGRAM_PRIVATE_H__
 
 #include "gskgltypes.h"
 
+#include "gskglcommandqueueprivate.h"
+
 G_BEGIN_DECLS
 
 #define GSK_TYPE_GL_PROGRAM (gsk_gl_program_get_type())
 
 G_DECLARE_FINAL_TYPE (GskGLProgram, gsk_gl_program, GSK, GL_PROGRAM, GObject)
 
+struct _GskGLProgram
+{
+  GObject            parent_instance;
+  int                id;
+  char              *name;
+  GArray            *uniform_locations;
+  GskGLCommandQueue *command_queue;
+  int                projection_location;
+  int                modelview_location;
+  int                viewport_location;
+  int                clip_rect_location;
+};
+
 GskGLProgram    *gsk_gl_program_new                      (GskGLCommandQueue       *command_queue,
                                                           const char              *name,
                                                           int                      program_id);
@@ -38,56 +53,6 @@ gboolean         gsk_gl_program_add_uniform              (GskGLProgram
                                                           const char              *name,
                                                           guint                    key);
 void             gsk_gl_program_delete                   (GskGLProgram            *self);
-void             gsk_gl_program_set_uniform1i            (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          int                      value0);
-void             gsk_gl_program_set_uniform2i            (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          int                      value0,
-                                                          int                      value1);
-void             gsk_gl_program_set_uniform3i            (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          int                      value0,
-                                                          int                      value1,
-                                                          int                      value2);
-void             gsk_gl_program_set_uniform4i            (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          int                      value0,
-                                                          int                      value1,
-                                                          int                      value2,
-                                                          int                      value3);
-void             gsk_gl_program_set_uniform1f            (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          float                    value0);
-void             gsk_gl_program_set_uniform2f            (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          float                    value0,
-                                                          float                    value1);
-void             gsk_gl_program_set_uniform3f            (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          float                    value0,
-                                                          float                    value1,
-                                                          float                    value2);
-void             gsk_gl_program_set_uniform4f            (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          float                    value0,
-                                                          float                    value1,
-                                                          float                    value2,
-                                                          float                    value3);
-void             gsk_gl_program_set_uniform_matrix       (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          const graphene_matrix_t *matrix);
-void             gsk_gl_program_set_uniform_color        (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          const GdkRGBA           *color);
-void             gsk_gl_program_set_uniform_texture      (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          GLenum                   texture_target,
-                                                          GLenum                   texture_slot,
-                                                          guint                    texture_id);
-void             gsk_gl_program_set_uniform_rounded_rect (GskGLProgram            *self,
-                                                          guint                    key,
-                                                          const GskRoundedRect    *rounded_rect);
 void             gsk_gl_program_begin_draw               (GskGLProgram            *self,
                                                           const graphene_rect_t   *viewport,
                                                           const graphene_matrix_t *projection,
@@ -95,6 +60,186 @@ void             gsk_gl_program_begin_draw               (GskGLProgram
                                                           const GskRoundedRect    *clip);
 void             gsk_gl_program_end_draw                 (GskGLProgram            *self);
 
+static inline int
+gsk_gl_program_get_uniform_location (GskGLProgram *self,
+                                     guint         key)
+{
+  if G_LIKELY (key < self->uniform_locations->len)
+    return g_array_index (self->uniform_locations, GLint, key);
+  else
+    return -1;
+}
+
+static inline void
+gsk_gl_program_set_uniform1fv (GskGLProgram *self,
+                               guint         key,
+                               guint         count,
+                               const float  *values)
+{
+  gsk_gl_command_queue_set_uniform1fv (self->command_queue, self->id,
+                                       gsk_gl_program_get_uniform_location (self, key),
+                                       count, values);
+}
+
+static inline void
+gsk_gl_program_set_uniform_rounded_rect (GskGLProgram         *self,
+                                         guint                 key,
+                                         const GskRoundedRect *rounded_rect)
+{
+  gsk_gl_command_queue_set_uniform_rounded_rect (self->command_queue, self->id,
+                                                 gsk_gl_program_get_uniform_location (self, key),
+                                                 rounded_rect);
+}
+
+static inline void
+gsk_gl_program_set_uniform1i (GskGLProgram *self,
+                              guint         key,
+                              int           value0)
+{
+  gsk_gl_command_queue_set_uniform1i (self->command_queue,
+                                      self->id,
+                                      gsk_gl_program_get_uniform_location (self, key),
+                                      value0);
+}
+
+static inline void
+gsk_gl_program_set_uniform2i (GskGLProgram *self,
+                              guint         key,
+                              int           value0,
+                              int           value1)
+{
+  gsk_gl_command_queue_set_uniform2i (self->command_queue,
+                                      self->id,
+                                      gsk_gl_program_get_uniform_location (self, key),
+                                      value0,
+                                      value1);
+}
+
+static inline void
+gsk_gl_program_set_uniform3i (GskGLProgram *self,
+                              guint         key,
+                              int           value0,
+                              int           value1,
+                              int           value2)
+{
+  gsk_gl_command_queue_set_uniform3i (self->command_queue,
+                                      self->id,
+                                      gsk_gl_program_get_uniform_location (self, key),
+                                      value0,
+                                      value1,
+                                      value2);
+}
+
+static inline void
+gsk_gl_program_set_uniform4i (GskGLProgram *self,
+                              guint         key,
+                              int           value0,
+                              int           value1,
+                              int           value2,
+                              int           value3)
+{
+  gsk_gl_command_queue_set_uniform4i (self->command_queue,
+                                      self->id,
+                                      gsk_gl_program_get_uniform_location (self, key),
+                                      value0,
+                                      value1,
+                                      value2,
+                                      value3);
+}
+
+static inline void
+gsk_gl_program_set_uniform1f (GskGLProgram *self,
+                              guint         key,
+                              float         value0)
+{
+  gsk_gl_command_queue_set_uniform1f (self->command_queue,
+                                      self->id,
+                                      gsk_gl_program_get_uniform_location (self, key),
+                                      value0);
+}
+
+static inline void
+gsk_gl_program_set_uniform2f (GskGLProgram *self,
+                              guint         key,
+                              float         value0,
+                              float         value1)
+{
+  gsk_gl_command_queue_set_uniform2f (self->command_queue,
+                                      self->id,
+                                      gsk_gl_program_get_uniform_location (self, key),
+                                      value0,
+                                      value1);
+}
+
+static inline void
+gsk_gl_program_set_uniform3f (GskGLProgram *self,
+                              guint         key,
+                              float         value0,
+                              float         value1,
+                              float         value2)
+{
+  gsk_gl_command_queue_set_uniform3f (self->command_queue,
+                                      self->id,
+                                      gsk_gl_program_get_uniform_location (self, key),
+                                      value0,
+                                      value1,
+                                      value2);
+}
+
+static inline void
+gsk_gl_program_set_uniform4f (GskGLProgram *self,
+                              guint         key,
+                              float         value0,
+                              float         value1,
+                              float         value2,
+                              float         value3)
+{
+  gsk_gl_command_queue_set_uniform4f (self->command_queue,
+                                      self->id,
+                                      gsk_gl_program_get_uniform_location (self, key),
+                                      value0,
+                                      value1,
+                                      value2,
+                                      value3);
+}
+
+static inline void
+gsk_gl_program_set_uniform_color (GskGLProgram  *self,
+                                  guint          key,
+                                  const GdkRGBA *color)
+{
+  gsk_gl_command_queue_set_uniform_color (self->command_queue,
+                                          self->id,
+                                          gsk_gl_program_get_uniform_location (self, key),
+                                          color);
+}
+
+static inline void
+gsk_gl_program_set_uniform_texture (GskGLProgram *self,
+                                    guint         key,
+                                    GLenum        texture_target,
+                                    GLenum        texture_slot,
+                                    guint         texture_id)
+{
+  gsk_gl_command_queue_set_uniform_texture (self->command_queue,
+                                            self->id,
+                                            gsk_gl_program_get_uniform_location (self, key),
+                                            texture_target,
+                                            texture_slot,
+                                            texture_id);
+}
+
+static inline void
+gsk_gl_program_set_uniform_matrix (GskGLProgram            *self,
+                                   guint                    key,
+                                   const graphene_matrix_t *matrix)
+{
+  gsk_gl_command_queue_set_uniform_matrix (self->command_queue,
+                                           self->id,
+                                           gsk_gl_program_get_uniform_location (self, key),
+                                           matrix);
+}
+
 G_END_DECLS
 
-#endif /* __GSK_GL_PROGRAM_H__ */
+#endif /* __GSK_GL_PROGRAM_PRIVATE_H__ */


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