diff --git a/interface/resources/qml/Stats.qml b/interface/resources/qml/Stats.qml index dde6c445c8..119f24c71f 100644 --- a/interface/resources/qml/Stats.qml +++ b/interface/resources/qml/Stats.qml @@ -270,30 +270,26 @@ Item { StatText { text: "GPU Textures: "; } - StatText { - text: " Pressure State: " + root.gpuTextureMemoryPressureState; - } StatText { text: " Count: " + root.gpuTextures; } StatText { - text: " Rectified: " + root.rectifiedTextureCount; + text: " Pressure State: " + root.gpuTextureMemoryPressureState; } StatText { - text: " Decimated: " + root.decimatedTextureCount; + text: " Resource Allocated / Populated / Pending: "; } StatText { - text: " Pending Transfer: " + root.texturePendingTransfers + " MB"; + text: " " + root.gpuTextureResourceMemory + " / " + root.gpuTextureResourcePopulatedMemory + " / " + root.texturePendingTransfers + " MB"; } StatText { - text: " Resource Memory: " + root.gpuTextureMemory + " MB"; + 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 976fa54c1e..5e3e09e778 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1340,8 +1340,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo 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..161c407a45 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -345,21 +345,21 @@ 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(gpuTextureResourcePopulatedMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResourcePopulatedGPUMemSize())); + 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..2abb84faea 100644 --- a/interface/src/ui/Stats.h +++ b/interface/src/ui/Stats.h @@ -117,15 +117,15 @@ 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, gpuTextureResourcePopulatedMemory, 0) + STATS_PROPERTY(int, gpuTextureExternalMemory, 0) STATS_PROPERTY(QString, gpuTextureMemoryPressureState, QString()) STATS_PROPERTY(int, gpuFreeMemory, 0) STATS_PROPERTY(float, gpuFrameTime, 0) @@ -245,13 +245,13 @@ signals: void gpuBuffersChanged(); void gpuBufferMemoryChanged(); void gpuTexturesChanged(); - void gpuTexturesSparseChanged(); void gpuTextureMemoryChanged(); - void gpuTextureVirtualMemoryChanged(); + void gpuTextureResidentMemoryChanged(); void gpuTextureFramebufferMemoryChanged(); - void gpuTextureSparseMemoryChanged(); + void gpuTextureResourceMemoryChanged(); + void gpuTextureResourcePopulatedMemoryChanged(); + 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..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); - decrementBufferGPUCount(); - updateBufferGPUMemoryUsage(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); - decrementTextureGPUCount(); - updateTextureGPUMemoryUsage(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..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) { @@ -26,7 +29,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/GLTexelFormat.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp index c57926feb4..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; @@ -349,8 +355,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::TILE4x4: { + 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; @@ -369,7 +398,6 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E case gpu::COMPRESSED_BC7_SRGBA: texel.internalFormat = GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM; break; - default: qCWarning(gpugllogging) << "Unknown combination of texel format"; } @@ -623,7 +651,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::TILE4x4: { + 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/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index b61a3b82c4..88e5cde330 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -115,24 +115,27 @@ 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; } 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 +148,7 @@ GLExternalTexture::~GLExternalTexture() { } const_cast(_id) = 0; } + Backend::textureExternalCount.decrement(); } @@ -211,7 +215,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 +237,7 @@ TransferJob::TransferJob(const GLTexture& parent, std::function transfer } TransferJob::~TransferJob() { - Backend::updateTextureTransferPendingSize(_transferSize, 0); + Backend::texturePendingGPUTransferMemSize.update(_transferSize, 0); } bool TransferJob::tryTransfer() { @@ -669,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 c6ce2a2495..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 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 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,7 +199,8 @@ 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 {} + 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 4caa29574c..2c64b9d23d 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h @@ -54,8 +54,8 @@ 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; - virtual void syncSampler() const; + 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 syncSampler() const override; void withPreservedTexture(std::function f) const; }; @@ -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 { @@ -109,10 +110,13 @@ 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 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 }; }; 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 968cc0e116..5998aebb33 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -76,16 +76,8 @@ using GL41Texture = GL41Backend::GL41Texture; GL41Texture::GL41Texture(const std::weak_ptr& backend, const Texture& texture) : GLTexture(backend, texture, allocate(texture)) { - incrementTextureGPUCount(); } -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); @@ -97,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); @@ -104,7 +104,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: @@ -139,8 +140,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 { @@ -212,17 +215,22 @@ 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 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,11 +248,19 @@ GL41StrictResourceTexture::GL41StrictResourceTexture(const std::weak_ptr& backend, const Texture& texture) : GL41Texture(backend, texture) { + Backend::textureResourceCount.increment(); + auto mipLevels = texture.getNumMips(); _allocatedMip = mipLevels; _maxAllocatedMip = _populatedMip = mipLevels; @@ -263,18 +279,15 @@ GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr allocateStorage(allocatedMip); _memoryPressureStateStale = true; - size_t maxFace = GLTexture::getFaceCount(_target); - 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); - } - } + copyMipsFromTexture(); + syncSampler(); } GL41VariableAllocationTexture::~GL41VariableAllocationTexture() { - Backend::updateTextureGPUMemoryUsage(_size, 0); + Backend::textureResourceCount.decrement(); + Backend::textureResourceGPUMemSize.update(_size, 0); + Backend::textureResourcePopulatedGPUMemSize.update(_populatedSize, 0); } void GL41VariableAllocationTexture::allocateStorage(uint16 allocatedMip) { @@ -293,14 +306,32 @@ 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); + } +Size GL41VariableAllocationTexture::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) { + amount += copyMipFaceFromTexture(sourceMip, targetMip, face); + } + } -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 { + + return amount; +} + +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); }); + incrementPopulatedSize(amountCopied); + return amountCopied; } void GL41VariableAllocationTexture::syncSampler() const { @@ -433,6 +464,17 @@ 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); + } + }); +} + void GL41VariableAllocationTexture::promote() { PROFILE_RANGE(render_gpu_gl, __FUNCTION__); Q_ASSERT(_allocatedMip > 0); @@ -451,20 +493,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::updateTextureGPUMemoryUsage(oldSize, 0); + Backend::textureResourceGPUMemSize.update(oldSize, 0); + // no change to Backend::textureResourcePopulatedGPUMemSize + populateTransferQueue(); } @@ -473,6 +513,7 @@ void GL41VariableAllocationTexture::demote() { Q_ASSERT(_allocatedMip < _maxAllocatedMip); auto oldId = _id; auto oldSize = _size; + auto oldPopulatedMip = _populatedMip; // allocate new texture const_cast(_id) = allocate(_gpuObject); @@ -480,22 +521,27 @@ 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::updateTextureGPUMemoryUsage(oldSize, 0); + 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.evalMipSize(oldPopulatedMip + i); + } + decrementPopulatedSize(amountUnpopulated); + } populateTransferQueue(); } diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index fe2761b37d..d5ff1a3485 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -50,8 +50,8 @@ 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; - virtual void syncSampler() const; + 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 syncSampler() const override; }; // @@ -86,6 +86,7 @@ public: friend class GL45Backend; protected: GL45StrictResourceTexture(const std::weak_ptr& backend, const Texture& texture); + ~GL45StrictResourceTexture(); }; // @@ -101,8 +102,12 @@ public: protected: GL45VariableAllocationTexture(const std::weak_ptr& backend, const Texture& texture); ~GL45VariableAllocationTexture(); + Size size() const override { return _size; } - Size _size { 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 { @@ -115,9 +120,10 @@ public: void promote() override; void demote() override; 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 442d456af9..ad54ccc3e9 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)) { - incrementTextureGPUCount(); } GLuint GL45Texture::allocate(const Texture& texture) { @@ -134,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: @@ -179,9 +179,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 { @@ -243,17 +246,22 @@ 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::textureFramebufferCount.increment(); + Backend::textureFramebufferGPUMemSize.update(0, size()); } GL45AttachmentTexture::~GL45AttachmentTexture() { - Backend::updateTextureGPUFramebufferMemoryUsage(size(), 0); + Backend::textureFramebufferCount.decrement(); + Backend::textureFramebufferGPUMemSize.update(size(), 0); } // Strict resource textures 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; @@ -267,3 +275,8 @@ GL45StrictResourceTexture::GL45StrictResourceTexture(const std::weak_ptr& backend, const Texture& texture) : GL45Texture(backend, texture) { ++_frameTexturesCreated; + Backend::textureResourceCount.increment(); } GL45VariableAllocationTexture::~GL45VariableAllocationTexture() { - Backend::updateTextureGPUMemoryUsage(_size, 0); + Backend::textureResourceCount.decrement(); + Backend::textureResourceGPUMemSize.update(_size, 0); + Backend::textureResourcePopulatedGPUMemSize.update(_populatedSize, 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; +} + + +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; @@ -61,7 +95,6 @@ GL45ResourceTexture::GL45ResourceTexture(const std::weak_ptr& backend _memoryPressureStateStale = true; copyMipsFromTexture(); syncSampler(); - } void GL45ResourceTexture::allocateStorage(uint16 allocatedMip) { @@ -76,20 +109,20 @@ void GL45ResourceTexture::allocateStorage(uint16 allocatedMip) { for (uint16_t mip = _allocatedMip; mip < mipLevels; ++mip) { _size += _gpuObject.evalMipSize(mip); } - - Backend::updateTextureGPUMemoryUsage(0, _size); - + 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 { @@ -97,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); @@ -133,14 +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 the memory usage - Backend::updateTextureGPUMemoryUsage(oldSize, 0); + + // Update sampler syncSampler(); + + // update the memory usage + Backend::textureResourceGPUMemSize.update(oldSize, 0); + // no change to Backend::textureResourcePopulatedGPUMemSize + populateTransferQueue(); } @@ -149,6 +168,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); @@ -157,18 +177,29 @@ 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 the memory usage - Backend::updateTextureGPUMemoryUsage(oldSize, 0); + + // Update sampler syncSampler(); + + // 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.evalMipSize(oldPopulatedMip + i); + } + decrementPopulatedSize(amountUnpopulated); + } + populateTransferQueue(); } - void GL45ResourceTexture::populateTransferQueue() { PROFILE_RANGE(render_gpu_gl, __FUNCTION__); if (_populatedMip <= _allocatedMip) { 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..2116ffd6fe 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,82 @@ 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::textureResidentCount; +ContextMetricCount Backend::textureFramebufferCount; +ContextMetricCount Backend::textureResourceCount; +ContextMetricCount Backend::textureExternalCount; + +ContextMetricSize Backend::textureResidentGPUMemSize; +ContextMetricSize Backend::textureFramebufferGPUMemSize; +ContextMetricSize Backend::textureResourceGPUMemSize; +ContextMetricSize Backend::textureExternalGPUMemSize; + +ContextMetricCount Backend::texturePendingGPUTransferCount; +ContextMetricSize Backend::texturePendingGPUTransferMemSize; + +ContextMetricSize Backend::textureResourcePopulatedGPUMemSize; + +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 getTextureResidentGPUCount() + getTextureResourceGPUCount() + getTextureFramebufferGPUCount(); +} +uint32_t Context::getTextureResidentGPUCount() { + return Backend::textureResidentCount.getValue(); +} +uint32_t Context::getTextureFramebufferGPUCount() { + return Backend::textureFramebufferCount.getValue(); +} +uint32_t Context::getTextureResourceGPUCount() { + return Backend::textureResourceCount.getValue(); +} +uint32_t Context::getTextureExternalGPUCount() { + return Backend::textureExternalCount.getValue(); } -uint32_t Context::getTextureGPUSparseCount() { - return _textureGPUSparseCount.load(); +Size Context::getTextureGPUMemSize() { + return getTextureResidentGPUMemSize() + getTextureResourceGPUMemSize() + getTextureFramebufferGPUMemSize(); +} +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::getTextureTransferPendingSize() { - return _textureTransferPendingSize.load(); +uint32_t Context::getTexturePendingGPUTransferCount() { + return Backend::texturePendingGPUTransferCount.getValue(); +} +Size Context::getTexturePendingGPUTransferMemSize() { + return Backend::texturePendingGPUTransferMemSize.getValue(); } -Context::Size Context::getTextureGPUMemoryUsage() { - return _textureGPUMemoryUsage.load(); +Size Context::getTextureResourcePopulatedGPUMemSize() { + return Backend::textureResourcePopulatedGPUMemSize.getValue(); } - -Context::Size Context::getTextureGPUVirtualMemoryUsage() { - return _textureGPUVirtualMemoryUsage.load(); -} - -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 c4b9453df3..de818ddcb0 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" @@ -94,24 +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(); + // 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 ContextMetricCount textureResidentCount; + static ContextMetricCount textureFramebufferCount; + static ContextMetricCount textureResourceCount; + static ContextMetricCount textureExternalCount; + + static ContextMetricSize textureResidentGPUMemSize; + static ContextMetricSize textureFramebufferGPUMemSize; + static ContextMetricSize textureResourceGPUMemSize; + static ContextMetricSize textureExternalGPUMemSize; + + static ContextMetricCount texturePendingGPUTransferCount; + static ContextMetricSize texturePendingGPUTransferMemSize; + static ContextMetricSize textureResourcePopulatedGPUMemSize; + protected: virtual bool isStereo() { @@ -220,19 +223,28 @@ 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 getTextureGPUSparseCount(); - static Size getFreeGPUMemory(); - static Size getUsedGPUMemory(); - static Size getTextureTransferPendingSize(); - static Size getTextureGPUMemoryUsage(); - static Size getTextureGPUVirtualMemoryUsage(); - static Size getTextureGPUFramebufferMemoryUsage(); - static Size getTextureGPUSparseMemoryUsage(); - static uint32_t getTextureGPUTransferCount(); + static uint32_t getTextureResidentGPUCount(); + static uint32_t getTextureFramebufferGPUCount(); + static uint32_t getTextureResourceGPUCount(); + static uint32_t getTextureExternalGPUCount(); + + static Size getTextureGPUMemSize(); + static Size getTextureResidentGPUMemSize(); + static Size getTextureFramebufferGPUMemSize(); + static Size getTextureResourceGPUMemSize(); + static Size getTextureExternalGPUMemSize(); + + static uint32_t getTexturePendingGPUTransferCount(); + static Size getTexturePendingGPUTransferMemSize(); + + static Size getTextureResourcePopulatedGPUMemSize(); protected: Context(const Context& context); @@ -257,44 +269,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 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 incrementTextureGPUTransferCount(); - static void decrementTextureGPUTransferCount(); - - // 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/Format.cpp b/libraries/gpu/src/gpu/Format.cpp index a4b7411599..b15f8d929f 100644 --- a/libraries/gpu/src/gpu/Format.cpp +++ b/libraries/gpu/src/gpu/Format.cpp @@ -19,12 +19,12 @@ 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_SRGBA_HIGH{ VEC4, NUINT8, COMPRESSED_BC7_SRGBA }; +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::COLOR_COMPRESSED_SRGBA_HIGH { TILE4x4, COMPRESSED, COMPRESSED_BC7_SRGBA }; 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 250d705e18..c4d88236da 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, @@ -61,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 @@ -80,11 +84,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,11 +98,12 @@ enum Dimension { MAT2, MAT3, MAT4, + 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, @@ -104,10 +111,11 @@ static const int LOCATION_COUNT[NUM_DIMENSIONS] = { 1, 3, 4, + 1, }; // 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, @@ -115,10 +123,11 @@ static const int SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = { 4, 3, 4, + 1, }; // 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, @@ -126,11 +135,24 @@ static const int SCALAR_COUNT[NUM_DIMENSIONS] = { 4, 9, 16, + 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 { +enum Semantic : uint8_t { RAW = 0, // used as RAW memory RED, @@ -156,6 +178,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, @@ -175,11 +199,62 @@ 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, + + 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 + 16, //COMPRESSED_BC7_SRGBA, 1 byte/pixel * 4x4 pixels = 16 bytes + + 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 // 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 @@ -206,12 +281,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]; } + 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/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 a545be9088..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,61 +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(); -} - -uint32_t Texture::getTextureGPUSparseCount() { - return Context::getTextureGPUSparseCount(); -} - -Texture::Size Texture::getTextureTransferPendingSize() { - return Context::getTextureTransferPendingSize(); -} - -Texture::Size Texture::getTextureGPUMemoryUsage() { - return Context::getTextureGPUMemoryUsage(); -} - -Texture::Size Texture::getTextureGPUVirtualMemoryUsage() { - return Context::getTextureGPUVirtualMemoryUsage(); -} - - -Texture::Size Texture::getTextureGPUFramebufferMemoryUsage() { - return Context::getTextureGPUFramebufferMemoryUsage(); -} - -Texture::Size Texture::getTextureGPUSparseMemoryUsage() { - return Context::getTextureGPUSparseMemoryUsage(); -} - -uint32_t Texture::getTextureGPUTransferCount() { - return Context::getTextureGPUTransferCount(); -} Texture::Size Texture::getAllowedGPUMemoryUsage() { return _allowedCPUMemoryUsage; @@ -262,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 3777f2bb50..98a4add3c8 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,15 +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 uint32_t getTextureGPUSparseCount(); - static Size getTextureTransferPendingSize(); - static Size getTextureGPUMemoryUsage(); - static Size getTextureGPUVirtualMemoryUsage(); - static Size getTextureGPUFramebufferMemoryUsage(); - static Size getTextureGPUSparseMemoryUsage(); - static uint32_t getTextureGPUTransferCount(); + static Size getTextureCPUMemSize(); + static Size getAllowedGPUMemoryUsage(); static void setAllowedGPUMemoryUsage(Size size); @@ -421,32 +416,44 @@ 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 size of a face is a multiple of the padded line = (width * texelFormat_size + alignment padding) - Size evalMipLineSize(uint16 level) const { return evalPaddedSize(evalMipWidth(level) * getTexelFormat().getSize()); } + // The true size of an image line or surface depends on the format, tiling and padding rules + // + // 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 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()); } + 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/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 ce116ed2c5..9e45be5dbd 100644 --- a/libraries/render/src/render/EngineStats.cpp +++ b/libraries/render/src/render/EngineStats.cpp @@ -24,16 +24,29 @@ 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->textureGPUCount = gpu::Context::getTextureGPUCount(); + 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(); + config->textureExternalGPUMemSize = gpu::Context::getTextureExternalGPUMemSize(); + + config->texturePendingGPUTransferCount = gpu::Context::getTexturePendingGPUTransferCount(); + config->texturePendingGPUTransferSize = gpu::Context::getTexturePendingGPUTransferMemSize(); + + config->textureResourcePopulatedGPUMemSize = gpu::Context::getTextureResourcePopulatedGPUMemSize(); renderContext->args->_context->getFrameStats(_gpuStats); diff --git a/libraries/render/src/render/EngineStats.h b/libraries/render/src/render/EngineStats.h index 8fd38eb501..46be372d5d 100644 --- a/libraries/render/src/render/EngineStats.h +++ b/libraries/render/src/render/EngineStats.h @@ -26,15 +26,26 @@ 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(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) + Q_PROPERTY(qint64 textureExternalGPUMemSize MEMBER textureExternalGPUMemSize NOTIFY dirty) + + 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) @@ -56,15 +67,25 @@ 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 }; + 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 }; + qint64 texturePendingGPUTransferSize { 0 }; + qint64 textureResourcePopulatedGPUMemSize { 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..7f08eb1eea --- /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: 300, +}); +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..97cc577ff9 --- /dev/null +++ b/scripts/developer/utilities/render/textureMonitor.qml @@ -0,0 +1,78 @@ +// +// 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: "gpu::Texture Memory" + height: parent.evalEvenHeight() + object: stats.config + valueScale: 1048576 + valueUnit: "Mb" + valueNumDigits: "1" + plots: [ + { + prop: "textureCPUMemSize", + label: "CPU", + color: "#00B4EF" + }, + { + prop: "textureGPUMemSize", + label: "GPU", + color: "#E3E3E3" + }, + { + prop: "textureResidentGPUMemSize", + label: "Resident", + color: "#A2277C" + }, + { + prop: "textureFramebufferGPUMemSize", + label: "Framebuffer", + color: "#EF93D1" + }, + { + prop: "textureResourceGPUMemSize", + label: "Resource", + color: "#1FC6A6" + }, + { + prop: "textureResourcePopulatedGPUMemSize", + label: "Populated", + color: "#C6A61F" + }, + { + prop: "texturePendingGPUTransferSize", + label: "Transfer", + color: "#FF6309" + } + ] + } + } + +} \ No newline at end of file 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