[gtk/wip/chergert/glproto: 516/526] use stamps to avoid costly comparisons




commit 8d5bf3d2b4071bede091463f50bb49dd8e365fca
Author: Christian Hergert <chergert redhat com>
Date:   Fri Feb 12 14:45:11 2021 -0800

    use stamps to avoid costly comparisons

 gsk/next/gskglrenderjob.c           |  5 +++++
 gsk/next/gskgluniformstate.c        |  2 +-
 gsk/next/gskgluniformstateprivate.h | 24 ++++++++++++------------
 3 files changed, 18 insertions(+), 13 deletions(-)
---
diff --git a/gsk/next/gskglrenderjob.c b/gsk/next/gskglrenderjob.c
index 7823417351..ea3cc382cc 100644
--- a/gsk/next/gskglrenderjob.c
+++ b/gsk/next/gskglrenderjob.c
@@ -927,6 +927,7 @@ gsk_gl_render_job_begin_draw (GskGLRenderJob *job,
     gsk_gl_uniform_state_set4fv (program->uniforms,
                                  program->program_info,
                                  program->uniform_locations[UNIFORM_SHARED_VIEWPORT],
+                                 job->driver->stamps[UNIFORM_SHARED_VIEWPORT],
                                  1,
                                  (const float *)&job->viewport);
 
@@ -934,24 +935,28 @@ gsk_gl_render_job_begin_draw (GskGLRenderJob *job,
     gsk_gl_uniform_state_set_matrix (program->uniforms,
                                      program->program_info,
                                      program->uniform_locations[UNIFORM_SHARED_MODELVIEW],
+                                     job->driver->stamps[UNIFORM_SHARED_MODELVIEW],
                                      &job->current_modelview->matrix);
 
   if (program->uniform_locations[UNIFORM_SHARED_PROJECTION] > -1)
     gsk_gl_uniform_state_set_matrix (program->uniforms,
                                      program->program_info,
                                      program->uniform_locations[UNIFORM_SHARED_PROJECTION],
+                                     job->driver->stamps[UNIFORM_SHARED_PROJECTION],
                                      &job->projection);
 
   if (program->uniform_locations[UNIFORM_SHARED_CLIP_RECT] > -1)
     gsk_gl_uniform_state_set_rounded_rect (program->uniforms,
                                            program->program_info,
                                            program->uniform_locations[UNIFORM_SHARED_CLIP_RECT],
+                                           job->driver->stamps[UNIFORM_SHARED_CLIP_RECT],
                                            &job->current_clip->rect);
 
   if (program->uniform_locations[UNIFORM_SHARED_ALPHA] > -1)
     gsk_gl_uniform_state_set1f (program->uniforms,
                                 program->program_info,
                                 program->uniform_locations[UNIFORM_SHARED_ALPHA],
+                                job->driver->stamps[UNIFORM_SHARED_ALPHA],
                                 job->alpha);
 }
 
diff --git a/gsk/next/gskgluniformstate.c b/gsk/next/gskgluniformstate.c
index 850c57c0f5..6e85853375 100644
--- a/gsk/next/gskgluniformstate.c
+++ b/gsk/next/gskgluniformstate.c
@@ -157,7 +157,7 @@ setup_info:
   info->info.offset = offset;
   info->info.array_count = array_count;
   info->info.initial = TRUE;
-  info->stamp = 1;
+  info->stamp = 0;
 
   *infoptr = info;
 
diff --git a/gsk/next/gskgluniformstateprivate.h b/gsk/next/gskgluniformstateprivate.h
index 0f574ad945..9024db908a 100644
--- a/gsk/next/gskgluniformstateprivate.h
+++ b/gsk/next/gskgluniformstateprivate.h
@@ -180,20 +180,20 @@ gsk_gl_uniform_state_get_value (GskGLUniformState        *state,
 {
   GskGLUniformInfoElement *info = &program->uniforms[location];
 
+  /* If the stamp is the same, then we can ignore the request
+   * and short-circuit as early as possible. This requires the
+   * caller to increment their private stamp when they change
+   * internal state.
+   *
+   * This is generally used for the shared uniforms like projection,
+   * modelview, clip, etc to avoid so many comparisons which cost
+   * considerable CPU.
+   */
+  if (stamp != 0 && stamp == info->stamp)
+    return NULL;
+
   if G_LIKELY (format == info->info.format && array_count <= info->info.array_count)
     {
-      /* If the stamp is the same, then we can ignore the request
-       * and short-circuit as early as possible. This requires the
-       * peer to also increment their private stamp when they change
-       * internal state.
-       *
-       * This is generally used for the shared uniforms like projection,
-       * modelview, clip, etc to avoid so many comparisons which cost
-       * considerable CPU.
-       */
-      if (stamp == info->stamp)
-        return NULL;
-
       *infoptr = info;
       return state->values_buf + info->info.offset;
     }


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