[gtk/wip/alexl/gl-debug: 6/6] GskGLRenderer: Add debug groups



commit 7e823ff2992386997e737aa9b4bf12bcaa85cd6b
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Apr 24 13:28:11 2019 +0200

    GskGLRenderer: Add debug groups
    
    This adds debug groups in various places, including the debug
    nodes if those are in use. This makes the traces in tools like
    renderdoc much easier to read.

 gsk/gl/gskglglyphcache.c       |  5 +++++
 gsk/gl/gskglrenderer.c         | 29 ++++++++++++++++++++++++++++-
 gsk/gl/gskglrenderops.c        | 22 ++++++++++++++++++++++
 gsk/gl/gskglrenderopsprivate.h |  9 +++++++++
 4 files changed, 64 insertions(+), 1 deletion(-)
---
diff --git a/gsk/gl/gskglglyphcache.c b/gsk/gl/gskglglyphcache.c
index d3627fb8ea..d3ad7a79c8 100644
--- a/gsk/gl/gskglglyphcache.c
+++ b/gsk/gl/gskglglyphcache.c
@@ -262,10 +262,15 @@ upload_dirty_glyph (GskGLGlyphCache *self,
 
   g_assert (atlas->pending_glyph.key != NULL);
 
+  gdk_gl_context_push_debug_group_printf (gsk_gl_driver_get_gl_context (self->gl_driver),
+                                          "Uploading glyph %d", atlas->pending_glyph.key->glyph);
+
   render_glyph (atlas, &atlas->pending_glyph, &region);
 
   gsk_gl_image_upload_regions (atlas->image, self->gl_driver, 1, &region);
 
+  gdk_gl_context_pop_debug_group (gsk_gl_driver_get_gl_context (self->gl_driver));
+
   g_free (region.data);
 
   atlas->pending_glyph.key = NULL;
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index 6cf6dba7c7..523abd434d 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -2516,9 +2516,11 @@ gsk_gl_renderer_add_render_ops (GskGLRenderer   *self,
     break;
 
     case GSK_DEBUG_NODE:
+      ops_push_debug_group (builder, gsk_debug_node_get_message (node));
       gsk_gl_renderer_add_render_ops (self,
                                       gsk_debug_node_get_child (node),
                                       builder);
+      ops_pop_debug_group (builder);
     break;
 
     case GSK_COLOR_NODE:
@@ -2783,7 +2785,9 @@ gsk_gl_renderer_render_ops (GskGLRenderer *self,
           op->op == OP_CHANGE_VAO)
         continue;
 
-      if (op->op != OP_CHANGE_PROGRAM &&
+      if (op->op != OP_PUSH_DEBUG_GROUP &&
+          op->op != OP_POP_DEBUG_GROUP &&
+          op->op != OP_CHANGE_PROGRAM &&
           op->op != OP_CHANGE_RENDER_TARGET &&
           op->op != OP_CLEAR &&
           program == NULL)
@@ -2888,6 +2892,14 @@ gsk_gl_renderer_render_ops (GskGLRenderer *self,
           dump_framebuffer (op->dump.filename, op->dump.width, op->dump.height);
           break;
 
+        case OP_PUSH_DEBUG_GROUP:
+          gdk_gl_context_push_debug_group (self->gl_context, op->debug_group.text);
+          break;
+
+        case OP_POP_DEBUG_GROUP:
+          gdk_gl_context_pop_debug_group (self->gl_context);
+          break;
+
         default:
           g_warn_if_reached ();
         }
@@ -2984,7 +2996,9 @@ gsk_gl_renderer_do_render (GskRenderer           *renderer,
   if (fbo_id != 0)
     ops_set_render_target (&render_op_builder, fbo_id);
 
+  gdk_gl_context_push_debug_group (self->gl_context, "Adding render ops");
   gsk_gl_renderer_add_render_ops (self, root, &render_op_builder);
+  gdk_gl_context_pop_debug_group (self->gl_context);
 
   /* We correctly reset the state everywhere */
   g_assert_cmpint (render_op_builder.current_render_target, ==, fbo_id);
@@ -3012,7 +3026,9 @@ gsk_gl_renderer_do_render (GskRenderer           *renderer,
   glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
   glBlendEquation (GL_FUNC_ADD);
 
+  gdk_gl_context_push_debug_group (self->gl_context, "Rendering ops");
   gsk_gl_renderer_render_ops (self, render_op_builder.buffer_size);
+  gdk_gl_context_pop_debug_group (self->gl_context);
 
 #ifdef G_ENABLE_DEBUG
   gsk_profiler_counter_inc (profiler, self->profile_counters.frames);
@@ -3040,6 +3056,9 @@ gsk_gl_renderer_render_texture (GskRenderer           *renderer,
 
   g_return_val_if_fail (self->gl_context != NULL, NULL);
 
+  gdk_gl_context_push_debug_group_printf (self->gl_context,
+                                          "Render %s<%p> to texture", root->node_class->type_name, root);
+
   width = ceilf (viewport->size.width);
   height = ceilf (viewport->size.height);
 
@@ -3077,6 +3096,9 @@ gsk_gl_renderer_render_texture (GskRenderer           *renderer,
                                 NULL, NULL);
 
   gsk_gl_driver_end_frame (self->gl_driver);
+
+  gdk_gl_context_pop_debug_group (self->gl_context);
+
   gsk_gl_renderer_clear_tree (self);
   return texture;
 }
@@ -3095,6 +3117,9 @@ gsk_gl_renderer_render (GskRenderer          *renderer,
   if (self->gl_context == NULL)
     return;
 
+  gdk_gl_context_push_debug_group_printf (self->gl_context,
+                                          "Render root node %p", root);
+
   surface = gsk_renderer_get_surface (renderer);
   whole_surface = (GdkRectangle) {
                       0, 0,
@@ -3140,6 +3165,8 @@ gsk_gl_renderer_render (GskRenderer          *renderer,
 
   gdk_draw_context_end_frame (GDK_DRAW_CONTEXT (self->gl_context));
 
+  gdk_gl_context_pop_debug_group (self->gl_context);
+
   g_clear_pointer (&self->render_region, cairo_region_destroy);
 }
 
diff --git a/gsk/gl/gskglrenderops.c b/gsk/gl/gskglrenderops.c
index f4c887fa59..88ee7513bd 100644
--- a/gsk/gl/gskglrenderops.c
+++ b/gsk/gl/gskglrenderops.c
@@ -44,6 +44,28 @@ ops_dump_framebuffer (RenderOpBuilder *builder,
   g_array_append_val (builder->render_ops, op);
 }
 
+void
+ops_push_debug_group (RenderOpBuilder *builder,
+                      const char *text)
+{
+  RenderOp op;
+
+  op.op = OP_PUSH_DEBUG_GROUP;
+  strncpy (op.debug_group.text, text, sizeof(op.debug_group.text) - 1);
+  op.debug_group.text[sizeof(op.debug_group.text)] = 0; /* Ensure zero terminated */
+
+  g_array_append_val (builder->render_ops, op);
+}
+
+void
+ops_pop_debug_group (RenderOpBuilder *builder)
+{
+  RenderOp op;
+
+  op.op = OP_POP_DEBUG_GROUP;
+  g_array_append_val (builder->render_ops, op);
+}
+
 float
 ops_get_scale (const RenderOpBuilder *builder)
 {
diff --git a/gsk/gl/gskglrenderopsprivate.h b/gsk/gl/gskglrenderopsprivate.h
index a2608b7450..e3aa145561 100644
--- a/gsk/gl/gskglrenderopsprivate.h
+++ b/gsk/gl/gskglrenderopsprivate.h
@@ -59,6 +59,8 @@ enum {
   OP_CLEAR                  =  21,
   OP_DRAW                   =  22,
   OP_DUMP_FRAMEBUFFER       =  23,
+  OP_PUSH_DEBUG_GROUP       =  24,
+  OP_POP_DEBUG_GROUP        =  25,
 };
 
 typedef struct
@@ -217,6 +219,9 @@ typedef struct
       int width;
       int height;
     } dump;
+    struct {
+      char text[80]; /* Size of outset_shadow, so 'should be enough' without growing RenderOp */
+    } debug_group;
   };
 } RenderOp;
 
@@ -278,6 +283,10 @@ void              ops_dump_framebuffer   (RenderOpBuilder         *builder,
                                           int                      width,
                                           int                      height);
 void              ops_init               (RenderOpBuilder         *builder);
+void              ops_push_debug_group    (RenderOpBuilder         *builder,
+                                           const char              *text);
+void              ops_pop_debug_group     (RenderOpBuilder         *builder);
+
 void              ops_finish             (RenderOpBuilder         *builder);
 void              ops_push_modelview     (RenderOpBuilder         *builder,
                                           const graphene_matrix_t *mv,


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