diff --git a/examples/utilities/tools/renderEngineDebug.js b/examples/utilities/tools/renderEngineDebug.js index 42786aa5f4..2d615872f6 100755 --- a/examples/utilities/tools/renderEngineDebug.js +++ b/examples/utilities/tools/renderEngineDebug.js @@ -104,12 +104,12 @@ panel.newSlider("Tone Mapping Exposure", -10, 10, panel.newSlider("Ambient Occlusion Radius", 0.0, 2.0, function (value) { Render.ambientOcclusion.radius = value; }, function() { return Render.ambientOcclusion.radius; }, - function (value) { return (value); }); + function (value) { return (value.toFixed(2)); }); panel.newSlider("Ambient Occlusion Level", 0.0, 1.0, function (value) { Render.ambientOcclusion.level = value; }, function() { return Render.ambientOcclusion.level; }, - function (value) { return (value); }); + function (value) { return (value.toFixed(2)); }); panel.newSlider("Ambient Occlusion Num Samples", 1, 32, function (value) { Render.ambientOcclusion.numSamples = value; }, @@ -119,7 +119,7 @@ panel.newSlider("Ambient Occlusion Num Samples", 1, 32, panel.newSlider("Ambient Occlusion Num Spiral Turns", 0.0, 30.0, function (value) { Render.ambientOcclusion.numSpiralTurns = value; }, function() { return Render.ambientOcclusion.numSpiralTurns; }, - function (value) { return (value); }); + function (value) { return (value.toFixed(2)); }); panel.newCheckbox("Ambient Occlusion Dithering", function (value) { Render.ambientOcclusion.ditheringEnabled = value; }, @@ -129,7 +129,7 @@ panel.newCheckbox("Ambient Occlusion Dithering", panel.newSlider("Ambient Occlusion Edge Sharpness", 0.0, 1.0, function (value) { Render.ambientOcclusion.edgeSharpness = value; }, function() { return Render.ambientOcclusion.edgeSharpness; }, - function (value) { return (value); }); + function (value) { return (value.toFixed(2)); }); panel.newSlider("Ambient Occlusion Blur Radius", 0.0, 6.0, function (value) { Render.ambientOcclusion.blurRadius = value; }, @@ -139,7 +139,14 @@ panel.newSlider("Ambient Occlusion Blur Radius", 0.0, 6.0, panel.newSlider("Ambient Occlusion Blur Deviation", 0.0, 3.0, function (value) { Render.ambientOcclusion.blurDeviation = value; }, function() { return Render.ambientOcclusion.blurDeviation; }, - function (value) { return (value); }); + function (value) { return (value.toFixed(2)); }); + + +panel.newSlider("Ambient Occlusion GPU time", 0.0, 10.0, + function (value) {}, + function() { return Render.ambientOcclusion.gpuTime; }, + function (value) { return (value.toFixed(2) + " ms"); }); + var tickTackPeriod = 500; @@ -147,6 +154,7 @@ function updateCounters() { opaquesCounter.update(); transparentsCounter.update(); overlaysCounter.update(); + panel.update("Ambient Occlusion GPU time"); } Script.setInterval(updateCounters, tickTackPeriod); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ccde915ecc..78cddad9e7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3853,6 +3853,8 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se auto engineContext = _renderEngine->getRenderContext(); renderInterface->setItemCounts(engineContext->getItemsConfig()); + renderInterface->setJobGPUTimes(engineContext->getAmbientOcclusion().gpuTime); + } activeRenderingThread = nullptr; diff --git a/libraries/gpu/src/gpu/Query.cpp b/libraries/gpu/src/gpu/Query.cpp index 24b8bcebd7..2e28dcd061 100644 --- a/libraries/gpu/src/gpu/Query.cpp +++ b/libraries/gpu/src/gpu/Query.cpp @@ -36,7 +36,7 @@ void Query::triggerReturnHandler(uint64_t queryResult) { } -Timer::Timer() { +RangeTimer::RangeTimer() { for (int i = 0; i < QUERY_QUEUE_SIZE; i++) { _timerQueries.push_back(std::make_shared([&, i] (const Query& query) { _tailIndex ++; @@ -46,11 +46,11 @@ Timer::Timer() { } } -void Timer::begin(gpu::Batch& batch) { +void RangeTimer::begin(gpu::Batch& batch) { _headIndex++; batch.beginQuery(_timerQueries[rangeIndex(_headIndex)]); } -void Timer::end(gpu::Batch& batch) { +void RangeTimer::end(gpu::Batch& batch) { if (_headIndex < 0) { return; } @@ -65,3 +65,7 @@ void Timer::end(gpu::Batch& batch) { batch.getQuery(_timerQueries[rangeIndex(_tailIndex)]); } } + +double RangeTimer::getAverage() const { + return _movingAverage.average; +} \ No newline at end of file diff --git a/libraries/gpu/src/gpu/Query.h b/libraries/gpu/src/gpu/Query.h index 5bfb21cb38..67dfc29438 100644 --- a/libraries/gpu/src/gpu/Query.h +++ b/libraries/gpu/src/gpu/Query.h @@ -44,12 +44,12 @@ namespace gpu { typedef std::vector< QueryPointer > Queries; - // gpu timer is just returning an estimate of the time taken by a chunck of work delimited by the + // gpu RangeTimer is just returning an estimate of the time taken by a chunck of work delimited by the // begin and end calls repeated for several times. // The result is always a late average of the time spent for that same task a few cycles ago. - class Timer { + class RangeTimer { public: - Timer(); + RangeTimer(); void begin(gpu::Batch& batch); void end(gpu::Batch& batch); diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h index 657e72cf31..8cda1c355c 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -56,7 +56,7 @@ public: float getBlurDeviation() const { return _parametersBuffer.get()._blurInfo.z; } - double getTimerAverage() const { return _gpuTimer.getAverage(); } + double getGPUTime() const { return _gpuTimer.getAverage(); } using JobModel = render::Task::Job::Model; @@ -113,7 +113,7 @@ private: gpu::PipelinePointer _hBlurPipeline; gpu::PipelinePointer _vBlurPipeline; - gpu::Timer _gpuTimer; + gpu::RangeTimer _gpuTimer; }; #endif // hifi_AmbientOcclusionEffect_h diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index af297d125c..17d957b432 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -202,6 +202,11 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend job.run(sceneContext, renderContext); } + if (_occlusionJobIndex >= 0 && renderContext->getOcclusionStatus()) { + renderContext->getAmbientOcclusion().gpuTime = _jobs[_occlusionJobIndex].edit().getGPUTime(); + } else { + renderContext->getAmbientOcclusion().gpuTime = 0.0; + } }; void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems) { diff --git a/libraries/render-utils/src/RenderScriptingInterface.cpp b/libraries/render-utils/src/RenderScriptingInterface.cpp index 6c7bbab6a9..6b3fedd97f 100644 --- a/libraries/render-utils/src/RenderScriptingInterface.cpp +++ b/libraries/render-utils/src/RenderScriptingInterface.cpp @@ -49,4 +49,8 @@ void RenderScriptingInterface::setItemCounts(const render::RenderContext::ItemsC _opaque->setCounts(items.opaque); _transparent->setCounts(items.transparent); _overlay3D->setCounts(items.overlay3D); +} + +void RenderScriptingInterface::setJobGPUTimes(double aoTime) { + _ambientOcclusion->gpuTime = aoTime; } \ No newline at end of file diff --git a/libraries/render-utils/src/RenderScriptingInterface.h b/libraries/render-utils/src/RenderScriptingInterface.h index 751026b1a2..95741ce641 100644 --- a/libraries/render-utils/src/RenderScriptingInterface.h +++ b/libraries/render-utils/src/RenderScriptingInterface.h @@ -78,6 +78,7 @@ namespace RenderScripting { Q_PROPERTY(float edgeSharpness MEMBER edgeSharpness) Q_PROPERTY(int blurRadius MEMBER blurRadius) Q_PROPERTY(float blurDeviation MEMBER blurDeviation) + Q_PROPERTY(double gpuTime MEMBER gpuTime) }; using AmbientOcclusionPointer = std::unique_ptr; }; @@ -103,6 +104,9 @@ class RenderScriptingInterface : public QObject, public Dependency { render::RenderContext getRenderContext(); void setItemCounts(const render::RenderContext::ItemsConfig& items); + // FIXME: It is ugly, we need a cleaner solution + void setJobGPUTimes(double aoTime); + protected: RenderScriptingInterface(); ~RenderScriptingInterface() {}; diff --git a/libraries/render/src/render/Context.h b/libraries/render/src/render/Context.h index 144b3bb434..baca2640a0 100644 --- a/libraries/render/src/render/Context.h +++ b/libraries/render/src/render/Context.h @@ -82,6 +82,8 @@ public: float edgeSharpness = 1.0f; int blurRadius = 3; float blurDeviation = 2.1f; + + double gpuTime = 0.0; }; RenderContext(ItemsConfig items, Tone tone, AmbientOcclusion ao, int drawStatus, bool drawHitEffect, glm::vec4 deferredDebugSize, int deferredDebugMode);