From bc579f2605e8cdf4968f91ef87ca8f37db18eea2 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 18 Jan 2016 09:53:41 -0800 Subject: [PATCH] Clening up the gpu::Timer behavior, now need a way to show it --- libraries/gpu/src/gpu/GLBackendQuery.cpp | 7 ++- libraries/gpu/src/gpu/Query.cpp | 45 +++++++++---------- libraries/gpu/src/gpu/Query.h | 11 +++-- .../render-utils/src/AmbientOcclusionEffect.h | 2 + .../render-utils/src/DeferredLightingEffect.h | 2 +- 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendQuery.cpp b/libraries/gpu/src/gpu/GLBackendQuery.cpp index ca7b96a7e5..f3a81d504c 100644 --- a/libraries/gpu/src/gpu/GLBackendQuery.cpp +++ b/libraries/gpu/src/gpu/GLBackendQuery.cpp @@ -98,9 +98,12 @@ void GLBackend::do_getQuery(Batch& batch, size_t paramOffset) { glGetQueryObjectui64vEXT(glquery->_qo, GL_QUERY_RESULT, &glquery->_result); #endif #else - glGetQueryObjectui64v(glquery->_qo, GL_QUERY_RESULT, &glquery->_result); + glGetQueryObjectui64v(glquery->_qo, GL_QUERY_RESULT_AVAILABLE, &glquery->_result); + if (glquery->_result == GL_TRUE) { + glGetQueryObjectui64v(glquery->_qo, GL_QUERY_RESULT, &glquery->_result); + query->triggerReturnHandler(glquery->_result); + } #endif - query->triggerReturnHandler(glquery->_result); (void)CHECK_GL_ERROR(); } } diff --git a/libraries/gpu/src/gpu/Query.cpp b/libraries/gpu/src/gpu/Query.cpp index 626cb192d7..24b8bcebd7 100644 --- a/libraries/gpu/src/gpu/Query.cpp +++ b/libraries/gpu/src/gpu/Query.cpp @@ -37,32 +37,31 @@ void Query::triggerReturnHandler(uint64_t queryResult) { Timer::Timer() { - _timerQueries.resize(6, std::make_shared([&] (const Query& query) { - auto elapsedTime = query.getElapsedTime(); - _movingAverage.addSample(elapsedTime); - - static int frameNum = 0; - frameNum++; - frameNum %= 10; - if (frameNum == 0) { - auto value = _movingAverage.average; - qCDebug(gpulogging) << "AO on gpu = " << value; - } - })); - + for (int i = 0; i < QUERY_QUEUE_SIZE; i++) { + _timerQueries.push_back(std::make_shared([&, i] (const Query& query) { + _tailIndex ++; + auto elapsedTime = query.getElapsedTime(); + _movingAverage.addSample(elapsedTime); + })); + } } void Timer::begin(gpu::Batch& batch) { - batch.beginQuery(_timerQueries[_currentTimerQueryIndex]); + _headIndex++; + batch.beginQuery(_timerQueries[rangeIndex(_headIndex)]); } void Timer::end(gpu::Batch& batch) { - batch.endQuery(_timerQueries[_currentTimerQueryIndex]); - _currentTimerQueryIndex = (_currentTimerQueryIndex + 1) % _timerQueries.size(); - - auto returnQuery = _timerQueries[_currentTimerQueryIndex]; - batch.getQuery(returnQuery); + if (_headIndex < 0) { + return; + } + batch.endQuery(_timerQueries[rangeIndex(_headIndex)]); + + if (_tailIndex < 0) { + _tailIndex = _headIndex; + } + + // Pull the previous tail query hopping to see it return + if (_tailIndex != _headIndex) { + batch.getQuery(_timerQueries[rangeIndex(_tailIndex)]); + } } - -void Timer::onQueryReturned(const Query& query) { - -} \ No newline at end of file diff --git a/libraries/gpu/src/gpu/Query.h b/libraries/gpu/src/gpu/Query.h index b468ba95ed..5bfb21cb38 100644 --- a/libraries/gpu/src/gpu/Query.h +++ b/libraries/gpu/src/gpu/Query.h @@ -56,12 +56,15 @@ namespace gpu { double getAverage() const; protected: - - void onQueryReturned(const Query& query); + + static const int QUERY_QUEUE_SIZE = 4; gpu::Queries _timerQueries; - int _currentTimerQueryIndex = 0; - MovingAverage _movingAverage; + int _headIndex = -1; + int _tailIndex = -1; + MovingAverage _movingAverage; + + int rangeIndex(int index) const { return (index % QUERY_QUEUE_SIZE); } }; }; diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h index 1274995f48..657e72cf31 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -56,6 +56,8 @@ public: float getBlurDeviation() const { return _parametersBuffer.get()._blurInfo.z; } + double getTimerAverage() const { return _gpuTimer.getAverage(); } + using JobModel = render::Task::Job::Model; private: diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index cb746153a1..cea12f3f3b 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -50,7 +50,7 @@ public: void setGlobalAtmosphere(const model::AtmospherePointer& atmosphere) { _atmosphere = atmosphere; } void setGlobalSkybox(const model::SkyboxPointer& skybox); - + private: DeferredLightingEffect() = default;