From 861b69aa9474ea311a63fdcc7139977d15d3b8b2 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 23 Oct 2016 11:43:46 -0700 Subject: [PATCH] Add free GPU memory to the displayed stats --- interface/resources/qml/Stats.qml | 3 +++ interface/src/ui/Stats.cpp | 3 +-- interface/src/ui/Stats.h | 2 ++ .../src/display-plugins/OpenGLDisplayPlugin.cpp | 2 ++ libraries/gl/src/gl/OffscreenQmlSurface.cpp | 2 +- libraries/gpu/src/gpu/Context.cpp | 12 ++++++++++++ libraries/gpu/src/gpu/Context.h | 5 +++++ 7 files changed, 26 insertions(+), 3 deletions(-) diff --git a/interface/resources/qml/Stats.qml b/interface/resources/qml/Stats.qml index 1ccc2de569..6ebe3f2278 100644 --- a/interface/resources/qml/Stats.qml +++ b/interface/resources/qml/Stats.qml @@ -193,6 +193,9 @@ Item { text: "Triangles: " + root.triangles + " / Material Switches: " + root.materialSwitches } + StatText { + text: "GPU Free Memory: " + root.gpuFreeMemory + " MB"; + } StatText { text: "GPU Textures: "; } diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 3d91bc68dc..6c301f6f0a 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -111,7 +111,6 @@ void Stats::updateStats(bool force) { PerformanceTimer::setActive(shouldDisplayTimingDetail); } - auto nodeList = DependencyManager::get(); auto avatarManager = DependencyManager::get(); // we need to take one avatar out so we don't include ourselves @@ -293,7 +292,7 @@ void Stats::updateStats(bool force) { STAT_UPDATE(gpuTextureVirtualMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUVirtualMemoryUsage())); STAT_UPDATE(gpuTextureSparseMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUSparseMemoryUsage())); STAT_UPDATE(gpuSparseTextureEnabled, gpu::Texture::getEnableSparseTextures() ? 1 : 0); - + STAT_UPDATE(gpuFreeMemory, (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemory())); // Incoming packets QLocale locale(QLocale::English); diff --git a/interface/src/ui/Stats.h b/interface/src/ui/Stats.h index 5a3e189beb..c9fccf02d9 100644 --- a/interface/src/ui/Stats.h +++ b/interface/src/ui/Stats.h @@ -95,6 +95,7 @@ class Stats : public QQuickItem { STATS_PROPERTY(int, gpuTextureVirtualMemory, 0) STATS_PROPERTY(int, gpuTextureSparseMemory, 0) STATS_PROPERTY(int, gpuSparseTextureEnabled, 0) + STATS_PROPERTY(int, gpuFreeMemory, 0) public: static Stats* getInstance(); @@ -188,6 +189,7 @@ signals: void gpuTextureVirtualMemoryChanged(); void gpuTextureSparseMemoryChanged(); void gpuSparseTextureEnabledChanged(); + void gpuFreeMemoryChanged(); private: int _recentMaxPackets{ 0 } ; // recent max incoming voxel packets to process diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index a92f36ed71..c84f6b9954 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -630,6 +630,8 @@ void OpenGLDisplayPlugin::present() { PROFILE_RANGE_EX("internalPresent", 0xff00ffff, (uint64_t)presentCount()) internalPresent(); } + + gpu::Backend::setFreeGPUMemory(gpu::gl::getFreeDedicatedMemory()); } } diff --git a/libraries/gl/src/gl/OffscreenQmlSurface.cpp b/libraries/gl/src/gl/OffscreenQmlSurface.cpp index 1e26f3b8ad..636ae9ad4f 100644 --- a/libraries/gl/src/gl/OffscreenQmlSurface.cpp +++ b/libraries/gl/src/gl/OffscreenQmlSurface.cpp @@ -123,7 +123,7 @@ private: void destroyTexture(GLuint texture) { --_allTextureCount; auto size = _textureSizes[texture]; - assert(getMemoryForSize(size) < _totalTextureUsage); + assert(getMemoryForSize(size) <= _totalTextureUsage); _totalTextureUsage -= getMemoryForSize(size); _textureSizes.erase(texture); glDeleteTextures(1, &texture); diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index 0adf70a78a..6e8a5e312f 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -162,6 +162,7 @@ Backend::TransformCamera Backend::TransformCamera::getEyeCamera(int eye, const S } // Counters for Buffer and Texture usage in GPU/Context +std::atomic Context::_freeGPUMemory { 0 }; std::atomic Context::_fenceCount { 0 }; std::atomic Context::_bufferGPUCount { 0 }; std::atomic Context::_bufferGPUMemoryUsage { 0 }; @@ -173,6 +174,14 @@ std::atomic Context::_textureGPUVirtualMemoryUsage{ 0 }; std::atomic Context::_textureGPUSparseMemoryUsage { 0 }; std::atomic Context::_textureGPUTransferCount { 0 }; +void Context::setFreeGPUMemory(Size size) { + _freeGPUMemory.store(size); +} + +Size Context::getFreeGPUMemory() { + return _freeGPUMemory.load(); +} + void Context::incrementBufferGPUCount() { static std::atomic max { 0 }; auto total = ++_bufferGPUCount; @@ -272,6 +281,7 @@ void Context::incrementTextureGPUTransferCount() { qCDebug(gpulogging) << "New max GPU textures transfers" << total; } } + void Context::decrementTextureGPUTransferCount() { --_textureGPUTransferCount; } @@ -308,6 +318,8 @@ uint32_t Context::getTextureGPUTransferCount() { return _textureGPUTransferCount.load(); } +void Backend::setFreeGPUMemory(Size size) { Context::setFreeGPUMemory(size); } +Resource::Size Backend::getFreeGPUMemory() { return Context::getFreeGPUMemory(); } void Backend::incrementBufferGPUCount() { Context::incrementBufferGPUCount(); } void Backend::decrementBufferGPUCount() { Context::decrementBufferGPUCount(); } void Backend::updateBufferGPUMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateBufferGPUMemoryUsage(prevObjectSize, newObjectSize); } diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index 5e938b03cc..ea199db3aa 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -89,6 +89,8 @@ public: // These should only be accessed by Backend implementation to repport the buffer and texture allocations, // they are NOT public calls + static Resource::Size getFreeGPUMemory(); + static void setFreeGPUMemory(Resource::Size prevObjectSize); static void incrementBufferGPUCount(); static void decrementBufferGPUCount(); static void updateBufferGPUMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize); @@ -205,6 +207,7 @@ public: static uint32_t getTextureGPUCount(); static uint32_t getTextureGPUSparseCount(); + static Size getFreeGPUMemory(); static Size getTextureGPUMemoryUsage(); static Size getTextureGPUVirtualMemoryUsage(); static Size getTextureGPUSparseMemoryUsage(); @@ -238,6 +241,7 @@ protected: static void incrementFenceCount(); static void decrementFenceCount(); + static void setFreeGPUMemory(Size size); static void incrementTextureGPUCount(); static void decrementTextureGPUCount(); static void incrementTextureGPUSparseCount(); @@ -249,6 +253,7 @@ protected: static void decrementTextureGPUTransferCount(); // Buffer, Texture and Fence Counters + static std::atomic _freeGPUMemory; static std::atomic _fenceCount; static std::atomic _bufferGPUCount;