From 89ec5471617809473d5d8b91103f10bf35b91a44 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 14 Jul 2016 18:20:20 -0700 Subject: [PATCH] Trying to get the gpu timer to work correctly --- libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp | 11 +++++++---- libraries/gpu-gl/src/gpu/gl/GLQuery.h | 14 ++++++++++---- .../gpu-gl/src/gpu/gl41/GL41BackendQuery.cpp | 2 +- .../gpu-gl/src/gpu/gl45/GL45BackendQuery.cpp | 4 ++-- libraries/gpu/src/gpu/Query.cpp | 2 +- scripts/developer/utilities/render/stats.qml | 18 +++++++++++++++++- 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp index 344f380339..45e0d8d53f 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp @@ -18,7 +18,7 @@ void GLBackend::do_beginQuery(Batch& batch, size_t paramOffset) { auto query = batch._queries.get(batch._params[paramOffset]._uint); GLQuery* glquery = syncGPUObject(*query); if (glquery) { - glBeginQuery(GL_TIME_ELAPSED, glquery->_qo); + glQueryCounter(glquery->_beginqo, GL_TIMESTAMP); (void)CHECK_GL_ERROR(); } } @@ -27,7 +27,7 @@ void GLBackend::do_endQuery(Batch& batch, size_t paramOffset) { auto query = batch._queries.get(batch._params[paramOffset]._uint); GLQuery* glquery = syncGPUObject(*query); if (glquery) { - glEndQuery(GL_TIME_ELAPSED); + glQueryCounter(glquery->_endqo, GL_TIMESTAMP); (void)CHECK_GL_ERROR(); } } @@ -36,9 +36,12 @@ void GLBackend::do_getQuery(Batch& batch, size_t paramOffset) { auto query = batch._queries.get(batch._params[paramOffset]._uint); GLQuery* glquery = syncGPUObject(*query); if (glquery) { - glGetQueryObjectui64v(glquery->_qo, GL_QUERY_RESULT_AVAILABLE, &glquery->_result); + glGetQueryObjectui64v(glquery->_endqo, GL_QUERY_RESULT_AVAILABLE, &glquery->_result); if (glquery->_result == GL_TRUE) { - glGetQueryObjectui64v(glquery->_qo, GL_QUERY_RESULT, &glquery->_result); + GLuint64 start, end; + glGetQueryObjectui64v(glquery->_beginqo, GL_QUERY_RESULT, &start); + glGetQueryObjectui64v(glquery->_endqo, GL_QUERY_RESULT, &end); + glquery->_result = end - start; query->triggerReturnHandler(glquery->_result); } (void)CHECK_GL_ERROR(); diff --git a/libraries/gpu-gl/src/gpu/gl/GLQuery.h b/libraries/gpu-gl/src/gpu/gl/GLQuery.h index 7b14b227ab..93f5ab20b3 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLQuery.h +++ b/libraries/gpu-gl/src/gpu/gl/GLQuery.h @@ -41,15 +41,21 @@ public: return 0; } - return object->_qo; + return object->_endqo; } - const GLuint& _qo { _id }; + const GLuint& _endqo = { _id }; + const GLuint _beginqo = { 0 }; GLuint64 _result { (GLuint64)-1 }; protected: - GLQuery(const Query& query, GLuint id) : Parent(query, id) {} - ~GLQuery() { if (_id) { glDeleteQueries(1, &_id); } } + GLQuery(const Query& query, GLuint endId, GLuint beginId) : Parent(query, endId), _beginqo(beginId){} + ~GLQuery() { + if (_id) { + GLuint ids[2] = { _endqo, _beginqo }; + glDeleteQueries(2, ids); + } + } }; } } diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendQuery.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendQuery.cpp index 478d210535..8cc47a43a4 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendQuery.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendQuery.cpp @@ -25,7 +25,7 @@ public: } GL41Query(const Query& query) - : Parent(query, allocateQuery()) { } + : Parent(query, allocateQuery(), allocateQuery()) { } }; gl::GLQuery* GL41Backend::syncGPUObject(const Query& query) { diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendQuery.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendQuery.cpp index a7a7c26bed..9e808aeb82 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendQuery.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendQuery.cpp @@ -19,12 +19,12 @@ class GL45Query : public gpu::gl::GLQuery { public: static GLuint allocateQuery() { GLuint result; - glCreateQueries(GL_TIME_ELAPSED, 1, &result); + glCreateQueries(GL_TIMESTAMP, 1, &result); return result; } GL45Query(const Query& query) - : Parent(query, allocateQuery()) { } + : Parent(query, allocateQuery(), allocateQuery()){} }; gl::GLQuery* GL45Backend::syncGPUObject(const Query& query) { diff --git a/libraries/gpu/src/gpu/Query.cpp b/libraries/gpu/src/gpu/Query.cpp index 2e28dcd061..76c239b1e0 100644 --- a/libraries/gpu/src/gpu/Query.cpp +++ b/libraries/gpu/src/gpu/Query.cpp @@ -25,7 +25,7 @@ Query::~Query() } double Query::getElapsedTime() const { - return ((double) _queryResult) * 0.000001; + return ((double)_queryResult) / 1000000.0; } void Query::triggerReturnHandler(uint64_t queryResult) { diff --git a/scripts/developer/utilities/render/stats.qml b/scripts/developer/utilities/render/stats.qml index 322af5389e..27f7580b57 100644 --- a/scripts/developer/utilities/render/stats.qml +++ b/scripts/developer/utilities/render/stats.qml @@ -241,7 +241,23 @@ Item { color: "#E2334D" } ] - } + } + PlotPerf { + title: "Timing" + height: parent.evalEvenHeight() + object: parent.drawOpaqueConfig + valueUnit: "ms" + valueScale: 1 + valueNumDigits: "4" + plots: [ + { + object: Render.getConfig("RenderDeferredTask"), + prop: "gpuTime", + label: "RenderFrameGPU", + color: "#00FFFF" + } + ] + } } }