From 7d1876fd261f5039e25d468e0cc7dcbf63229912 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Thu, 11 Jun 2009 11:54:01 +0100 Subject: [PATCH] [cogl journal] Adds a --cogl-debug=batching option to trace batching Enabling this option makes Cogl trace how the journal is managing to batch your rectangles. The journal staggers how it emmits state to the GL driver and the batches will normally get smaller for each stage, but ideally you don't want to be in a situation where Cogl is only able to draw one quad per modelview change and draw call. E.g. this is a fairly ideal example: BATCHING: journal len = 101 BATCHING: vbo offset batch len = 101 BATCHING: material batch len = 101 BATCHING: modelview batch len = 101 This isn't: BATCHING: journal len = 1 BATCHING: vbo offset batch len = 1 BATCHING: material batch len = 1 BATCHING: modelview batch len = 1 BATCHING: journal len = 1 BATCHING: vbo offset batch len = 1 BATCHING: material batch len = 1 BATCHING: modelview batch len = 1 --- clutter/cogl/cogl-debug.h | 5 +++-- clutter/cogl/common/cogl-debug.c | 3 ++- clutter/cogl/common/cogl-primitives.c | 17 ++++++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/clutter/cogl/cogl-debug.h b/clutter/cogl/cogl-debug.h index 1785114b1..c8c1f566e 100644 --- a/clutter/cogl/cogl-debug.h +++ b/clutter/cogl/cogl-debug.h @@ -41,8 +41,9 @@ typedef enum { COGL_DEBUG_BLEND_STRINGS = 1 << 9, COGL_DEBUG_DISABLE_BATCHING = 1 << 10, COGL_DEBUG_FORCE_CLIENT_SIDE_MATRICES = 1 << 11, - COGL_DEBUG_DISABLE_VBOS = 1 << 12, - COGL_DEBUG_JOURNAL = 1 << 13 + COGL_DEBUG_DISABLE_VBOS = 1 << 12, + COGL_DEBUG_JOURNAL = 1 << 13, + COGL_DEBUG_BATCHING = 1 << 14 } CoglDebugFlags; #ifdef COGL_ENABLE_DEBUG diff --git a/clutter/cogl/common/cogl-debug.c b/clutter/cogl/common/cogl-debug.c index 82d5864a8..e093a344c 100644 --- a/clutter/cogl/common/cogl-debug.c +++ b/clutter/cogl/common/cogl-debug.c @@ -44,7 +44,8 @@ static const GDebugKey cogl_debug_keys[] = { { "disable-batching", COGL_DEBUG_DISABLE_BATCHING }, { "client-side-matrices", COGL_DEBUG_FORCE_CLIENT_SIDE_MATRICES }, { "disable-vbos", COGL_DEBUG_DISABLE_VBOS }, - { "journal", COGL_DEBUG_JOURNAL } + { "journal", COGL_DEBUG_JOURNAL }, + { "batching", COGL_DEBUG_BATCHING } }; static const gint n_cogl_debug_keys = G_N_ELEMENTS (cogl_debug_keys); diff --git a/clutter/cogl/common/cogl-primitives.c b/clutter/cogl/common/cogl-primitives.c index ed3561672..3b9f7f5d4 100644 --- a/clutter/cogl/common/cogl-primitives.c +++ b/clutter/cogl/common/cogl-primitives.c @@ -178,6 +178,9 @@ _cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start, { CoglJournalFlushState *state = data; + if (cogl_debug_flags & COGL_DEBUG_BATCHING) + g_print ("BATCHING: modelview batch len = %d\n", batch_len); + GE (glLoadMatrixf ((GLfloat *)&batch_start->model_view)); #ifdef HAVE_COGL_GL @@ -263,10 +266,8 @@ _cogl_journal_flush_material_and_entries (CoglJournalEntry *batch_start, _COGL_GET_CONTEXT (ctx, NO_RETVAL); -#if 0 - if (batch_len != 1) - g_debug ("batch len = %d", batch_len); -#endif + if (cogl_debug_flags & COGL_DEBUG_BATCHING) + g_print ("BATCHING: material batch len = %d\n", batch_len); _cogl_material_flush_gl_state (batch_start->material, &batch_start->flush_options); @@ -382,6 +383,9 @@ _cogl_journal_flush_vbo_offsets_and_entries (CoglJournalEntry *batch_start, _COGL_GET_CONTEXT (ctx, NO_RETVAL); + if (cogl_debug_flags & COGL_DEBUG_BATCHING) + g_print ("BATCHING: vbo offset batch len = %d\n", batch_len); + /* XXX NB: * Our journal's vertex data is arranged as follows: * 4 vertices per quad: @@ -418,7 +422,7 @@ _cogl_journal_flush_vbo_offsets_and_entries (CoglJournalEntry *batch_start, /* We only call gl{Vertex,Color,Texture}Pointer when the stride within * the VBO changes. (due to a change in the number of material layers) * While the stride remains constant we walk forward through the above - * VBO use a vertex offset passed to glDraw{Arrays,Elements} */ + * VBO using a vertex offset passed to glDraw{Arrays,Elements} */ state->vertex_offset = 0; if (cogl_debug_flags & COGL_DEBUG_JOURNAL) @@ -522,6 +526,9 @@ _cogl_journal_flush (void) if (ctx->journal->len == 0) return; + if (cogl_debug_flags & COGL_DEBUG_BATCHING && ctx->journal->len != 1) + g_print ("BATCHING: journal len = %d\n", ctx->journal->len); + /* Load all the vertex data we have accumulated so far into a single VBO * to minimize memory management costs within the GL driver. */ if (!vbo_fallback)