From e4f9f2935ed6237e958a09f6e930f62f4403d698 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 22 May 2017 15:42:18 -0700 Subject: [PATCH] Solving the size evaluation for compressed format --- interface/resources/qml/Stats.qml | 2 +- interface/src/ui/Stats.cpp | 1 + interface/src/ui/Stats.h | 2 + libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp | 4 +- libraries/gpu/src/gpu/Format.cpp | 10 ++-- libraries/gpu/src/gpu/Format.h | 42 +++++++++----- libraries/gpu/src/gpu/Texture.h | 41 +++++++------ .../utilities/render/textureMonitor.js | 2 +- .../utilities/render/textureMonitor.qml | 57 ++++--------------- 9 files changed, 74 insertions(+), 87 deletions(-) diff --git a/interface/resources/qml/Stats.qml b/interface/resources/qml/Stats.qml index 97117fff0c..7b5c81d683 100644 --- a/interface/resources/qml/Stats.qml +++ b/interface/resources/qml/Stats.qml @@ -280,7 +280,7 @@ Item { text: " Pending Transfer: " + root.texturePendingTransfers + " MB"; } StatText { - text: " Resource Memory: " + root.gpuTextureResourceMemory + " MB"; + text: " Resource Allocated/Populated: " + root.gpuTextureResourceMemory + " / " + root.gpuTextureResourcePopulatedMemory + " MB"; } StatText { text: " Resident Memory: " + root.gpuTextureResidentMemory + " MB"; diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 131658461b..161c407a45 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -356,6 +356,7 @@ void Stats::updateStats(bool force) { STAT_UPDATE(gpuTextureResidentMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResidentGPUMemSize())); STAT_UPDATE(gpuTextureFramebufferMemory, (int)BYTES_TO_MB(gpu::Context::getTextureFramebufferGPUMemSize())); STAT_UPDATE(gpuTextureResourceMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResourceGPUMemSize())); + STAT_UPDATE(gpuTextureResourcePopulatedMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResourcePopulatedGPUMemSize())); STAT_UPDATE(gpuTextureExternalMemory, (int)BYTES_TO_MB(gpu::Context::getTextureExternalGPUMemSize())); STAT_UPDATE(gpuTextureMemoryPressureState, getTextureMemoryPressureModeString()); STAT_UPDATE(gpuFreeMemory, (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemSize())); diff --git a/interface/src/ui/Stats.h b/interface/src/ui/Stats.h index bb7c40a105..2abb84faea 100644 --- a/interface/src/ui/Stats.h +++ b/interface/src/ui/Stats.h @@ -124,6 +124,7 @@ class Stats : public QQuickItem { STATS_PROPERTY(int, gpuTextureResidentMemory, 0) STATS_PROPERTY(int, gpuTextureFramebufferMemory, 0) STATS_PROPERTY(int, gpuTextureResourceMemory, 0) + STATS_PROPERTY(int, gpuTextureResourcePopulatedMemory, 0) STATS_PROPERTY(int, gpuTextureExternalMemory, 0) STATS_PROPERTY(QString, gpuTextureMemoryPressureState, QString()) STATS_PROPERTY(int, gpuFreeMemory, 0) @@ -248,6 +249,7 @@ signals: void gpuTextureResidentMemoryChanged(); void gpuTextureFramebufferMemoryChanged(); void gpuTextureResourceMemoryChanged(); + void gpuTextureResourcePopulatedMemoryChanged(); void gpuTextureExternalMemoryChanged(); void gpuTextureMemoryPressureStateChanged(); void gpuFreeMemoryChanged(); diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp index ad706da8ae..a5beca8dfd 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp @@ -354,7 +354,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E break; } - case gpu::BLOB: { + case gpu::TILE4x4: { texel.format = GL_RGBA; texel.type = ELEMENT_TYPE_TO_GL[srcFormat.getType()]; @@ -646,7 +646,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E break; } - case gpu::BLOB: { + case gpu::TILE4x4: { texel.format = GL_RGBA; texel.type = ELEMENT_TYPE_TO_GL[srcFormat.getType()]; diff --git a/libraries/gpu/src/gpu/Format.cpp b/libraries/gpu/src/gpu/Format.cpp index 458939bcbe..787c09c63e 100644 --- a/libraries/gpu/src/gpu/Format.cpp +++ b/libraries/gpu/src/gpu/Format.cpp @@ -19,11 +19,11 @@ const Element Element::COLOR_SRGBA_32{ VEC4, NUINT8, SRGBA }; const Element Element::COLOR_BGRA_32{ VEC4, NUINT8, BGRA }; const Element Element::COLOR_SBGRA_32{ VEC4, NUINT8, SBGRA }; -const Element Element::COLOR_COMPRESSED_RED{ BLOB, COMPRESSED, COMPRESSED_BC4_RED }; -const Element Element::COLOR_COMPRESSED_SRGB { BLOB, COMPRESSED, COMPRESSED_BC1_SRGB }; -const Element Element::COLOR_COMPRESSED_SRGBA_MASK { BLOB, COMPRESSED, COMPRESSED_BC1_SRGBA }; -const Element Element::COLOR_COMPRESSED_SRGBA { BLOB, COMPRESSED, COMPRESSED_BC3_SRGBA }; -const Element Element::COLOR_COMPRESSED_XY { BLOB, COMPRESSED, COMPRESSED_BC5_XY }; +const Element Element::COLOR_COMPRESSED_RED{ TILE4x4, COMPRESSED, COMPRESSED_BC4_RED }; +const Element Element::COLOR_COMPRESSED_SRGB { TILE4x4, COMPRESSED, COMPRESSED_BC1_SRGB }; +const Element Element::COLOR_COMPRESSED_SRGBA_MASK { TILE4x4, COMPRESSED, COMPRESSED_BC1_SRGBA }; +const Element Element::COLOR_COMPRESSED_SRGBA { TILE4x4, COMPRESSED, COMPRESSED_BC3_SRGBA }; +const Element Element::COLOR_COMPRESSED_XY { TILE4x4, COMPRESSED, COMPRESSED_BC5_XY }; const Element Element::VEC2NU8_XY{ VEC2, NUINT8, XY }; diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 8fab7f9be7..b2f2252119 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -98,12 +98,12 @@ enum Dimension : uint8_t { MAT2, MAT3, MAT4, - BLOB, // Blob element's size is defined from the type and semantic, it s counted as 1 component + TILE4x4, // Blob element's size is defined from the type and semantic, it s counted as 1 component NUM_DIMENSIONS, }; // Count (of scalars) in an Element for a given Dimension -static const int LOCATION_COUNT[NUM_DIMENSIONS] = { +static const int DIMENSION_LOCATION_COUNT[NUM_DIMENSIONS] = { 1, 1, 1, @@ -115,7 +115,7 @@ static const int LOCATION_COUNT[NUM_DIMENSIONS] = { }; // Count (of scalars) in an Element for a given Dimension's location -static const int SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = { +static const int DIMENSION_SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = { 1, 2, 3, @@ -127,7 +127,7 @@ static const int SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = { }; // Count (of scalars) in an Element for a given Dimension -static const int SCALAR_COUNT[NUM_DIMENSIONS] = { +static const int DIMENSION_SCALAR_COUNT[NUM_DIMENSIONS] = { 1, 2, 3, @@ -138,6 +138,18 @@ static const int SCALAR_COUNT[NUM_DIMENSIONS] = { 1, }; +// Tile dimension described by the ELement for "Tilexxx" DIMENSIONs +static const glm::ivec2 DIMENSION_TILE_DIM[NUM_DIMENSIONS] = { + { 1, 1 }, + { 1, 1 }, + { 1, 1 }, + { 1, 1 }, + { 1, 1 }, + { 1, 1 }, + { 1, 1 }, + { 4, 4 }, +}; + // Semantic of an Element // Provide information on how to use the element enum Semantic : uint8_t { @@ -222,11 +234,11 @@ static const int SEMANTIC_SIZE_FACTOR[NUM_SEMANTICS] = { // THe size of a compressed element is defined from the semantic 1, //_FIRST_COMPRESSED, - 1, //COMPRESSED_BC1_SRGB, - 1, //COMPRESSED_BC1_SRGBA, - 1, //COMPRESSED_BC3_SRGBA, - 1, //COMPRESSED_BC4_RED, - 1, //COMPRESSED_BC5_XY, + 8, //COMPRESSED_BC1_SRGB, 1/2 byte/pixel * 4x4 pixels = 8 bytes + 8, //COMPRESSED_BC1_SRGBA, 1/2 byte/pixel * 4x4 pixels = 8 bytes + 16, //COMPRESSED_BC3_SRGBA, 1 byte/pixel * 4x4 pixels = 16 bytes + 8, //COMPRESSED_BC4_RED, 1/2 byte/pixel * 4x4 pixels = 8 bytes + 16, //COMPRESSED_BC5_XY, 1 byte/pixel * 4x4 pixels = 16 bytes 1, //_LAST_COMPRESSED, @@ -240,6 +252,7 @@ static const int SEMANTIC_SIZE_FACTOR[NUM_SEMANTICS] = { 1, //SAMPLER_SHADOW, }; + // Element is a simple 16bit value that contains everything we need to know about an element // of a buffer, a pixel of a texture, a varying input/output or uniform from a shader pipeline. // Type and dimension of the element, and semantic @@ -266,12 +279,13 @@ public: bool isNormalized() const { return (getType() >= NORMALIZED_START); } bool isInteger() const { return TYPE_IS_INTEGER[getType()]; } - uint8 getScalarCount() const { return SCALAR_COUNT[(Dimension)_dimension]; } - uint32 getSize() const { return (SCALAR_COUNT[_dimension] * TYPE_SIZE[_type] * SEMANTIC_SIZE_FACTOR[_semantic]); } + uint8 getScalarCount() const { return DIMENSION_SCALAR_COUNT[(Dimension)_dimension]; } + uint32 getSize() const { return (DIMENSION_SCALAR_COUNT[_dimension] * TYPE_SIZE[_type] * SEMANTIC_SIZE_FACTOR[_semantic]); } + const glm::ivec2& getTile() const { return (DIMENSION_TILE_DIM[_dimension]); } - uint8 getLocationCount() const { return LOCATION_COUNT[(Dimension)_dimension]; } - uint8 getLocationScalarCount() const { return SCALAR_COUNT_PER_LOCATION[(Dimension)_dimension]; } - uint32 getLocationSize() const { return SCALAR_COUNT_PER_LOCATION[_dimension] * TYPE_SIZE[_type]; } + uint8 getLocationCount() const { return DIMENSION_LOCATION_COUNT[(Dimension)_dimension]; } + uint8 getLocationScalarCount() const { return DIMENSION_SCALAR_COUNT_PER_LOCATION[(Dimension)_dimension]; } + uint32 getLocationSize() const { return DIMENSION_SCALAR_COUNT_PER_LOCATION[_dimension] * TYPE_SIZE[_type]; } uint16 getRaw() const { return *((uint16*) (this)); } diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 39398558fe..da6071e72a 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -416,36 +416,43 @@ public: // Same but applied to this texture's num max mips from evalNumMips() uint16 safeNumMips(uint16 askedNumMips) const; - // Eval the size that the mips level SHOULD have + // Eval the dimensions & sizes that the mips level SHOULD have // not the one stored in the Texture + // Dimensions Vec3u evalMipDimensions(uint16 level) const; uint16 evalMipWidth(uint16 level) const { return std::max(_width >> level, 1); } uint16 evalMipHeight(uint16 level) const { return std::max(_height >> level, 1); } uint16 evalMipDepth(uint16 level) const { return std::max(_depth >> level, 1); } - // The true size of a line or a sirface depends on the format and the padding - // is a multiple of the padded line = (width * texelFormat_size + alignment padding) + // The true size of an image line or surface depends on the format, tiling and padding rules // - uint16 evaTiledWidth(uint16 width) const { return width >> 2 + width & 0x03; } - Size evalMipLineSize(uint16 level) const { return evalPaddedSize(evalMipWidth(level) * getTexelFormat().getSize()); } - Size evalMipSurfaceSize(uint16 level) const { return evalPaddedSize(evalMipWidth(level) * getTexelFormat().getSize()); } + // Here are the static function to compute the different sizes from parametered dimensions and format + // Tile size must be a power of 2 + static uint16 evalTiledLength(uint16 length, int tile) { return length / tile + ((~length & tile) != 0); } + static uint16 evalTiledWidth(uint16 width, int tileX) { return evalTiledLength(width, tileX); } + static uint16 evalTiledHeight(uint16 height, int tileY) { return evalTiledLength(height, tileY); } + static Size evalLineSize(uint16 width, const Element& format) { return evalPaddedSize(evalTiledWidth(width, format.getTile().x) * format.getSize()); } + static Size evalSurfaceSize(uint16 width, uint16 height, const Element& format) { return evalLineSize(width, format) * evalTiledHeight(height, format.getTile().x); } - // Size for each face of a mip at a particular level - uint32 evalMipFaceNumTexels(uint16 level) const { return evalMipWidth(level) * evalMipHeight(level) * evalMipDepth(level); } - Size evalMipFaceSize(uint16 level) const { return evalMipLineSize(level) * evalMipHeight(level) * evalMipDepth(level); } - - // Total size for the mip - uint32 evalMipNumTexels(uint16 level) const { return evalMipFaceNumTexels(level) * getNumFaces(); } - Size evalMipSize(uint16 level) const { return evalMipFaceSize(level) * getNumFaces(); } + // Compute the theorical size of the texture elements storage depending on the specified format + Size evalStoredMipLineSize(uint16 level, const Element& format) const { return evalLineSize(evalMipWidth(level), format); } + Size evalStoredMipSurfaceSize(uint16 level, const Element& format) const { return evalSurfaceSize(evalMipWidth(level), evalMipHeight(level), format); } + Size evalStoredMipFaceSize(uint16 level, const Element& format) const { return evalStoredMipSurfaceSize(level, format) * evalMipDepth(level); } + Size evalStoredMipSize(uint16 level, const Element& format) const { return evalStoredMipFaceSize(level, format) * getNumFaces(); } + + // For this texture's texel format and dimensions, compute the various mem sizes + Size evalMipLineSize(uint16 level) const { return evalStoredMipLineSize(level, getTexelFormat()); } + Size evalMipSurfaceSize(uint16 level) const { return evalStoredMipSurfaceSize(level, getTexelFormat()); } + Size evalMipFaceSize(uint16 level) const { return evalStoredMipFaceSize(level, getTexelFormat()); } + Size evalMipSize(uint16 level) const { return evalStoredMipSize(level, getTexelFormat()); } // Total size for all the mips of the texture Size evalTotalSize(uint16 startingMip = 0) const; - // Compute the theorical size of the texture elements storage depending on the specified format - Size evalStoredMipLineSize(uint16 level, const Element& format) const { return evalPaddedSize(evalMipWidth(level) * format.getSize()); } - Size evalStoredMipFaceSize(uint16 level, const Element& format) const { return evalMipFaceNumTexels(level) * format.getSize(); } - Size evalStoredMipSize(uint16 level, const Element& format) const { return evalMipNumTexels(level) * format.getSize(); } + // Number of texels (not it s not directly proprtional to the size! + uint32 evalMipFaceNumTexels(uint16 level) const { return evalMipWidth(level) * evalMipHeight(level) * evalMipDepth(level); } + uint32 evalMipNumTexels(uint16 level) const { return evalMipFaceNumTexels(level) * getNumFaces(); } // For convenience assign a source name const std::string& source() const { return _source; } diff --git a/scripts/developer/utilities/render/textureMonitor.js b/scripts/developer/utilities/render/textureMonitor.js index f8abe47e55..779e3b8950 100644 --- a/scripts/developer/utilities/render/textureMonitor.js +++ b/scripts/developer/utilities/render/textureMonitor.js @@ -15,7 +15,7 @@ var window = new OverlayWindow({ title: 'Textures', source: qml, width: 320, - height: 720 + height: 400 }); window.setPosition(500, 50); window.closed.connect(function() { Script.stop(); }); \ No newline at end of file diff --git a/scripts/developer/utilities/render/textureMonitor.qml b/scripts/developer/utilities/render/textureMonitor.qml index 1df51031c1..d29db439c9 100644 --- a/scripts/developer/utilities/render/textureMonitor.qml +++ b/scripts/developer/utilities/render/textureMonitor.qml @@ -28,43 +28,6 @@ Item { // Why do we have to do that manually ? cannot seem to find a qml / anchor / layout mode that does that ? return (height - spacing * (children.length - 1)) / children.length } - PlotPerf { - title: "Num Textures" - height: parent.evalEvenHeight() - object: stats.config - plots: [ - { - prop: "textureCPUCount", - label: "CPU", - color: "#00B4EF" - }, - { - prop: "texturePendingGPUTransferCount", - label: "Transfer", - color: "#359D85" - }, - { - prop: "textureResourceGPUCount", - label: "Resource", - color: "#1FC6A6" - }, - { - prop: "textureResidentGPUCount", - label: "Resident", - color: "#FF6309" - }, - { - prop: "textureFramebufferGPUCount", - label: "Framebuffer", - color: "#EF93D1" - }, - { - prop: "textureExternalGPUCount", - label: "External", - color: "#C62147" - } - ] - } PlotPerf { title: "gpu::Texture Memory" height: parent.evalEvenHeight() @@ -78,21 +41,11 @@ Item { label: "CPU", color: "#00B4EF" }, - { - prop: "texturePendingGPUTransferSize", - label: "Transfer", - color: "#359D85" - }, { prop: "textureGPUMemSize", label: "GPU", color: "#E3E3E3" }, - { - prop: "textureResourceGPUMemSize", - label: "Resource", - color: "#1FC6A6" - }, { prop: "textureResidentGPUMemSize", label: "Resident", @@ -103,10 +56,20 @@ Item { label: "Framebuffer", color: "#EF93D1" }, + { + prop: "textureResourceGPUMemSize", + label: "Resource", + color: "#1FC6A6" + }, { prop: "textureResourcePopulatedGPUMemSize", label: "Populated", color: "#C6A61F" + }, + { + prop: "texturePendingGPUTransferSize", + label: "Transfer", + color: "#A2277C" } ] }