From 8f96729e0652e72d3f9e617f00f7b3f68c03ac47 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 13 May 2018 09:48:19 +0200 Subject: [PATCH] - fixed portal benchmarking and added separate output for 2D and finishing the main scene. --- src/gl/renderer/gl_renderer.cpp | 9 ++++++++- src/gl/scene/gl_portal.cpp | 17 +++-------------- src/gl/system/gl_framebuffer.cpp | 7 ++++++- src/hwrenderer/utility/hw_clock.cpp | 16 +++++++++++----- src/hwrenderer/utility/hw_clock.h | 2 +- src/stats.h | 24 ++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 6143842059..b04ba5e79d 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -36,6 +36,7 @@ #include "d_player.h" #include "a_dynlight.h" #include "swrenderer/r_swscene.h" +#include "hwrenderer/utility/hw_clock.h" #include "gl/system/gl_interface.h" #include "gl/system/gl_framebuffer.h" @@ -463,6 +464,7 @@ CVAR(Bool, gl_aalines, false, CVAR_ARCHIVE) void FGLRenderer::Draw2D(F2DDrawer *drawer) { + twoD.Clock(); if (buffersActive) { mBuffers->BindCurrentFB(); @@ -491,7 +493,11 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) auto &indices = drawer->mIndices; auto &commands = drawer->mData; - if (commands.Size() == 0) return; + if (commands.Size() == 0) + { + twoD.Unclock(); + return; + } for (auto &v : vertices) { @@ -633,4 +639,5 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) gl_RenderState.ResetColor(); gl_RenderState.Apply(); delete vb; + twoD.Unclock(); } diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index c7ea025066..4556f75e5b 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -163,12 +163,11 @@ void GLPortal::DrawPortalStencil() bool GLPortal::Start(bool usestencil, bool doquery) { rendered_portals++; -// PortalAll.Clock(); + Clocker c(PortalAll); if (usestencil) { if (!gl_portals) { -// PortalAll.Unclock(); return false; } @@ -226,7 +225,6 @@ bool GLPortal::Start(bool usestencil, bool doquery) // restore default stencil op. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glStencilFunc(GL_EQUAL, recursion, ~0); // draw sky into stencil - PortalAll.Unclock(); return false; } } @@ -285,7 +283,6 @@ bool GLPortal::Start(bool usestencil, bool doquery) GLRenderer->mCurrentPortal = this; if (PrevPortal != NULL) PrevPortal->PushState(); -// PortalAll.Unclock(); return true; } @@ -326,7 +323,7 @@ void GLPortal::End(bool usestencil) { bool needdepth = NeedDepthBuffer(); - PortalAll.Clock(); + Clocker c(PortalAll); if (PrevPortal != NULL) PrevPortal->PopState(); GLRenderer->mCurrentPortal = PrevPortal; GLRenderer->mClipPortal = PrevClipPortal; @@ -425,7 +422,6 @@ void GLPortal::End(bool usestencil) } glDepthFunc(GL_LESS); } - PortalAll.Unclock(); } @@ -1151,7 +1147,7 @@ GLHorizonPortal::GLHorizonPortal(GLHorizonInfo * pt, bool local) //----------------------------------------------------------------------------- void GLHorizonPortal::DrawContents() { - PortalAll.Clock(); + Clocker c(PortalAll); FMaterial * gltexture; PalEntry color; @@ -1162,7 +1158,6 @@ void GLHorizonPortal::DrawContents() if (!gltexture) { ClearScreen(); - PortalAll.Unclock(); return; } gl_RenderState.SetCameraPos(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z); @@ -1198,8 +1193,6 @@ void GLHorizonPortal::DrawContents() GLRenderer->mVBO->RenderArray(GL_TRIANGLE_STRIP, voffset + vcount, 10); gl_RenderState.EnableTextureMatrix(false); - PortalAll.Unclock(); - } @@ -1225,7 +1218,6 @@ void GLHorizonPortal::DrawContents() void GLEEHorizonPortal::DrawContents() { - PortalAll.Clock(); sector_t *sector = portal->mOrigin; if (sector->GetTexture(sector_t::floor) == skyflatnum || sector->GetTexture(sector_t::ceiling) == skyflatnum) @@ -1263,9 +1255,6 @@ void GLEEHorizonPortal::DrawContents() GLHorizonPortal floor(&horz, true); floor.DrawContents(); } - - - } void GLPortal::Initialize() diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 51441fd8fd..69d6445435 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -149,8 +149,13 @@ void OpenGLFrameBuffer::InitializeState() void OpenGLFrameBuffer::Update() { + twoD.Reset(); + Flush3D.Reset(); + DrawRateStuff(); + Flush3D.Clock(); GLRenderer->Flush(); + Flush3D.Unclock(); Swap(); CheckBench(); @@ -244,7 +249,7 @@ uint32_t OpenGLFrameBuffer::GetCaps() // legacy mode always has truecolor because palette tonemap is not available FlagSet |= RFF_TRUECOLOR; } - else if (!(FGLRenderBuffers::IsEnabled())) + else if (!RenderBuffersEnabled()) { // truecolor is always available when renderbuffers are unavailable because palette tonemap is not possible FlagSet |= RFF_TRUECOLOR | RFF_MATSHADER | RFF_BRIGHTMAP; diff --git a/src/hwrenderer/utility/hw_clock.cpp b/src/hwrenderer/utility/hw_clock.cpp index e015bae829..f0480f2c45 100644 --- a/src/hwrenderer/utility/hw_clock.cpp +++ b/src/hwrenderer/utility/hw_clock.cpp @@ -50,6 +50,7 @@ glcycle_t ProcessAll; glcycle_t RenderAll; glcycle_t Dirty; glcycle_t drawcalls; +glcycle_t twoD, Flush3D; int vertexcount, flatvertices, flatprimitives; int rendered_lines,rendered_flats,rendered_sprites,render_vertexsplit,render_texsplit,rendered_decals, rendered_portals; @@ -88,13 +89,18 @@ static void AppendRenderTimes(FString &str) double clipwall = ClipWall.TimeMS() - SetupWall.TimeMS(); double bsp = Bsp.TimeMS() - ClipWall.TimeMS() - SetupFlat.TimeMS() - SetupSprite.TimeMS(); - str.AppendFormat("W: Render=%2.3f, Setup=%2.3f, Clip=%2.3f\n" + str.AppendFormat("BSP = %2.3f, Clip=%2.3f\n" + "W: Render=%2.3f, Setup=%2.3f\n" "F: Render=%2.3f, Setup=%2.3f\n" "S: Render=%2.3f, Setup=%2.3f\n" - "All=%2.3f, Render=%2.3f, Setup=%2.3f, BSP = %2.3f, Portal=%2.3f, Drawcalls=%2.3f, Finish=%2.3f\n", - RenderWall.TimeMS(), setupwall, clipwall, RenderFlat.TimeMS(), SetupFlat.TimeMS(), - RenderSprite.TimeMS(), SetupSprite.TimeMS(), All.TimeMS() + Finish.TimeMS(), RenderAll.TimeMS(), - ProcessAll.TimeMS(), bsp, PortalAll.TimeMS(), drawcalls.TimeMS(), Finish.TimeMS()); + "2D: %2.3f Finish3D: %2.3f\n" + "All=%2.3f, Render=%2.3f, Setup=%2.3f, Portal=%2.3f, Drawcalls=%2.3f, Finish=%2.3f\n", + bsp, clipwall, + RenderWall.TimeMS(), setupwall, + RenderFlat.TimeMS(), SetupFlat.TimeMS(), + RenderSprite.TimeMS(), SetupSprite.TimeMS(), + twoD.TimeMS(), Flush3D.TimeMS() - twoD.TimeMS(), + All.TimeMS() + Finish.TimeMS(), RenderAll.TimeMS(), ProcessAll.TimeMS(), PortalAll.TimeMS(), drawcalls.TimeMS(), Finish.TimeMS()); } static void AppendRenderStats(FString &out) diff --git a/src/hwrenderer/utility/hw_clock.h b/src/hwrenderer/utility/hw_clock.h index 2c0448eed9..7cb82fedcd 100644 --- a/src/hwrenderer/utility/hw_clock.h +++ b/src/hwrenderer/utility/hw_clock.h @@ -12,7 +12,7 @@ extern glcycle_t All, Finish, PortalAll, Bsp; extern glcycle_t ProcessAll; extern glcycle_t RenderAll; extern glcycle_t Dirty; -extern glcycle_t drawcalls; +extern glcycle_t drawcalls, twoD, Flush3D; extern int iter_dlightf, iter_dlight, draw_dlight, draw_dlightf; extern int rendered_lines,rendered_flats,rendered_sprites,rendered_decals,render_vertexsplit,render_texsplit; diff --git a/src/stats.h b/src/stats.h index e9f11aed0e..4eefdc9a9f 100644 --- a/src/stats.h +++ b/src/stats.h @@ -212,6 +212,30 @@ public: } }; +// Helper for code that uses a timer and has multiple exit points. +class Clocker +{ +public: + + explicit Clocker(glcycle_t& clck) + : clock(clck) + { + clock.Clock(); + } + + ~Clocker() + { // unlock + clock.Unclock(); + } + + Clocker(const Clocker&) = delete; + Clocker& operator=(const Clocker&) = delete; +private: + glcycle_t & clock; +}; + + + class FStat { public: