From b9ec573c8b2765e5bec4a393499c1565f86a0e48 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 26 Apr 2017 10:04:52 -0700 Subject: [PATCH] Update gl41 an gl45 texture backends to take into account min avail mip --- libraries/gpu-gl/src/gpu/gl41/GL41Backend.h | 2 +- .../src/gpu/gl41/GL41BackendTexture.cpp | 19 ++++++++++++++++--- .../gpu/gl45/GL45BackendVariableTexture.cpp | 13 ++++++++++--- .../src/model-networking/TextureCache.cpp | 3 +-- .../src/model-networking/TextureCache.h | 1 - 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h index dc6d2b3aa7..c0b9ea0e45 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h @@ -100,7 +100,7 @@ public: GL41VariableAllocationTexture(const std::weak_ptr& backend, const Texture& texture); ~GL41VariableAllocationTexture(); - bool canPopulate() const override { return _populatedMip > _allocatedMip && _gpuObject.isStoredMipFaceAvailable(_populatedMip - 1, 0); } + bool canPopulate() const override { return _gpuObject.isStoredMipFaceAvailable(_populatedMip - 1, 0); } void allocateStorage(uint16 allocatedMip); void syncSampler() const override; void promote() override; diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 7c43a585b7..51307511c2 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -231,15 +231,20 @@ using GL41VariableAllocationTexture = GL41Backend::GL41VariableAllocationTexture GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr& backend, const Texture& texture) : GL41Texture(backend, texture) { auto mipLevels = texture.getNumMips(); _allocatedMip = mipLevels; + _maxAllocatedMip = _populatedMip = mipLevels; + uint16_t minAvailableMip = texture.minAvailableMipLevel(); uvec3 mipDimensions; for (uint16_t mip = 0; mip < mipLevels; ++mip) { - if (glm::all(glm::lessThanEqual(texture.evalMipDimensions(mip), INITIAL_MIP_TRANSFER_DIMENSIONS))) { + if (glm::all(glm::lessThanEqual(texture.evalMipDimensions(mip), INITIAL_MIP_TRANSFER_DIMENSIONS)) + && mip >= minAvailableMip) { _maxAllocatedMip = _populatedMip = mip; break; } } - uint16_t allocatedMip = _populatedMip - std::min(_populatedMip, 2); + auto targetMip = _populatedMip - std::min(_populatedMip, 2); + uint16_t allocatedMip = std::max(minAvailableMip, targetMip); + allocateStorage(allocatedMip); _memoryPressureStateStale = true; size_t maxFace = GLTexture::getFaceCount(_target); @@ -292,6 +297,14 @@ void GL41VariableAllocationTexture::syncSampler() const { void GL41VariableAllocationTexture::promote() { PROFILE_RANGE(render_gpu_gl, __FUNCTION__); Q_ASSERT(_allocatedMip > 0); + + uint16_t targetAllocatedMip = _allocatedMip - std::min(_allocatedMip, 2); + targetAllocatedMip = std::max(_gpuObject.minAvailableMipLevel(), targetAllocatedMip); + + if (targetAllocatedMip >= _allocatedMip || !_gpuObject.isStoredMipFaceAvailable(targetAllocatedMip, 0)) { + return; + } + GLuint oldId = _id; auto oldSize = _size; // create new texture @@ -299,7 +312,7 @@ void GL41VariableAllocationTexture::promote() { uint16_t oldAllocatedMip = _allocatedMip; // allocate storage for new level - allocateStorage(_allocatedMip - std::min(_allocatedMip, 2)); + allocateStorage(targetAllocatedMip); withPreservedTexture([&] { GLuint fbo { 0 }; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index e3f694f551..9b35f35934 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -46,16 +46,20 @@ GL45ResourceTexture::GL45ResourceTexture(const std::weak_ptr& backend _maxAllocatedMip = _populatedMip = mipLevels; + uint16_t minAvailableMip = texture.minAvailableMipLevel(); + uvec3 mipDimensions; for (uint16_t mip = 0; mip < mipLevels; ++mip) { if (glm::all(glm::lessThanEqual(texture.evalMipDimensions(mip), INITIAL_MIP_TRANSFER_DIMENSIONS)) - && texture.isStoredMipFaceAvailable(mip)) { + && mip >= minAvailableMip) { _maxAllocatedMip = _populatedMip = mip; break; } } - uint16_t allocatedMip = _populatedMip - std::min(_populatedMip, 2); + auto targetMip = _populatedMip - std::min(_populatedMip, 2); + uint16_t allocatedMip = std::max(minAvailableMip, targetMip); + allocateStorage(allocatedMip); _memoryPressureStateStale = true; copyMipsFromTexture(); @@ -99,8 +103,11 @@ void GL45ResourceTexture::syncSampler() const { void GL45ResourceTexture::promote() { PROFILE_RANGE(render_gpu_gl, __FUNCTION__); Q_ASSERT(_allocatedMip > 0); + uint16_t targetAllocatedMip = _allocatedMip - std::min(_allocatedMip, 2); - if (!_gpuObject.isStoredMipFaceAvailable(targetAllocatedMip, 0)) { + targetAllocatedMip = std::max(_gpuObject.minAvailableMipLevel(), targetAllocatedMip); + + if (targetAllocatedMip >= _allocatedMip || !_gpuObject.isStoredMipFaceAvailable(targetAllocatedMip, 0)) { return; } GLuint oldId = _id; diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index 1d37a26f37..62b94ed455 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -588,8 +588,7 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() { _ktxResourceState = FAILED_TO_LOAD; finishedLoading(false); return; - } - else { + } else { _file = file; } diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index c7a7799216..1e61b9ecee 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -46,7 +46,6 @@ class NetworkTexture : public Resource, public Texture { public: NetworkTexture(const QUrl& url, image::TextureUsage::Type type, const QByteArray& content, int maxNumPixels); - ~NetworkTexture() override; QString getType() const override { return "NetworkTexture"; }