From a71d246e754bb93a358d2ee3bde55c7808f003a0 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 26 Apr 2017 12:50:42 -0700 Subject: [PATCH] Replace canPopulate with _minAllocatedMip --- libraries/gpu-gl/src/gpu/gl/GLTexture.cpp | 6 ++---- libraries/gpu-gl/src/gpu/gl/GLTexture.h | 6 ++++-- libraries/gpu-gl/src/gpu/gl41/GL41Backend.h | 1 - libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp | 12 ++++++++++++ libraries/gpu-gl/src/gpu/gl45/GL45Backend.h | 1 - libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp | 9 ++++++--- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index fceed7c2eb..dc4b828fbb 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -437,7 +437,6 @@ void GLVariableAllocationSupport::updateMemoryPressure() { size_t idealMemoryAllocation = 0; bool canDemote = false; bool canPromote = false; - bool canPopulate = false; bool hasTransfers = false; for (const auto& texture : strongTextures) { // Race conditions can still leave nulls in the list, so we need to check @@ -452,7 +451,6 @@ void GLVariableAllocationSupport::updateMemoryPressure() { totalVariableMemoryAllocation += gltexture->size(); canDemote |= vartexture->canDemote(); canPromote |= vartexture->canPromote(); - canPopulate |= vartexture->canPopulate(); hasTransfers |= vartexture->hasPendingTransfers(); } @@ -464,7 +462,7 @@ void GLVariableAllocationSupport::updateMemoryPressure() { newState = MemoryPressureState::Transfer; } else if (pressure > OVERSUBSCRIBED_PRESSURE_VALUE && canDemote) { newState = MemoryPressureState::Oversubscribed; - } else if (pressure < UNDERSUBSCRIBED_PRESSURE_VALUE && ((unallocated != 0 && canPromote) && canPopulate)) { + } else if (pressure < UNDERSUBSCRIBED_PRESSURE_VALUE && (unallocated != 0 && canPromote)) { newState = MemoryPressureState::Undersubscribed; } @@ -521,7 +519,7 @@ void GLVariableAllocationSupport::processWorkQueues() { vartexture->demote(); _memoryPressureStateStale = true; } else if (MemoryPressureState::Undersubscribed == _memoryPressureState) { - if (!vartexture->canPromote() || !vartexture->canPopulate()) { + if (!vartexture->canPromote()) { continue; } vartexture->promote(); diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.h b/libraries/gpu-gl/src/gpu/gl/GLTexture.h index 9aad49546e..3e944ed70d 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.h +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.h @@ -112,8 +112,7 @@ protected: static void manageMemory(); //bool canPromoteNoAllocate() const { return _allocatedMip < _populatedMip; } - virtual bool canPopulate() const = 0; - bool canPromote() const { return _allocatedMip > 0; } + bool canPromote() const { return _allocatedMip > _minAllocatedMip; } bool canDemote() const { return _allocatedMip < _maxAllocatedMip; } bool hasPendingTransfers() const { return _pendingTransfers.size() > 0; } void executeNextTransfer(const TexturePointer& currentTexture); @@ -131,6 +130,9 @@ protected: // The highest (lowest resolution) mip that we will support, relative to the number // of mips in the gpu::Texture object uint16 _maxAllocatedMip { 0 }; + // The lowest (highest resolution) mip that we will support, relative to the number + // of mips in the gpu::Texture object + uint16 _minAllocatedMip { 0 }; // Contains a series of lambdas that when executed will transfer data to the GPU, modify // the _populatedMip and update the sampler in order to fully populate the allocated texture // until _populatedMip == _allocatedMip diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h index c0b9ea0e45..19979a1778 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h @@ -100,7 +100,6 @@ public: GL41VariableAllocationTexture(const std::weak_ptr& backend, const Texture& texture); ~GL41VariableAllocationTexture(); - 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 51307511c2..9fa873f6e2 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -55,6 +55,18 @@ GLTexture* GL41Backend::syncGPUObject(const TexturePointer& texturePointer) { default: Q_UNREACHABLE(); } + } else { + if (texture.getUsageType() == TextureUsageType::RESOURCE) { + auto varTex = static_cast (object); + + if (varTex->_minAllocatedMip > 0) { + auto minAvailableMip = texture.minAvailableMipLevel(); + if (minAvailableMip < varTex->_minAllocatedMip) { + varTex->_minAllocatedMip = minAvailableMip; + GL41VariableAllocationTexture::_memoryPressureStateStale = true; + } + } + } } return object; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index 15e98c3af7..dbedd81c76 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -100,7 +100,6 @@ public: GL45VariableAllocationTexture(const std::weak_ptr& backend, const Texture& texture); ~GL45VariableAllocationTexture(); Size size() const override { return _size; } - bool canPopulate() const override { return _gpuObject.isStoredMipFaceAvailable(_populatedMip - 1, 0); } Size _size { 0 }; }; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 299a52eddd..120be923f5 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -85,10 +85,13 @@ GLTexture* GL45Backend::syncGPUObject(const TexturePointer& texturePointer) { if (texture.getUsageType() == TextureUsageType::RESOURCE) { auto varTex = static_cast (object); - if (varTex->canPromote() && varTex->canPopulate()) { - GL45VariableAllocationTexture::_memoryPressureStateStale = true; + if (varTex->_minAllocatedMip > 0) { + auto minAvailableMip = texture.minAvailableMipLevel(); + if (minAvailableMip < varTex->_minAllocatedMip) { + varTex->_minAllocatedMip = minAvailableMip; + GL45VariableAllocationTexture::_memoryPressureStateStale = true; + } } - } }