[gtk/wip/chergert/glproto] add stamp when we change uniform value



commit fe8f7910748efe16a308fed3076435b65eaa09da
Author: Christian Hergert <chergert redhat com>
Date:   Thu Feb 11 17:31:29 2021 -0800

    add stamp when we change uniform value
    
    so that we can use this for faster compares later on

 gsk/next/gskgluniformstate.c        |  55 +++++++--------
 gsk/next/gskgluniformstateprivate.h | 129 +++++++++++++++++++-----------------
 2 files changed, 97 insertions(+), 87 deletions(-)
---
diff --git a/gsk/next/gskgluniformstate.c b/gsk/next/gskgluniformstate.c
index 6e7b46641a..850c57c0f5 100644
--- a/gsk/next/gskgluniformstate.c
+++ b/gsk/next/gskgluniformstate.c
@@ -90,14 +90,14 @@ gsk_gl_uniform_state_unref (GskGLUniformState *state)
 }
 
 gpointer
-gsk_gl_uniform_state_init_value (GskGLUniformState    *state,
-                                 GskGLUniformProgram  *program,
-                                 GskGLUniformFormat    format,
-                                 guint                 array_count,
-                                 guint                 location,
-                                 GskGLUniformInfo    **infoptr)
+gsk_gl_uniform_state_init_value (GskGLUniformState        *state,
+                                 GskGLUniformProgram      *program,
+                                 GskGLUniformFormat        format,
+                                 guint                     array_count,
+                                 guint                     location,
+                                 GskGLUniformInfoElement **infoptr)
 {
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
   guint offset;
 
   g_assert (state != NULL);
@@ -113,12 +113,12 @@ gsk_gl_uniform_state_init_value (GskGLUniformState    *state,
 
   info = &program->uniforms[location];
 
-  if G_LIKELY (format == info->format)
+  if G_LIKELY (format == info->info.format)
     {
-      if G_LIKELY (array_count <= info->array_count)
+      if G_LIKELY (array_count <= info->info.array_count)
         {
           *infoptr = info;
-          return state->values_buf + info->offset;
+          return state->values_buf + info->info.offset;
         }
 
       /* We found the uniform, but there is not enough space for the
@@ -131,7 +131,7 @@ gsk_gl_uniform_state_init_value (GskGLUniformState    *state,
        */
       goto setup_info;
     }
-  else if (info->format == 0)
+  else if (info->info.format == 0)
     {
       goto setup_info;
     }
@@ -140,8 +140,8 @@ gsk_gl_uniform_state_init_value (GskGLUniformState    *state,
       g_critical ("Attempt to access uniform with different type of value "
                   "than it was initialized with. Program %u Location %u. "
                   "Was %d now %d (array length %d now %d).",
-                  program->program_id, location, info->format, format,
-                  info->array_count, array_count);
+                  program->program_id, location, info->info.format, format,
+                  info->info.array_count, array_count);
       *infoptr = NULL;
       return NULL;
     }
@@ -152,11 +152,12 @@ setup_info:
                                 uniform_sizes[format] * MAX (1, array_count),
                                 &offset);
 
-  info->changed = FALSE;
-  info->format = format;
-  info->offset = offset;
-  info->array_count = array_count;
-  info->initial = TRUE;
+  info->info.changed = FALSE;
+  info->info.format = format;
+  info->info.offset = offset;
+  info->info.array_count = array_count;
+  info->info.initial = TRUE;
+  info->stamp = 1;
 
   *infoptr = info;
 
@@ -183,22 +184,22 @@ gsk_gl_uniform_state_end_frame (GskGLUniformState *state)
     {
       for (guint j = 0; j < program->n_uniforms; j++)
         {
-          GskGLUniformInfo *info = &program->uniforms[j];
+          GskGLUniformInfoElement *info = &program->uniforms[j];
           guint size;
 
-          if (info->format == 0)
+          if (info->info.format == 0)
             continue;
 
           /* Calculate how much size is needed for the uniform, including arrays */
-          size = uniform_sizes[info->format] * MAX (1, info->array_count);
+          size = uniform_sizes[info->info.format] * MAX (1, info->info.array_count);
 
           /* Adjust alignment for value */
           allocator += gsk_gl_uniform_state_align (allocator, size);
 
-          info->offset = allocator;
-          info->changed = FALSE;
-          info->initial = TRUE;
-          info->send_corners = FALSE;
+          info->info.offset = allocator;
+          info->info.changed = FALSE;
+          info->info.initial = TRUE;
+          info->info.send_corners = FALSE;
 
           /* Now advance for this items data */
           allocator += size;
@@ -236,7 +237,7 @@ gsk_gl_uniform_state_get_program (GskGLUniformState *state,
 
   if (ret == NULL)
     {
-      gsize uniform_size = n_uniforms * sizeof (GskGLUniformInfo);
+      gsize uniform_size = n_uniforms * sizeof (GskGLUniformInfoElement);
       gsize changed_size = n_uniforms * sizeof (guint);
       gsize size = sizeof (GskGLUniformProgram) + uniform_size + changed_size;
 
@@ -247,7 +248,7 @@ gsk_gl_uniform_state_get_program (GskGLUniformState *state,
       ret->changed = (guint *)&ret->uniforms[n_uniforms];
 
       for (guint i = 0; i < n_uniforms; i++)
-        ret->uniforms[i].initial = TRUE;
+        ret->uniforms[i].info.initial = TRUE;
 
       g_hash_table_insert (state->programs, GUINT_TO_POINTER (program), ret);
     }
diff --git a/gsk/next/gskgluniformstateprivate.h b/gsk/next/gskgluniformstateprivate.h
index 76fd546737..a0dc1b0933 100644
--- a/gsk/next/gskgluniformstateprivate.h
+++ b/gsk/next/gskgluniformstateprivate.h
@@ -50,6 +50,14 @@ typedef struct _GskGLUniformInfo
 
 G_STATIC_ASSERT (sizeof (GskGLUniformInfo) == 4);
 
+typedef struct _GskGLUniformInfoElement
+{
+  GskGLUniformInfo info;
+  guint stamp;
+} GskGLUniformInfoElement;
+
+G_STATIC_ASSERT (sizeof (GskGLUniformInfoElement) == 8);
+
 typedef struct _GskGLUniformProgram
 {
   guint program_id;
@@ -65,7 +73,7 @@ typedef struct _GskGLUniformProgram
   /* Uniforms are provided inline at the end of structure to avoid
    * an extra dereference.
    */
-  GskGLUniformInfo uniforms[0];
+  GskGLUniformInfoElement uniforms[0];
 } GskGLUniformProgram;
 
 typedef struct _GskGLUniformState
@@ -135,7 +143,7 @@ gpointer             gsk_gl_uniform_state_init_value  (GskGLUniformState
                                                        GskGLUniformFormat         format,
                                                        guint                      array_count,
                                                        guint                      location,
-                                                       GskGLUniformInfo         **infoptr);
+                                                       GskGLUniformInfoElement  **infoptr);
 
 #define gsk_gl_uniform_state_get_uniform_data(state,offset) \
   ((gconstpointer)(state->values_buf + offset))
@@ -147,7 +155,7 @@ gpointer             gsk_gl_uniform_state_init_value  (GskGLUniformState
         for (guint z = 0; z < program_info->n_changed; z++)                     \
           {                                                                     \
             guint location = program_info->changed[z];                          \
-            GskGLUniformInfo *info = &program_info->uniforms[location];         \
+            GskGLUniformInfo *info = &program_info->uniforms[location].info;    \
                                                                                 \
             g_assert (info->changed);                                           \
                                                                                 \
@@ -162,19 +170,19 @@ gpointer             gsk_gl_uniform_state_init_value  (GskGLUniformState
   } G_STMT_END
 
 static inline gpointer
-gsk_gl_uniform_state_get_value (GskGLUniformState    *state,
-                                GskGLUniformProgram  *program,
-                                GskGLUniformFormat    format,
-                                guint                 array_count,
-                                guint                 location,
-                                GskGLUniformInfo    **infoptr)
+gsk_gl_uniform_state_get_value (GskGLUniformState        *state,
+                                GskGLUniformProgram      *program,
+                                GskGLUniformFormat        format,
+                                guint                     array_count,
+                                guint                     location,
+                                GskGLUniformInfoElement **infoptr)
 {
-  GskGLUniformInfo *info = &program->uniforms[location];
+  GskGLUniformInfoElement *info = &program->uniforms[location];
 
-  if G_LIKELY (format == info->format && array_count <= info->array_count)
+  if G_LIKELY (format == info->info.format && array_count <= info->info.array_count)
     {
       *infoptr = info;
-      return state->values_buf + info->offset;
+      return state->values_buf + info->info.offset;
     }
 
   return gsk_gl_uniform_state_init_value (state, program, format, array_count, location, infoptr);
@@ -215,29 +223,30 @@ gsk_gl_uniform_state_realloc (GskGLUniformState *state,
 
 #define GSK_GL_UNIFORM_STATE_REPLACE(info, u, type, count)                                \
   G_STMT_START {                                                                          \
-    if ((info)->initial && count == (info)->array_count)                                  \
+    if ((info)->info.initial && count == (info)->info.array_count)                        \
       {                                                                                   \
-        u = (gpointer)(state->values_buf + (info)->offset);                               \
+        u = (gpointer)(state->values_buf + (info)->info.offset);                          \
       }                                                                                   \
     else                                                                                  \
       {                                                                                   \
         guint offset;                                                                     \
         u = gsk_gl_uniform_state_realloc (state, sizeof(type) * MAX (1, count), &offset); \
-        (info)->offset = offset;                                                          \
+        (info)->info.offset = offset;                                                     \
         /* We might have increased array length */                                        \
-        (info)->array_count = count;                                                      \
+        (info)->info.array_count = count;                                                 \
       }                                                                                   \
+    (info)->stamp++;                                                                      \
   } G_STMT_END
 
 static inline void
-gsk_gl_uniform_program_changed (GskGLUniformProgram *program,
-                                GskGLUniformInfo    *info,
-                                guint                location)
+gsk_gl_uniform_program_changed (GskGLUniformProgram     *program,
+                                GskGLUniformInfoElement *info,
+                                guint                    location)
 {
-  if (info->changed == FALSE)
+  if (info->info.changed == FALSE)
     {
-      info->changed = TRUE;
-      info->initial = FALSE;
+      info->info.changed = TRUE;
+      info->info.initial = FALSE;
 
       program->changed[program->n_changed++] = location;
     }
@@ -251,14 +260,14 @@ gsk_gl_uniform_state_set1f (GskGLUniformState   *state,
                             float                value0)
 {
   Uniform1f *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != 0);
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_1F, 1, location, &info)))
     {
-      if (info->initial || u->v0 != value0)
+      if (info->info.initial || u->v0 != value0)
         {
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, Uniform1f , 1);
           u->v0 = value0;
@@ -275,14 +284,14 @@ gsk_gl_uniform_state_set2f (GskGLUniformState   *state,
                             float                value1)
 {
   Uniform2f *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_2F, 1, location, &info)))
     {
-      if (info->initial || u->v0 != value0 || u->v1 != value1)
+      if (info->info.initial || u->v0 != value0 || u->v1 != value1)
         {
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, Uniform2f, 1);
           u->v0 = value0;
@@ -301,14 +310,14 @@ gsk_gl_uniform_state_set3f (GskGLUniformState   *state,
                             float                value2)
 {
   Uniform3f *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_3F, 1, location, &info)))
     {
-      if (info->initial || u->v0 != value0 || u->v1 != value1 || u->v2 != value2)
+      if (info->info.initial || u->v0 != value0 || u->v1 != value1 || u->v2 != value2)
         {
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, Uniform3f, 1);
           u->v0 = value0;
@@ -329,14 +338,14 @@ gsk_gl_uniform_state_set4f (GskGLUniformState   *state,
                             float                value3)
 {
   Uniform4f *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_4F, 1, location, &info)))
     {
-      if (info->initial || u->v0 != value0 || u->v1 != value1 || u->v2 != value2 || u->v3 != value3)
+      if (info->info.initial || u->v0 != value0 || u->v1 != value1 || u->v2 != value2 || u->v3 != value3)
         {
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, Uniform4f, 1);
           u->v0 = value0;
@@ -355,14 +364,14 @@ gsk_gl_uniform_state_set1ui (GskGLUniformState   *state,
                              guint                value0)
 {
   Uniform1ui *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_1UI, 1, location, &info)))
     {
-      if (info->initial || u->v0 != value0)
+      if (info->info.initial || u->v0 != value0)
         {
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, Uniform1ui, 1);
           u->v0 = value0;
@@ -378,14 +387,14 @@ gsk_gl_uniform_state_set1i (GskGLUniformState   *state,
                             int                  value0)
 {
   Uniform1i *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_1I, 1, location, &info)))
     {
-      if (info->initial || u->v0 != value0)
+      if (info->info.initial || u->v0 != value0)
         {
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, Uniform1i, 1);
           u->v0 = value0;
@@ -402,14 +411,14 @@ gsk_gl_uniform_state_set2i (GskGLUniformState   *state,
                             int                  value1)
 {
   Uniform2i *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_2I, 1, location, &info)))
     {
-      if (info->initial || u->v0 != value0 || u->v1 != value1)
+      if (info->info.initial || u->v0 != value0 || u->v1 != value1)
         {
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, Uniform2i, 1);
           u->v0 = value0;
@@ -428,14 +437,14 @@ gsk_gl_uniform_state_set3i (GskGLUniformState   *state,
                             int                  value2)
 {
   Uniform3i *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_3I, 1, location, &info)))
     {
-      if (info->initial || u->v0 != value0 || u->v1 != value1 || u->v2 != value2)
+      if (info->info.initial || u->v0 != value0 || u->v1 != value1 || u->v2 != value2)
         {
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, Uniform3i, 1);
           u->v0 = value0;
@@ -456,14 +465,14 @@ gsk_gl_uniform_state_set4i (GskGLUniformState   *state,
                             int                  value3)
 {
   Uniform4i *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_4I, 1, location, &info)))
     {
-      if (info->initial || u->v0 != value0 || u->v1 != value1 || u->v2 != value2 || u->v3 != value3)
+      if (info->info.initial || u->v0 != value0 || u->v1 != value1 || u->v2 != value2 || u->v3 != value3)
         {
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, Uniform4i, 1);
           u->v0 = value0;
@@ -500,7 +509,7 @@ gsk_gl_uniform_state_set_rounded_rect (GskGLUniformState    *state,
                                        const GskRoundedRect *rounded_rect)
 {
   GskRoundedRect *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
@@ -508,15 +517,15 @@ gsk_gl_uniform_state_set_rounded_rect (GskGLUniformState    *state,
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_ROUNDED_RECT, 1, location, 
&info)))
     {
-      if (info->initial || !rounded_rect_equal (rounded_rect, u))
+      if (info->info.initial || !rounded_rect_equal (rounded_rect, u))
         {
-          g_assert (!info->send_corners || info->changed);
+          g_assert (!info->info.send_corners || info->info.changed);
 
-          if (!info->send_corners)
+          if (!info->info.send_corners)
             {
-              if (info->initial ||
+              if (info->info.initial ||
                   memcmp (u->corner, rounded_rect->corner, sizeof u->corner) != 0)
-                info->send_corners = TRUE;
+                info->info.send_corners = TRUE;
             }
 
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, GskRoundedRect, 1);
@@ -534,7 +543,7 @@ gsk_gl_uniform_state_set_matrix (GskGLUniformState       *state,
                                  const graphene_matrix_t *matrix)
 {
   graphene_matrix_t *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
@@ -542,7 +551,7 @@ gsk_gl_uniform_state_set_matrix (GskGLUniformState       *state,
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_MATRIX, 1, location, 
&info)))
     {
-      if (!info->initial && memcmp (u, matrix, sizeof *u) == 0)
+      if (!info->info.initial && memcmp (u, matrix, sizeof *u) == 0)
         return;
 
       GSK_GL_UNIFORM_STATE_REPLACE (info, u, graphene_matrix_t, 1);
@@ -571,7 +580,7 @@ gsk_gl_uniform_state_set_texture (GskGLUniformState   *state,
                                   guint                location,
                                   guint                texture_slot)
 {
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
   guint *u;
 
   g_assert (texture_slot >= GL_TEXTURE0);
@@ -581,7 +590,7 @@ gsk_gl_uniform_state_set_texture (GskGLUniformState   *state,
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_TEXTURE, 1, location, 
&info)))
     {
-      if (info->initial || *u != texture_slot)
+      if (info->info.initial || *u != texture_slot)
         {
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, guint, 1);
           *u = texture_slot;
@@ -608,7 +617,7 @@ gsk_gl_uniform_state_set_color (GskGLUniformState   *state,
                                 const GdkRGBA       *color)
 {
   static const GdkRGBA transparent = {0};
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
   GdkRGBA *u;
 
   g_assert (state != NULL);
@@ -619,7 +628,7 @@ gsk_gl_uniform_state_set_color (GskGLUniformState   *state,
       if (color == NULL)
         color = &transparent;
 
-      if (info->initial || memcmp (color, u, sizeof *color) != 0)
+      if (info->info.initial || memcmp (color, u, sizeof *color) != 0)
         {
           GSK_GL_UNIFORM_STATE_REPLACE (info, u, GdkRGBA, 1);
           memcpy (u, color, sizeof *color);
@@ -636,7 +645,7 @@ gsk_gl_uniform_state_set1fv (GskGLUniformState   *state,
                              const float         *value)
 {
   Uniform1f *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
@@ -644,7 +653,7 @@ gsk_gl_uniform_state_set1fv (GskGLUniformState   *state,
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_1FV, count, location, 
&info)))
     {
-      gboolean changed = info->initial || memcmp (u, value, sizeof *u * count) != 0;
+      gboolean changed = info->info.initial || memcmp (u, value, sizeof *u * count) != 0;
 
       if (changed)
         {
@@ -663,7 +672,7 @@ gsk_gl_uniform_state_set2fv (GskGLUniformState   *state,
                              const float         *value)
 {
   Uniform2f *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
@@ -671,7 +680,7 @@ gsk_gl_uniform_state_set2fv (GskGLUniformState   *state,
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_2FV, count, location, 
&info)))
     {
-      gboolean changed = info->initial || memcmp (u, value, sizeof *u * count) != 0;
+      gboolean changed = info->info.initial || memcmp (u, value, sizeof *u * count) != 0;
 
       if (changed)
         {
@@ -690,7 +699,7 @@ gsk_gl_uniform_state_set3fv (GskGLUniformState   *state,
                              const float         *value)
 {
   Uniform3f *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
@@ -698,7 +707,7 @@ gsk_gl_uniform_state_set3fv (GskGLUniformState   *state,
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_3FV, count, location, 
&info)))
     {
-      gboolean changed = info->initial || memcmp (u, value, sizeof *u * count) != 0;
+      gboolean changed = info->info.initial || memcmp (u, value, sizeof *u * count) != 0;
 
       if (changed)
         {
@@ -717,7 +726,7 @@ gsk_gl_uniform_state_set4fv (GskGLUniformState   *state,
                              const float         *value)
 {
   Uniform4f *u;
-  GskGLUniformInfo *info;
+  GskGLUniformInfoElement *info;
 
   g_assert (state != NULL);
   g_assert (program != NULL);
@@ -725,7 +734,7 @@ gsk_gl_uniform_state_set4fv (GskGLUniformState   *state,
 
   if ((u = gsk_gl_uniform_state_get_value (state, program, GSK_GL_UNIFORM_FORMAT_4FV, count, location, 
&info)))
     {
-      gboolean changed = info->initial || memcmp (u, value, sizeof *u * count) != 0;
+      gboolean changed = info->info.initial || memcmp (u, value, sizeof *u * count) != 0;
 
       if (changed)
         {


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