[gtk/wip/chergert/fewer-uniforms] wip




commit 0a316468fcfecf1def870e10d6c54ebaf8f48f8c
Author: Christian Hergert <chergert redhat com>
Date:   Fri Mar 12 10:16:52 2021 -0800

    wip

 gsk/ngl/gsknglcommandqueue.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/gsk/ngl/gsknglcommandqueue.c b/gsk/ngl/gsknglcommandqueue.c
index 9426c199b1..e06aae314a 100644
--- a/gsk/ngl/gsknglcommandqueue.c
+++ b/gsk/ngl/gsknglcommandqueue.c
@@ -732,9 +732,10 @@ gsk_ngl_command_queue_delete_program (GskNglCommandQueue *self,
 }
 
 static inline void
-apply_uniform (gconstpointer     dataptr,
+apply_uniform (guint             program,
                GskNglUniformInfo info,
-               guint             location)
+               guint             location,
+               gconstpointer     dataptr)
 {
   g_assert (dataptr != NULL);
   g_assert (info.format > 0);
@@ -1048,6 +1049,7 @@ gsk_ngl_command_queue_execute (GskNglCommandQueue   *self,
   guint n_uniforms = 0;
   guint vao_id;
   guint vbo_id;
+  GHashTable *state;
   int textures[4];
   int framebuffer = -1;
   int next_batch_index;
@@ -1062,6 +1064,8 @@ gsk_ngl_command_queue_execute (GskNglCommandQueue   *self,
   for (guint i = 0; i < G_N_ELEMENTS (textures); i++)
     textures[i] = -1;
 
+  state = g_hash_table_new (NULL, NULL);
+
   gsk_ngl_command_queue_sort_batches (self);
 
   gsk_ngl_command_queue_make_current (self);
@@ -1187,8 +1191,16 @@ gsk_ngl_command_queue_execute (GskNglCommandQueue   *self,
               const GskNglCommandUniform *u = &self->batch_uniforms.items[batch->draw.uniform_offset];
 
               for (guint i = 0; i < batch->draw.uniform_count; i++, u++)
-                apply_uniform (gsk_ngl_uniform_state_get_uniform_data (self->uniforms, u->info.offset),
-                               u->info, u->location);
+                {
+                  gconstpointer data = gsk_ngl_uniform_state_get_uniform_data (self->uniforms, 
u->info.offset);
+                  guint key = (program << 16) | u->location;
+
+                  if (g_hash_table_lookup (state, GUINT_TO_POINTER (key)) != data)
+                    {
+                      apply_uniform (program, u->info, u->location, data);
+                      g_hash_table_insert (state, GUINT_TO_POINTER (key), (gpointer)data);
+                    }
+                }
 
               n_uniforms += batch->draw.uniform_count;
             }
@@ -1225,6 +1237,8 @@ gsk_ngl_command_queue_execute (GskNglCommandQueue   *self,
   glDeleteBuffers (1, &vbo_id);
   glDeleteVertexArrays (1, &vao_id);
 
+  g_hash_table_unref (state);
+
   gdk_profiler_set_int_counter (self->metrics.n_binds, n_binds);
   gdk_profiler_set_int_counter (self->metrics.n_uniforms, n_uniforms);
   gdk_profiler_set_int_counter (self->metrics.n_fbos, n_fbos);


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