gsk: Add GskProfiler to GskRenderer

The profiler instance is per-renderer, and is accesible to
implementations.
This commit is contained in:
Emmanuele Bassi 2016-08-03 16:51:21 +01:00
parent 005fea59b6
commit d227b9ce38
3 changed files with 103 additions and 2 deletions

View File

@ -6,6 +6,7 @@
#include "gskenums.h" #include "gskenums.h"
#include "gskgldriverprivate.h" #include "gskgldriverprivate.h"
#include "gskglprofilerprivate.h" #include "gskglprofilerprivate.h"
#include "gskprofilerprivate.h"
#include "gskrendererprivate.h" #include "gskrendererprivate.h"
#include "gskrendernodeprivate.h" #include "gskrendernodeprivate.h"
#include "gskrendernodeiter.h" #include "gskrendernodeiter.h"
@ -75,6 +76,18 @@ enum {
N_ATTRIBUTES N_ATTRIBUTES
}; };
#ifdef G_ENABLE_DEBUG
typedef struct {
GQuark frames;
GQuark draw_calls;
} ProfileCounters;
typedef struct {
GQuark cpu_time;
GQuark gpu_time;
} ProfileTimers;
#endif
struct _GskGLRenderer struct _GskGLRenderer
{ {
GskRenderer parent_instance; GskRenderer parent_instance;
@ -102,6 +115,11 @@ struct _GskGLRenderer
GArray *render_items; GArray *render_items;
#ifdef G_ENABLE_DEBUG
ProfileCounters profile_counters;
ProfileTimers profile_timers;
#endif
gboolean has_buffers : 1; gboolean has_buffers : 1;
}; };
@ -419,6 +437,11 @@ render_item (GskGLRenderer *self,
glDrawArrays (GL_TRIANGLES, 0, N_VERTICES); glDrawArrays (GL_TRIANGLES, 0, N_VERTICES);
#ifdef G_ENABLE_DEBUG
gsk_profiler_counter_inc (gsk_renderer_get_profiler (GSK_RENDERER (self)),
self->profile_counters.draw_calls);
#endif
/* Render all children items, so we can take the result /* Render all children items, so we can take the result
* render target texture during the compositing * render target texture during the compositing
*/ */
@ -797,12 +820,17 @@ gsk_gl_renderer_render (GskRenderer *renderer,
graphene_matrix_t modelview, projection; graphene_matrix_t modelview, projection;
graphene_rect_t viewport; graphene_rect_t viewport;
guint i; guint i;
guint64 gpu_time;
int scale_factor; int scale_factor;
#ifdef G_ENABLE_DEBUG
GskProfiler *profiler;
gint64 gpu_time, cpu_time;
#endif
if (self->gl_context == NULL) if (self->gl_context == NULL)
return; return;
profiler = gsk_renderer_get_profiler (renderer);
gdk_gl_context_make_current (self->gl_context); gdk_gl_context_make_current (self->gl_context);
gsk_renderer_get_viewport (renderer, &viewport); gsk_renderer_get_viewport (renderer, &viewport);
@ -823,7 +851,11 @@ gsk_gl_renderer_render (GskRenderer *renderer,
goto out; goto out;
gsk_gl_driver_begin_frame (self->gl_driver); gsk_gl_driver_begin_frame (self->gl_driver);
#ifdef G_ENABLE_DEBUG
gsk_gl_profiler_begin_gpu_region (self->gl_profiler); gsk_gl_profiler_begin_gpu_region (self->gl_profiler);
gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
#endif
/* Ensure that the viewport is up to date */ /* Ensure that the viewport is up to date */
if (gsk_gl_driver_bind_render_target (self->gl_driver, self->texture_id)) if (gsk_gl_driver_bind_render_target (self->gl_driver, self->texture_id))
@ -848,8 +880,18 @@ gsk_gl_renderer_render (GskRenderer *renderer,
/* Draw the output of the GL rendering to the window */ /* Draw the output of the GL rendering to the window */
gsk_gl_driver_end_frame (self->gl_driver); gsk_gl_driver_end_frame (self->gl_driver);
#ifdef G_ENABLE_DEBUG
gsk_profiler_counter_inc (profiler, self->profile_counters.frames);
cpu_time = gsk_profiler_timer_end (profiler, self->profile_timers.cpu_time);
gsk_profiler_timer_set (profiler, self->profile_timers.cpu_time, cpu_time);
gpu_time = gsk_gl_profiler_end_gpu_region (self->gl_profiler); gpu_time = gsk_gl_profiler_end_gpu_region (self->gl_profiler);
GSK_NOTE (OPENGL, g_print ("GPU time: %g usec\n", (double) gpu_time / 1000.0)); gsk_profiler_timer_set (profiler, self->profile_timers.gpu_time, gpu_time);
gsk_profiler_push_samples (profiler);
#endif
out: out:
/* XXX: Add GdkDrawingContext API */ /* XXX: Add GdkDrawingContext API */
@ -886,4 +928,16 @@ gsk_gl_renderer_init (GskGLRenderer *self)
gsk_ensure_resources (); gsk_ensure_resources ();
graphene_matrix_init_identity (&self->mvp); graphene_matrix_init_identity (&self->mvp);
#ifdef G_ENABLE_DEBUG
{
GskProfiler *profiler = gsk_renderer_get_profiler (GSK_RENDERER (self));
self->profile_counters.frames = gsk_profiler_add_counter (profiler, "frames", "Frames", FALSE);
self->profile_counters.draw_calls = gsk_profiler_add_counter (profiler, "draws", "glDrawArrays", TRUE);
self->profile_timers.cpu_time = gsk_profiler_add_timer (profiler, "cpu-time", "CPU time", FALSE, TRUE);
self->profile_timers.gpu_time = gsk_profiler_add_timer (profiler, "gpu-time", "GPU time", FALSE, TRUE);
}
#endif
} }

View File

@ -39,6 +39,7 @@
#include "gskdebugprivate.h" #include "gskdebugprivate.h"
#include "gskglrendererprivate.h" #include "gskglrendererprivate.h"
#include "gskprofilerprivate.h"
#include "gskrendernodeprivate.h" #include "gskrendernodeprivate.h"
#include "gskenumtypes.h" #include "gskenumtypes.h"
@ -70,6 +71,8 @@ typedef struct
GskRenderNode *root_node; GskRenderNode *root_node;
GdkDisplay *display; GdkDisplay *display;
GskProfiler *profiler;
int scale_factor; int scale_factor;
gboolean is_realized : 1; gboolean is_realized : 1;
@ -489,6 +492,8 @@ gsk_renderer_init (GskRenderer *self)
graphene_matrix_init_identity (&priv->modelview); graphene_matrix_init_identity (&priv->modelview);
graphene_matrix_init_identity (&priv->projection); graphene_matrix_init_identity (&priv->projection);
priv->profiler = gsk_profiler_new ();
priv->auto_clear = TRUE; priv->auto_clear = TRUE;
priv->scale_factor = 1; priv->scale_factor = 1;
@ -927,8 +932,29 @@ gsk_renderer_render (GskRenderer *renderer,
priv->root_node = gsk_render_node_ref (root); priv->root_node = gsk_render_node_ref (root);
gsk_render_node_make_immutable (priv->root_node); gsk_render_node_make_immutable (priv->root_node);
#ifdef G_ENABLE_DEBUG
gsk_profiler_reset (priv->profiler);
#endif
GSK_RENDERER_GET_CLASS (renderer)->render (renderer, root, context); GSK_RENDERER_GET_CLASS (renderer)->render (renderer, root, context);
#ifdef G_ENABLE_DEBUG
if (GSK_DEBUG_CHECK (RENDERER))
{
GString *buf = g_string_new ("*** Frame stats ***\n\n");
gsk_profiler_append_counters (priv->profiler, buf);
g_string_append_c (buf, '\n');
gsk_profiler_append_timers (priv->profiler, buf);
g_string_append_c (buf, '\n');
g_print ("%s\n***\n\n", buf->str);
g_string_free (buf, TRUE);
}
#endif
g_clear_object (&priv->drawing_context); g_clear_object (&priv->drawing_context);
g_clear_pointer (&priv->root_node, gsk_render_node_unref); g_clear_pointer (&priv->root_node, gsk_render_node_unref);
} }
@ -1053,6 +1079,24 @@ gsk_renderer_create_render_node (GskRenderer *renderer)
return gsk_render_node_new (renderer); return gsk_render_node_new (renderer);
} }
/*< private >
* gsk_renderer_get_profiler:
* @renderer: a #GskRenderer
*
* Retrieves a pointer to the GskProfiler instance of the renderer.
*
* Returns: (transfer none): the profiler
*/
GskProfiler *
gsk_renderer_get_profiler (GskRenderer *renderer)
{
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
g_return_val_if_fail (GSK_IS_RENDERER (renderer), NULL);
return priv->profiler;
}
/** /**
* gsk_renderer_get_for_display: * gsk_renderer_get_for_display:
* @display: a #GdkDisplay * @display: a #GdkDisplay

View File

@ -20,6 +20,7 @@
#define __GSK_RENDERER_PRIVATE_H__ #define __GSK_RENDERER_PRIVATE_H__
#include "gskrenderer.h" #include "gskrenderer.h"
#include "gskprofilerprivate.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -49,6 +50,8 @@ gboolean gsk_renderer_is_realized (GskRenderer *renderer);
GskRenderNode * gsk_renderer_get_root_node (GskRenderer *renderer); GskRenderNode * gsk_renderer_get_root_node (GskRenderer *renderer);
GdkDrawingContext * gsk_renderer_get_drawing_context (GskRenderer *renderer); GdkDrawingContext * gsk_renderer_get_drawing_context (GskRenderer *renderer);
GskProfiler * gsk_renderer_get_profiler (GskRenderer *renderer);
G_END_DECLS G_END_DECLS
#endif /* __GSK_RENDERER_PRIVATE_H__ */ #endif /* __GSK_RENDERER_PRIVATE_H__ */