From b466964817bc52d7de720b4b23335af40d00494b Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 16 May 2017 18:21:24 -0700 Subject: [PATCH 01/12] REvisiting the stats counter for the gpu context in the hope of better understanding the gpu texture streaming behavior --- libraries/gpu/src/gpu/Context.h | 87 ++++++++++++++++--- libraries/gpu/src/gpu/Texture.cpp | 15 ++-- libraries/gpu/src/gpu/Texture.h | 5 +- libraries/render/src/render/EngineStats.cpp | 3 + libraries/render/src/render/EngineStats.h | 9 +- .../utilities/render/textureMonitor.js | 21 +++++ .../utilities/render/textureMonitor.qml | 85 ++++++++++++++++++ 7 files changed, 199 insertions(+), 26 deletions(-) create mode 100644 scripts/developer/utilities/render/textureMonitor.js create mode 100644 scripts/developer/utilities/render/textureMonitor.qml 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 From 80b6fd65ae5a318374faac08b40e3f5e91e998ee Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 17 May 2017 18:31:28 -0700 Subject: [PATCH 02/12] Cleaning up counters and naming schemes... --- interface/resources/qml/Stats.qml | 16 +- interface/src/Application.cpp | 4 +- .../src/scripting/TestScriptingInterface.cpp | 2 +- interface/src/ui/Stats.cpp | 17 +- interface/src/ui/Stats.h | 14 +- .../display-plugins/OpenGLDisplayPlugin.cpp | 2 +- libraries/gpu-gl/src/gpu/gl/GLBackend.cpp | 8 +- libraries/gpu-gl/src/gpu/gl/GLBuffer.cpp | 4 +- libraries/gpu-gl/src/gpu/gl/GLTexture.cpp | 9 +- .../src/gpu/gl41/GL41BackendTexture.cpp | 20 +- .../src/gpu/gl45/GL45BackendTexture.cpp | 6 +- .../gpu/gl45/GL45BackendVariableTexture.cpp | 9 +- libraries/gpu/src/gpu/Buffer.cpp | 45 +--- libraries/gpu/src/gpu/Buffer.h | 14 +- libraries/gpu/src/gpu/Context.cpp | 243 ++++-------------- libraries/gpu/src/gpu/Context.h | 151 +++-------- libraries/gpu/src/gpu/Metric.h | 64 +++++ libraries/gpu/src/gpu/Resource.h | 1 + libraries/gpu/src/gpu/Texture.cpp | 53 +--- libraries/gpu/src/gpu/Texture.h | 16 +- libraries/render/src/render/EngineStats.cpp | 23 +- libraries/render/src/render/EngineStats.h | 37 +-- .../utilities/render/textureMonitor.qml | 18 +- tests/render-perf/src/main.cpp | 4 +- 24 files changed, 279 insertions(+), 501 deletions(-) create mode 100644 libraries/gpu/src/gpu/Metric.h diff --git a/interface/resources/qml/Stats.qml b/interface/resources/qml/Stats.qml index dde6c445c8..97117fff0c 100644 --- a/interface/resources/qml/Stats.qml +++ b/interface/resources/qml/Stats.qml @@ -276,24 +276,20 @@ Item { StatText { text: " Count: " + root.gpuTextures; } - StatText { - text: " Rectified: " + root.rectifiedTextureCount; - } - StatText { - text: " Decimated: " + root.decimatedTextureCount; - } StatText { text: " Pending Transfer: " + root.texturePendingTransfers + " MB"; } StatText { - text: " Resource Memory: " + root.gpuTextureMemory + " MB"; + text: " Resource Memory: " + root.gpuTextureResourceMemory + " MB"; + } + StatText { + text: " Resident Memory: " + root.gpuTextureResidentMemory + " MB"; } StatText { text: " Framebuffer Memory: " + root.gpuTextureFramebufferMemory + " MB"; } StatText { - text: " Sparse Memory: " + root.gpuTextureSparseMemory + " MB"; - visible: 0 != root.gpuSparseTextureEnabled; + text: " External Memory: " + root.gpuTextureExternalMemory + " MB"; } StatText { text: "GPU Buffers: " @@ -302,7 +298,7 @@ Item { text: " Count: " + root.gpuBuffers; } StatText { - text: " Memory: " + root.gpuBufferMemory; + text: " Memory: " + root.gpuBufferMemory + " MB"; } StatText { text: "GL Swapchain Memory: " + root.glContextSwapchainMemory + " MB"; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3a09a2181c..2b16257772 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1340,8 +1340,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : auto glInfo = getGLContextData(); properties["gl_info"] = glInfo; - properties["gpu_used_memory"] = (int)BYTES_TO_MB(gpu::Context::getUsedGPUMemory()); - properties["gpu_free_memory"] = (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemory()); + properties["gpu_used_memory"] = (int)BYTES_TO_MB(gpu::Context::getUsedGPUMemSize()); + properties["gpu_free_memory"] = (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemSize()); properties["gpu_frame_time"] = (float)(qApp->getGPUContext()->getFrameTimerGPUAverage()); properties["batch_frame_time"] = (float)(qApp->getGPUContext()->getFrameTimerBatchAverage()); properties["ideal_thread_count"] = QThread::idealThreadCount(); diff --git a/interface/src/scripting/TestScriptingInterface.cpp b/interface/src/scripting/TestScriptingInterface.cpp index a8901365e5..b8892fae7e 100644 --- a/interface/src/scripting/TestScriptingInterface.cpp +++ b/interface/src/scripting/TestScriptingInterface.cpp @@ -31,7 +31,7 @@ void TestScriptingInterface::quit() { void TestScriptingInterface::waitForTextureIdle() { waitForCondition(0, []()->bool { - return (0 == gpu::Context::getTextureGPUTransferCount()); + return (0 == gpu::Context::getTexturePendingGPUTransferCount()); }); } diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 803104dd6d..131658461b 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -345,21 +345,20 @@ void Stats::updateStats(bool force) { STAT_UPDATE(gpuBuffers, (int)gpu::Context::getBufferGPUCount()); - STAT_UPDATE(gpuBufferMemory, (int)BYTES_TO_MB(gpu::Context::getBufferGPUMemoryUsage())); + STAT_UPDATE(gpuBufferMemory, (int)BYTES_TO_MB(gpu::Context::getBufferGPUMemSize())); STAT_UPDATE(gpuTextures, (int)gpu::Context::getTextureGPUCount()); - STAT_UPDATE(gpuTexturesSparse, (int)gpu::Context::getTextureGPUSparseCount()); STAT_UPDATE(glContextSwapchainMemory, (int)BYTES_TO_MB(gl::Context::getSwapchainMemoryUsage())); STAT_UPDATE(qmlTextureMemory, (int)BYTES_TO_MB(OffscreenQmlSurface::getUsedTextureMemory())); - STAT_UPDATE(texturePendingTransfers, (int)BYTES_TO_MB(gpu::Texture::getTextureTransferPendingSize())); - STAT_UPDATE(gpuTextureMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUMemoryUsage())); - STAT_UPDATE(gpuTextureVirtualMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUVirtualMemoryUsage())); - STAT_UPDATE(gpuTextureFramebufferMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUFramebufferMemoryUsage())); - STAT_UPDATE(gpuTextureSparseMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUSparseMemoryUsage())); + STAT_UPDATE(texturePendingTransfers, (int)BYTES_TO_MB(gpu::Context::getTexturePendingGPUTransferMemSize())); + STAT_UPDATE(gpuTextureMemory, (int)BYTES_TO_MB(gpu::Context::getTextureGPUMemSize())); + STAT_UPDATE(gpuTextureResidentMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResidentGPUMemSize())); + STAT_UPDATE(gpuTextureFramebufferMemory, (int)BYTES_TO_MB(gpu::Context::getTextureFramebufferGPUMemSize())); + STAT_UPDATE(gpuTextureResourceMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResourceGPUMemSize())); + STAT_UPDATE(gpuTextureExternalMemory, (int)BYTES_TO_MB(gpu::Context::getTextureExternalGPUMemSize())); STAT_UPDATE(gpuTextureMemoryPressureState, getTextureMemoryPressureModeString()); - STAT_UPDATE(gpuSparseTextureEnabled, gpuContext->getBackend()->isTextureManagementSparseEnabled() ? 1 : 0); - STAT_UPDATE(gpuFreeMemory, (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemory())); + STAT_UPDATE(gpuFreeMemory, (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemSize())); STAT_UPDATE(rectifiedTextureCount, (int)RECTIFIED_TEXTURE_COUNT.load()); STAT_UPDATE(decimatedTextureCount, (int)DECIMATED_TEXTURE_COUNT.load()); diff --git a/interface/src/ui/Stats.h b/interface/src/ui/Stats.h index 85c64bae90..bb7c40a105 100644 --- a/interface/src/ui/Stats.h +++ b/interface/src/ui/Stats.h @@ -117,15 +117,14 @@ class Stats : public QQuickItem { STATS_PROPERTY(int, gpuBuffers, 0) STATS_PROPERTY(int, gpuBufferMemory, 0) STATS_PROPERTY(int, gpuTextures, 0) - STATS_PROPERTY(int, gpuTexturesSparse, 0) STATS_PROPERTY(int, glContextSwapchainMemory, 0) STATS_PROPERTY(int, qmlTextureMemory, 0) STATS_PROPERTY(int, texturePendingTransfers, 0) STATS_PROPERTY(int, gpuTextureMemory, 0) - STATS_PROPERTY(int, gpuTextureVirtualMemory, 0) + STATS_PROPERTY(int, gpuTextureResidentMemory, 0) STATS_PROPERTY(int, gpuTextureFramebufferMemory, 0) - STATS_PROPERTY(int, gpuTextureSparseMemory, 0) - STATS_PROPERTY(int, gpuSparseTextureEnabled, 0) + STATS_PROPERTY(int, gpuTextureResourceMemory, 0) + STATS_PROPERTY(int, gpuTextureExternalMemory, 0) STATS_PROPERTY(QString, gpuTextureMemoryPressureState, QString()) STATS_PROPERTY(int, gpuFreeMemory, 0) STATS_PROPERTY(float, gpuFrameTime, 0) @@ -245,13 +244,12 @@ signals: void gpuBuffersChanged(); void gpuBufferMemoryChanged(); void gpuTexturesChanged(); - void gpuTexturesSparseChanged(); void gpuTextureMemoryChanged(); - void gpuTextureVirtualMemoryChanged(); + void gpuTextureResidentMemoryChanged(); void gpuTextureFramebufferMemoryChanged(); - void gpuTextureSparseMemoryChanged(); + void gpuTextureResourceMemoryChanged(); + void gpuTextureExternalMemoryChanged(); void gpuTextureMemoryPressureStateChanged(); - void gpuSparseTextureEnabledChanged(); void gpuFreeMemoryChanged(); void gpuFrameTimeChanged(); void batchFrameTimeChanged(); diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 306db98b35..f6f7da0ecd 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -645,7 +645,7 @@ void OpenGLDisplayPlugin::present() { internalPresent(); } - gpu::Backend::setFreeGPUMemory(gpu::gl::getFreeDedicatedMemory()); + gpu::Backend::freeGPUMemSize.set(gpu::gl::getFreeDedicatedMemory()); } } diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index 1210112a78..5ba1fb09f8 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -644,8 +644,8 @@ void GLBackend::recycle() const { ids.reserve(buffersTrash.size()); for (auto pair : buffersTrash) { ids.push_back(pair.first); - decrementBufferGPUCount(); - updateBufferGPUMemoryUsage(pair.second, 0); + bufferCount.decrement(); + bufferGPUMemSize.update(pair.second, 0); } if (!ids.empty()) { glDeleteBuffers((GLsizei)ids.size(), ids.data()); @@ -678,8 +678,8 @@ void GLBackend::recycle() const { ids.reserve(texturesTrash.size()); for (auto pair : texturesTrash) { ids.push_back(pair.first); - decrementTextureGPUCount(); - updateTextureGPUMemoryUsage(pair.second, 0); + textureCount.decrement(); + textureGPUMemSize.update(pair.second, 0); } if (!ids.empty()) { glDeleteTextures((GLsizei)ids.size(), ids.data()); diff --git a/libraries/gpu-gl/src/gpu/gl/GLBuffer.cpp b/libraries/gpu-gl/src/gpu/gl/GLBuffer.cpp index f05e7341c9..f0307e4aa3 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBuffer.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBuffer.cpp @@ -26,7 +26,7 @@ GLBuffer::GLBuffer(const std::weak_ptr& backend, const Buffer& buffer _size((GLuint)buffer._renderSysmem.getSize()), _stamp(buffer._renderSysmem.getStamp()) { - Backend::incrementBufferGPUCount(); - Backend::updateBufferGPUMemoryUsage(0, _size); + Backend::bufferCount.increment(); + Backend::bufferGPUMemSize.update(0, _size); } diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index 84dc49deba..afc257fcd1 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -132,7 +132,9 @@ void GLTexture::copyMipFaceFromTexture(uint16_t sourceMip, uint16_t targetMip, u GLExternalTexture::GLExternalTexture(const std::weak_ptr& backend, const Texture& texture, GLuint id) - : Parent(backend, texture, id) { } + : Parent(backend, texture, id) { + Backend::textureExternalCount.increment(); +} GLExternalTexture::~GLExternalTexture() { auto backend = _backend.lock(); @@ -145,6 +147,7 @@ GLExternalTexture::~GLExternalTexture() { } const_cast(_id) = 0; } + Backend::textureExternalCount.decrement(); } @@ -211,7 +214,7 @@ TransferJob::TransferJob(const GLTexture& parent, uint16_t sourceMip, uint16_t t _transferSize = bytesPerLine * lines; } - Backend::updateTextureTransferPendingSize(0, _transferSize); + Backend::texturePendingGPUTransferMemSize.update(0, _transferSize); if (_transferSize > GLVariableAllocationSupport::MAX_TRANSFER_SIZE) { qCWarning(gpugllogging) << "Transfer size of " << _transferSize << " exceeds theoretical maximum transfer size"; @@ -233,7 +236,7 @@ TransferJob::TransferJob(const GLTexture& parent, std::function transfer } TransferJob::~TransferJob() { - Backend::updateTextureTransferPendingSize(_transferSize, 0); + Backend::texturePendingGPUTransferMemSize.update(_transferSize, 0); } bool TransferJob::tryTransfer() { diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 146554952e..6561f6cb50 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -76,7 +76,7 @@ using GL41Texture = GL41Backend::GL41Texture; GL41Texture::GL41Texture(const std::weak_ptr& backend, const Texture& texture) : GLTexture(backend, texture, allocate(texture)) { - incrementTextureGPUCount(); + Backend::textureCount.increment(); } GLuint GL41Texture::allocate(const Texture& texture) { @@ -210,11 +210,13 @@ void GL41FixedAllocationTexture::syncSampler() const { using GL41AttachmentTexture = GL41Backend::GL41AttachmentTexture; GL41AttachmentTexture::GL41AttachmentTexture(const std::weak_ptr& backend, const Texture& texture) : GL41FixedAllocationTexture(backend, texture) { - Backend::updateTextureGPUFramebufferMemoryUsage(0, size()); + Backend::textureFramebufferCount.increment(); + Backend::textureFramebufferGPUMemSize.update(0, size()); } GL41AttachmentTexture::~GL41AttachmentTexture() { - Backend::updateTextureGPUFramebufferMemoryUsage(size(), 0); + Backend::textureFramebufferCount.decrement(); + Backend::textureFramebufferGPUMemSize.update(size(), 0); } // Strict resource textures @@ -243,6 +245,8 @@ using GL41VariableAllocationTexture = GL41Backend::GL41VariableAllocationTexture GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr& backend, const Texture& texture) : GL41Texture(backend, texture) { + Backend::textureResourceCount.increment(); + auto mipLevels = texture.getNumMips(); _allocatedMip = mipLevels; _maxAllocatedMip = _populatedMip = mipLevels; @@ -272,7 +276,8 @@ GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr } GL41VariableAllocationTexture::~GL41VariableAllocationTexture() { - Backend::updateTextureGPUMemoryUsage(_size, 0); + Backend::textureResourceCount.decrement(); + Backend::textureResourceGPUMemSize.update(_size, 0); } void GL41VariableAllocationTexture::allocateStorage(uint16 allocatedMip) { @@ -291,7 +296,8 @@ void GL41VariableAllocationTexture::allocateStorage(uint16 allocatedMip) { for (uint16_t mip = _allocatedMip; mip < mipLevels; ++mip) { _size += _gpuObject.evalMipSize(mip); } - Backend::updateTextureGPUMemoryUsage(0, _size); + Backend::textureResourceGPUMemSize.update(0, _size); + } @@ -462,7 +468,7 @@ void GL41VariableAllocationTexture::promote() { // destroy the old texture glDeleteTextures(1, &oldId); // update the memory usage - Backend::updateTextureGPUMemoryUsage(oldSize, 0); + Backend::textureResourceGPUMemSize.update(oldSize, 0); populateTransferQueue(); } @@ -493,7 +499,7 @@ void GL41VariableAllocationTexture::demote() { // destroy the old texture glDeleteTextures(1, &oldId); // update the memory usage - Backend::updateTextureGPUMemoryUsage(oldSize, 0); + Backend::textureResourceGPUMemSize.update(oldSize, 0); populateTransferQueue(); } diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 120be923f5..560dd3dabd 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -116,7 +116,7 @@ using GL45Texture = GL45Backend::GL45Texture; GL45Texture::GL45Texture(const std::weak_ptr& backend, const Texture& texture) : GLTexture(backend, texture, allocate(texture)) { - incrementTextureGPUCount(); + Backend::textureCount.increment(); } GLuint GL45Texture::allocate(const Texture& texture) { @@ -241,11 +241,11 @@ void GL45FixedAllocationTexture::syncSampler() const { using GL45AttachmentTexture = GL45Backend::GL45AttachmentTexture; GL45AttachmentTexture::GL45AttachmentTexture(const std::weak_ptr& backend, const Texture& texture) : GL45FixedAllocationTexture(backend, texture) { - Backend::updateTextureGPUFramebufferMemoryUsage(0, size()); + Backend::textureFramebufferGPUMemSize.update(0, size()); } GL45AttachmentTexture::~GL45AttachmentTexture() { - Backend::updateTextureGPUFramebufferMemoryUsage(size(), 0); + Backend::textureFramebufferGPUMemSize.update(size(), 0); } // Strict resource textures diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index 59e8c59d58..954cd3b912 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -34,7 +34,7 @@ GL45VariableAllocationTexture::GL45VariableAllocationTexture(const std::weak_ptr } GL45VariableAllocationTexture::~GL45VariableAllocationTexture() { - Backend::updateTextureGPUMemoryUsage(_size, 0); + Backend::textureGPUMemSize.update(_size, 0); } // Managed size resource textures @@ -77,8 +77,7 @@ void GL45ResourceTexture::allocateStorage(uint16 allocatedMip) { _size += _gpuObject.evalMipSize(mip); } - Backend::updateTextureGPUMemoryUsage(0, _size); - + Backend::textureResourceGPUMemSize.update(0, _size); } void GL45ResourceTexture::copyMipsFromTexture() { @@ -139,7 +138,7 @@ void GL45ResourceTexture::promote() { // destroy the old texture glDeleteTextures(1, &oldId); // update the memory usage - Backend::updateTextureGPUMemoryUsage(oldSize, 0); + Backend::textureResourceGPUMemSize.update(oldSize, 0); syncSampler(); populateTransferQueue(); } @@ -163,7 +162,7 @@ void GL45ResourceTexture::demote() { // destroy the old texture glDeleteTextures(1, &oldId); // update the memory usage - Backend::updateTextureGPUMemoryUsage(oldSize, 0); + Backend::textureResourceGPUMemSize.update(oldSize, 0); syncSampler(); populateTransferQueue(); } diff --git a/libraries/gpu/src/gpu/Buffer.cpp b/libraries/gpu/src/gpu/Buffer.cpp index 54533b3263..7ed2411c71 100644 --- a/libraries/gpu/src/gpu/Buffer.cpp +++ b/libraries/gpu/src/gpu/Buffer.cpp @@ -11,47 +11,20 @@ using namespace gpu; -std::atomic Buffer::_bufferCPUCount{ 0 }; -std::atomic Buffer::_bufferCPUMemoryUsage{ 0 }; - -void Buffer::updateBufferCPUMemoryUsage(Size prevObjectSize, Size newObjectSize) { - if (prevObjectSize == newObjectSize) { - return; - } - if (prevObjectSize > newObjectSize) { - _bufferCPUMemoryUsage.fetch_sub(prevObjectSize - newObjectSize); - } else { - _bufferCPUMemoryUsage.fetch_add(newObjectSize - prevObjectSize); - } -} - -void Buffer::incrementBufferCPUCount() { - _bufferCPUCount++; -} - -void Buffer::decrementBufferCPUCount() { - _bufferCPUCount--; -} +ContextMetricCount Buffer::_bufferCPUCount; +ContextMetricSize Buffer::_bufferCPUMemSize; uint32_t Buffer::getBufferCPUCount() { - return _bufferCPUCount.load(); + return _bufferCPUCount.getValue(); } -Buffer::Size Buffer::getBufferCPUMemoryUsage() { - return _bufferCPUMemoryUsage.load(); -} - -uint32_t Buffer::getBufferGPUCount() { - return Context::getBufferGPUCount(); -} - -Buffer::Size Buffer::getBufferGPUMemoryUsage() { - return Context::getBufferGPUMemoryUsage(); +Buffer::Size Buffer::getBufferCPUMemSize() { + return _bufferCPUMemSize.getValue(); } Buffer::Buffer(Size pageSize) : _renderPages(pageSize), _pages(pageSize) { - Buffer::incrementBufferCPUCount(); + _bufferCPUCount.increment(); } Buffer::Buffer(Size size, const Byte* bytes, Size pageSize) : Buffer(pageSize) { @@ -69,8 +42,8 @@ Buffer& Buffer::operator=(const Buffer& buf) { } Buffer::~Buffer() { - Buffer::decrementBufferCPUCount(); - Buffer::updateBufferCPUMemoryUsage(_sysmem.getSize(), 0); + _bufferCPUCount.decrement(); + _bufferCPUMemSize.update(_sysmem.getSize(), 0); } Buffer::Size Buffer::resize(Size size) { @@ -78,7 +51,7 @@ Buffer::Size Buffer::resize(Size size) { auto prevSize = _sysmem.getSize(); if (prevSize < size) { _sysmem.resize(_pages.accommodate(_end)); - Buffer::updateBufferCPUMemoryUsage(prevSize, _sysmem.getSize()); + _bufferCPUMemSize.update(prevSize, _sysmem.getSize()); } return _end; } diff --git a/libraries/gpu/src/gpu/Buffer.h b/libraries/gpu/src/gpu/Buffer.h index 290b84bef0..2eb2267f0d 100644 --- a/libraries/gpu/src/gpu/Buffer.h +++ b/libraries/gpu/src/gpu/Buffer.h @@ -21,16 +21,12 @@ #include "Resource.h" #include "Sysmem.h" #include "PageManager.h" +#include "Metric.h" namespace gpu { - class Buffer : public Resource { - static std::atomic _bufferCPUCount; - static std::atomic _bufferCPUMemoryUsage; - static void updateBufferCPUMemoryUsage(Size prevObjectSize, Size newObjectSize); - static void incrementBufferCPUCount(); - static void decrementBufferCPUCount(); - + static ContextMetricCount _bufferCPUCount; + static ContextMetricSize _bufferCPUMemSize; public: using Flag = PageManager::Flag; @@ -50,9 +46,7 @@ public: }; static uint32_t getBufferCPUCount(); - static Size getBufferCPUMemoryUsage(); - static uint32_t getBufferGPUCount(); - static Size getBufferGPUMemoryUsage(); + static Size getBufferCPUMemSize(); Buffer(Size pageSize = PageManager::DEFAULT_PAGE_SIZE); Buffer(Size size, const Byte* bytes, Size pageSize = PageManager::DEFAULT_PAGE_SIZE); diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index 78fef0af59..30b625522e 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -17,7 +17,6 @@ using namespace gpu; - void ContextStats::evalDelta(const ContextStats& begin, const ContextStats& end) { _ISNumFormatChanges = end._ISNumFormatChanges - begin._ISNumFormatChanges; _ISNumInputBufferChanges = end._ISNumInputBufferChanges - begin._ISNumInputBufferChanges; @@ -238,213 +237,75 @@ 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 }; -std::atomic Context::_textureGPUCount{ 0 }; -std::atomic Context::_textureGPUSparseCount { 0 }; -std::atomic Context::_textureTransferPendingSize { 0 }; -std::atomic Context::_textureGPUMemoryUsage { 0 }; -std::atomic Context::_textureGPUVirtualMemoryUsage { 0 }; -std::atomic Context::_textureGPUFramebufferMemoryUsage { 0 }; -std::atomic Context::_textureGPUSparseMemoryUsage { 0 }; -std::atomic Context::_textureGPUTransferCount { 0 }; +ContextMetricSize Backend::freeGPUMemSize; -void Context::setFreeGPUMemory(Size size) { - _freeGPUMemory.store(size); +ContextMetricCount Backend::bufferCount; +ContextMetricSize Backend::bufferGPUMemSize; + +ContextMetricCount Backend::textureCount; +ContextMetricCount Backend::textureFramebufferCount; +ContextMetricCount Backend::textureResourceCount; +ContextMetricCount Backend::textureExternalCount; + +ContextMetricSize Backend::textureGPUMemSize; +ContextMetricSize Backend::textureResidentGPUMemSize; +ContextMetricSize Backend::textureFramebufferGPUMemSize; +ContextMetricSize Backend::textureResourceGPUMemSize; +ContextMetricSize Backend::textureExternalGPUMemSize; + +ContextMetricCount Backend::texturePendingGPUTransferCount; +ContextMetricSize Backend::texturePendingGPUTransferMemSize; + +Size Context::getFreeGPUMemSize() { + return Backend::freeGPUMemSize.getValue(); } -Size Context::getFreeGPUMemory() { - return _freeGPUMemory.load(); -} - -Size Context::getUsedGPUMemory() { - return getTextureGPUMemoryUsage() + getBufferGPUMemoryUsage(); +Size Context::getUsedGPUMemSize() { + return getTextureGPUMemSize() + getBufferGPUMemSize(); }; -void Context::incrementBufferGPUCount() { - static std::atomic max { 0 }; - auto total = ++_bufferGPUCount; - if (total > max.load()) { - max = total; - // qCDebug(gpulogging) << "New max GPU buffers " << total; - } -} -void Context::decrementBufferGPUCount() { - --_bufferGPUCount; -} -void Context::updateBufferGPUMemoryUsage(Size prevObjectSize, Size newObjectSize) { - if (prevObjectSize == newObjectSize) { - return; - } - if (newObjectSize > prevObjectSize) { - _bufferGPUMemoryUsage.fetch_add(newObjectSize - prevObjectSize); - } else { - _bufferGPUMemoryUsage.fetch_sub(prevObjectSize - newObjectSize); - } -} - -void Context::incrementFenceCount() { - static std::atomic max { 0 }; - auto total = ++_fenceCount; - if (total > max.load()) { - max = total; - qCDebug(gpulogging) << "New max Fences " << total; - } -} -void Context::decrementFenceCount() { - --_fenceCount; -} - -void Context::incrementTextureGPUCount() { - static std::atomic max { 0 }; - auto total = ++_textureGPUCount; - if (total > max.load()) { - max = total; - // qCDebug(gpulogging) << "New max GPU textures " << total; - } -} -void Context::decrementTextureGPUCount() { - --_textureGPUCount; -} - -void Context::incrementTextureGPUSparseCount() { - static std::atomic max { 0 }; - auto total = ++_textureGPUSparseCount; - if (total > max.load()) { - max = total; - // qCDebug(gpulogging) << "New max GPU textures " << total; - } -} -void Context::decrementTextureGPUSparseCount() { - --_textureGPUSparseCount; -} - -void Context::updateTextureTransferPendingSize(Size prevObjectSize, Size newObjectSize) { - if (prevObjectSize == newObjectSize) { - return; - } - if (newObjectSize > prevObjectSize) { - _textureTransferPendingSize.fetch_add(newObjectSize - prevObjectSize); - } else { - _textureTransferPendingSize.fetch_sub(prevObjectSize - newObjectSize); - } -} - -void Context::updateTextureGPUMemoryUsage(Size prevObjectSize, Size newObjectSize) { - if (prevObjectSize == newObjectSize) { - return; - } - if (newObjectSize > prevObjectSize) { - _textureGPUMemoryUsage.fetch_add(newObjectSize - prevObjectSize); - } else { - _textureGPUMemoryUsage.fetch_sub(prevObjectSize - newObjectSize); - } -} - -void Context::updateTextureGPUVirtualMemoryUsage(Size prevObjectSize, Size newObjectSize) { - if (prevObjectSize == newObjectSize) { - return; - } - if (newObjectSize > prevObjectSize) { - _textureGPUVirtualMemoryUsage.fetch_add(newObjectSize - prevObjectSize); - } else { - _textureGPUVirtualMemoryUsage.fetch_sub(prevObjectSize - newObjectSize); - } -} - -void Context::updateTextureGPUFramebufferMemoryUsage(Size prevObjectSize, Size newObjectSize) { - if (prevObjectSize == newObjectSize) { - return; - } - if (newObjectSize > prevObjectSize) { - _textureGPUFramebufferMemoryUsage.fetch_add(newObjectSize - prevObjectSize); - } else { - _textureGPUFramebufferMemoryUsage.fetch_sub(prevObjectSize - newObjectSize); - } -} - -void Context::updateTextureGPUSparseMemoryUsage(Size prevObjectSize, Size newObjectSize) { - if (prevObjectSize == newObjectSize) { - return; - } - if (newObjectSize > prevObjectSize) { - _textureGPUSparseMemoryUsage.fetch_add(newObjectSize - prevObjectSize); - } else { - _textureGPUSparseMemoryUsage.fetch_sub(prevObjectSize - newObjectSize); - } -} - -void Context::incrementTextureGPUTransferCount() { - static std::atomic max { 0 }; - auto total = ++_textureGPUTransferCount; - if (total > max.load()) { - max = total; - // qCDebug(gpulogging) << "New max GPU textures transfers" << total; - } -} - -void Context::decrementTextureGPUTransferCount() { - --_textureGPUTransferCount; -} - uint32_t Context::getBufferGPUCount() { - return _bufferGPUCount.load(); + return Backend::bufferCount.getValue(); } -Context::Size Context::getBufferGPUMemoryUsage() { - return _bufferGPUMemoryUsage.load(); +Context::Size Context::getBufferGPUMemSize() { + return Backend::bufferGPUMemSize.getValue(); } uint32_t Context::getTextureGPUCount() { - return _textureGPUCount.load(); + return Backend::textureCount.getValue(); } -uint32_t Context::getTextureGPUSparseCount() { - return _textureGPUSparseCount.load(); +uint32_t Context::getTextureFramebufferGPUCount() { + return Backend::textureFramebufferCount.getValue(); +} +uint32_t Context::getTextureResourceGPUCount() { + return Backend::textureResourceCount.getValue(); +} +uint32_t Context::getTextureExternalGPUCount() { + return Backend::textureExternalCount.getValue(); } -Context::Size Context::getTextureTransferPendingSize() { - return _textureTransferPendingSize.load(); +Size Context::getTextureGPUMemSize() { + return Backend::textureGPUMemSize.getValue(); +} +Size Context::getTextureResidentGPUMemSize() { + return Backend::textureResidentGPUMemSize.getValue(); +} +Size Context::getTextureFramebufferGPUMemSize() { + return Backend::textureFramebufferGPUMemSize.getValue(); +} +Size Context::getTextureResourceGPUMemSize() { + return Backend::textureResourceGPUMemSize.getValue(); +} +Size Context::getTextureExternalGPUMemSize() { + return Backend::textureExternalGPUMemSize.getValue(); } -Context::Size Context::getTextureGPUMemoryUsage() { - return _textureGPUMemoryUsage.load(); +uint32_t Context::getTexturePendingGPUTransferCount() { + return Backend::texturePendingGPUTransferCount.getValue(); } - -Context::Size Context::getTextureGPUVirtualMemoryUsage() { - return _textureGPUVirtualMemoryUsage.load(); +Size Context::getTexturePendingGPUTransferMemSize() { + return Backend::texturePendingGPUTransferMemSize.getValue(); } - -Context::Size Context::getTextureGPUFramebufferMemoryUsage() { - return _textureGPUFramebufferMemoryUsage.load(); -} - -Context::Size Context::getTextureGPUSparseMemoryUsage() { - return _textureGPUSparseMemoryUsage.load(); -} - -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); } -void Backend::incrementTextureGPUCount() { Context::incrementTextureGPUCount(); } -void Backend::decrementTextureGPUCount() { Context::decrementTextureGPUCount(); } -void Backend::incrementTextureGPUSparseCount() { Context::incrementTextureGPUSparseCount(); } -void Backend::decrementTextureGPUSparseCount() { Context::decrementTextureGPUSparseCount(); } -void Backend::updateTextureTransferPendingSize(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateTextureTransferPendingSize(prevObjectSize, newObjectSize); } -void Backend::updateTextureGPUMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateTextureGPUMemoryUsage(prevObjectSize, newObjectSize); } -void Backend::updateTextureGPUVirtualMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateTextureGPUVirtualMemoryUsage(prevObjectSize, newObjectSize); } -void Backend::updateTextureGPUFramebufferMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateTextureGPUFramebufferMemoryUsage(prevObjectSize, newObjectSize); } -void Backend::updateTextureGPUSparseMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateTextureGPUSparseMemoryUsage(prevObjectSize, newObjectSize); } -void Backend::incrementTextureGPUTransferCount() { Context::incrementTextureGPUTransferCount(); } -void Backend::decrementTextureGPUTransferCount() { Context::decrementTextureGPUTransferCount(); } - - diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index 55e0bf1abb..34207bea5f 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -18,7 +18,7 @@ #include "Forward.h" #include "Batch.h" -#include "Resource.h" +#include "Buffer.h" #include "Texture.h" #include "Pipeline.h" #include "Framebuffer.h" @@ -28,47 +28,6 @@ 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; @@ -135,38 +94,27 @@ public: virtual bool isTextureManagementSparseEnabled() const = 0; - // 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); - static void incrementTextureGPUCount(); - static void decrementTextureGPUCount(); - static void incrementTextureGPUSparseCount(); - 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 updateTextureGPUFramebufferMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize); - static void incrementTextureGPUTransferCount(); - static void decrementTextureGPUTransferCount(); - - static ContextMetricSize freeGPUMemSize; + // These should only be accessed by Backend implementation to report the buffer and texture allocations, + // they are NOT public objects + static ContextMetricSize freeGPUMemSize; static ContextMetricCount bufferCount; - static ContextMetricSize bufferGPUMemSize; + static ContextMetricSize bufferGPUMemSize; static ContextMetricCount textureCount; - static ContextMetricSize textureGPUMemSize; - static ContextMetricSize textureResidentGPUMemSize; - static ContextMetricSize textureResourceGPUMemSize; - static ContextMetricSize textureFramebufferGPUMemSize; + static ContextMetricCount textureFramebufferCount; + static ContextMetricCount textureResourceCount; + static ContextMetricCount textureExternalCount; - static ContextMetricCount textureTransferCount; + static ContextMetricSize textureGPUMemSize; + static ContextMetricSize textureResidentGPUMemSize; + static ContextMetricSize textureFramebufferGPUMemSize; + static ContextMetricSize textureResourceGPUMemSize; + static ContextMetricSize textureExternalGPUMemSize; + + static ContextMetricCount texturePendingGPUTransferCount; + static ContextMetricSize texturePendingGPUTransferMemSize; protected: @@ -276,21 +224,25 @@ public: double getFrameTimerGPUAverage() const; double getFrameTimerBatchAverage() const; + static Size getFreeGPUMemSize(); + static Size getUsedGPUMemSize(); + static uint32_t getBufferGPUCount(); - static Size getBufferGPUMemoryUsage(); + static Size getBufferGPUMemSize(); static uint32_t getTextureGPUCount(); - static uint32_t getTextureGPUResourceCount(); - static Size getFreeGPUMemory(); - static Size getUsedGPUMemory(); - static Size getTextureTransferPendingSize(); - static Size getTextureGPUMemoryUsage(); + static uint32_t getTextureFramebufferGPUCount(); + static uint32_t getTextureResourceGPUCount(); + static uint32_t getTextureExternalGPUCount(); - static Size getTextureGPUResourceMemoryUsage(); - static Size getTextureGPUResidentMemoryUsage(); - static Size getTextureGPUFramebufferMemoryUsage(); + static Size getTextureGPUMemSize(); + static Size getTextureResidentGPUMemSize(); + static Size getTextureFramebufferGPUMemSize(); + static Size getTextureResourceGPUMemSize(); + static Size getTextureExternalGPUMemSize(); - static uint32_t getTextureGPUTransferCount(); + static uint32_t getTexturePendingGPUTransferCount(); + static Size getTexturePendingGPUTransferMemSize(); protected: Context(const Context& context); @@ -315,49 +267,6 @@ protected: static std::once_flag _initialized; friend class Shader; - - // These should only be accessed by the Backend, they are NOT public calls - static void incrementBufferGPUCount(); - static void decrementBufferGPUCount(); - static void updateBufferGPUMemoryUsage(Size prevObjectSize, Size newObjectSize); - - static void incrementFenceCount(); - static void decrementFenceCount(); - - static void setFreeGPUMemory(Size size); - static void incrementTextureGPUCount(); - static void decrementTextureGPUCount(); - 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; - - static std::atomic _bufferGPUCount; - static std::atomic _bufferGPUMemoryUsage; - - static std::atomic _textureGPUCount; - static std::atomic _textureGPUSparseCount; - static std::atomic _textureTransferPendingSize; - static std::atomic _textureGPUMemoryUsage; - static std::atomic _textureGPUSparseMemoryUsage; - static std::atomic _textureGPUVirtualMemoryUsage; - static std::atomic _textureGPUFramebufferMemoryUsage; - static std::atomic _textureGPUTransferCount; - friend class Backend; }; typedef std::shared_ptr ContextPointer; diff --git a/libraries/gpu/src/gpu/Metric.h b/libraries/gpu/src/gpu/Metric.h new file mode 100644 index 0000000000..3e5cea6f69 --- /dev/null +++ b/libraries/gpu/src/gpu/Metric.h @@ -0,0 +1,64 @@ +// +// Metric.h +// libraries/gpu/src/gpu +// +// Created by Sam Gateau on 5/17/2017. +// Copyright 2017 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 +// +#ifndef hifi_gpu_Metric_h +#define hifi_gpu_Metric_h + +#include "Forward.h" + +namespace gpu { + +template +class Metric { + std::atomic _value { 0 }; + std::atomic _maximum { 0 }; + +public: + T getValue() { return _value; } + T getMaximum() { return _maximum; } + + void set(T newValue) { + _value = newValue; + } + void increment() { + auto total = ++_value; + if (total > _maximum.load()) { + _maximum = total; + } + } + void decrement() { + --_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 = Metric; +using ContextMetricSize = Metric; + +} +#endif diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index c65723c854..78f8e7da9e 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -42,6 +42,7 @@ protected: } + // FIXME Compatibility with headers that rely on Resource.h for the buffer and buffer view definitions #include "Buffer.h" diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index 1a11df876b..4dd40eb861 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -31,8 +31,9 @@ using namespace gpu; int TexturePointerMetaTypeId = qRegisterMetaType(); -std::atomic Texture::_textureCPUCount{ 0 }; -std::atomic Texture::_textureCPUMemoryUsage{ 0 }; + +ContextMetricCount Texture::_textureCPUCount; +ContextMetricSize Texture::_textureCPUMemSize; std::atomic Texture::_allowedCPUMemoryUsage { 0 }; @@ -58,56 +59,18 @@ void Texture::setEnableSparseTextures(bool enabled) { #endif } -void Texture::updateTextureCPUMemoryUsage(Size prevObjectSize, Size newObjectSize) { - if (prevObjectSize == newObjectSize) { - return; - } - if (prevObjectSize > newObjectSize) { - _textureCPUMemoryUsage.fetch_sub(prevObjectSize - newObjectSize); - } else { - _textureCPUMemoryUsage.fetch_add(newObjectSize - prevObjectSize); - } -} - bool Texture::getEnableSparseTextures() { return _enableSparseTextures.load(); } uint32_t Texture::getTextureCPUCount() { - return _textureCPUCount.load(); + return _textureCPUCount.getValue(); } -Texture::Size Texture::getTextureCPUMemoryUsage() { - return _textureCPUMemoryUsage.load(); +Texture::Size Texture::getTextureCPUMemSize() { + return _textureCPUMemSize.getValue(); } -uint32_t Texture::getTextureGPUCount() { - return Context::getTextureGPUCount(); -} - -Texture::Size Texture::getTextureTransferPendingSize() { - return Context::getTextureTransferPendingSize(); -} - -Texture::Size Texture::getTextureGPUMemoryUsage() { - return Context::getTextureGPUMemoryUsage(); -} - -Texture::Size getTextureGPUResourceMemoryUsage() { - return Context::getTextureGPUResourceMemoryUsage(); -} - -Texture::Size getTextureGPUResidentMemoryUsage() { - return Context::getTextureGPUResidentMemoryUsage(); -} - -Texture::Size Texture::getTextureGPUFramebufferMemoryUsage() { - return Context::getTextureGPUFramebufferMemoryUsage(); -} - -uint32_t Texture::getTextureGPUTransferCount() { - return Context::getTextureGPUTransferCount(); -} Texture::Size Texture::getAllowedGPUMemoryUsage() { return _allowedCPUMemoryUsage; @@ -257,11 +220,11 @@ TexturePointer Texture::create(TextureUsageType usageType, Type type, const Elem Texture::Texture(TextureUsageType usageType) : Resource(), _usageType(usageType) { - _textureCPUCount++; + _textureCPUCount.increment(); } Texture::~Texture() { - _textureCPUCount--; + _textureCPUCount.decrement(); if (_usageType == TextureUsageType::EXTERNAL) { Texture::ExternalUpdates externalUpdates; { diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 1b197d04d2..3e4fdf113a 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -21,6 +21,7 @@ #include "Forward.h" #include "Resource.h" +#include "Metric.h" const int ABSOLUTE_MAX_TEXTURE_NUM_PIXELS = 8192 * 8192; @@ -167,8 +168,9 @@ enum class TextureUsageType : uint8 { }; class Texture : public Resource { - static std::atomic _textureCPUCount; - static std::atomic _textureCPUMemoryUsage; + static ContextMetricCount _textureCPUCount; + static ContextMetricSize _textureCPUMemSize; + static std::atomic _allowedCPUMemoryUsage; static std::atomic _enableSparseTextures; static void updateTextureCPUMemoryUsage(Size prevObjectSize, Size newObjectSize); @@ -176,14 +178,8 @@ class Texture : public Resource { public: static const uint32_t CUBE_FACE_COUNT { 6 }; static uint32_t getTextureCPUCount(); - static Size getTextureCPUMemoryUsage(); - static uint32_t getTextureGPUCount(); - static Size getTextureTransferPendingSize(); - static Size getTextureGPUMemoryUsage(); - static Size getTextureGPUResourceMemoryUsage(); - static Size getTextureGPUResidentMemoryUsage(); - static Size getTextureGPUFramebufferMemoryUsage(); - static uint32_t getTextureGPUTransferCount(); + static Size getTextureCPUMemSize(); + 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 a3ad7a0a5c..9a76f31ef5 100644 --- a/libraries/render/src/render/EngineStats.cpp +++ b/libraries/render/src/render/EngineStats.cpp @@ -24,19 +24,22 @@ void EngineStats::run(const RenderContextPointer& renderContext) { auto config = std::static_pointer_cast(renderContext->jobConfig); config->bufferCPUCount = gpu::Buffer::getBufferCPUCount(); - config->bufferGPUCount = gpu::Buffer::getBufferGPUCount(); - config->bufferCPUMemoryUsage = gpu::Buffer::getBufferCPUMemoryUsage(); - config->bufferGPUMemoryUsage = gpu::Buffer::getBufferGPUMemoryUsage(); + config->bufferGPUCount = gpu::Context::getBufferGPUCount(); + config->bufferCPUMemSize = gpu::Buffer::getBufferCPUMemSize(); + config->bufferGPUMemSize = gpu::Context::getBufferGPUMemSize(); config->textureCPUCount = gpu::Texture::getTextureCPUCount(); - config->textureGPUCount = gpu::Texture::getTextureGPUCount(); - config->textureCPUMemoryUsage = gpu::Texture::getTextureCPUMemoryUsage(); - config->textureGPUMemoryUsage = gpu::Texture::getTextureGPUMemoryUsage(); - config->textureGPUVirtualMemoryUsage = gpu::Texture::getTextureGPUVirtualMemoryUsage(); - config->textureGPUTransferCount = gpu::Texture::getTextureGPUTransferCount(); - config->textureTransferPendingSize = gpu::Texture::getTextureTransferPendingSize(); + config->textureGPUCount = gpu::Context::getTextureGPUCount(); + config->textureCPUMemSize = gpu::Texture::getTextureCPUMemSize(); + config->textureGPUMemSize = gpu::Context::getTextureGPUMemSize(); - config->textureGPUFramebufferSize = gpu::Texture::getTextureGPUFramebufferMemoryUsage(); + config->textureResidentGPUMemSize = gpu::Context::getTextureResidentGPUMemSize(); + config->textureFramebufferGPUMemSize = gpu::Context::getTextureFramebufferGPUMemSize(); + config->textureResourceGPUMemSize = gpu::Context::getTextureResourceGPUMemSize(); + config->textureExternalGPUMemSize = gpu::Context::getTextureExternalGPUMemSize(); + + config->texturePendingGPUTransferCount = gpu::Context::getTexturePendingGPUTransferCount(); + config->texturePendingGPUTransferSize = gpu::Context::getTexturePendingGPUTransferMemSize(); renderContext->args->_context->getFrameStats(_gpuStats); diff --git a/libraries/render/src/render/EngineStats.h b/libraries/render/src/render/EngineStats.h index ee89d0845f..5fd97eed38 100644 --- a/libraries/render/src/render/EngineStats.h +++ b/libraries/render/src/render/EngineStats.h @@ -26,19 +26,21 @@ namespace render { Q_PROPERTY(quint32 bufferCPUCount MEMBER bufferCPUCount NOTIFY dirty) Q_PROPERTY(quint32 bufferGPUCount MEMBER bufferGPUCount NOTIFY dirty) - Q_PROPERTY(qint64 bufferCPUMemoryUsage MEMBER bufferCPUMemoryUsage NOTIFY dirty) - Q_PROPERTY(qint64 bufferGPUMemoryUsage MEMBER bufferGPUMemoryUsage NOTIFY dirty) + Q_PROPERTY(qint64 bufferCPUMemSize MEMBER bufferCPUMemSize NOTIFY dirty) + Q_PROPERTY(qint64 bufferGPUMemSize MEMBER bufferGPUMemSize NOTIFY dirty) Q_PROPERTY(quint32 textureCPUCount MEMBER textureCPUCount NOTIFY dirty) Q_PROPERTY(quint32 textureGPUCount MEMBER textureGPUCount NOTIFY dirty) - Q_PROPERTY(qint64 textureCPUMemoryUsage MEMBER textureCPUMemoryUsage NOTIFY dirty) - Q_PROPERTY(qint64 textureGPUMemoryUsage MEMBER textureGPUMemoryUsage NOTIFY dirty) - Q_PROPERTY(qint64 textureGPUVirtualMemoryUsage MEMBER textureGPUVirtualMemoryUsage NOTIFY dirty) - Q_PROPERTY(quint32 textureGPUTransferCount MEMBER textureGPUTransferCount NOTIFY dirty) + Q_PROPERTY(qint64 textureCPUMemSize MEMBER textureCPUMemSize NOTIFY dirty) + Q_PROPERTY(qint64 textureGPUMemSize MEMBER textureGPUMemSize NOTIFY dirty) - Q_PROPERTY(quint32 textureTransferPendingSize MEMBER textureTransferPendingSize NOTIFY dirty) + Q_PROPERTY(qint64 textureResidentGPUMemSize MEMBER textureResidentGPUMemSize NOTIFY dirty) + Q_PROPERTY(qint64 textureFramebufferGPUMemSize MEMBER textureFramebufferGPUMemSize NOTIFY dirty) + Q_PROPERTY(qint64 textureResourceGPUMemSize MEMBER textureResourceGPUMemSize NOTIFY dirty) + Q_PROPERTY(qint64 textureExternalGPUMemSize MEMBER textureExternalGPUMemSize NOTIFY dirty) - Q_PROPERTY(qint64 textureGPUFramebufferSize MEMBER textureGPUFramebufferSize NOTIFY dirty) + Q_PROPERTY(quint32 texturePendingGPUTransferCount MEMBER texturePendingGPUTransferCount NOTIFY dirty) + Q_PROPERTY(qint64 texturePendingGPUTransferSize MEMBER texturePendingGPUTransferSize NOTIFY dirty) Q_PROPERTY(quint32 frameAPIDrawcallCount MEMBER frameAPIDrawcallCount NOTIFY dirty) Q_PROPERTY(quint32 frameDrawcallCount MEMBER frameDrawcallCount NOTIFY dirty) @@ -60,18 +62,19 @@ namespace render { quint32 bufferCPUCount{ 0 }; quint32 bufferGPUCount{ 0 }; - qint64 bufferCPUMemoryUsage{ 0 }; - qint64 bufferGPUMemoryUsage{ 0 }; + qint64 bufferCPUMemSize { 0 }; + qint64 bufferGPUMemSize { 0 }; quint32 textureCPUCount{ 0 }; quint32 textureGPUCount{ 0 }; - qint64 textureCPUMemoryUsage{ 0 }; - qint64 textureGPUMemoryUsage{ 0 }; - qint64 textureGPUVirtualMemoryUsage{ 0 }; - quint32 textureGPUTransferCount { 0 }; - qint64 textureTransferPendingSize { 0 }; - - qint64 textureGPUFramebufferSize { 0 }; + qint64 textureCPUMemSize { 0 }; + qint64 textureGPUMemSize { 0 }; + qint64 textureResidentGPUMemSize { 0 }; + qint64 textureFramebufferGPUMemSize { 0 }; + qint64 textureResourceGPUMemSize { 0 }; + qint64 textureExternalGPUMemSize { 0 }; + quint32 texturePendingGPUTransferCount { 0 }; + qint64 texturePendingGPUTransferSize { 0 }; quint32 frameAPIDrawcallCount{ 0 }; quint32 frameDrawcallCount{ 0 }; diff --git a/scripts/developer/utilities/render/textureMonitor.qml b/scripts/developer/utilities/render/textureMonitor.qml index 726e7fe88b..eba35bfc5b 100644 --- a/scripts/developer/utilities/render/textureMonitor.qml +++ b/scripts/developer/utilities/render/textureMonitor.qml @@ -44,7 +44,7 @@ Item { color: "#1AC567" }, { - prop: "textureGPUTransferCount", + prop: "texturePendingGPUTransferCount", label: "Transfer", color: "#9495FF" } @@ -59,12 +59,12 @@ Item { valueNumDigits: "1" plots: [ { - prop: "textureCPUMemoryUsage", + prop: "textureCPUMemSize", label: "CPU", color: "#00B4EF" }, { - prop: "textureGPUMemoryUsage", + prop: "textureGPUMemSize", label: "GPU", color: "#1AC567" }, @@ -74,7 +74,17 @@ Item { color: "#9495FF" }, { - prop: "textureGPUFramebufferSize", + prop: "textureResourceGPUMemSize", + label: "Resource", + color: "#1FC6A6" + }, + { + prop: "textureResidentGPUMemSize", + label: "Resident", + color: "#FF6309" + }, + { + prop: "textureFramebufferGPUMemSize", label: "Framebuffer", color: "#EF93D1" } diff --git a/tests/render-perf/src/main.cpp b/tests/render-perf/src/main.cpp index cff866edbf..1e81ee590e 100644 --- a/tests/render-perf/src/main.cpp +++ b/tests/render-perf/src/main.cpp @@ -753,8 +753,8 @@ private: void updateText() { QString title = QString("FPS %1 Culling %2 TextureMemory GPU %3 CPU %4 Max GPU %5") .arg(_fps).arg(_cullingEnabled) - .arg(toHumanSize(gpu::Context::getTextureGPUMemoryUsage(), 2)) - .arg(toHumanSize(gpu::Texture::getTextureCPUMemoryUsage(), 2)) + .arg(toHumanSize(gpu::Context::getTextureGPUMemSize(), 2)) + .arg(toHumanSize(gpu::Texture::getTextureCPUMemSize(), 2)) .arg(toHumanSize(gpu::Texture::getAllowedGPUMemoryUsage(), 2)); setTitle(title); #if 0 From 9c154122d38c4bcdd2157ff9a7744d713ba253b9 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 18 May 2017 13:08:13 -0700 Subject: [PATCH 03/12] Introdicing the format factor and merging with master becasue of protocol change... --- libraries/gpu/src/gpu/Format.h | 75 ++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 8b7bbdcbed..729a1bbdc0 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -21,7 +21,7 @@ namespace gpu { class Backend; // Description of a scalar type -enum Type { +enum Type : uint8_t { FLOAT = 0, INT32, @@ -39,6 +39,8 @@ enum Type { NINT8, NUINT8, + COMPRESSED, + NUM_TYPES, BOOL = UINT8, @@ -80,11 +82,13 @@ static const bool TYPE_IS_INTEGER[NUM_TYPES] = { false, false, false, - false + false, + + false, }; // Dimension of an Element -enum Dimension { +enum Dimension : uint8_t { SCALAR = 0, VEC2, VEC3, @@ -92,6 +96,7 @@ enum Dimension { MAT2, MAT3, MAT4, + BLOB, // Blob element's size is defined from the type and semantic, it s counted as 1 component NUM_DIMENSIONS, }; @@ -104,6 +109,7 @@ static const int LOCATION_COUNT[NUM_DIMENSIONS] = { 1, 3, 4, + 1, }; // Count (of scalars) in an Element for a given Dimension's location @@ -115,6 +121,7 @@ static const int SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = { 4, 3, 4, + 1, }; // Count (of scalars) in an Element for a given Dimension @@ -126,11 +133,12 @@ static const int SCALAR_COUNT[NUM_DIMENSIONS] = { 4, 9, 16, + 1, }; // Semantic of an Element // Provide information on how to use the element -enum Semantic { +enum Semantic : uint8_t { RAW = 0, // used as RAW memory RED, @@ -156,6 +164,8 @@ enum Semantic { SBGRA, // These are generic compression format smeantic for images + // THey must be used with Dim = BLOB and Type = Compressed + // THe size of a compressed element is defined from the semantic _FIRST_COMPRESSED, COMPRESSED_BC1_SRGB, @@ -174,9 +184,58 @@ enum Semantic { SAMPLER, SAMPLER_MULTISAMPLE, SAMPLER_SHADOW, - - - NUM_SEMANTICS, + + + NUM_SEMANTICS, // total Number of semantics (not a valid Semantic)! +}; + +// Array providing the scaling factor to size in bytes depending on a given semantic +static const int SEMANTIC_SIZE_FACTOR[NUM_SEMANTICS] = { + 1, //RAW = 0, // used as RAW memory + + 1, //RED, + 1, //RGB, + 1, //RGBA, + 1, //BGRA, + + 1, //XY, + 1, //XYZ, + 1, //XYZW, + 1, //QUAT, + 1, //UV, + 1, //INDEX, //used by index buffer of a mesh + 1, //PART, // used by part buffer of a mesh + + 1, //DEPTH, // Depth only buffer + 1, //STENCIL, // Stencil only buffer + 1, //DEPTH_STENCIL, // Depth Stencil buffer + + 1, //SRED, + 1, //SRGB, + 1, //SRGBA, + 1, //SBGRA, + + // These are generic compression format smeantic for images + // THey must be used with Dim = BLOB and Type = Compressed + // THe size of a compressed element is defined from the semantic + 1, //_FIRST_COMPRESSED, + + 1, //COMPRESSED_BC1_SRGB, + 1, //COMPRESSED_BC1_SRGBA, + 1, //COMPRESSED_BC3_SRGBA, + 1, //COMPRESSED_BC4_RED, + 1, //COMPRESSED_BC5_XY, + + 1, //_LAST_COMPRESSED, + + 1, //R11G11B10, + + 1, //UNIFORM, + 1, //UNIFORM_BUFFER, + 1, //RESOURCE_BUFFER, + 1, //SAMPLER, + 1, //SAMPLER_MULTISAMPLE, + 1, //SAMPLER_SHADOW, }; // Element is a simple 16bit value that contains everything we need to know about an element @@ -206,7 +265,7 @@ public: bool isInteger() const { return TYPE_IS_INTEGER[getType()]; } uint8 getScalarCount() const { return SCALAR_COUNT[(Dimension)_dimension]; } - uint32 getSize() const { return SCALAR_COUNT[_dimension] * TYPE_SIZE[_type]; } + uint32 getSize() const { return (SCALAR_COUNT[_dimension] * TYPE_SIZE[_type] * SEMANTIC_SIZE_FACTOR[_semantic]); } uint8 getLocationCount() const { return LOCATION_COUNT[(Dimension)_dimension]; } uint8 getLocationScalarCount() const { return SCALAR_COUNT_PER_LOCATION[(Dimension)_dimension]; } From c449229850b4209971bf3c260632aa8a04ef44a5 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 19 May 2017 17:52:56 -0700 Subject: [PATCH 04/12] Cleaned up the counters for memory --- libraries/gpu-gl/src/gpu/gl/GLBackend.cpp | 8 ++-- libraries/gpu-gl/src/gpu/gl/GLBuffer.cpp | 3 ++ libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp | 47 ++++++++++++++++++- libraries/gpu-gl/src/gpu/gl41/GL41Backend.h | 1 + .../src/gpu/gl41/GL41BackendTexture.cpp | 10 +++- libraries/gpu-gl/src/gpu/gl45/GL45Backend.h | 1 + .../src/gpu/gl45/GL45BackendTexture.cpp | 11 ++++- .../gpu/gl45/GL45BackendVariableTexture.cpp | 4 +- libraries/gpu/src/gpu/Context.cpp | 11 +++-- libraries/gpu/src/gpu/Context.h | 5 +- libraries/gpu/src/gpu/Format.cpp | 10 ++-- libraries/physics/src/ObjectMotionState.cpp | 2 +- libraries/render/src/render/EngineStats.cpp | 5 ++ libraries/render/src/render/EngineStats.h | 15 ++++-- .../utilities/render/textureMonitor.qml | 41 +++++++++++----- 15 files changed, 136 insertions(+), 38 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index 5ba1fb09f8..0d7c1f2ca1 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -644,8 +644,8 @@ void GLBackend::recycle() const { ids.reserve(buffersTrash.size()); for (auto pair : buffersTrash) { ids.push_back(pair.first); - bufferCount.decrement(); - bufferGPUMemSize.update(pair.second, 0); + // bufferCount.decrement(); + // bufferGPUMemSize.update(pair.second, 0); } if (!ids.empty()) { glDeleteBuffers((GLsizei)ids.size(), ids.data()); @@ -678,8 +678,8 @@ void GLBackend::recycle() const { ids.reserve(texturesTrash.size()); for (auto pair : texturesTrash) { ids.push_back(pair.first); - textureCount.decrement(); - textureGPUMemSize.update(pair.second, 0); + // textureCount.decrement(); + // textureGPUMemSize.update(pair.second, 0); } if (!ids.empty()) { glDeleteTextures((GLsizei)ids.size(), ids.data()); diff --git a/libraries/gpu-gl/src/gpu/gl/GLBuffer.cpp b/libraries/gpu-gl/src/gpu/gl/GLBuffer.cpp index f0307e4aa3..b058b5afd8 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBuffer.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBuffer.cpp @@ -13,6 +13,9 @@ using namespace gpu; using namespace gpu::gl; GLBuffer::~GLBuffer() { + Backend::bufferCount.decrement(); + Backend::bufferGPUMemSize.update(_size, 0); + if (_id) { auto backend = _backend.lock(); if (backend) { diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp index 12bfb8e70b..ad706da8ae 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp @@ -347,8 +347,31 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E case gpu::SRGBA: texel.internalFormat = GL_SRGB8_ALPHA8; break; + default: + qCWarning(gpugllogging) << "Unknown combination of texel format"; + } + break; + } + case gpu::BLOB: { + texel.format = GL_RGBA; + texel.type = ELEMENT_TYPE_TO_GL[srcFormat.getType()]; + + switch (srcFormat.getSemantic()) { + case gpu::BGRA: + case gpu::SBGRA: + texel.format = GL_BGRA; + break; + case gpu::RGB: + case gpu::RGBA: + case gpu::SRGB: + case gpu::SRGBA: + default: + break; + }; + + switch (dstFormat.getSemantic()) { case gpu::COMPRESSED_BC4_RED: texel.internalFormat = GL_COMPRESSED_RED_RGTC1; break; @@ -364,7 +387,6 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E case gpu::COMPRESSED_BC5_XY: texel.internalFormat = GL_COMPRESSED_RG_RGTC2; break; - default: qCWarning(gpugllogging) << "Unknown combination of texel format"; } @@ -618,7 +640,30 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E case gpu::SRGBA: texel.internalFormat = GL_SRGB8_ALPHA8; // standard 2.2 gamma correction color break; + default: + qCWarning(gpugllogging) << "Unknown combination of texel format"; + } + break; + } + case gpu::BLOB: { + texel.format = GL_RGBA; + texel.type = ELEMENT_TYPE_TO_GL[srcFormat.getType()]; + + switch (srcFormat.getSemantic()) { + case gpu::BGRA: + case gpu::SBGRA: + texel.format = GL_BGRA; + break; + case gpu::RGB: + case gpu::RGBA: + case gpu::SRGB: + case gpu::SRGBA: + default: + break; + }; + + switch (dstFormat.getSemantic()) { case gpu::COMPRESSED_BC4_RED: texel.internalFormat = GL_COMPRESSED_RED_RGTC1; break; diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h index 4caa29574c..003e7e83c3 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h @@ -92,6 +92,7 @@ public: friend class GL41Backend; protected: GL41StrictResourceTexture(const std::weak_ptr& backend, const Texture& texture); + ~GL41StrictResourceTexture(); }; class GL41VariableAllocationTexture : public GL41Texture, public GLVariableAllocationSupport { diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 6561f6cb50..1dfad78d47 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -76,7 +76,6 @@ using GL41Texture = GL41Backend::GL41Texture; GL41Texture::GL41Texture(const std::weak_ptr& backend, const Texture& texture) : GLTexture(backend, texture, allocate(texture)) { - Backend::textureCount.increment(); } GLuint GL41Texture::allocate(const Texture& texture) { @@ -223,6 +222,9 @@ GL41AttachmentTexture::~GL41AttachmentTexture() { using GL41StrictResourceTexture = GL41Backend::GL41StrictResourceTexture; GL41StrictResourceTexture::GL41StrictResourceTexture(const std::weak_ptr& backend, const Texture& texture) : GL41FixedAllocationTexture(backend, texture) { + Backend::textureResidentCount.increment(); + Backend::textureResidentGPUMemSize.update(0, size()); + withPreservedTexture([&] { auto mipLevels = _gpuObject.getNumMips(); @@ -240,6 +242,12 @@ GL41StrictResourceTexture::GL41StrictResourceTexture(const std::weak_ptr& backend, const Texture& texture) : diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index fe2761b37d..a0a919f4ad 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -86,6 +86,7 @@ public: friend class GL45Backend; protected: GL45StrictResourceTexture(const std::weak_ptr& backend, const Texture& texture); + ~GL45StrictResourceTexture(); }; // diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 560dd3dabd..60408b05fb 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -116,7 +116,6 @@ using GL45Texture = GL45Backend::GL45Texture; GL45Texture::GL45Texture(const std::weak_ptr& backend, const Texture& texture) : GLTexture(backend, texture, allocate(texture)) { - Backend::textureCount.increment(); } GLuint GL45Texture::allocate(const Texture& texture) { @@ -241,10 +240,12 @@ void GL45FixedAllocationTexture::syncSampler() const { using GL45AttachmentTexture = GL45Backend::GL45AttachmentTexture; GL45AttachmentTexture::GL45AttachmentTexture(const std::weak_ptr& backend, const Texture& texture) : GL45FixedAllocationTexture(backend, texture) { + Backend::textureFramebufferCount.increment(); Backend::textureFramebufferGPUMemSize.update(0, size()); } GL45AttachmentTexture::~GL45AttachmentTexture() { + Backend::textureFramebufferCount.decrement(); Backend::textureFramebufferGPUMemSize.update(size(), 0); } @@ -252,6 +253,9 @@ GL45AttachmentTexture::~GL45AttachmentTexture() { using GL45StrictResourceTexture = GL45Backend::GL45StrictResourceTexture; GL45StrictResourceTexture::GL45StrictResourceTexture(const std::weak_ptr& backend, const Texture& texture) : GL45FixedAllocationTexture(backend, texture) { + Backend::textureResidentCount.increment(); + Backend::textureResidentGPUMemSize.update(0, size()); + auto mipLevels = _gpuObject.getNumMips(); for (uint16_t sourceMip = 0; sourceMip < mipLevels; ++sourceMip) { uint16_t targetMip = sourceMip; @@ -265,3 +269,8 @@ GL45StrictResourceTexture::GL45StrictResourceTexture(const std::weak_ptr& backend, const Texture& texture) : GL45Texture(backend, texture) { ++_frameTexturesCreated; + Backend::textureResourceCount.increment(); } GL45VariableAllocationTexture::~GL45VariableAllocationTexture() { - Backend::textureGPUMemSize.update(_size, 0); + Backend::textureResourceCount.decrement(); + Backend::textureResourceGPUMemSize.update(_size, 0); } // Managed size resource textures diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index 30b625522e..9f83e1250c 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -243,12 +243,11 @@ ContextMetricSize Backend::freeGPUMemSize; ContextMetricCount Backend::bufferCount; ContextMetricSize Backend::bufferGPUMemSize; -ContextMetricCount Backend::textureCount; +ContextMetricCount Backend::textureResidentCount; ContextMetricCount Backend::textureFramebufferCount; ContextMetricCount Backend::textureResourceCount; ContextMetricCount Backend::textureExternalCount; -ContextMetricSize Backend::textureGPUMemSize; ContextMetricSize Backend::textureResidentGPUMemSize; ContextMetricSize Backend::textureFramebufferGPUMemSize; ContextMetricSize Backend::textureResourceGPUMemSize; @@ -274,9 +273,11 @@ Context::Size Context::getBufferGPUMemSize() { } uint32_t Context::getTextureGPUCount() { - return Backend::textureCount.getValue(); + return getTextureResidentGPUCount() + getTextureResourceGPUCount() + getTextureFramebufferGPUCount(); +} +uint32_t Context::getTextureResidentGPUCount() { + return Backend::textureResidentCount.getValue(); } - uint32_t Context::getTextureFramebufferGPUCount() { return Backend::textureFramebufferCount.getValue(); } @@ -288,7 +289,7 @@ uint32_t Context::getTextureExternalGPUCount() { } Size Context::getTextureGPUMemSize() { - return Backend::textureGPUMemSize.getValue(); + return getTextureResidentGPUMemSize() + getTextureResourceGPUMemSize() + getTextureFramebufferGPUMemSize(); } Size Context::getTextureResidentGPUMemSize() { return Backend::textureResidentGPUMemSize.getValue(); diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index 34207bea5f..4de6631eb1 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -101,13 +101,11 @@ public: static ContextMetricCount bufferCount; static ContextMetricSize bufferGPUMemSize; - static ContextMetricCount textureCount; + static ContextMetricCount textureResidentCount; static ContextMetricCount textureFramebufferCount; static ContextMetricCount textureResourceCount; static ContextMetricCount textureExternalCount; - static ContextMetricSize textureGPUMemSize; - static ContextMetricSize textureResidentGPUMemSize; static ContextMetricSize textureFramebufferGPUMemSize; static ContextMetricSize textureResourceGPUMemSize; @@ -231,6 +229,7 @@ public: static Size getBufferGPUMemSize(); static uint32_t getTextureGPUCount(); + static uint32_t getTextureResidentGPUCount(); static uint32_t getTextureFramebufferGPUCount(); static uint32_t getTextureResourceGPUCount(); static uint32_t getTextureExternalGPUCount(); diff --git a/libraries/gpu/src/gpu/Format.cpp b/libraries/gpu/src/gpu/Format.cpp index 43bcd35b88..458939bcbe 100644 --- a/libraries/gpu/src/gpu/Format.cpp +++ b/libraries/gpu/src/gpu/Format.cpp @@ -19,11 +19,11 @@ const Element Element::COLOR_SRGBA_32{ VEC4, NUINT8, SRGBA }; const Element Element::COLOR_BGRA_32{ VEC4, NUINT8, BGRA }; const Element Element::COLOR_SBGRA_32{ VEC4, NUINT8, SBGRA }; -const Element Element::COLOR_COMPRESSED_RED{ VEC4, NUINT8, COMPRESSED_BC4_RED }; -const Element Element::COLOR_COMPRESSED_SRGB{ VEC4, NUINT8, COMPRESSED_BC1_SRGB }; -const Element Element::COLOR_COMPRESSED_SRGBA_MASK{ VEC4, NUINT8, COMPRESSED_BC1_SRGBA }; -const Element Element::COLOR_COMPRESSED_SRGBA{ VEC4, NUINT8, COMPRESSED_BC3_SRGBA }; -const Element Element::COLOR_COMPRESSED_XY{ VEC4, NUINT8, COMPRESSED_BC5_XY }; +const Element Element::COLOR_COMPRESSED_RED{ BLOB, COMPRESSED, COMPRESSED_BC4_RED }; +const Element Element::COLOR_COMPRESSED_SRGB { BLOB, COMPRESSED, COMPRESSED_BC1_SRGB }; +const Element Element::COLOR_COMPRESSED_SRGBA_MASK { BLOB, COMPRESSED, COMPRESSED_BC1_SRGBA }; +const Element Element::COLOR_COMPRESSED_SRGBA { BLOB, COMPRESSED, COMPRESSED_BC3_SRGBA }; +const Element Element::COLOR_COMPRESSED_XY { BLOB, COMPRESSED, COMPRESSED_BC5_XY }; const Element Element::VEC2NU8_XY{ VEC2, NUINT8, XY }; diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index 5a36d69035..a877887840 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -239,7 +239,7 @@ void ObjectMotionState::handleEasyChanges(uint32_t& flags) { } } - if (_body->getCollisionShape()->getShapeType() != TRIANGLE_MESH_SHAPE_PROXYTYPE) { + if (_body && _body->getCollisionShape()->getShapeType() != TRIANGLE_MESH_SHAPE_PROXYTYPE) { if (flags & Simulation::DIRTY_LINEAR_VELOCITY) { btVector3 newLinearVelocity = glmToBullet(getObjectLinearVelocity()); if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) { diff --git a/libraries/render/src/render/EngineStats.cpp b/libraries/render/src/render/EngineStats.cpp index 9a76f31ef5..b2b78cf2a7 100644 --- a/libraries/render/src/render/EngineStats.cpp +++ b/libraries/render/src/render/EngineStats.cpp @@ -33,6 +33,11 @@ void EngineStats::run(const RenderContextPointer& renderContext) { config->textureCPUMemSize = gpu::Texture::getTextureCPUMemSize(); config->textureGPUMemSize = gpu::Context::getTextureGPUMemSize(); + config->textureResidentGPUCount = gpu::Context::getTextureResidentGPUCount(); + config->textureFramebufferGPUCount = gpu::Context::getTextureFramebufferGPUCount(); + config->textureResourceGPUCount = gpu::Context::getTextureResourceGPUCount(); + config->textureExternalGPUCount = gpu::Context::getTextureExternalGPUCount(); + config->textureResidentGPUMemSize = gpu::Context::getTextureResidentGPUMemSize(); config->textureFramebufferGPUMemSize = gpu::Context::getTextureFramebufferGPUMemSize(); config->textureResourceGPUMemSize = gpu::Context::getTextureResourceGPUMemSize(); diff --git a/libraries/render/src/render/EngineStats.h b/libraries/render/src/render/EngineStats.h index 5fd97eed38..b8a52b6ed0 100644 --- a/libraries/render/src/render/EngineStats.h +++ b/libraries/render/src/render/EngineStats.h @@ -31,9 +31,13 @@ namespace render { Q_PROPERTY(quint32 textureCPUCount MEMBER textureCPUCount NOTIFY dirty) Q_PROPERTY(quint32 textureGPUCount MEMBER textureGPUCount NOTIFY dirty) + Q_PROPERTY(quint32 textureResidentGPUCount MEMBER textureResidentGPUCount NOTIFY dirty) + Q_PROPERTY(quint32 textureFramebufferGPUCount MEMBER textureFramebufferGPUCount NOTIFY dirty) + Q_PROPERTY(quint32 textureResourceGPUCount MEMBER textureResourceGPUCount NOTIFY dirty) + Q_PROPERTY(quint32 textureExternalGPUCount MEMBER textureExternalGPUCount NOTIFY dirty) + Q_PROPERTY(qint64 textureCPUMemSize MEMBER textureCPUMemSize NOTIFY dirty) Q_PROPERTY(qint64 textureGPUMemSize MEMBER textureGPUMemSize NOTIFY dirty) - Q_PROPERTY(qint64 textureResidentGPUMemSize MEMBER textureResidentGPUMemSize NOTIFY dirty) Q_PROPERTY(qint64 textureFramebufferGPUMemSize MEMBER textureFramebufferGPUMemSize NOTIFY dirty) Q_PROPERTY(qint64 textureResourceGPUMemSize MEMBER textureResourceGPUMemSize NOTIFY dirty) @@ -66,14 +70,19 @@ namespace render { qint64 bufferGPUMemSize { 0 }; quint32 textureCPUCount{ 0 }; - quint32 textureGPUCount{ 0 }; + quint32 textureGPUCount { 0 }; + quint32 textureResidentGPUCount { 0 }; + quint32 textureFramebufferGPUCount { 0 }; + quint32 textureResourceGPUCount { 0 }; + quint32 textureExternalGPUCount { 0 }; + quint32 texturePendingGPUTransferCount { 0 }; + qint64 textureCPUMemSize { 0 }; qint64 textureGPUMemSize { 0 }; qint64 textureResidentGPUMemSize { 0 }; qint64 textureFramebufferGPUMemSize { 0 }; qint64 textureResourceGPUMemSize { 0 }; qint64 textureExternalGPUMemSize { 0 }; - quint32 texturePendingGPUTransferCount { 0 }; qint64 texturePendingGPUTransferSize { 0 }; quint32 frameAPIDrawcallCount{ 0 }; diff --git a/scripts/developer/utilities/render/textureMonitor.qml b/scripts/developer/utilities/render/textureMonitor.qml index eba35bfc5b..9a79bf62a9 100644 --- a/scripts/developer/utilities/render/textureMonitor.qml +++ b/scripts/developer/utilities/render/textureMonitor.qml @@ -23,7 +23,7 @@ Item { 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 @@ -38,15 +38,30 @@ Item { label: "CPU", color: "#00B4EF" }, - { - prop: "textureGPUCount", - label: "GPU", - color: "#1AC567" - }, { prop: "texturePendingGPUTransferCount", label: "Transfer", - color: "#9495FF" + color: "#359D85" + }, + { + prop: "textureResourceGPUCount", + label: "Resource", + color: "#1FC6A6" + }, + { + prop: "textureResidentGPUCount", + label: "Resident", + color: "#FF6309" + }, + { + prop: "textureFramebufferGPUCount", + label: "Framebuffer", + color: "#EF93D1" + }, + { + prop: "textureExternalGPUCount", + label: "External", + color: "#C62147" } ] } @@ -64,14 +79,14 @@ Item { color: "#00B4EF" }, { - prop: "textureGPUMemSize", - label: "GPU", - color: "#1AC567" + prop: "texturePendingGPUTransferSize", + label: "Transfer", + color: "#359D85" }, { - prop: "textureTransferPendingSize", - label: "Pending Transfer", - color: "#9495FF" + prop: "textureGPUMemSize", + label: "GPU", + color: "#E3E3E3" }, { prop: "textureResourceGPUMemSize", From 56e9b1bb37569ef087fe20ae55535c8e52eec2c1 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 19 May 2017 18:46:19 -0700 Subject: [PATCH 05/12] Adding the populated counter --- libraries/gpu/src/gpu/Context.cpp | 4 ++++ libraries/gpu/src/gpu/Context.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index 9f83e1250c..140019f96f 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -310,3 +310,7 @@ uint32_t Context::getTexturePendingGPUTransferCount() { Size Context::getTexturePendingGPUTransferMemSize() { return Backend::texturePendingGPUTransferMemSize.getValue(); } + +Size Context::getTextureResourcePopulatedGPUMemSize() { + return Backend::textureResourcePopulatedGPUMemSize.getValue(); +} diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index 4de6631eb1..de818ddcb0 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -113,6 +113,7 @@ public: static ContextMetricCount texturePendingGPUTransferCount; static ContextMetricSize texturePendingGPUTransferMemSize; + static ContextMetricSize textureResourcePopulatedGPUMemSize; protected: @@ -243,6 +244,8 @@ public: static uint32_t getTexturePendingGPUTransferCount(); static Size getTexturePendingGPUTransferMemSize(); + static Size getTextureResourcePopulatedGPUMemSize(); + protected: Context(const Context& context); From 1f090d8148210566f9bd2f2595dd7a002676cd1c Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Mon, 22 May 2017 01:00:34 -0700 Subject: [PATCH 06/12] Debugging the size problem and fixing the compression size evaluation --- libraries/gpu-gl/src/gpu/gl/GLTexture.cpp | 9 ++-- libraries/gpu-gl/src/gpu/gl/GLTexture.h | 6 +-- libraries/gpu-gl/src/gpu/gl41/GL41Backend.h | 4 +- .../src/gpu/gl41/GL41BackendTexture.cpp | 18 ++++++-- libraries/gpu-gl/src/gpu/gl45/GL45Backend.h | 9 +++- .../src/gpu/gl45/GL45BackendTexture.cpp | 8 +++- .../gpu/gl45/GL45BackendVariableTexture.cpp | 46 +++++++++++++++++-- libraries/gpu/src/gpu/Context.cpp | 2 + libraries/gpu/src/gpu/Format.h | 2 + libraries/gpu/src/gpu/Texture.h | 6 ++- libraries/render/src/render/EngineStats.cpp | 2 + libraries/render/src/render/EngineStats.h | 2 + .../utilities/render/textureMonitor.qml | 5 ++ 13 files changed, 97 insertions(+), 22 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index afc257fcd1..15fdbace4c 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -115,19 +115,20 @@ GLTexture::~GLTexture() { } } -void GLTexture::copyMipFaceFromTexture(uint16_t sourceMip, uint16_t targetMip, uint8_t face) const { +Size GLTexture::copyMipFaceFromTexture(uint16_t sourceMip, uint16_t targetMip, uint8_t face) const { if (!_gpuObject.isStoredMipFaceAvailable(sourceMip)) { - return; + return 0; } - auto size = _gpuObject.evalMipDimensions(sourceMip); + auto dim = _gpuObject.evalMipDimensions(sourceMip); auto mipData = _gpuObject.accessStoredMipFace(sourceMip, face); auto mipSize = _gpuObject.getStoredMipFaceSize(sourceMip, face); if (mipData) { GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat(), _gpuObject.getStoredMipFormat()); - copyMipFaceLinesFromTexture(targetMip, face, size, 0, texelFormat.internalFormat, texelFormat.format, texelFormat.type, mipSize, mipData->readData()); + return copyMipFaceLinesFromTexture(targetMip, face, dim, 0, texelFormat.internalFormat, texelFormat.format, texelFormat.type, mipSize, mipData->readData()); } else { qCDebug(gpugllogging) << "Missing mipData level=" << sourceMip << " face=" << (int)face << " for texture " << _gpuObject.source().c_str(); } + return 0; } diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.h b/libraries/gpu-gl/src/gpu/gl/GLTexture.h index c6ce2a2495..61312f588a 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.h +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.h @@ -174,8 +174,8 @@ public: protected: virtual Size size() const = 0; virtual void generateMips() const = 0; - virtual void copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const = 0; - virtual void copyMipFaceFromTexture(uint16_t sourceMip, uint16_t targetMip, uint8_t face) const final; + virtual Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const = 0; + virtual Size copyMipFaceFromTexture(uint16_t sourceMip, uint16_t targetMip, uint8_t face) const final; GLTexture(const std::weak_ptr& backend, const Texture& texture, GLuint id); }; @@ -188,7 +188,7 @@ public: protected: GLExternalTexture(const std::weak_ptr& backend, const Texture& texture, GLuint id); void generateMips() const override {} - void copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override {} + Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override { return 0;} Size size() const override { return 0; } }; diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h index 003e7e83c3..e5c8b07aa8 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h @@ -54,7 +54,7 @@ public: protected: GL41Texture(const std::weak_ptr& backend, const Texture& texture); void generateMips() const override; - void copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; + Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; virtual void syncSampler() const; void withPreservedTexture(std::function f) const; @@ -110,7 +110,7 @@ public: void promote() override; void demote() override; void populateTransferQueue() override; - void copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; + Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; Size size() const override { return _size; } Size _size { 0 }; diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 1dfad78d47..6cc8c0afb7 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -103,7 +103,8 @@ void GL41Texture::generateMips() const { (void)CHECK_GL_ERROR(); } -void GL41Texture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const { +Size GL41Texture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const { + Size amountCopied = sourceSize; if (GL_TEXTURE_2D == _target) { switch (internalFormat) { case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: @@ -136,8 +137,10 @@ void GL41Texture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const } } else { assert(false); + amountCopied = 0; } (void)CHECK_GL_ERROR(); + return amountCopied; } void GL41Texture::syncSampler() const { @@ -274,18 +277,21 @@ GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr allocateStorage(allocatedMip); _memoryPressureStateStale = true; size_t maxFace = GLTexture::getFaceCount(_target); + Size amount = 0; for (uint16_t sourceMip = _populatedMip; sourceMip < mipLevels; ++sourceMip) { uint16_t targetMip = sourceMip - _allocatedMip; for (uint8_t face = 0; face < maxFace; ++face) { - copyMipFaceFromTexture(sourceMip, targetMip, face); + amount += copyMipFaceFromTexture(sourceMip, targetMip, face); } } + Backend::textureResourcePopulatedGPUMemSize.update(0, amount); syncSampler(); } GL41VariableAllocationTexture::~GL41VariableAllocationTexture() { Backend::textureResourceCount.decrement(); Backend::textureResourceGPUMemSize.update(_size, 0); + Backend::textureResourcePopulatedGPUMemSize.update(_size, 0); } void GL41VariableAllocationTexture::allocateStorage(uint16 allocatedMip) { @@ -309,10 +315,12 @@ void GL41VariableAllocationTexture::allocateStorage(uint16 allocatedMip) { } -void GL41VariableAllocationTexture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const { +Size GL41VariableAllocationTexture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const { + Size amountCopied = 0; withPreservedTexture([&] { - Parent::copyMipFaceLinesFromTexture(mip, face, size, yOffset, internalFormat, format, type, sourceSize, sourcePointer); + amountCopied = Parent::copyMipFaceLinesFromTexture(mip, face, size, yOffset, internalFormat, format, type, sourceSize, sourcePointer); }); + return amountCopied; } void GL41VariableAllocationTexture::syncSampler() const { @@ -477,6 +485,7 @@ void GL41VariableAllocationTexture::promote() { glDeleteTextures(1, &oldId); // update the memory usage Backend::textureResourceGPUMemSize.update(oldSize, 0); + // no change to Backend::textureResourcePopulatedGPUMemSize populateTransferQueue(); } @@ -508,6 +517,7 @@ void GL41VariableAllocationTexture::demote() { glDeleteTextures(1, &oldId); // update the memory usage Backend::textureResourceGPUMemSize.update(oldSize, 0); + Backend::textureResourcePopulatedGPUMemSize.update(oldSize, _size); // Demoting unpopulate the memory delta old - _size populateTransferQueue(); } diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index a0a919f4ad..46599e072c 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -50,7 +50,7 @@ public: protected: GL45Texture(const std::weak_ptr& backend, const Texture& texture); void generateMips() const override; - void copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; + Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; virtual void syncSampler() const; }; @@ -98,12 +98,17 @@ public: friend class GL45Backend; using PromoteLambda = std::function; + // Overight copy to inject counter for populated amount + Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; protected: GL45VariableAllocationTexture(const std::weak_ptr& backend, const Texture& texture); ~GL45VariableAllocationTexture(); Size size() const override { return _size; } Size _size { 0 }; + void incrementPopulatedSize(Size delta) const; + void decrementPopulatedSize(Size delta) const; + mutable Size _populatedSize { 0 }; }; class GL45ResourceTexture : public GL45VariableAllocationTexture { @@ -118,7 +123,7 @@ public: void populateTransferQueue() override; void allocateStorage(uint16 mip); - void copyMipsFromTexture(); + Size copyMipsFromTexture(); }; #if 0 diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 60408b05fb..7dbd5c0ace 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -133,7 +133,8 @@ void GL45Texture::generateMips() const { (void)CHECK_GL_ERROR(); } -void GL45Texture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const { +Size GL45Texture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const { + Size amountCopied = sourceSize; if (GL_TEXTURE_2D == _target) { switch (internalFormat) { case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: @@ -176,9 +177,12 @@ void GL45Texture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const break; } } else { - Q_ASSERT(false); + assert(false); + amountCopied = 0; } (void)CHECK_GL_ERROR(); + + return amountCopied; } void GL45Texture::syncSampler() const { diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index d78e068487..5bf022d515 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -37,6 +37,31 @@ GL45VariableAllocationTexture::GL45VariableAllocationTexture(const std::weak_ptr GL45VariableAllocationTexture::~GL45VariableAllocationTexture() { Backend::textureResourceCount.decrement(); Backend::textureResourceGPUMemSize.update(_size, 0); + Backend::textureResourcePopulatedGPUMemSize.update(_populatedSize, 0); +} +void GL45VariableAllocationTexture::incrementPopulatedSize(Size delta) const { + _populatedSize += delta; + if (_size < _populatedSize) { + + Backend::textureResourcePopulatedGPUMemSize.update(0, delta); + } else { + Backend::textureResourcePopulatedGPUMemSize.update(0, delta); + } +} +void GL45VariableAllocationTexture::decrementPopulatedSize(Size delta) const { + _populatedSize -= delta; + if (_size < _populatedSize) { + Backend::textureResourcePopulatedGPUMemSize.update(delta, 0); + } else { + Backend::textureResourcePopulatedGPUMemSize.update(delta, 0); + } +} + +Size GL45VariableAllocationTexture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const { + Size amountCopied = 0; + amountCopied = Parent::copyMipFaceLinesFromTexture(mip, face, size, yOffset, internalFormat, format, type, sourceSize, sourcePointer); + incrementPopulatedSize(amountCopied); + return amountCopied; } // Managed size resource textures @@ -63,7 +88,6 @@ GL45ResourceTexture::GL45ResourceTexture(const std::weak_ptr& backend _memoryPressureStateStale = true; copyMipsFromTexture(); syncSampler(); - } void GL45ResourceTexture::allocateStorage(uint16 allocatedMip) { @@ -75,22 +99,24 @@ void GL45ResourceTexture::allocateStorage(uint16 allocatedMip) { glTextureStorage2D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y); auto mipLevels = _gpuObject.getNumMips(); _size = 0; + bool wtf = false; for (uint16_t mip = _allocatedMip; mip < mipLevels; ++mip) { _size += _gpuObject.evalMipSize(mip); } - Backend::textureResourceGPUMemSize.update(0, _size); } -void GL45ResourceTexture::copyMipsFromTexture() { +Size GL45ResourceTexture::copyMipsFromTexture() { auto mipLevels = _gpuObject.getNumMips(); size_t maxFace = GLTexture::getFaceCount(_target); + Size amount = 0; for (uint16_t sourceMip = _populatedMip; sourceMip < mipLevels; ++sourceMip) { uint16_t targetMip = sourceMip - _allocatedMip; for (uint8_t face = 0; face < maxFace; ++face) { - copyMipFaceFromTexture(sourceMip, targetMip, face); + amount += copyMipFaceFromTexture(sourceMip, targetMip, face); } } + return amount; } void GL45ResourceTexture::syncSampler() const { @@ -141,6 +167,7 @@ void GL45ResourceTexture::promote() { glDeleteTextures(1, &oldId); // update the memory usage Backend::textureResourceGPUMemSize.update(oldSize, 0); + // no change to Backend::textureResourcePopulatedGPUMemSize syncSampler(); populateTransferQueue(); } @@ -150,6 +177,7 @@ void GL45ResourceTexture::demote() { Q_ASSERT(_allocatedMip < _maxAllocatedMip); auto oldId = _id; auto oldSize = _size; + auto oldPopulatedMip = _populatedMip; // allocate new texture const_cast(_id) = allocate(_gpuObject); @@ -165,6 +193,16 @@ void GL45ResourceTexture::demote() { glDeleteTextures(1, &oldId); // update the memory usage Backend::textureResourceGPUMemSize.update(oldSize, 0); + // Demoting unpopulate the memory delta + if (oldPopulatedMip != _populatedMip) { + auto numPopulatedDemoted = _populatedMip - oldPopulatedMip; + Size amountUnpopulated = 0; + for (int i = 0; i < numPopulatedDemoted; i++) { + //amountUnpopulated += _gpuObject.getStoredMipSize(oldPopulatedMip + i); + amountUnpopulated += _gpuObject.evalMipSize(oldPopulatedMip + i); + } + decrementPopulatedSize(amountUnpopulated); + } syncSampler(); populateTransferQueue(); } diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index 140019f96f..2116ffd6fe 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -256,6 +256,8 @@ ContextMetricSize Backend::textureExternalGPUMemSize; ContextMetricCount Backend::texturePendingGPUTransferCount; ContextMetricSize Backend::texturePendingGPUTransferMemSize; +ContextMetricSize Backend::textureResourcePopulatedGPUMemSize; + Size Context::getFreeGPUMemSize() { return Backend::freeGPUMemSize.getValue(); } diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 729a1bbdc0..8fab7f9be7 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -63,6 +63,8 @@ static const int TYPE_SIZE[NUM_TYPES] = { 2, 2, 1, + 1, + 1 }; // Array answering the question Does this type is integer or not diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 3e4fdf113a..39398558fe 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -424,8 +424,12 @@ public: uint16 evalMipHeight(uint16 level) const { return std::max(_height >> level, 1); } uint16 evalMipDepth(uint16 level) const { return std::max(_depth >> level, 1); } - // The size of a face is a multiple of the padded line = (width * texelFormat_size + alignment padding) + // The true size of a line or a sirface depends on the format and the padding + // is a multiple of the padded line = (width * texelFormat_size + alignment padding) + // + uint16 evaTiledWidth(uint16 width) const { return width >> 2 + width & 0x03; } Size evalMipLineSize(uint16 level) const { return evalPaddedSize(evalMipWidth(level) * getTexelFormat().getSize()); } + Size evalMipSurfaceSize(uint16 level) const { return evalPaddedSize(evalMipWidth(level) * getTexelFormat().getSize()); } // Size for each face of a mip at a particular level uint32 evalMipFaceNumTexels(uint16 level) const { return evalMipWidth(level) * evalMipHeight(level) * evalMipDepth(level); } diff --git a/libraries/render/src/render/EngineStats.cpp b/libraries/render/src/render/EngineStats.cpp index b2b78cf2a7..9e45be5dbd 100644 --- a/libraries/render/src/render/EngineStats.cpp +++ b/libraries/render/src/render/EngineStats.cpp @@ -46,6 +46,8 @@ void EngineStats::run(const RenderContextPointer& renderContext) { config->texturePendingGPUTransferCount = gpu::Context::getTexturePendingGPUTransferCount(); config->texturePendingGPUTransferSize = gpu::Context::getTexturePendingGPUTransferMemSize(); + config->textureResourcePopulatedGPUMemSize = gpu::Context::getTextureResourcePopulatedGPUMemSize(); + renderContext->args->_context->getFrameStats(_gpuStats); config->frameAPIDrawcallCount = _gpuStats._DSNumAPIDrawcalls; diff --git a/libraries/render/src/render/EngineStats.h b/libraries/render/src/render/EngineStats.h index b8a52b6ed0..46be372d5d 100644 --- a/libraries/render/src/render/EngineStats.h +++ b/libraries/render/src/render/EngineStats.h @@ -45,6 +45,7 @@ namespace render { Q_PROPERTY(quint32 texturePendingGPUTransferCount MEMBER texturePendingGPUTransferCount NOTIFY dirty) Q_PROPERTY(qint64 texturePendingGPUTransferSize MEMBER texturePendingGPUTransferSize NOTIFY dirty) + Q_PROPERTY(qint64 textureResourcePopulatedGPUMemSize MEMBER textureResourcePopulatedGPUMemSize NOTIFY dirty) Q_PROPERTY(quint32 frameAPIDrawcallCount MEMBER frameAPIDrawcallCount NOTIFY dirty) Q_PROPERTY(quint32 frameDrawcallCount MEMBER frameDrawcallCount NOTIFY dirty) @@ -84,6 +85,7 @@ namespace render { qint64 textureResourceGPUMemSize { 0 }; qint64 textureExternalGPUMemSize { 0 }; qint64 texturePendingGPUTransferSize { 0 }; + qint64 textureResourcePopulatedGPUMemSize { 0 }; quint32 frameAPIDrawcallCount{ 0 }; quint32 frameDrawcallCount{ 0 }; diff --git a/scripts/developer/utilities/render/textureMonitor.qml b/scripts/developer/utilities/render/textureMonitor.qml index 9a79bf62a9..1df51031c1 100644 --- a/scripts/developer/utilities/render/textureMonitor.qml +++ b/scripts/developer/utilities/render/textureMonitor.qml @@ -102,6 +102,11 @@ Item { prop: "textureFramebufferGPUMemSize", label: "Framebuffer", color: "#EF93D1" + }, + { + prop: "textureResourcePopulatedGPUMemSize", + label: "Populated", + color: "#C6A61F" } ] } From e4f9f2935ed6237e958a09f6e930f62f4403d698 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 22 May 2017 15:42:18 -0700 Subject: [PATCH 07/12] Solving the size evaluation for compressed format --- interface/resources/qml/Stats.qml | 2 +- interface/src/ui/Stats.cpp | 1 + interface/src/ui/Stats.h | 2 + libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp | 4 +- libraries/gpu/src/gpu/Format.cpp | 10 ++-- libraries/gpu/src/gpu/Format.h | 42 +++++++++----- libraries/gpu/src/gpu/Texture.h | 41 +++++++------ .../utilities/render/textureMonitor.js | 2 +- .../utilities/render/textureMonitor.qml | 57 ++++--------------- 9 files changed, 74 insertions(+), 87 deletions(-) diff --git a/interface/resources/qml/Stats.qml b/interface/resources/qml/Stats.qml index 97117fff0c..7b5c81d683 100644 --- a/interface/resources/qml/Stats.qml +++ b/interface/resources/qml/Stats.qml @@ -280,7 +280,7 @@ Item { text: " Pending Transfer: " + root.texturePendingTransfers + " MB"; } StatText { - text: " Resource Memory: " + root.gpuTextureResourceMemory + " MB"; + text: " Resource Allocated/Populated: " + root.gpuTextureResourceMemory + " / " + root.gpuTextureResourcePopulatedMemory + " MB"; } StatText { text: " Resident Memory: " + root.gpuTextureResidentMemory + " MB"; diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 131658461b..161c407a45 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -356,6 +356,7 @@ void Stats::updateStats(bool force) { STAT_UPDATE(gpuTextureResidentMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResidentGPUMemSize())); STAT_UPDATE(gpuTextureFramebufferMemory, (int)BYTES_TO_MB(gpu::Context::getTextureFramebufferGPUMemSize())); STAT_UPDATE(gpuTextureResourceMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResourceGPUMemSize())); + STAT_UPDATE(gpuTextureResourcePopulatedMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResourcePopulatedGPUMemSize())); STAT_UPDATE(gpuTextureExternalMemory, (int)BYTES_TO_MB(gpu::Context::getTextureExternalGPUMemSize())); STAT_UPDATE(gpuTextureMemoryPressureState, getTextureMemoryPressureModeString()); STAT_UPDATE(gpuFreeMemory, (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemSize())); diff --git a/interface/src/ui/Stats.h b/interface/src/ui/Stats.h index bb7c40a105..2abb84faea 100644 --- a/interface/src/ui/Stats.h +++ b/interface/src/ui/Stats.h @@ -124,6 +124,7 @@ class Stats : public QQuickItem { STATS_PROPERTY(int, gpuTextureResidentMemory, 0) STATS_PROPERTY(int, gpuTextureFramebufferMemory, 0) STATS_PROPERTY(int, gpuTextureResourceMemory, 0) + STATS_PROPERTY(int, gpuTextureResourcePopulatedMemory, 0) STATS_PROPERTY(int, gpuTextureExternalMemory, 0) STATS_PROPERTY(QString, gpuTextureMemoryPressureState, QString()) STATS_PROPERTY(int, gpuFreeMemory, 0) @@ -248,6 +249,7 @@ signals: void gpuTextureResidentMemoryChanged(); void gpuTextureFramebufferMemoryChanged(); void gpuTextureResourceMemoryChanged(); + void gpuTextureResourcePopulatedMemoryChanged(); void gpuTextureExternalMemoryChanged(); void gpuTextureMemoryPressureStateChanged(); void gpuFreeMemoryChanged(); diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp index ad706da8ae..a5beca8dfd 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp @@ -354,7 +354,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E break; } - case gpu::BLOB: { + case gpu::TILE4x4: { texel.format = GL_RGBA; texel.type = ELEMENT_TYPE_TO_GL[srcFormat.getType()]; @@ -646,7 +646,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E break; } - case gpu::BLOB: { + case gpu::TILE4x4: { texel.format = GL_RGBA; texel.type = ELEMENT_TYPE_TO_GL[srcFormat.getType()]; diff --git a/libraries/gpu/src/gpu/Format.cpp b/libraries/gpu/src/gpu/Format.cpp index 458939bcbe..787c09c63e 100644 --- a/libraries/gpu/src/gpu/Format.cpp +++ b/libraries/gpu/src/gpu/Format.cpp @@ -19,11 +19,11 @@ const Element Element::COLOR_SRGBA_32{ VEC4, NUINT8, SRGBA }; const Element Element::COLOR_BGRA_32{ VEC4, NUINT8, BGRA }; const Element Element::COLOR_SBGRA_32{ VEC4, NUINT8, SBGRA }; -const Element Element::COLOR_COMPRESSED_RED{ BLOB, COMPRESSED, COMPRESSED_BC4_RED }; -const Element Element::COLOR_COMPRESSED_SRGB { BLOB, COMPRESSED, COMPRESSED_BC1_SRGB }; -const Element Element::COLOR_COMPRESSED_SRGBA_MASK { BLOB, COMPRESSED, COMPRESSED_BC1_SRGBA }; -const Element Element::COLOR_COMPRESSED_SRGBA { BLOB, COMPRESSED, COMPRESSED_BC3_SRGBA }; -const Element Element::COLOR_COMPRESSED_XY { BLOB, COMPRESSED, COMPRESSED_BC5_XY }; +const Element Element::COLOR_COMPRESSED_RED{ TILE4x4, COMPRESSED, COMPRESSED_BC4_RED }; +const Element Element::COLOR_COMPRESSED_SRGB { TILE4x4, COMPRESSED, COMPRESSED_BC1_SRGB }; +const Element Element::COLOR_COMPRESSED_SRGBA_MASK { TILE4x4, COMPRESSED, COMPRESSED_BC1_SRGBA }; +const Element Element::COLOR_COMPRESSED_SRGBA { TILE4x4, COMPRESSED, COMPRESSED_BC3_SRGBA }; +const Element Element::COLOR_COMPRESSED_XY { TILE4x4, COMPRESSED, COMPRESSED_BC5_XY }; const Element Element::VEC2NU8_XY{ VEC2, NUINT8, XY }; diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 8fab7f9be7..b2f2252119 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -98,12 +98,12 @@ enum Dimension : uint8_t { MAT2, MAT3, MAT4, - BLOB, // Blob element's size is defined from the type and semantic, it s counted as 1 component + TILE4x4, // Blob element's size is defined from the type and semantic, it s counted as 1 component NUM_DIMENSIONS, }; // Count (of scalars) in an Element for a given Dimension -static const int LOCATION_COUNT[NUM_DIMENSIONS] = { +static const int DIMENSION_LOCATION_COUNT[NUM_DIMENSIONS] = { 1, 1, 1, @@ -115,7 +115,7 @@ static const int LOCATION_COUNT[NUM_DIMENSIONS] = { }; // Count (of scalars) in an Element for a given Dimension's location -static const int SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = { +static const int DIMENSION_SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = { 1, 2, 3, @@ -127,7 +127,7 @@ static const int SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = { }; // Count (of scalars) in an Element for a given Dimension -static const int SCALAR_COUNT[NUM_DIMENSIONS] = { +static const int DIMENSION_SCALAR_COUNT[NUM_DIMENSIONS] = { 1, 2, 3, @@ -138,6 +138,18 @@ static const int SCALAR_COUNT[NUM_DIMENSIONS] = { 1, }; +// Tile dimension described by the ELement for "Tilexxx" DIMENSIONs +static const glm::ivec2 DIMENSION_TILE_DIM[NUM_DIMENSIONS] = { + { 1, 1 }, + { 1, 1 }, + { 1, 1 }, + { 1, 1 }, + { 1, 1 }, + { 1, 1 }, + { 1, 1 }, + { 4, 4 }, +}; + // Semantic of an Element // Provide information on how to use the element enum Semantic : uint8_t { @@ -222,11 +234,11 @@ static const int SEMANTIC_SIZE_FACTOR[NUM_SEMANTICS] = { // THe size of a compressed element is defined from the semantic 1, //_FIRST_COMPRESSED, - 1, //COMPRESSED_BC1_SRGB, - 1, //COMPRESSED_BC1_SRGBA, - 1, //COMPRESSED_BC3_SRGBA, - 1, //COMPRESSED_BC4_RED, - 1, //COMPRESSED_BC5_XY, + 8, //COMPRESSED_BC1_SRGB, 1/2 byte/pixel * 4x4 pixels = 8 bytes + 8, //COMPRESSED_BC1_SRGBA, 1/2 byte/pixel * 4x4 pixels = 8 bytes + 16, //COMPRESSED_BC3_SRGBA, 1 byte/pixel * 4x4 pixels = 16 bytes + 8, //COMPRESSED_BC4_RED, 1/2 byte/pixel * 4x4 pixels = 8 bytes + 16, //COMPRESSED_BC5_XY, 1 byte/pixel * 4x4 pixels = 16 bytes 1, //_LAST_COMPRESSED, @@ -240,6 +252,7 @@ static const int SEMANTIC_SIZE_FACTOR[NUM_SEMANTICS] = { 1, //SAMPLER_SHADOW, }; + // Element is a simple 16bit value that contains everything we need to know about an element // of a buffer, a pixel of a texture, a varying input/output or uniform from a shader pipeline. // Type and dimension of the element, and semantic @@ -266,12 +279,13 @@ public: bool isNormalized() const { return (getType() >= NORMALIZED_START); } bool isInteger() const { return TYPE_IS_INTEGER[getType()]; } - uint8 getScalarCount() const { return SCALAR_COUNT[(Dimension)_dimension]; } - uint32 getSize() const { return (SCALAR_COUNT[_dimension] * TYPE_SIZE[_type] * SEMANTIC_SIZE_FACTOR[_semantic]); } + uint8 getScalarCount() const { return DIMENSION_SCALAR_COUNT[(Dimension)_dimension]; } + uint32 getSize() const { return (DIMENSION_SCALAR_COUNT[_dimension] * TYPE_SIZE[_type] * SEMANTIC_SIZE_FACTOR[_semantic]); } + const glm::ivec2& getTile() const { return (DIMENSION_TILE_DIM[_dimension]); } - uint8 getLocationCount() const { return LOCATION_COUNT[(Dimension)_dimension]; } - uint8 getLocationScalarCount() const { return SCALAR_COUNT_PER_LOCATION[(Dimension)_dimension]; } - uint32 getLocationSize() const { return SCALAR_COUNT_PER_LOCATION[_dimension] * TYPE_SIZE[_type]; } + uint8 getLocationCount() const { return DIMENSION_LOCATION_COUNT[(Dimension)_dimension]; } + uint8 getLocationScalarCount() const { return DIMENSION_SCALAR_COUNT_PER_LOCATION[(Dimension)_dimension]; } + uint32 getLocationSize() const { return DIMENSION_SCALAR_COUNT_PER_LOCATION[_dimension] * TYPE_SIZE[_type]; } uint16 getRaw() const { return *((uint16*) (this)); } diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 39398558fe..da6071e72a 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -416,36 +416,43 @@ public: // Same but applied to this texture's num max mips from evalNumMips() uint16 safeNumMips(uint16 askedNumMips) const; - // Eval the size that the mips level SHOULD have + // Eval the dimensions & sizes that the mips level SHOULD have // not the one stored in the Texture + // Dimensions Vec3u evalMipDimensions(uint16 level) const; uint16 evalMipWidth(uint16 level) const { return std::max(_width >> level, 1); } uint16 evalMipHeight(uint16 level) const { return std::max(_height >> level, 1); } uint16 evalMipDepth(uint16 level) const { return std::max(_depth >> level, 1); } - // The true size of a line or a sirface depends on the format and the padding - // is a multiple of the padded line = (width * texelFormat_size + alignment padding) + // The true size of an image line or surface depends on the format, tiling and padding rules // - uint16 evaTiledWidth(uint16 width) const { return width >> 2 + width & 0x03; } - Size evalMipLineSize(uint16 level) const { return evalPaddedSize(evalMipWidth(level) * getTexelFormat().getSize()); } - Size evalMipSurfaceSize(uint16 level) const { return evalPaddedSize(evalMipWidth(level) * getTexelFormat().getSize()); } + // Here are the static function to compute the different sizes from parametered dimensions and format + // Tile size must be a power of 2 + static uint16 evalTiledLength(uint16 length, int tile) { return length / tile + ((~length & tile) != 0); } + static uint16 evalTiledWidth(uint16 width, int tileX) { return evalTiledLength(width, tileX); } + static uint16 evalTiledHeight(uint16 height, int tileY) { return evalTiledLength(height, tileY); } + static Size evalLineSize(uint16 width, const Element& format) { return evalPaddedSize(evalTiledWidth(width, format.getTile().x) * format.getSize()); } + static Size evalSurfaceSize(uint16 width, uint16 height, const Element& format) { return evalLineSize(width, format) * evalTiledHeight(height, format.getTile().x); } - // Size for each face of a mip at a particular level - uint32 evalMipFaceNumTexels(uint16 level) const { return evalMipWidth(level) * evalMipHeight(level) * evalMipDepth(level); } - Size evalMipFaceSize(uint16 level) const { return evalMipLineSize(level) * evalMipHeight(level) * evalMipDepth(level); } - - // Total size for the mip - uint32 evalMipNumTexels(uint16 level) const { return evalMipFaceNumTexels(level) * getNumFaces(); } - Size evalMipSize(uint16 level) const { return evalMipFaceSize(level) * getNumFaces(); } + // Compute the theorical size of the texture elements storage depending on the specified format + Size evalStoredMipLineSize(uint16 level, const Element& format) const { return evalLineSize(evalMipWidth(level), format); } + Size evalStoredMipSurfaceSize(uint16 level, const Element& format) const { return evalSurfaceSize(evalMipWidth(level), evalMipHeight(level), format); } + Size evalStoredMipFaceSize(uint16 level, const Element& format) const { return evalStoredMipSurfaceSize(level, format) * evalMipDepth(level); } + Size evalStoredMipSize(uint16 level, const Element& format) const { return evalStoredMipFaceSize(level, format) * getNumFaces(); } + + // For this texture's texel format and dimensions, compute the various mem sizes + Size evalMipLineSize(uint16 level) const { return evalStoredMipLineSize(level, getTexelFormat()); } + Size evalMipSurfaceSize(uint16 level) const { return evalStoredMipSurfaceSize(level, getTexelFormat()); } + Size evalMipFaceSize(uint16 level) const { return evalStoredMipFaceSize(level, getTexelFormat()); } + Size evalMipSize(uint16 level) const { return evalStoredMipSize(level, getTexelFormat()); } // Total size for all the mips of the texture Size evalTotalSize(uint16 startingMip = 0) const; - // Compute the theorical size of the texture elements storage depending on the specified format - Size evalStoredMipLineSize(uint16 level, const Element& format) const { return evalPaddedSize(evalMipWidth(level) * format.getSize()); } - Size evalStoredMipFaceSize(uint16 level, const Element& format) const { return evalMipFaceNumTexels(level) * format.getSize(); } - Size evalStoredMipSize(uint16 level, const Element& format) const { return evalMipNumTexels(level) * format.getSize(); } + // Number of texels (not it s not directly proprtional to the size! + uint32 evalMipFaceNumTexels(uint16 level) const { return evalMipWidth(level) * evalMipHeight(level) * evalMipDepth(level); } + uint32 evalMipNumTexels(uint16 level) const { return evalMipFaceNumTexels(level) * getNumFaces(); } // For convenience assign a source name const std::string& source() const { return _source; } diff --git a/scripts/developer/utilities/render/textureMonitor.js b/scripts/developer/utilities/render/textureMonitor.js index f8abe47e55..779e3b8950 100644 --- a/scripts/developer/utilities/render/textureMonitor.js +++ b/scripts/developer/utilities/render/textureMonitor.js @@ -15,7 +15,7 @@ var window = new OverlayWindow({ title: 'Textures', source: qml, width: 320, - height: 720 + height: 400 }); 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 index 1df51031c1..d29db439c9 100644 --- a/scripts/developer/utilities/render/textureMonitor.qml +++ b/scripts/developer/utilities/render/textureMonitor.qml @@ -28,43 +28,6 @@ Item { // 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: "texturePendingGPUTransferCount", - label: "Transfer", - color: "#359D85" - }, - { - prop: "textureResourceGPUCount", - label: "Resource", - color: "#1FC6A6" - }, - { - prop: "textureResidentGPUCount", - label: "Resident", - color: "#FF6309" - }, - { - prop: "textureFramebufferGPUCount", - label: "Framebuffer", - color: "#EF93D1" - }, - { - prop: "textureExternalGPUCount", - label: "External", - color: "#C62147" - } - ] - } PlotPerf { title: "gpu::Texture Memory" height: parent.evalEvenHeight() @@ -78,21 +41,11 @@ Item { label: "CPU", color: "#00B4EF" }, - { - prop: "texturePendingGPUTransferSize", - label: "Transfer", - color: "#359D85" - }, { prop: "textureGPUMemSize", label: "GPU", color: "#E3E3E3" }, - { - prop: "textureResourceGPUMemSize", - label: "Resource", - color: "#1FC6A6" - }, { prop: "textureResidentGPUMemSize", label: "Resident", @@ -103,10 +56,20 @@ Item { label: "Framebuffer", color: "#EF93D1" }, + { + prop: "textureResourceGPUMemSize", + label: "Resource", + color: "#1FC6A6" + }, { prop: "textureResourcePopulatedGPUMemSize", label: "Populated", color: "#C6A61F" + }, + { + prop: "texturePendingGPUTransferSize", + label: "Transfer", + color: "#A2277C" } ] } From e0487f7e0408c6a6fc265f4f81c66c14374254d7 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 22 May 2017 16:51:54 -0700 Subject: [PATCH 08/12] Solving the size evaluation for compressed format --- interface/resources/qml/Stats.qml | 10 +++++----- .../gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp | 5 +++-- libraries/gpu/src/gpu/Texture.h | 3 ++- scripts/developer/utilities/render/textureMonitor.qml | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/interface/resources/qml/Stats.qml b/interface/resources/qml/Stats.qml index 7b5c81d683..119f24c71f 100644 --- a/interface/resources/qml/Stats.qml +++ b/interface/resources/qml/Stats.qml @@ -270,17 +270,17 @@ Item { StatText { text: "GPU Textures: "; } - StatText { - text: " Pressure State: " + root.gpuTextureMemoryPressureState; - } StatText { text: " Count: " + root.gpuTextures; } StatText { - text: " Pending Transfer: " + root.texturePendingTransfers + " MB"; + text: " Pressure State: " + root.gpuTextureMemoryPressureState; } StatText { - text: " Resource Allocated/Populated: " + root.gpuTextureResourceMemory + " / " + root.gpuTextureResourcePopulatedMemory + " MB"; + text: " Resource Allocated / Populated / Pending: "; + } + StatText { + text: " " + root.gpuTextureResourceMemory + " / " + root.gpuTextureResourcePopulatedMemory + " / " + root.texturePendingTransfers + " MB"; } StatText { text: " Resident Memory: " + root.gpuTextureResidentMemory + " MB"; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index 5bf022d515..1ae3b405c3 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -42,7 +42,6 @@ GL45VariableAllocationTexture::~GL45VariableAllocationTexture() { void GL45VariableAllocationTexture::incrementPopulatedSize(Size delta) const { _populatedSize += delta; if (_size < _populatedSize) { - Backend::textureResourcePopulatedGPUMemSize.update(0, delta); } else { Backend::textureResourcePopulatedGPUMemSize.update(0, delta); @@ -101,6 +100,9 @@ void GL45ResourceTexture::allocateStorage(uint16 allocatedMip) { _size = 0; bool wtf = false; for (uint16_t mip = _allocatedMip; mip < mipLevels; ++mip) { + if (_gpuObject.evalMipSize(mip) == 0) { + wtf = true; + } _size += _gpuObject.evalMipSize(mip); } Backend::textureResourceGPUMemSize.update(0, _size); @@ -198,7 +200,6 @@ void GL45ResourceTexture::demote() { auto numPopulatedDemoted = _populatedMip - oldPopulatedMip; Size amountUnpopulated = 0; for (int i = 0; i < numPopulatedDemoted; i++) { - //amountUnpopulated += _gpuObject.getStoredMipSize(oldPopulatedMip + i); amountUnpopulated += _gpuObject.evalMipSize(oldPopulatedMip + i); } decrementPopulatedSize(amountUnpopulated); diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index da6071e72a..98a4add3c8 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -429,7 +429,8 @@ public: // // Here are the static function to compute the different sizes from parametered dimensions and format // Tile size must be a power of 2 - static uint16 evalTiledLength(uint16 length, int tile) { return length / tile + ((~length & tile) != 0); } + static uint16 evalTiledPadding(uint16 length, int tile) { int tileMinusOne = (tile - 1); return (tileMinusOne - (length + tileMinusOne) % tile); } + static uint16 evalTiledLength(uint16 length, int tile) { return length / tile + (evalTiledPadding(length, tile) != 0); } static uint16 evalTiledWidth(uint16 width, int tileX) { return evalTiledLength(width, tileX); } static uint16 evalTiledHeight(uint16 height, int tileY) { return evalTiledLength(height, tileY); } static Size evalLineSize(uint16 width, const Element& format) { return evalPaddedSize(evalTiledWidth(width, format.getTile().x) * format.getSize()); } diff --git a/scripts/developer/utilities/render/textureMonitor.qml b/scripts/developer/utilities/render/textureMonitor.qml index d29db439c9..97cc577ff9 100644 --- a/scripts/developer/utilities/render/textureMonitor.qml +++ b/scripts/developer/utilities/render/textureMonitor.qml @@ -49,7 +49,7 @@ Item { { prop: "textureResidentGPUMemSize", label: "Resident", - color: "#FF6309" + color: "#A2277C" }, { prop: "textureFramebufferGPUMemSize", @@ -69,7 +69,7 @@ Item { { prop: "texturePendingGPUTransferSize", label: "Transfer", - color: "#A2277C" + color: "#FF6309" } ] } From 2301954d62bb6e18406e1f25bad1a1a73bef2fcd Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Mon, 22 May 2017 23:40:23 -0700 Subject: [PATCH 09/12] fixing the Populated metric --- libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index ec687ade9f..9ae98bc88b 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -285,7 +285,7 @@ GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr GL41VariableAllocationTexture::~GL41VariableAllocationTexture() { Backend::textureResourceCount.decrement(); Backend::textureResourceGPUMemSize.update(_size, 0); - Backend::textureResourcePopulatedGPUMemSize.update(_size, 0); + Backend::textureResourcePopulatedGPUMemSize.update(_populatedSize, 0); } void GL41VariableAllocationTexture::incrementPopulatedSize(Size delta) const { From 542ec3dc46f897ff296b769a58a3a91f0f92b384 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 23 May 2017 11:36:06 -0700 Subject: [PATCH 10/12] More clean up per review request --- libraries/gpu-gl/src/gpu/gl/GLTexture.cpp | 21 +++++ libraries/gpu-gl/src/gpu/gl/GLTexture.h | 12 +++ libraries/gpu-gl/src/gpu/gl41/GL41Backend.h | 8 +- .../src/gpu/gl41/GL41BackendTexture.cpp | 62 ++++++-------- libraries/gpu-gl/src/gpu/gl45/GL45Backend.h | 14 ++-- .../gpu/gl45/GL45BackendVariableTexture.cpp | 81 +++++++++---------- 6 files changed, 104 insertions(+), 94 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index 8920a3ea76..88e5cde330 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -673,3 +673,24 @@ void GLVariableAllocationSupport::executeNextBuffer(const TexturePointer& curren } } #endif + +void GLVariableAllocationSupport::incrementPopulatedSize(Size delta) const { + _populatedSize += delta; + // Keep the 2 code paths to be able to debug + if (_size < _populatedSize) { + Backend::textureResourcePopulatedGPUMemSize.update(0, delta); + } else { + Backend::textureResourcePopulatedGPUMemSize.update(0, delta); + } +} +void GLVariableAllocationSupport::decrementPopulatedSize(Size delta) const { + _populatedSize -= delta; + // Keep the 2 code paths to be able to debug + if (_size < _populatedSize) { + Backend::textureResourcePopulatedGPUMemSize.update(delta, 0); + } else { + Backend::textureResourcePopulatedGPUMemSize.update(delta, 0); + } +} + + diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.h b/libraries/gpu-gl/src/gpu/gl/GLTexture.h index 61312f588a..c2483eb2a1 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.h +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.h @@ -127,6 +127,14 @@ protected: virtual void promote() = 0; virtual void demote() = 0; + // THe amount of memory currently allocated + Size _size { 0 }; + + // The amount of memory currnently populated + void incrementPopulatedSize(Size delta) const; + void decrementPopulatedSize(Size delta) const; + mutable Size _populatedSize { 0 }; + // The allocated mip level, relative to the number of mips in the gpu::Texture object // The relationship between a given glMip to the original gpu::Texture mip is always // glMip + _allocatedMip @@ -174,8 +182,11 @@ public: protected: virtual Size size() const = 0; virtual void generateMips() const = 0; + virtual void syncSampler() const = 0; + virtual Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const = 0; virtual Size copyMipFaceFromTexture(uint16_t sourceMip, uint16_t targetMip, uint8_t face) const final; + virtual void copyTextureMipsInGPUMem(GLuint srcId, GLuint destId, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips) {} // Only relevant for Variable Allocation textures GLTexture(const std::weak_ptr& backend, const Texture& texture, GLuint id); }; @@ -188,6 +199,7 @@ public: protected: GLExternalTexture(const std::weak_ptr& backend, const Texture& texture, GLuint id); void generateMips() const override {} + void syncSampler() const override {} Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override { return 0;} Size size() const override { return 0; } diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h index 53598e3b93..2c64b9d23d 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h @@ -55,7 +55,7 @@ public: GL41Texture(const std::weak_ptr& backend, const Texture& texture); void generateMips() const override; Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; - virtual void syncSampler() const; + void syncSampler() const override; void withPreservedTexture(std::function f) const; }; @@ -114,11 +114,9 @@ public: Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; Size copyMipsFromTexture(); + void copyTextureMipsInGPUMem(GLuint srcId, GLuint destId, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips) override; + Size size() const override { return _size; } - Size _size { 0 }; - void incrementPopulatedSize(Size delta) const; - void decrementPopulatedSize(Size delta) const; - mutable Size _populatedSize { 0 }; }; class GL41ResourceTexture : public GL41VariableAllocationTexture { diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 9ae98bc88b..1f3b929ec7 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -288,25 +288,6 @@ GL41VariableAllocationTexture::~GL41VariableAllocationTexture() { Backend::textureResourcePopulatedGPUMemSize.update(_populatedSize, 0); } -void GL41VariableAllocationTexture::incrementPopulatedSize(Size delta) const { - _populatedSize += delta; - // Keep the 2 code paths to be able to debug - if (_size < _populatedSize) { - Backend::textureResourcePopulatedGPUMemSize.update(0, delta); - } else { - Backend::textureResourcePopulatedGPUMemSize.update(0, delta); - } -} -void GL41VariableAllocationTexture::decrementPopulatedSize(Size delta) const { - _populatedSize -= delta; - // Keep the 2 code paths to be able to debug - if (_size < _populatedSize) { - Backend::textureResourcePopulatedGPUMemSize.update(delta, 0); - } else { - Backend::textureResourcePopulatedGPUMemSize.update(delta, 0); - } -} - void GL41VariableAllocationTexture::allocateStorage(uint16 allocatedMip) { _allocatedMip = allocatedMip; @@ -479,6 +460,18 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui glDeleteBuffers(1, &pbo); } +void GL41VariableAllocationTexture::copyTextureMipsInGPUMem(GLuint srcId, GLuint destId, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips) { + uint16_t numMips = _gpuObject.getNumMips(); + withPreservedTexture([&] { + if (_texelFormat.isCompressed()) { + copyCompressedTexGPUMem(_gpuObject, _target, srcId, destId, numMips, srcMipOffset, destMipOffset, populatedMips); + } else { + copyUncompressedTexGPUMem(_gpuObject, _target, srcId, destId, numMips, srcMipOffset, destMipOffset, populatedMips); + } + syncSampler(); + }); +} + void GL41VariableAllocationTexture::promote() { PROFILE_RANGE(render_gpu_gl, __FUNCTION__); Q_ASSERT(_allocatedMip > 0); @@ -497,21 +490,18 @@ void GL41VariableAllocationTexture::promote() { allocateStorage(targetAllocatedMip); // copy pre-existing mips - uint16_t numMips = _gpuObject.getNumMips(); - withPreservedTexture([&] { - if (_texelFormat.isCompressed()) { - copyCompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - } else { - copyUncompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - } - syncSampler(); - }); + copyTextureMipsInGPUMem(oldId, _id, oldAllocatedMip, _allocatedMip, _populatedMip); // destroy the old texture glDeleteTextures(1, &oldId); + + // Update sampler + syncSampler(); + // update the memory usage Backend::textureResourceGPUMemSize.update(oldSize, 0); // no change to Backend::textureResourcePopulatedGPUMemSize + populateTransferQueue(); } @@ -528,20 +518,16 @@ void GL41VariableAllocationTexture::demote() { allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); - // copy pre-existing mips - uint16_t numMips = _gpuObject.getNumMips(); - withPreservedTexture([&] { - if (_texelFormat.isCompressed()) { - copyCompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - } else { - copyUncompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - } - syncSampler(); - }); + // copy pre-existing mips + copyTextureMipsInGPUMem(oldId, _id, oldAllocatedMip, _allocatedMip, _populatedMip); // destroy the old texture glDeleteTextures(1, &oldId); + + // Update sampler + syncSampler(); + // update the memory usage Backend::textureResourceGPUMemSize.update(oldSize, 0); // Demoting unpopulate the memory delta diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index 46599e072c..d5ff1a3485 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -51,7 +51,7 @@ public: GL45Texture(const std::weak_ptr& backend, const Texture& texture); void generateMips() const override; Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; - virtual void syncSampler() const; + void syncSampler() const override; }; // @@ -98,17 +98,16 @@ public: friend class GL45Backend; using PromoteLambda = std::function; - // Overight copy to inject counter for populated amount - Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; protected: GL45VariableAllocationTexture(const std::weak_ptr& backend, const Texture& texture); ~GL45VariableAllocationTexture(); + Size size() const override { return _size; } - Size _size { 0 }; - void incrementPopulatedSize(Size delta) const; - void decrementPopulatedSize(Size delta) const; - mutable Size _populatedSize { 0 }; + + Size copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const override; + void copyTextureMipsInGPUMem(GLuint srcId, GLuint destId, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips) override; + }; class GL45ResourceTexture : public GL45VariableAllocationTexture { @@ -121,6 +120,7 @@ public: void promote() override; void demote() override; void populateTransferQueue() override; + void allocateStorage(uint16 mip); Size copyMipsFromTexture(); diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index d3088c8341..0f1de0f868 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -39,25 +39,7 @@ GL45VariableAllocationTexture::~GL45VariableAllocationTexture() { Backend::textureResourceGPUMemSize.update(_size, 0); Backend::textureResourcePopulatedGPUMemSize.update(_populatedSize, 0); } -void GL45VariableAllocationTexture::incrementPopulatedSize(Size delta) const { - _populatedSize += delta; - // Keep the 2 code paths to be able to debug - if (_size < _populatedSize) { - Backend::textureResourcePopulatedGPUMemSize.update(0, delta); - } else { - Backend::textureResourcePopulatedGPUMemSize.update(0, delta); - } -} -void GL45VariableAllocationTexture::decrementPopulatedSize(Size delta) const { - _populatedSize -= delta; - // Keep the 2 code paths to be able to debug - if (_size < _populatedSize) { - Backend::textureResourcePopulatedGPUMemSize.update(delta, 0); - } else { - Backend::textureResourcePopulatedGPUMemSize.update(delta, 0); - } -} - + Size GL45VariableAllocationTexture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const { Size amountCopied = 0; amountCopied = Parent::copyMipFaceLinesFromTexture(mip, face, size, yOffset, internalFormat, format, type, sourceSize, sourcePointer); @@ -65,6 +47,30 @@ Size GL45VariableAllocationTexture::copyMipFaceLinesFromTexture(uint16_t mip, ui return amountCopied; } + +void copyTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips) { + for (uint16_t mip = populatedMips; mip < numMips; ++mip) { + auto mipDimensions = texture.evalMipDimensions(mip); + uint16_t targetMip = mip - destMipOffset; + uint16_t sourceMip = mip - srcMipOffset; + auto faces = GLTexture::getFaceCount(texTarget); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + srcId, texTarget, sourceMip, 0, 0, face, + destId, texTarget, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); + } + } +} + +void GL45VariableAllocationTexture::copyTextureMipsInGPUMem(GLuint srcId, GLuint destId, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips) { + uint16_t numMips = _gpuObject.getNumMips(); + copyTexGPUMem(_gpuObject, _target, srcId, destId, numMips, srcMipOffset, destMipOffset, populatedMips); +} + + // Managed size resource textures using GL45ResourceTexture = GL45Backend::GL45ResourceTexture; @@ -124,24 +130,6 @@ void GL45ResourceTexture::syncSampler() const { glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, _populatedMip - _allocatedMip); } - -void copyTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips) { - for (uint16_t mip = populatedMips; mip < numMips; ++mip) { - auto mipDimensions = texture.evalMipDimensions(mip); - uint16_t targetMip = mip - destMipOffset; - uint16_t sourceMip = mip - srcMipOffset; - auto faces = GLTexture::getFaceCount(texTarget); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - srcId, texTarget, sourceMip, 0, 0, face, - destId, texTarget, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); - } - } -} - void GL45ResourceTexture::promote() { PROFILE_RANGE(render_gpu_gl, __FUNCTION__); Q_ASSERT(_allocatedMip > 0); @@ -160,15 +148,18 @@ void GL45ResourceTexture::promote() { allocateStorage(targetAllocatedMip); // copy pre-existing mips - uint16_t numMips = _gpuObject.getNumMips(); - copyTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + copyTextureMipsInGPUMem(oldId, _id, oldAllocatedMip, _allocatedMip, _populatedMip); // destroy the old texture glDeleteTextures(1, &oldId); + + // Update sampler + syncSampler(); + // update the memory usage Backend::textureResourceGPUMemSize.update(oldSize, 0); // no change to Backend::textureResourcePopulatedGPUMemSize - syncSampler(); + populateTransferQueue(); } @@ -186,11 +177,14 @@ void GL45ResourceTexture::demote() { _populatedMip = std::max(_populatedMip, _allocatedMip); // copy pre-existing mips - uint16_t numMips = _gpuObject.getNumMips(); - copyTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + copyTextureMipsInGPUMem(oldId, _id, oldAllocatedMip, _allocatedMip, _populatedMip); // destroy the old texture glDeleteTextures(1, &oldId); + + // Update sampler + syncSampler(); + // update the memory usage Backend::textureResourceGPUMemSize.update(oldSize, 0); // Demoting unpopulate the memory delta @@ -202,11 +196,10 @@ void GL45ResourceTexture::demote() { } decrementPopulatedSize(amountUnpopulated); } - syncSampler(); + populateTransferQueue(); } - void GL45ResourceTexture::populateTransferQueue() { PROFILE_RANGE(render_gpu_gl, __FUNCTION__); if (_populatedMip <= _allocatedMip) { From 2be1e36c47ffa6386ec84009d3a26df990ad0ad3 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 23 May 2017 14:14:45 -0700 Subject: [PATCH 11/12] fixing the gl41 bug --- libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp | 8 +++++++- .../src/gpu/gl41/GL41BackendTexture.cpp | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp index b42ffedf37..26ce56b387 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp @@ -221,7 +221,13 @@ GLenum GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) { case gpu::SRGBA: result = GL_SRGB8_ALPHA8; // standard 2.2 gamma correction color break; - + default: + qCWarning(gpugllogging) << "Unknown combination of texel format"; + } + break; + } + case gpu::TILE4x4: { + switch (dstFormat.getSemantic()) { case gpu::COMPRESSED_BC4_RED: result = GL_COMPRESSED_RED_RGTC1; break; diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 1f3b929ec7..5998aebb33 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -78,13 +78,6 @@ GL41Texture::GL41Texture(const std::weak_ptr& backend, const Texture& : GLTexture(backend, texture, allocate(texture)) { } -GLuint GL41Texture::allocate(const Texture& texture) { - GLuint result; - glGenTextures(1, &result); - return result; -} - - void GL41Texture::withPreservedTexture(std::function f) const { glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT); glBindTexture(_target, _texture); @@ -96,6 +89,14 @@ void GL41Texture::withPreservedTexture(std::function f) const { } +GLuint GL41Texture::allocate(const Texture& texture) { + GLuint result; + glGenTextures(1, &result); + return result; +} + + + void GL41Texture::generateMips() const { withPreservedTexture([&] { glGenerateMipmap(_target); @@ -279,6 +280,7 @@ GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr allocateStorage(allocatedMip); _memoryPressureStateStale = true; copyMipsFromTexture(); + syncSampler(); } @@ -318,6 +320,8 @@ Size GL41VariableAllocationTexture::copyMipsFromTexture() { amount += copyMipFaceFromTexture(sourceMip, targetMip, face); } } + + return amount; } @@ -468,7 +472,6 @@ void GL41VariableAllocationTexture::copyTextureMipsInGPUMem(GLuint srcId, GLuint } else { copyUncompressedTexGPUMem(_gpuObject, _target, srcId, destId, numMips, srcMipOffset, destMipOffset, populatedMips); } - syncSampler(); }); } From f2f4ad28e80efc8953352c952d706d0a6d909701 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 23 May 2017 14:16:42 -0700 Subject: [PATCH 12/12] removing comments not needed anymore --- libraries/gpu-gl/src/gpu/gl/GLBackend.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index 0d7c1f2ca1..ed81b502fc 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -644,8 +644,6 @@ void GLBackend::recycle() const { ids.reserve(buffersTrash.size()); for (auto pair : buffersTrash) { ids.push_back(pair.first); - // bufferCount.decrement(); - // bufferGPUMemSize.update(pair.second, 0); } if (!ids.empty()) { glDeleteBuffers((GLsizei)ids.size(), ids.data()); @@ -678,8 +676,6 @@ void GLBackend::recycle() const { ids.reserve(texturesTrash.size()); for (auto pair : texturesTrash) { ids.push_back(pair.first); - // textureCount.decrement(); - // textureGPUMemSize.update(pair.second, 0); } if (!ids.empty()) { glDeleteTextures((GLsizei)ids.size(), ids.data());