From c5e1f2aedc514078a13bd0b4b003d35d1b693da8 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 11 Jun 2019 11:52:51 -0700 Subject: [PATCH] change ContextStats::evalDelta to better handle wrapping values in graphics stats --- .../src/gpu/gl/GLBackendPipeline.cpp | 2 +- libraries/gpu/src/gpu/Context.cpp | 28 +++++++++++++------ libraries/gpu/src/gpu/Context.h | 20 ++++++------- libraries/render/src/render/EngineStats.h | 4 +-- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackendPipeline.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackendPipeline.cpp index 1e811653f9..e94d2986ee 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackendPipeline.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackendPipeline.cpp @@ -309,7 +309,7 @@ void GLBackend::setResourceTexture(unsigned int slot, const TexturePointer& reso glActiveTexture(GL_TEXTURE0 + slot); glBindTexture(textureState._target, to); (void)CHECK_GL_ERROR(); - _stats._RSAmountTextureMemoryBounded += (int)object->size(); + _stats._RSAmountTextureMemoryBounded += (uint64_t)object->size(); } else { releaseResourceTexture(slot); diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index 45ee4263a3..927e872fbc 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -8,6 +8,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include "Context.h" #include @@ -18,19 +19,28 @@ using namespace gpu; +template +T subWrap(T endValue, T beginValue) { + if (endValue >= beginValue) { + return endValue - beginValue; + } else { + return endValue + ((std::numeric_limits::max() - beginValue) + 1); + } +} + void ContextStats::evalDelta(const ContextStats& begin, const ContextStats& end) { - _ISNumFormatChanges = end._ISNumFormatChanges - begin._ISNumFormatChanges; - _ISNumInputBufferChanges = end._ISNumInputBufferChanges - begin._ISNumInputBufferChanges; - _ISNumIndexBufferChanges = end._ISNumIndexBufferChanges - begin._ISNumIndexBufferChanges; + _ISNumFormatChanges = subWrap(end._ISNumFormatChanges, begin._ISNumFormatChanges); + _ISNumInputBufferChanges = subWrap(end._ISNumInputBufferChanges, begin._ISNumInputBufferChanges); + _ISNumIndexBufferChanges = subWrap(end._ISNumIndexBufferChanges, begin._ISNumIndexBufferChanges); - _RSNumTextureBounded = end._RSNumTextureBounded - begin._RSNumTextureBounded; - _RSAmountTextureMemoryBounded = end._RSAmountTextureMemoryBounded - begin._RSAmountTextureMemoryBounded; + _RSNumTextureBounded = subWrap(end._RSNumTextureBounded, begin._RSNumTextureBounded); + _RSAmountTextureMemoryBounded = subWrap(end._RSAmountTextureMemoryBounded, begin._RSAmountTextureMemoryBounded); - _DSNumAPIDrawcalls = end._DSNumAPIDrawcalls - begin._DSNumAPIDrawcalls; - _DSNumDrawcalls = end._DSNumDrawcalls - begin._DSNumDrawcalls; - _DSNumTriangles= end._DSNumTriangles - begin._DSNumTriangles; + _DSNumAPIDrawcalls = subWrap(end._DSNumAPIDrawcalls, begin._DSNumAPIDrawcalls); + _DSNumDrawcalls = subWrap(end._DSNumDrawcalls, begin._DSNumDrawcalls); + _DSNumTriangles= subWrap(end._DSNumTriangles, begin._DSNumTriangles); - _PSNumSetPipelines = end._PSNumSetPipelines - begin._PSNumSetPipelines; + _PSNumSetPipelines = subWrap(end._PSNumSetPipelines, begin._PSNumSetPipelines); } diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index 7109b3dfeb..1946f447f8 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -32,19 +32,19 @@ namespace gpu { struct ContextStats { public: - int _ISNumFormatChanges = 0; - int _ISNumInputBufferChanges = 0; - int _ISNumIndexBufferChanges = 0; + uint32_t _ISNumFormatChanges { 0 }; + uint32_t _ISNumInputBufferChanges { 0 }; + uint32_t _ISNumIndexBufferChanges { 0 }; - int _RSNumResourceBufferBounded = 0; - int _RSNumTextureBounded = 0; - int _RSAmountTextureMemoryBounded = 0; + uint32_t _RSNumResourceBufferBounded { 0 }; + uint32_t _RSNumTextureBounded { 0 }; + uint64_t _RSAmountTextureMemoryBounded { 0 }; - int _DSNumAPIDrawcalls = 0; - int _DSNumDrawcalls = 0; - int _DSNumTriangles = 0; + uint32_t _DSNumAPIDrawcalls { 0 }; + uint32_t _DSNumDrawcalls { 0 }; + uint32_t _DSNumTriangles { 0 }; - int _PSNumSetPipelines = 0; + uint32_t _PSNumSetPipelines { 0 }; ContextStats() {} ContextStats(const ContextStats& stats) = default; diff --git a/libraries/render/src/render/EngineStats.h b/libraries/render/src/render/EngineStats.h index 46be372d5d..f323038ff3 100644 --- a/libraries/render/src/render/EngineStats.h +++ b/libraries/render/src/render/EngineStats.h @@ -56,7 +56,7 @@ namespace render { Q_PROPERTY(quint32 frameTextureCount MEMBER frameTextureCount NOTIFY dirty) Q_PROPERTY(quint32 frameTextureRate MEMBER frameTextureRate NOTIFY dirty) - Q_PROPERTY(quint32 frameTextureMemoryUsage MEMBER frameTextureMemoryUsage NOTIFY dirty) + Q_PROPERTY(quint64 frameTextureMemoryUsage MEMBER frameTextureMemoryUsage NOTIFY dirty) Q_PROPERTY(quint32 frameSetPipelineCount MEMBER frameSetPipelineCount NOTIFY dirty) Q_PROPERTY(quint32 frameSetInputFormatCount MEMBER frameSetInputFormatCount NOTIFY dirty) @@ -124,4 +124,4 @@ namespace render { }; } -#endif \ No newline at end of file +#endif