[gtk/wip/chergert/glproto: 408/526] add various renderer timers and counters




commit b598621644c7499a2eb71014d7e51ef43516f0fa
Author: Christian Hergert <chergert redhat com>
Date:   Tue Feb 2 13:24:00 2021 -0800

    add various renderer timers and counters
    
    this also adds some more like # of attachments, uniforms, etc

 gsk/next/gskglcommandqueue.c        | 69 +++++++++++++++++++++++++++++++++++--
 gsk/next/gskglcommandqueueprivate.h | 22 +++++++++++-
 gsk/next/gskglrenderer.c            |  7 ++++
 3 files changed, 95 insertions(+), 3 deletions(-)
---
diff --git a/gsk/next/gskglcommandqueue.c b/gsk/next/gskglcommandqueue.c
index 78121c6048..3b5c4ffffe 100644
--- a/gsk/next/gskglcommandqueue.c
+++ b/gsk/next/gskglcommandqueue.c
@@ -23,12 +23,14 @@
 
 #include "config.h"
 
+#include <epoxy/gl.h>
+#include <string.h>
+
 #include <gdk/gdkglcontextprivate.h>
 #include <gdk/gdkmemorytextureprivate.h>
+#include <gdk/gdkprofilerprivate.h>
 #include <gsk/gskdebugprivate.h>
 #include <gsk/gskroundedrectprivate.h>
-#include <epoxy/gl.h>
-#include <string.h>
 
 #include "gskglattachmentstateprivate.h"
 #include "gskglbufferprivate.h"
@@ -385,6 +387,8 @@ gsk_gl_command_queue_dispose (GObject *object)
 
   g_assert (GSK_IS_GL_COMMAND_QUEUE (self));
 
+  g_clear_object (&self->profiler);
+  g_clear_object (&self->gl_profiler);
   g_clear_object (&self->context);
   g_clear_pointer (&self->batches, g_array_unref);
   g_clear_pointer (&self->attachments, gsk_gl_attachment_state_unref);
@@ -929,6 +933,11 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
   guint16 width = 0;
   guint16 height = 0;
   guint count = 0;
+#ifdef G_ENABLE_DEBUG
+  guint n_binds = 0;
+  guint n_fbos = 0;
+  guint n_uniforms = 0;
+#endif
 
   g_return_if_fail (GSK_IS_GL_COMMAND_QUEUE (self));
   g_return_if_fail (self->in_draw == FALSE);
@@ -936,6 +945,11 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
   if (self->batches->len == 0)
     return;
 
+#ifdef G_ENABLE_DEBUG
+  gsk_gl_profiler_begin_gpu_region (self->gl_profiler);
+  gsk_profiler_timer_begin (self->profiler, self->metrics.cpu_time);
+#endif
+
   gsk_gl_command_queue_make_current (self);
 
   glEnable (GL_DEPTH_TEST);
@@ -998,6 +1012,9 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
                              scale_factor,
                              &scissor_rect,
                              scissor != NULL);
+#ifdef G_ENABLE_DEBUG
+              n_fbos++;
+#endif
             }
 
           apply_viewport (&width,
@@ -1032,6 +1049,9 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
                              scale_factor,
                              &scissor_rect,
                              scissor != NULL);
+#ifdef G_ENABLE_DEBUG
+              n_fbos++;
+#endif
             }
 
           apply_viewport (&width,
@@ -1062,6 +1082,11 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
 
                   apply_uniform (self->uniforms, &u->info, u->location);
                 }
+
+#ifdef G_ENABLE_DEBUG
+              n_uniforms += batch->draw.uniform_count;
+              n_binds += batch->draw.bind_count;
+#endif
             }
 
           glDrawArrays (GL_TRIANGLES, batch->draw.vbo_offset, batch->draw.vbo_count);
@@ -1094,6 +1119,24 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
     }
 
   glDeleteVertexArrays (1, &vao_id);
+
+#ifdef G_ENABLE_DEBUG
+  {
+    gint64 start_time G_GNUC_UNUSED = gsk_profiler_timer_get_start (self->profiler, self->metrics.cpu_time);
+    gint64 cpu_time = gsk_profiler_timer_end (self->profiler, self->metrics.cpu_time);
+    gint64 gpu_time = gsk_gl_profiler_end_gpu_region (self->gl_profiler);
+
+    gsk_profiler_timer_set (self->profiler, self->metrics.gpu_time, gpu_time);
+    gsk_profiler_timer_set (self->profiler, self->metrics.cpu_time, cpu_time);
+    gsk_profiler_counter_inc (self->profiler, self->metrics.n_frames);
+    gsk_profiler_counter_set (self->profiler, self->metrics.n_binds, n_binds);
+    gsk_profiler_counter_set (self->profiler, self->metrics.n_uniforms, n_uniforms);
+    gsk_profiler_counter_set (self->profiler, self->metrics.n_fbos, n_fbos);
+    gsk_profiler_push_samples (self->profiler);
+
+    gdk_profiler_add_mark (start_time * 1000, cpu_time * 1000, "GL render", "");
+  }
+#endif
 }
 
 void
@@ -1329,3 +1372,25 @@ gsk_gl_command_queue_upload_texture (GskGLCommandQueue *self,
 
   return texture_id;
 }
+
+void
+gsk_gl_command_queue_set_profiler (GskGLCommandQueue *self,
+                                   GskProfiler       *profiler)
+{
+#ifdef G_ENABLE_DEBUG
+  g_return_if_fail (GSK_IS_GL_COMMAND_QUEUE (self));
+  g_return_if_fail (GSK_IS_PROFILER (profiler));
+
+  if (g_set_object (&self->profiler, profiler))
+    {
+      self->gl_profiler = gsk_gl_profiler_new (self->context);
+
+      self->metrics.n_fbos = gsk_profiler_add_counter (profiler, "fbos", "Framebuffers Changed", FALSE);
+      self->metrics.n_frames = gsk_profiler_add_counter (profiler, "frames", "Frames", FALSE);
+      self->metrics.n_uniforms = gsk_profiler_add_counter (profiler, "uniforms", "Uniforms Changed", FALSE);
+      self->metrics.n_binds = gsk_profiler_add_counter (profiler, "attachments", "Attachments Changed", 
FALSE);
+      self->metrics.cpu_time = gsk_profiler_add_timer (profiler, "cpu-time", "CPU Time", FALSE, TRUE);
+      self->metrics.gpu_time = gsk_profiler_add_timer (profiler, "gpu-time", "GPU Time", FALSE, TRUE);
+    }
+#endif
+}
diff --git a/gsk/next/gskglcommandqueueprivate.h b/gsk/next/gskglcommandqueueprivate.h
index 0fa5087c08..7409c4b94d 100644
--- a/gsk/next/gskglcommandqueueprivate.h
+++ b/gsk/next/gskglcommandqueueprivate.h
@@ -21,11 +21,14 @@
 #ifndef __GSK_GL_COMMAND_QUEUE_PRIVATE_H__
 #define __GSK_GL_COMMAND_QUEUE_PRIVATE_H__
 
-#include "gskgltypesprivate.h"
+#include <gsk/gskprofilerprivate.h>
 
+#include "gskgltypesprivate.h"
 #include "gskglattachmentstateprivate.h"
 #include "gskgluniformstateprivate.h"
 
+#include "../gl/gskglprofilerprivate.h"
+
 G_BEGIN_DECLS
 
 #define GSK_TYPE_GL_COMMAND_QUEUE (gsk_gl_command_queue_get_type())
@@ -65,6 +68,10 @@ struct _GskGLCommandQueue
    */
   GskGLUniformState *uniforms;
 
+  /* The profiler instance to deliver timing/etc data */
+  GskProfiler *profiler;
+  GskGLProfiler *gl_profiler;
+
   /* Array of GskGLCommandDraw which allows us to have a static size field
    * in GskGLCommandBatch to coalesce draws. Multiple GskGLCommandDraw may
    * be processed together (and out-of-order) to reduce the number of state
@@ -106,6 +113,17 @@ struct _GskGLCommandQueue
    */
   int tail_batch_index;
 
+#ifdef G_ENABLE_DEBUG
+  struct {
+    GQuark n_binds;
+    GQuark n_frames;
+    GQuark n_uniforms;
+    GQuark n_fbos;
+    GQuark cpu_time;
+    GQuark gpu_time;
+  } metrics;
+#endif
+
   /* If we're inside a begin/end_frame pair */
   guint in_frame : 1;
 
@@ -115,6 +133,8 @@ struct _GskGLCommandQueue
 
 GskGLCommandQueue *gsk_gl_command_queue_new                  (GdkGLContext             *context,
                                                               GskGLUniformState        *uniforms);
+void               gsk_gl_command_queue_set_profiler         (GskGLCommandQueue        *self,
+                                                              GskProfiler              *profiler);
 GdkGLContext      *gsk_gl_command_queue_get_context          (GskGLCommandQueue        *self);
 void               gsk_gl_command_queue_make_current         (GskGLCommandQueue        *self);
 void               gsk_gl_command_queue_begin_frame          (GskGLCommandQueue        *self);
diff --git a/gsk/next/gskglrenderer.c b/gsk/next/gskglrenderer.c
index 199e038915..c6c83471e8 100644
--- a/gsk/next/gskglrenderer.c
+++ b/gsk/next/gskglrenderer.c
@@ -20,6 +20,7 @@
 
 #include "config.h"
 
+#include <gdk/gdkprofilerprivate.h>
 #include <gdk/gdksurfaceprivate.h>
 #include <gsk/gskdebugprivate.h>
 #include <gsk/gskrendererprivate.h>
@@ -73,6 +74,7 @@ gsk_next_renderer_realize (GskRenderer  *renderer,
                            GdkSurface   *surface,
                            GError      **error)
 {
+  G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
   GskNextRenderer *self = (GskNextRenderer *)renderer;
   GdkGLContext *context = NULL;
   GdkGLContext *shared_context;
@@ -115,12 +117,17 @@ gsk_next_renderer_realize (GskRenderer  *renderer,
   self->context = g_steal_pointer (&context);
   self->driver = g_steal_pointer (&driver);
 
+  gsk_gl_command_queue_set_profiler (self->command_queue,
+                                     gsk_renderer_get_profiler (renderer));
+
   ret = TRUE;
 
 failure:
   g_clear_object (&driver);
   g_clear_object (&context);
 
+  gdk_profiler_end_mark (start_time, "GskNextRenderer realize", NULL);
+
   return ret;
 }
 


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