[gtk/wip/chergert/glproto] special case growing array sizes



commit 5d783d51fae2e5d0a87952807db92d11c9653363
Author: Christian Hergert <chergert redhat com>
Date:   Thu Feb 18 20:09:01 2021 -0800

    special case growing array sizes
    
    also fix our offset calculation here (and we really need a macro to make
    that cleaner everywhere).

 gsk/next/gskgluniformstate.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/gsk/next/gskgluniformstate.c b/gsk/next/gskgluniformstate.c
index ec133d3cc6..84a149a037 100644
--- a/gsk/next/gskgluniformstate.c
+++ b/gsk/next/gskgluniformstate.c
@@ -106,7 +106,7 @@ gsk_gl_uniform_state_init_value (GskGLUniformState        *state,
   g_assert (format > 0);
   g_assert (program != NULL);
   g_assert (program->sparse != NULL);
-  g_assert (program->n_sparse < program->n_uniforms);
+  g_assert (program->n_sparse <= program->n_uniforms);
   g_assert (location < GL_MAX_UNIFORM_LOCATIONS || location == (guint)-1);
   g_assert (location < program->n_uniforms);
 
@@ -121,7 +121,7 @@ gsk_gl_uniform_state_init_value (GskGLUniformState        *state,
       if G_LIKELY (array_count <= info->info.array_count)
         {
           *infoptr = info;
-          return state->values_buf + info->info.offset;
+          return state->values_buf + (info->info.offset*4);
         }
 
       /* We found the uniform, but there is not enough space for the
@@ -158,17 +158,22 @@ setup_info:
   /* we have 21 bits for offset */
   g_assert (offset < (1 << GSK_GL_UNIFORM_OFFSET_BITS));
 
+  /* We could once again be setting up this info if the array size grew.
+   * So make sure that we have space in our space array for the value.
+   */
+  g_assert (info->info.format != 0 || program->n_sparse < program->n_uniforms);
+  if (info->info.format == 0)
+    program->sparse[program->n_sparse++] = location;
+
   info->info.format = format;
   info->info.offset = offset;
   info->info.array_count = array_count;
   info->info.initial = TRUE;
   info->stamp = 0;
 
-  program->sparse[program->n_sparse++] = location;
-
   *infoptr = info;
 
-  return state->values_buf + offset;
+  return state->values_buf + (offset*4);
 }
 
 void


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