[cogl/wip/neil/pipeline-uniforms: 17/17] Stash



commit c9c95c811cbf9b24b3fb3cc606edec3cec79a83b
Author: Neil Roberts <neil linux intel com>
Date:   Wed Nov 2 14:03:09 2011 +0000

    Stash

 cogl/cogl-pipeline-progend-glsl.c  |   85 ++-------------------------------
 cogl/cogl-pipeline-state-private.h |    5 ++
 cogl/cogl-pipeline-state.c         |   91 +++++++++++++++++++++++++++++++++++-
 3 files changed, 99 insertions(+), 82 deletions(-)
---
diff --git a/cogl/cogl-pipeline-progend-glsl.c b/cogl/cogl-pipeline-progend-glsl.c
index 84a516c..3e70ef4 100644
--- a/cogl/cogl-pipeline-progend-glsl.c
+++ b/cogl/cogl-pipeline-progend-glsl.c
@@ -46,6 +46,7 @@
 #include "cogl-pipeline-fragend-glsl-private.h"
 #include "cogl-pipeline-vertend-glsl-private.h"
 #include "cogl-pipeline-cache.h"
+#include "cogl-pipeline-state-private.h"
 
 #ifdef HAVE_COGL_GLES2
 
@@ -611,83 +612,6 @@ typedef struct
   CoglPipelineUniformOverride *override;
 } FlushUniformsClosure;
 
-static void
-compare_uniform_differences (FlushUniformsClosure *data,
-                             CoglPipeline *pipeline0,
-                             CoglPipeline *pipeline1)
-{
-  GSList *head0 = NULL;
-  GSList *head1 = NULL;
-  CoglPipeline *node0;
-  CoglPipeline *node1;
-  int len0 = 0;
-  int len1 = 0;
-  int count;
-  GSList *common_ancestor0;
-  GSList *common_ancestor1;
-
-  /* This algorithm is copied from
-     _cogl_pipeline_compare_differences(). It might be nice to share
-     the code more */
-
-  for (node0 = pipeline0; node0; node0 = _cogl_pipeline_get_parent (node0))
-    {
-      GSList *link = alloca (sizeof (GSList));
-      link->next = head0;
-      link->data = node0;
-      head0 = link;
-      len0++;
-    }
-  for (node1 = pipeline1; node1; node1 = _cogl_pipeline_get_parent (node1))
-    {
-      GSList *link = alloca (sizeof (GSList));
-      link->next = head1;
-      link->data = node1;
-      head1 = link;
-      len1++;
-    }
-
-  /* NB: There's no point looking at the head entries since we know both
-   * pipelines must have the same default pipeline as their root node. */
-  common_ancestor0 = head0;
-  common_ancestor1 = head1;
-  head0 = head0->next;
-  head1 = head1->next;
-  count = MIN (len0, len1) - 1;
-  while (count--)
-    {
-      if (head0->data != head1->data)
-        break;
-      common_ancestor0 = head0;
-      common_ancestor1 = head1;
-      head0 = head0->next;
-      head1 = head1->next;
-    }
-
-  for (head0 = common_ancestor0->next; head0; head0 = head0->next)
-    {
-      node0 = head0->data;
-      if ((node0->differences & COGL_PIPELINE_STATE_UNIFORMS))
-        {
-          const CoglPipelineUniformsState *uniforms_state =
-            &node0->big_state->uniforms_state;
-          _cogl_bitmask_set_flags (&uniforms_state->override_mask,
-                                   data->uniform_differences);
-        }
-    }
-  for (head1 = common_ancestor1->next; head1; head1 = head1->next)
-    {
-      node1 = head1->data;
-      if ((node1->differences & COGL_PIPELINE_STATE_UNIFORMS))
-        {
-          const CoglPipelineUniformsState *uniforms_state =
-            &node1->big_state->uniforms_state;
-          _cogl_bitmask_set_flags (&uniforms_state->override_mask,
-                                   data->uniform_differences);
-        }
-    }
-}
-
 static gboolean
 flush_uniform_cb (int uniform_num, void *user_data)
 {
@@ -796,9 +720,10 @@ _cogl_pipeline_progend_glsl_flush_uniforms (CoglPipeline *pipeline,
 
       memset (data.uniform_differences, 0,
               n_uniform_longs * sizeof (unsigned long));
-      compare_uniform_differences (&data,
-                                   program_state->last_used_for_pipeline,
-                                   pipeline);
+      _cogl_pipeline_compare_uniform_differences
+        (data.uniform_differences,
+         program_state->last_used_for_pipeline,
+         pipeline);
 
       /* We need to be sure to flush any uniforms that have changed
          since the last flush */
diff --git a/cogl/cogl-pipeline-state-private.h b/cogl/cogl-pipeline-state-private.h
index dbc0bc6..57eff5b 100644
--- a/cogl/cogl-pipeline-state-private.h
+++ b/cogl/cogl-pipeline-state-private.h
@@ -147,4 +147,9 @@ void
 _cogl_pipeline_hash_uniforms_state (CoglPipeline *authority,
                                     CoglPipelineHashState *state);
 
+void
+_cogl_pipeline_compare_uniform_differences (unsigned long *differences,
+                                            CoglPipeline *pipeline0,
+                                            CoglPipeline *pipeline1);
+
 #endif /* __COGL_PIPELINE_STATE_PRIVATE_H */
diff --git a/cogl/cogl-pipeline-state.c b/cogl/cogl-pipeline-state.c
index cb91335..fcc424a 100644
--- a/cogl/cogl-pipeline-state.c
+++ b/cogl/cogl-pipeline-state.c
@@ -34,7 +34,7 @@
 #include "cogl-blend-string.h"
 #include "cogl-util.h"
 #include "cogl-depth-state-private.h"
-#include "cogl-pipeline-private.h"
+#include "cogl-pipeline-state-private.h"
 
 #include "string.h"
 
@@ -291,7 +291,9 @@ gboolean
 _cogl_pipeline_uniforms_state_equal (CoglPipeline *authority0,
                                      CoglPipeline *authority1)
 {
+  unsigned long *differences;
   const CoglBoxedValue **values0, **values1;
+  int n_longs;
   int i;
 
   _COGL_GET_CONTEXT (ctx, FALSE);
@@ -302,10 +304,17 @@ _cogl_pipeline_uniforms_state_equal (CoglPipeline *authority0,
   values0 = g_alloca (sizeof (const CoglBoxedValue *) * ctx->n_uniform_names);
   values1 = g_alloca (sizeof (const CoglBoxedValue *) * ctx->n_uniform_names);
 
+  n_longs = COGL_FLAGS_N_LONGS_FOR_SIZE (ctx->n_uniform_names);
+  differences = g_alloca (n_longs * sizeof (unsigned long));
+  memset (differences, 0, sizeof (unsigned long) * n_longs);
+  _cogl_pipeline_compare_uniform_differences (differences,
+                                              authority0,
+                                              authority1);
+
   _cogl_pipeline_get_all_uniform_values (authority0, values0);
   _cogl_pipeline_get_all_uniform_values (authority1, values1);
 
-  for (i = 0; i < ctx->n_uniform_names; i++)
+  COGL_FLAGS_FOREACH_START (differences, n_longs, i)
     {
       const CoglBoxedValue *value0 = values0[i];
       const CoglBoxedValue *value1 = values1[i];
@@ -318,6 +327,7 @@ _cogl_pipeline_uniforms_state_equal (CoglPipeline *authority0,
       else if (!_cogl_boxed_value_equal (value0, value1))
         return FALSE;
     }
+  COGL_FLAGS_FOREACH_END;
 
   return TRUE;
 }
@@ -1645,3 +1655,80 @@ _cogl_pipeline_hash_uniforms_state (CoglPipeline *authority,
      let's just leave it until something actually needs it */
   g_warn_if_reached ();
 }
+
+void
+_cogl_pipeline_compare_uniform_differences (unsigned long *differences,
+                                            CoglPipeline *pipeline0,
+                                            CoglPipeline *pipeline1)
+{
+  GSList *head0 = NULL;
+  GSList *head1 = NULL;
+  CoglPipeline *node0;
+  CoglPipeline *node1;
+  int len0 = 0;
+  int len1 = 0;
+  int count;
+  GSList *common_ancestor0;
+  GSList *common_ancestor1;
+
+  /* This algorithm is copied from
+     _cogl_pipeline_compare_differences(). It might be nice to share
+     the code more */
+
+  for (node0 = pipeline0; node0; node0 = _cogl_pipeline_get_parent (node0))
+    {
+      GSList *link = alloca (sizeof (GSList));
+      link->next = head0;
+      link->data = node0;
+      head0 = link;
+      len0++;
+    }
+  for (node1 = pipeline1; node1; node1 = _cogl_pipeline_get_parent (node1))
+    {
+      GSList *link = alloca (sizeof (GSList));
+      link->next = head1;
+      link->data = node1;
+      head1 = link;
+      len1++;
+    }
+
+  /* NB: There's no point looking at the head entries since we know both
+   * pipelines must have the same default pipeline as their root node. */
+  common_ancestor0 = head0;
+  common_ancestor1 = head1;
+  head0 = head0->next;
+  head1 = head1->next;
+  count = MIN (len0, len1) - 1;
+  while (count--)
+    {
+      if (head0->data != head1->data)
+        break;
+      common_ancestor0 = head0;
+      common_ancestor1 = head1;
+      head0 = head0->next;
+      head1 = head1->next;
+    }
+
+  for (head0 = common_ancestor0->next; head0; head0 = head0->next)
+    {
+      node0 = head0->data;
+      if ((node0->differences & COGL_PIPELINE_STATE_UNIFORMS))
+        {
+          const CoglPipelineUniformsState *uniforms_state =
+            &node0->big_state->uniforms_state;
+          _cogl_bitmask_set_flags (&uniforms_state->override_mask,
+                                   differences);
+        }
+    }
+  for (head1 = common_ancestor1->next; head1; head1 = head1->next)
+    {
+      node1 = head1->data;
+      if ((node1->differences & COGL_PIPELINE_STATE_UNIFORMS))
+        {
+          const CoglPipelineUniformsState *uniforms_state =
+            &node1->big_state->uniforms_state;
+          _cogl_bitmask_set_flags (&uniforms_state->override_mask,
+                                   differences);
+        }
+    }
+}



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