diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index c4b9453df3..55e0bf1abb 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -28,6 +28,47 @@ class QImage; namespace gpu { +template +struct ContextMetric { + std::atomic _value { 0 }; + std::atomic _maximum { 0 }; + + T getValue() { return _value; } + T getMaximum() { return _maximum; } + + void increment() { + auto total = ++_value; + if (total > _maximum.load()) { + _maximum = total; + } + } + void increment() { + --_value; + } + + void update(T prevValue, T newValue) { + if (prevValue == newValue) { + return; + } + if (newValue > prevValue) { + auto total = _value.fetch_add(newValue - prevValue); + if (total > _maximum.load()) { + _maximum = total; + } + } else { + _value.fetch_sub(prevValue - newValue); + } + } + + void reset() { + _value = 0; + _maximum = 0; + } +}; + +using ContextMetricCount = ContextMetric; +using ContextMetricSize = ContextMetric; + struct ContextStats { public: int _ISNumFormatChanges = 0; @@ -107,12 +148,27 @@ public: static void decrementTextureGPUSparseCount(); static void updateTextureTransferPendingSize(Resource::Size prevObjectSize, Resource::Size newObjectSize); static void updateTextureGPUMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize); - static void updateTextureGPUSparseMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize); - static void updateTextureGPUVirtualMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize); + // static void updateTextureGPUSparseMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize); + // static void updateTextureGPUVirtualMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize); static void updateTextureGPUFramebufferMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize); static void incrementTextureGPUTransferCount(); static void decrementTextureGPUTransferCount(); + static ContextMetricSize freeGPUMemSize; + + static ContextMetricCount bufferCount; + static ContextMetricSize bufferGPUMemSize; + + static ContextMetricCount textureCount; + static ContextMetricSize textureGPUMemSize; + static ContextMetricSize textureResidentGPUMemSize; + static ContextMetricSize textureResourceGPUMemSize; + static ContextMetricSize textureFramebufferGPUMemSize; + + static ContextMetricCount textureTransferCount; + + + protected: virtual bool isStereo() { return _stereo._enable; @@ -224,14 +280,16 @@ public: static Size getBufferGPUMemoryUsage(); static uint32_t getTextureGPUCount(); - static uint32_t getTextureGPUSparseCount(); + static uint32_t getTextureGPUResourceCount(); static Size getFreeGPUMemory(); static Size getUsedGPUMemory(); static Size getTextureTransferPendingSize(); static Size getTextureGPUMemoryUsage(); - static Size getTextureGPUVirtualMemoryUsage(); + + static Size getTextureGPUResourceMemoryUsage(); + static Size getTextureGPUResidentMemoryUsage(); static Size getTextureGPUFramebufferMemoryUsage(); - static Size getTextureGPUSparseMemoryUsage(); + static uint32_t getTextureGPUTransferCount(); protected: @@ -269,16 +327,21 @@ protected: static void setFreeGPUMemory(Size size); static void incrementTextureGPUCount(); static void decrementTextureGPUCount(); - static void incrementTextureGPUSparseCount(); - static void decrementTextureGPUSparseCount(); - static void updateTextureTransferPendingSize(Size prevObjectSize, Size newObjectSize); - static void updateTextureGPUMemoryUsage(Size prevObjectSize, Size newObjectSize); - static void updateTextureGPUSparseMemoryUsage(Size prevObjectSize, Size newObjectSize); - static void updateTextureGPUVirtualMemoryUsage(Size prevObjectSize, Size newObjectSize); - static void updateTextureGPUFramebufferMemoryUsage(Size prevObjectSize, Size newObjectSize); + static void incrementTextureGPUResourceCount(); + static void decrementTextureGPUResourceCount(); + static void incrementTextureGPUTransferCount(); static void decrementTextureGPUTransferCount(); + static void updateTextureTransferPendingSize(Size prevObjectSize, Size newObjectSize); + static void updateTextureGPUMemoryUsage(Size prevObjectSize, Size newObjectSize); + + static void updateTextureGPUResourceMemoryUsage(Size prevObjectSize, Size newObjectSize); + static void updateTextureGPUResidentMemoryUsage(Size prevObjectSize, Size newObjectSize); + static void updateTextureGPUFramebufferMemoryUsage(Size prevObjectSize, Size newObjectSize); + + + // Buffer, Texture and Fence Counters static std::atomic _freeGPUMemory; static std::atomic _fenceCount; diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index a545be9088..1a11df876b 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -85,10 +85,6 @@ uint32_t Texture::getTextureGPUCount() { return Context::getTextureGPUCount(); } -uint32_t Texture::getTextureGPUSparseCount() { - return Context::getTextureGPUSparseCount(); -} - Texture::Size Texture::getTextureTransferPendingSize() { return Context::getTextureTransferPendingSize(); } @@ -97,19 +93,18 @@ Texture::Size Texture::getTextureGPUMemoryUsage() { return Context::getTextureGPUMemoryUsage(); } -Texture::Size Texture::getTextureGPUVirtualMemoryUsage() { - return Context::getTextureGPUVirtualMemoryUsage(); +Texture::Size getTextureGPUResourceMemoryUsage() { + return Context::getTextureGPUResourceMemoryUsage(); } +Texture::Size getTextureGPUResidentMemoryUsage() { + return Context::getTextureGPUResidentMemoryUsage(); +} Texture::Size Texture::getTextureGPUFramebufferMemoryUsage() { return Context::getTextureGPUFramebufferMemoryUsage(); } -Texture::Size Texture::getTextureGPUSparseMemoryUsage() { - return Context::getTextureGPUSparseMemoryUsage(); -} - uint32_t Texture::getTextureGPUTransferCount() { return Context::getTextureGPUTransferCount(); } diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 3777f2bb50..1b197d04d2 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -178,12 +178,11 @@ public: static uint32_t getTextureCPUCount(); static Size getTextureCPUMemoryUsage(); static uint32_t getTextureGPUCount(); - static uint32_t getTextureGPUSparseCount(); static Size getTextureTransferPendingSize(); static Size getTextureGPUMemoryUsage(); - static Size getTextureGPUVirtualMemoryUsage(); + static Size getTextureGPUResourceMemoryUsage(); + static Size getTextureGPUResidentMemoryUsage(); static Size getTextureGPUFramebufferMemoryUsage(); - static Size getTextureGPUSparseMemoryUsage(); static uint32_t getTextureGPUTransferCount(); static Size getAllowedGPUMemoryUsage(); static void setAllowedGPUMemoryUsage(Size size); diff --git a/libraries/render/src/render/EngineStats.cpp b/libraries/render/src/render/EngineStats.cpp index ce116ed2c5..a3ad7a0a5c 100644 --- a/libraries/render/src/render/EngineStats.cpp +++ b/libraries/render/src/render/EngineStats.cpp @@ -34,6 +34,9 @@ void EngineStats::run(const RenderContextPointer& renderContext) { config->textureGPUMemoryUsage = gpu::Texture::getTextureGPUMemoryUsage(); config->textureGPUVirtualMemoryUsage = gpu::Texture::getTextureGPUVirtualMemoryUsage(); config->textureGPUTransferCount = gpu::Texture::getTextureGPUTransferCount(); + config->textureTransferPendingSize = gpu::Texture::getTextureTransferPendingSize(); + + config->textureGPUFramebufferSize = gpu::Texture::getTextureGPUFramebufferMemoryUsage(); renderContext->args->_context->getFrameStats(_gpuStats); diff --git a/libraries/render/src/render/EngineStats.h b/libraries/render/src/render/EngineStats.h index 8fd38eb501..ee89d0845f 100644 --- a/libraries/render/src/render/EngineStats.h +++ b/libraries/render/src/render/EngineStats.h @@ -36,6 +36,10 @@ namespace render { Q_PROPERTY(qint64 textureGPUVirtualMemoryUsage MEMBER textureGPUVirtualMemoryUsage NOTIFY dirty) Q_PROPERTY(quint32 textureGPUTransferCount MEMBER textureGPUTransferCount NOTIFY dirty) + Q_PROPERTY(quint32 textureTransferPendingSize MEMBER textureTransferPendingSize NOTIFY dirty) + + Q_PROPERTY(qint64 textureGPUFramebufferSize MEMBER textureGPUFramebufferSize NOTIFY dirty) + Q_PROPERTY(quint32 frameAPIDrawcallCount MEMBER frameAPIDrawcallCount NOTIFY dirty) Q_PROPERTY(quint32 frameDrawcallCount MEMBER frameDrawcallCount NOTIFY dirty) Q_PROPERTY(quint32 frameDrawcallRate MEMBER frameDrawcallRate NOTIFY dirty) @@ -64,7 +68,10 @@ namespace render { qint64 textureCPUMemoryUsage{ 0 }; qint64 textureGPUMemoryUsage{ 0 }; qint64 textureGPUVirtualMemoryUsage{ 0 }; - quint32 textureGPUTransferCount{ 0 }; + quint32 textureGPUTransferCount { 0 }; + qint64 textureTransferPendingSize { 0 }; + + qint64 textureGPUFramebufferSize { 0 }; quint32 frameAPIDrawcallCount{ 0 }; quint32 frameDrawcallCount{ 0 }; diff --git a/scripts/developer/utilities/render/textureMonitor.js b/scripts/developer/utilities/render/textureMonitor.js new file mode 100644 index 0000000000..f8abe47e55 --- /dev/null +++ b/scripts/developer/utilities/render/textureMonitor.js @@ -0,0 +1,21 @@ +// +// textureMonitor.js +// examples/utilities/tools/render +// +// Sam Gateau, created on 3/22/2016. +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// Set up the qml ui +var qml = Script.resolvePath('textureMonitor.qml'); +var window = new OverlayWindow({ + title: 'Textures', + source: qml, + width: 320, + height: 720 +}); +window.setPosition(500, 50); +window.closed.connect(function() { Script.stop(); }); \ No newline at end of file diff --git a/scripts/developer/utilities/render/textureMonitor.qml b/scripts/developer/utilities/render/textureMonitor.qml new file mode 100644 index 0000000000..726e7fe88b --- /dev/null +++ b/scripts/developer/utilities/render/textureMonitor.qml @@ -0,0 +1,85 @@ +// +// texture monitor.qml +// examples/utilities/render +// +// Created by Sam Gateau on 5/17/2017 +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.5 +import QtQuick.Controls 1.4 +import "../lib/plotperf" + + +Item { + id: texMex + anchors.fill:parent + + Column { + id: stats + spacing: 8 + anchors.fill:parent + + property var config: Render.getConfig("Stats") + + function evalEvenHeight() { + // Why do we have to do that manually ? cannot seem to find a qml / anchor / layout mode that does that ? + return (height - spacing * (children.length - 1)) / children.length + } + PlotPerf { + title: "Num Textures" + height: parent.evalEvenHeight() + object: stats.config + plots: [ + { + prop: "textureCPUCount", + label: "CPU", + color: "#00B4EF" + }, + { + prop: "textureGPUCount", + label: "GPU", + color: "#1AC567" + }, + { + prop: "textureGPUTransferCount", + label: "Transfer", + color: "#9495FF" + } + ] + } + PlotPerf { + title: "gpu::Texture Memory" + height: parent.evalEvenHeight() + object: stats.config + valueScale: 1048576 + valueUnit: "Mb" + valueNumDigits: "1" + plots: [ + { + prop: "textureCPUMemoryUsage", + label: "CPU", + color: "#00B4EF" + }, + { + prop: "textureGPUMemoryUsage", + label: "GPU", + color: "#1AC567" + }, + { + prop: "textureTransferPendingSize", + label: "Pending Transfer", + color: "#9495FF" + }, + { + prop: "textureGPUFramebufferSize", + label: "Framebuffer", + color: "#EF93D1" + } + ] + } + } + +} \ No newline at end of file