From c449229850b4209971bf3c260632aa8a04ef44a5 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 19 May 2017 17:52:56 -0700 Subject: [PATCH] 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",