From 14f8c91e23442b48bd108dfa5aab4f6113cbe1a1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 21 Apr 2017 01:11:30 -0700 Subject: [PATCH] Adjust gl45 backend to request interest in mips and keep track of min requested --- libraries/gpu-gl/src/gpu/gl45/GL45Backend.h | 2 ++ .../src/gpu/gl45/GL45BackendTexture.cpp | 2 ++ .../gpu/gl45/GL45BackendVariableTexture.cpp | 23 +++++++++++-------- libraries/gpu/src/gpu/Texture.cpp | 1 - 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index 15e98c3af7..21c429c577 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -117,6 +117,8 @@ public: void allocateStorage(uint16 mip); void copyMipsFromTexture(); + + uint16 _lowestRequestedMip { 0 }; }; #if 0 diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 761cd305bb..299a52eddd 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -119,8 +119,10 @@ GL45Texture::GL45Texture(const std::weak_ptr& backend, const Texture& GLuint GL45Texture::allocate(const Texture& texture) { GLuint result; glCreateTextures(getGLTextureType(texture), 1, &result); +#ifdef DEBUG auto source = texture.source(); glObjectLabel(GL_TEXTURE, result, source.length(), source.data()); +#endif return result; } diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index 77e42e7fdb..5dfbd6e727 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -75,6 +75,11 @@ void GL45ResourceTexture::allocateStorage(uint16 allocatedMip) { for (uint16_t mip = _allocatedMip; mip < mipLevels; ++mip) { _size += _gpuObject.evalMipSize(mip); } + + if (!_gpuObject.isStoredMipFaceAvailable(allocatedMip, 0)) { + const_cast(_gpuObject).requestInterestInMip(allocatedMip); + } + Backend::updateTextureGPUMemoryUsage(0, _size); } @@ -98,9 +103,11 @@ void GL45ResourceTexture::syncSampler() const { void GL45ResourceTexture::promote() { PROFILE_RANGE(render_gpu_gl, __FUNCTION__); - //Q_ASSERT(_allocatedMip > 0); - if (!_gpuObject.isStoredMipFaceAvailable(_populatedMip - 1, 0)) { - const_cast(_gpuObject).requestInterestInMip(_populatedMip - 1); + Q_ASSERT(_allocatedMip > 0); + uint16_t targetAllocatedMip = _allocatedMip - std::min(_allocatedMip, 2); + if (!_gpuObject.isStoredMipFaceAvailable(targetAllocatedMip, 0)) { + _lowestRequestedMip = targetAllocatedMip; + const_cast(_gpuObject).requestInterestInMip(targetAllocatedMip); return; } GLuint oldId = _id; @@ -109,7 +116,7 @@ void GL45ResourceTexture::promote() { const_cast(_id) = allocate(_gpuObject); uint16_t oldAllocatedMip = _allocatedMip; // allocate storage for new level - allocateStorage(_allocatedMip - std::min(_allocatedMip, 2)); + allocateStorage(targetAllocatedMip); uint16_t mips = _gpuObject.getNumMips(); // copy pre-existing mips for (uint16_t mip = _populatedMip; mip < mips; ++mip) { @@ -176,23 +183,21 @@ void GL45ResourceTexture::populateTransferQueue() { const uint8_t maxFace = GLTexture::getFaceCount(_target); uint16_t sourceMip = _populatedMip; - //qDebug() << "populateTransferQueue info : " << _populatedMip << " " << _maxAllocatedMip << " " << _allocatedMip; do { --sourceMip; auto targetMip = sourceMip - _allocatedMip; auto mipDimensions = _gpuObject.evalMipDimensions(sourceMip); bool transferQueued = false; - //qDebug() << "populateTransferQueue " << QString::fromStdString(_gpuObject.source()) << sourceMip << " " << targetMip; for (uint8_t face = 0; face < maxFace; ++face) { if (!_gpuObject.isStoredMipFaceAvailable(sourceMip, face)) { const_cast(_gpuObject).requestInterestInMip(sourceMip); - _minRequestedMip = sourceMip; + _lowestRequestedMip = sourceMip; continue; } + _lowestRequestedMip = sourceMip; // If the mip is less than the max transfer size, then just do it in one transfer if (glm::all(glm::lessThanEqual(mipDimensions, MAX_TRANSFER_DIMENSIONS))) { - qDebug() << "mip is less than max transfer size"; // Can the mip be transferred in one go _pendingTransfers.emplace(new TransferJob(*this, sourceMip, targetMip, face)); transferQueued = true; @@ -207,14 +212,12 @@ void GL45ResourceTexture::populateTransferQueue() { Q_ASSERT(0 == (mipSize % lines)); uint32_t linesPerTransfer = (uint32_t)(MAX_TRANSFER_SIZE / bytesPerLine); uint32_t lineOffset = 0; - qDebug() << "queing up single line transfers " << linesPerTransfer << " " << lineOffset; while (lineOffset < lines) { uint32_t linesToCopy = std::min(lines - lineOffset, linesPerTransfer); _pendingTransfers.emplace(new TransferJob(*this, sourceMip, targetMip, face, linesToCopy, lineOffset)); lineOffset += linesToCopy; transferQueued = true; } - _minRequestedMip = std::min(_minRequestedMip, sourceMip); } // queue up the sampler and populated mip change for after the transfer has completed diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index bed01a805d..1dbe9db2b4 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -397,7 +397,6 @@ Size Texture::evalTotalSize(uint16 startingMip) const { Size size = 0; uint16 minMipLevel = std::max(getMinMip(), startingMip); uint16 maxMipLevel = getMaxMip(); - qDebug() << " min: " << minMipLevel << " " << maxMipLevel; for (uint16 level = minMipLevel; level <= maxMipLevel; level++) { size += evalMipSize(level); }