From bcef138545b423ca3415e2d185a6fc6feee9e5fc Mon Sep 17 00:00:00 2001 From: sam Date: Fri, 4 Nov 2016 18:59:30 -0700 Subject: [PATCH] FIx the context stats --- .../gpu-gl/src/gpu/gl45/GL45BackendInput.cpp | 2 -- libraries/gpu/src/gpu/Context.cpp | 32 +++++++++++++++++-- libraries/gpu/src/gpu/Context.h | 6 +++- libraries/render/src/render/EngineStats.cpp | 15 ++++----- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendInput.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendInput.cpp index 9c5303e71f..694bbe6f9c 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendInput.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendInput.cpp @@ -27,9 +27,7 @@ void GL45Backend::resetInputStage() { } void GL45Backend::updateInput() { - if (_input._invalidFormat) { - InputStageState::ActivationCache newActivation; // Assign the vertex format required diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index 46d1b84e47..beb0e1d6bc 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -13,6 +13,23 @@ #include "GPULogging.h" using namespace gpu; + +void ContextStats::evalDelta(const ContextStats& begin, const ContextStats& end) { + _ISNumFormatChanges = end._ISNumFormatChanges - begin._ISNumFormatChanges; + _ISNumInputBufferChanges = end._ISNumInputBufferChanges - begin._ISNumInputBufferChanges; + _ISNumIndexBufferChanges = end._ISNumIndexBufferChanges - begin._ISNumIndexBufferChanges; + + _RSNumTextureBounded = end._RSNumTextureBounded - begin._RSNumTextureBounded; + _RSAmountTextureMemoryBounded = end._RSAmountTextureMemoryBounded - begin._RSAmountTextureMemoryBounded; + + _DSNumAPIDrawcalls = end._DSNumAPIDrawcalls - begin._DSNumAPIDrawcalls; + _DSNumDrawcalls = end._DSNumDrawcalls - begin._DSNumDrawcalls; + _DSNumTriangles= end._DSNumTriangles - begin._DSNumTriangles; + + _PSNumSetPipelines = end._PSNumSetPipelines - begin._PSNumSetPipelines; +} + + Context::CreateBackend Context::_createBackendCallback = nullptr; Context::MakeProgram Context::_makeProgramCallback = nullptr; std::once_flag Context::_initialized; @@ -69,6 +86,10 @@ void Context::consumeFrameUpdates(const FramePointer& frame) const { } void Context::executeFrame(const FramePointer& frame) const { + // Grab the stats at the around the frame and delta to have a consistent sampling + ContextStats beginStats; + getStats(beginStats); + // FIXME? probably not necessary, but safe consumeFrameUpdates(frame); _backend->setStereoState(frame->stereoState); @@ -79,8 +100,9 @@ void Context::executeFrame(const FramePointer& frame) const { } } - // Grab the stats at the end of the frame that just executed so we can have a consistent sampling - getFrameStats(_frameStats); + ContextStats endStats; + getStats(endStats); + _frameStats.evalDelta(beginStats, endStats); } bool Context::makeProgram(Shader& shader, const Shader::BindingSet& bindings) { @@ -126,12 +148,16 @@ void Context::downloadFramebuffer(const FramebufferPointer& srcFramebuffer, cons _backend->downloadFramebuffer(srcFramebuffer, region, destImage); } +void Context::resetStats() const { + _backend->resetStats(); +} + void Context::getStats(ContextStats& stats) const { _backend->getStats(stats); } void Context::getFrameStats(ContextStats& stats) const { - memcpy(&stats, &_frameStats, sizeof(ContextStats)); + stats = _frameStats; } const Backend::TransformCamera& Backend::TransformCamera::recomputeDerived(const Transform& xformView) const { diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index b61ed764d4..c5ab673686 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -45,6 +45,8 @@ public: ContextStats() {} ContextStats(const ContextStats& stats) = default; + + void evalDelta(const ContextStats& begin, const ContextStats& end); }; class Backend { @@ -83,6 +85,7 @@ public: return reinterpret_cast(object.gpuObject.getGPUObject()); } + void resetStats() const { _stats = ContextStats(); } void getStats(ContextStats& stats) const { stats = _stats; } virtual bool isTextureManagementSparseEnabled() const = 0; @@ -124,7 +127,7 @@ protected: } friend class Context; - ContextStats _stats; + mutable ContextStats _stats; StereoState _stereo; }; @@ -202,6 +205,7 @@ public: void downloadFramebuffer(const FramebufferPointer& srcFramebuffer, const Vec4i& region, QImage& destImage); // Repporting stats of the context + void resetStats() const; void getStats(ContextStats& stats) const; // Same as above but grabbed at every end of a frame diff --git a/libraries/render/src/render/EngineStats.cpp b/libraries/render/src/render/EngineStats.cpp index 27d64129cd..2cb23bb41c 100644 --- a/libraries/render/src/render/EngineStats.cpp +++ b/libraries/render/src/render/EngineStats.cpp @@ -35,22 +35,21 @@ void EngineStats::run(const SceneContextPointer& sceneContext, const RenderConte config->textureGPUVirtualMemoryUsage = gpu::Texture::getTextureGPUVirtualMemoryUsage(); config->textureGPUTransferCount = gpu::Texture::getTextureGPUTransferCount(); - gpu::ContextStats gpuStats(_gpuStats); renderContext->args->_context->getFrameStats(_gpuStats); - config->frameAPIDrawcallCount = _gpuStats._DSNumAPIDrawcalls - gpuStats._DSNumAPIDrawcalls; - config->frameDrawcallCount = _gpuStats._DSNumDrawcalls - gpuStats._DSNumDrawcalls; + config->frameAPIDrawcallCount = _gpuStats._DSNumAPIDrawcalls; + config->frameDrawcallCount = _gpuStats._DSNumDrawcalls; config->frameDrawcallRate = config->frameDrawcallCount * frequency; - config->frameTriangleCount = _gpuStats._DSNumTriangles - gpuStats._DSNumTriangles; + config->frameTriangleCount = _gpuStats._DSNumTriangles; config->frameTriangleRate = config->frameTriangleCount * frequency; - config->frameTextureCount = _gpuStats._RSNumTextureBounded - gpuStats._RSNumTextureBounded; + config->frameTextureCount = _gpuStats._RSNumTextureBounded; config->frameTextureRate = config->frameTextureCount * frequency; - config->frameTextureMemoryUsage = _gpuStats._RSAmountTextureMemoryBounded - gpuStats._RSAmountTextureMemoryBounded; + config->frameTextureMemoryUsage = _gpuStats._RSAmountTextureMemoryBounded; - config->frameSetPipelineCount = _gpuStats._PSNumSetPipelines - gpuStats._PSNumSetPipelines; - config->frameSetInputFormatCount = _gpuStats._ISNumFormatChanges - gpuStats._ISNumFormatChanges; + config->frameSetPipelineCount = _gpuStats._PSNumSetPipelines; + config->frameSetInputFormatCount = _gpuStats._ISNumFormatChanges; config->emitDirty(); }