From: David Gow Date: Sun, 27 Apr 2014 13:59:06 +0000 (+0800) Subject: Add GPU performance queries. X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=6229c121e63cf53459cf82cb1eaa8af063da592a;p=ipdf%2Fcode.git Add GPU performance queries. --- diff --git a/bin/ipdf b/bin/ipdf index 29d876f..a39e28c 100755 Binary files a/bin/ipdf and b/bin/ipdf differ diff --git a/src/main.h b/src/main.h index e6100ed..6821399 100644 --- a/src/main.h +++ b/src/main.h @@ -70,7 +70,8 @@ inline void MainLoop(Document & doc, const Rect & bounds = Rect(0,0,1,1), const { scr.Clear(); view.Render(scr.ViewportWidth(), scr.ViewportHeight()); - scr.DebugFontPrintF("[CPU] Render took %lf ms (%lf FPS)\n", (SDL_GetPerformanceCounter() - init_time)* 1000.0/SDL_GetPerformanceFrequency(), SDL_GetPerformanceFrequency()/(SDL_GetPerformanceCounter() - init_time)); + scr.DebugFontPrintF("[CPU] Render took %lf ms (%lf FPS)\n", (scr.GetLastFrameTimeCPU())* 1000.0, 1.0/scr.GetLastFrameTimeCPU()); + scr.DebugFontPrintF("[GPU] Render took %lf ms (%lf FPS)\n", (scr.GetLastFrameTimeGPU())* 1000.0, 1.0/scr.GetLastFrameTimeGPU()); scr.DebugFontPrintF("View bounds: %s\n", view.GetBounds().Str().c_str()); if (view.UsingGPUTransform()) { diff --git a/src/screen.cpp b/src/screen.cpp index 40754b3..9687c55 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -94,6 +94,12 @@ Screen::Screen() Fatal("Your system does not support the ARB_explicit_attrib_location extension, which is required."); } + m_frame_begin_time = SDL_GetPerformanceCounter(); + m_last_frame_time = 0; + m_last_frame_gpu_timer = 0; + glGenQueries(1, &m_frame_gpu_timer); + glBeginQuery(GL_TIME_ELAPSED, m_frame_gpu_timer); + glDebugMessageCallback(opengl_debug_callback, 0); GLuint default_vao; @@ -230,7 +236,24 @@ void Screen::Present() { if (m_debug_font_atlas) DebugFontFlush(); + m_last_frame_time = SDL_GetPerformanceCounter() - m_frame_begin_time; + glEndQuery(GL_TIME_ELAPSED); SDL_GL_SwapWindow(m_window); + m_frame_begin_time = SDL_GetPerformanceCounter(); + if (m_last_frame_gpu_timer) + glDeleteQueries(1, &m_last_frame_gpu_timer); + m_last_frame_gpu_timer = m_frame_gpu_timer; + glGenQueries(1, &m_frame_gpu_timer); + glBeginQuery(GL_TIME_ELAPSED, m_frame_gpu_timer); +} + +double Screen::GetLastFrameTimeGPU() const +{ + if (!m_last_frame_gpu_timer) + return 0; + uint64_t frame_time_ns; + glGetQueryObjectui64v(m_last_frame_gpu_timer, GL_QUERY_RESULT, &frame_time_ns); + return frame_time_ns/1000000000.0; } void Screen::ScreenShot(const char * filename) const diff --git a/src/screen.h b/src/screen.h index d918dd1..f66c7aa 100644 --- a/src/screen.h +++ b/src/screen.h @@ -59,6 +59,11 @@ namespace IPDF void ScreenShot(const char * filename) const; void RenderBMP(const char * filename) const; + + // Returns the CPU time (in seconds) it took to render the last completed frame. + double GetLastFrameTimeCPU() const { return m_last_frame_time / SDL_GetPerformanceFrequency(); } + // Returns the GPU time (in seconds) it took to render the last completed frame. + double GetLastFrameTimeGPU() const; private: void ResizeViewport(int width, int height); void DebugFontFlush(); @@ -67,6 +72,11 @@ namespace IPDF int m_last_mouse_x; int m_last_mouse_y; + double m_last_frame_time; + double m_frame_begin_time; + GLuint m_frame_gpu_timer; + GLuint m_last_frame_gpu_timer; + int m_viewport_width; int m_viewport_height; SDL_Window *m_window;