Cleaned up the counters for memory

This commit is contained in:
samcake 2017-05-19 17:52:56 -07:00
parent 9c154122d3
commit c449229850
15 changed files with 136 additions and 38 deletions

View file

@ -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());

View file

@ -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) {

View file

@ -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;

View file

@ -92,6 +92,7 @@ public:
friend class GL41Backend;
protected:
GL41StrictResourceTexture(const std::weak_ptr<GLBackend>& backend, const Texture& texture);
~GL41StrictResourceTexture();
};
class GL41VariableAllocationTexture : public GL41Texture, public GLVariableAllocationSupport {

View file

@ -76,7 +76,6 @@ using GL41Texture = GL41Backend::GL41Texture;
GL41Texture::GL41Texture(const std::weak_ptr<GLBackend>& 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<GLBackend>& 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<GLBacke
}
}
GL41StrictResourceTexture::~GL41StrictResourceTexture() {
Backend::textureResidentCount.decrement();
Backend::textureResidentGPUMemSize.update(size(), 0);
}
using GL41VariableAllocationTexture = GL41Backend::GL41VariableAllocationTexture;
GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr<GLBackend>& backend, const Texture& texture) :

View file

@ -86,6 +86,7 @@ public:
friend class GL45Backend;
protected:
GL45StrictResourceTexture(const std::weak_ptr<GLBackend>& backend, const Texture& texture);
~GL45StrictResourceTexture();
};
//

View file

@ -116,7 +116,6 @@ using GL45Texture = GL45Backend::GL45Texture;
GL45Texture::GL45Texture(const std::weak_ptr<GLBackend>& 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<GLBackend>& 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<GLBackend>& 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<GLBacke
}
}
GL45StrictResourceTexture::~GL45StrictResourceTexture() {
Backend::textureResidentCount.decrement();
Backend::textureResidentGPUMemSize.update(size(), 0);
}

View file

@ -31,10 +31,12 @@ using GL45VariableAllocationTexture = GL45Backend::GL45VariableAllocationTexture
GL45VariableAllocationTexture::GL45VariableAllocationTexture(const std::weak_ptr<GLBackend>& 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

View file

@ -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();

View file

@ -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();

View file

@ -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 };

View file

@ -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)) {

View file

@ -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();

View file

@ -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 };

View file

@ -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",