From 6a3cd6378a833e15dc0af76d14d1602a34049824 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 30 Aug 2014 14:33:06 +0200 Subject: [PATCH] - found out that reading the CPU's real time clock costs a not insignificant amount of time so this is now only done when either the benchmark command is running or the rendertimes are shown. --- src/gl/scene/gl_scene.cpp | 29 ++++++++++++++--------------- src/gl/utility/gl_clock.cpp | 11 ++++++++++- src/gl/utility/gl_clock.h | 6 ++++-- src/stats.h | 4 ++++ 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 89d505168..f9b713335 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -351,11 +351,11 @@ void FGLRenderer::RenderScene(int recursion) if (mLightCount > 0 && gl_fixedcolormap == CM_DEFAULT && gl_lights && !(gl.flags & RFL_BUFFER_STORAGE)) { GLRenderer->mLights->Begin(); - gl_drawinfo->drawlists[GLDL_PLAINWALLS].Draw(GLPASS_LIGHTSONLY); - gl_drawinfo->drawlists[GLDL_PLAINFLATS].Draw(GLPASS_LIGHTSONLY); - gl_drawinfo->drawlists[GLDL_MASKEDWALLS].Draw(GLPASS_LIGHTSONLY); - gl_drawinfo->drawlists[GLDL_MASKEDFLATS].Draw(GLPASS_LIGHTSONLY); - gl_drawinfo->drawlists[GLDL_MASKEDWALLSOFS].Draw(GLPASS_LIGHTSONLY); + gl_drawinfo->drawlists[GLDL_PLAINWALLS].DrawWalls(GLPASS_LIGHTSONLY); + gl_drawinfo->drawlists[GLDL_PLAINFLATS].DrawFlats(GLPASS_LIGHTSONLY); + gl_drawinfo->drawlists[GLDL_MASKEDWALLS].DrawWalls(GLPASS_LIGHTSONLY); + gl_drawinfo->drawlists[GLDL_MASKEDFLATS].DrawFlats(GLPASS_LIGHTSONLY); + gl_drawinfo->drawlists[GLDL_MASKEDWALLSOFS].DrawWalls(GLPASS_LIGHTSONLY); gl_drawinfo->drawlists[GLDL_TRANSLUCENTBORDER].Draw(GLPASS_LIGHTSONLY); gl_drawinfo->drawlists[GLDL_TRANSLUCENT].Draw(GLPASS_LIGHTSONLY); GLRenderer->mLights->Finish(); @@ -379,8 +379,8 @@ void FGLRenderer::RenderScene(int recursion) gl_RenderState.EnableTexture(gl_texture); gl_RenderState.EnableBrightmap(true); - gl_drawinfo->drawlists[GLDL_PLAINWALLS].Draw(pass); - gl_drawinfo->drawlists[GLDL_PLAINFLATS].Draw(pass); + gl_drawinfo->drawlists[GLDL_PLAINWALLS].DrawWalls(pass); + gl_drawinfo->drawlists[GLDL_PLAINFLATS].DrawFlats(pass); // Part 2: masked geometry. This is set up so that only pixels with alpha>gl_mask_threshold will show @@ -390,15 +390,15 @@ void FGLRenderer::RenderScene(int recursion) gl_RenderState.SetTextureMode(TM_MASK); } gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); - gl_drawinfo->drawlists[GLDL_MASKEDWALLS].Draw(pass); - gl_drawinfo->drawlists[GLDL_MASKEDFLATS].Draw(pass); + gl_drawinfo->drawlists[GLDL_MASKEDWALLS].DrawWalls(pass); + gl_drawinfo->drawlists[GLDL_MASKEDFLATS].DrawFlats(pass); // Part 3: masked geometry with polygon offset. This list is empty most of the time so only waste time on it when in use. if (gl_drawinfo->drawlists[GLDL_MASKEDWALLSOFS].Size() > 0) { glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(-1.0f, -128.0f); - gl_drawinfo->drawlists[GLDL_MASKEDWALLSOFS].Draw(pass); + gl_drawinfo->drawlists[GLDL_MASKEDWALLSOFS].DrawWalls(pass); glDisable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0, 0); } @@ -413,10 +413,8 @@ void FGLRenderer::RenderScene(int recursion) glPolygonOffset(-1.0f, -128.0f); glDepthMask(false); - for(int i=0; idrawlists[i].Draw(GLPASS_DECALS); - } + // this is the only geometry type on which decals can possibly appear + gl_drawinfo->drawlists[GLDL_PLAINWALLS].Draw(GLPASS_DECALS); gl_RenderState.SetTextureMode(TM_MODULATE); @@ -439,8 +437,8 @@ void FGLRenderer::RenderScene(int recursion) glPolygonOffset(0.0f, 0.0f); glDisable(GL_POLYGON_OFFSET_FILL); - RenderAll.Unclock(); + } //----------------------------------------------------------------------------- @@ -821,6 +819,7 @@ void FGLRenderer::RenderView (player_t* player) OpenGLFrameBuffer* GLTarget = static_cast(screen); AActor *&LastCamera = GLTarget->LastCamera; + checkBenchActive(); if (player->camera != LastCamera) { // If the camera changed don't interpolate diff --git a/src/gl/utility/gl_clock.cpp b/src/gl/utility/gl_clock.cpp index d8d3c28be..48c21dde2 100644 --- a/src/gl/utility/gl_clock.cpp +++ b/src/gl/utility/gl_clock.cpp @@ -221,4 +221,13 @@ CCMD(bench) switchfps = false; } C_HideConsole (); -} \ No newline at end of file +} + +bool gl_benching = false; + +void checkBenchActive() +{ + FStat *stat = FStat::FindStat("rendertimes"); + gl_benching = ((stat != NULL && stat->isActive()) || printstats); +} + diff --git a/src/gl/utility/gl_clock.h b/src/gl/utility/gl_clock.h index 604a40a02..f12cf1ef9 100644 --- a/src/gl/utility/gl_clock.h +++ b/src/gl/utility/gl_clock.h @@ -9,6 +9,7 @@ extern double gl_SecondsPerCycle; extern double gl_MillisecPerCycle; +extern bool gl_benching; __forceinline long long GetClockCycle () @@ -75,13 +76,13 @@ public: // Not using QueryPerformanceCounter directly, so we don't need // to pull in the Windows headers for every single file that // wants to do some profiling. - long long time = GetClockCycle(); + long long time = (gl_benching? GetClockCycle() : 0); Counter -= time; } __forceinline void Unclock() { - long long time = GetClockCycle(); + long long time = (gl_benching? GetClockCycle() : 0); Counter += time; } @@ -118,6 +119,7 @@ extern int vertexcount, flatvertices, flatprimitives; void ResetProfilingData(); void CheckBench(); +void checkBenchActive(); #endif \ No newline at end of file diff --git a/src/stats.h b/src/stats.h index ed493188b..24ab24cdf 100644 --- a/src/stats.h +++ b/src/stats.h @@ -267,6 +267,10 @@ public: virtual FString GetStats () = 0; void ToggleStat (); + bool isActive() const + { + return m_Active; + } static void PrintStat (); static FStat *FindStat (const char *name);