Timing for renderers
authorGunnar Sletta <gunnar.sletta@nokia.com>
Mon, 2 May 2011 05:13:00 +0000 (07:13 +0200)
committerGunnar Sletta <gunnar.sletta@nokia.com>
Mon, 2 May 2011 05:19:57 +0000 (07:19 +0200)
src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp
src/declarative/scenegraph/coreapi/qsgrenderer.cpp

index 05e5025..8b8eebc 100644 (file)
 #include <QtCore/qvarlengtharray.h>
 #include <QtGui/qapplication.h>
 #include <QtCore/qpair.h>
+#include <QtCore/QElapsedTimer>
 
 //#define FORCE_NO_REORDER
 
+// #define RENDERER_DEBUG
+#ifdef RENDERER_DEBUG
+#define DEBUG_THRESHOLD 0
+QElapsedTimer debugTimer;
+int materialChanges;
+int geometryNodesDrawn;
+#endif
+
 QT_BEGIN_NAMESPACE
 
 static bool nodeLessThan(QSGGeometryNode *a, QSGGeometryNode *b)
@@ -187,6 +196,13 @@ void QMLRenderer::render()
     }
 #endif
 
+#ifdef RENDERER_DEBUG
+    debugTimer.invalidate();
+    debugTimer.start();
+    geometryNodesDrawn = 0;
+    materialChanges = 0;
+#endif
+
     glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
     glDisable(GL_BLEND);
 
@@ -205,8 +221,16 @@ void QMLRenderer::render()
     glDisable(GL_SCISSOR_TEST);
     glClearColor(m_clear_color.redF(), m_clear_color.greenF(), m_clear_color.blueF(), m_clear_color.alphaF());
 
+#ifdef RENDERER_DEBUG
+    int debugtimeSetup = debugTimer.elapsed();
+#endif
+
     bindable()->clear(clearMode());
 
+#ifdef RENDERER_DEBUG
+    int debugtimeClear = debugTimer.elapsed();
+#endif
+
     QRect r = viewportRect();
     glViewport(r.x(), deviceRect().bottom() - r.bottom(), r.width(), r.height());
     m_projectionMatrix = projectMatrix();
@@ -228,6 +252,11 @@ void QMLRenderer::render()
         m_rebuild_lists = false;
     }
 
+#ifdef RENDERER_DEBUG
+    int debugtimeLists = debugTimer.elapsed();
+#endif
+
+
     if (m_needs_sorting) {
         qSort(m_opaqueNodes.begin(), m_opaqueNodes.end(),
               m_sort_front_to_back
@@ -236,6 +265,10 @@ void QMLRenderer::render()
         m_needs_sorting = false;
     }
 
+#ifdef RENDERER_DEBUG
+    int debugtimeSorting = debugTimer.elapsed();
+#endif
+
     m_renderOrderMatrix.setToIdentity();
     m_renderOrderMatrix.scale(1, 1, qreal(1) / m_currentRenderOrder);
 
@@ -252,6 +285,12 @@ void QMLRenderer::render()
         renderNodes(m_opaqueNodes);
     }
 
+#ifdef RENDERER_DEBUG
+    int debugtimeOpaque = debugTimer.elapsed();
+    int opaqueNodes = geometryNodesDrawn;
+    int opaqueMaterialChanges = materialChanges;
+#endif
+
     glEnable(GL_BLEND);
     glDepthMask(false);
 #ifdef QML_RUNTIME_TESTING
@@ -265,10 +304,33 @@ void QMLRenderer::render()
         renderNodes(m_transparentNodes);
     }
 
+#ifdef RENDERER_DEBUG
+    int debugtimeAlpha = debugTimer.elapsed();
+#endif
+
+
     if (m_currentProgram)
         m_currentProgram->deactivate();
 
     m_projectionMatrix.pop();
+
+#ifdef RENDERER_DEBUG
+    if (debugTimer.elapsed() > DEBUG_THRESHOLD) {
+        printf(" --- Renderer breakdown:\n"
+               "     - setup=%d, clear=%d, building=%d, sorting=%d, opaque=%d, alpha=%d\n"
+               "     - material changes: opaque=%d, alpha=%d, total=%d\n"
+               "     - geometry ndoes: opaque=%d, alpha=%d, total=%d\n",
+               debugtimeSetup,
+               debugtimeClear - debugtimeSetup,
+               debugtimeLists - debugtimeClear,
+               debugtimeSorting - debugtimeLists,
+               debugtimeOpaque - debugtimeSorting,
+               debugtimeAlpha - debugtimeOpaque,
+               opaqueMaterialChanges, materialChanges - opaqueMaterialChanges, materialChanges,
+               opaqueNodes, geometryNodesDrawn - opaqueNodes, geometryNodesDrawn);
+    }
+#endif
+
 }
 
 class Foo : public QPair<int, QSGGeometryNode *>
@@ -426,6 +488,10 @@ void QMLRenderer::renderNodes(const QVector<QSGGeometryNode *> &list)
             m_currentProgram->activate();
             //++programChangeCount;
             updates |= (QSGMaterialShader::RenderState::DirtyMatrix | QSGMaterialShader::RenderState::DirtyOpacity);
+
+#ifdef RENDERER_DEBUG
+            materialChanges++;
+#endif
         }
 
         bool changeRenderOrder = currentRenderOrder != geomNode->renderOrder();
@@ -449,6 +515,10 @@ void QMLRenderer::renderNodes(const QVector<QSGGeometryNode *> &list)
         const QSGGeometry *g = geomNode->geometry();
         bindGeometry(program, g);
         draw(geomNode);
+
+#ifdef RENDERER_DEBUG
+        geometryNodesDrawn++;
+#endif
     }
     //qDebug("Clip: %i, shader program: %i, material: %i times changed while drawing %s items",
     //    clipChangeCount, programChangeCount, materialChangeCount,
index eb7b830..04c0817 100644 (file)
@@ -243,8 +243,7 @@ void QSGRenderer::renderScene(const Bindable &bindable)
     m_bindable = 0;
 
 #ifdef QSG_RENDERER_TIMING
-    printf("Frame #%d: Breakdown of frametime: preprocess=%d, updates=%d, binding=%d, render=%d, total=%d\n",
-           ++frameNumber,
+    printf(" - Breakdown of frametime: preprocess=%d, updates=%d, binding=%d, render=%d, total=%d\n",
            preprocessTime,
            updatePassTime - preprocessTime,
            bindTime - updatePassTime,