Replace canPopulate with _minAllocatedMip

This commit is contained in:
Ryan Huffman 2017-04-26 12:50:42 -07:00
parent 70ece9f0fd
commit a71d246e75
6 changed files with 24 additions and 11 deletions

View file

@ -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();

View file

@ -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

View file

@ -100,7 +100,6 @@ public:
GL41VariableAllocationTexture(const std::weak_ptr<GLBackend>& 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;

View file

@ -55,6 +55,18 @@ GLTexture* GL41Backend::syncGPUObject(const TexturePointer& texturePointer) {
default:
Q_UNREACHABLE();
}
} else {
if (texture.getUsageType() == TextureUsageType::RESOURCE) {
auto varTex = static_cast<GL41VariableAllocationTexture*> (object);
if (varTex->_minAllocatedMip > 0) {
auto minAvailableMip = texture.minAvailableMipLevel();
if (minAvailableMip < varTex->_minAllocatedMip) {
varTex->_minAllocatedMip = minAvailableMip;
GL41VariableAllocationTexture::_memoryPressureStateStale = true;
}
}
}
}
return object;

View file

@ -100,7 +100,6 @@ public:
GL45VariableAllocationTexture(const std::weak_ptr<GLBackend>& backend, const Texture& texture);
~GL45VariableAllocationTexture();
Size size() const override { return _size; }
bool canPopulate() const override { return _gpuObject.isStoredMipFaceAvailable(_populatedMip - 1, 0); }
Size _size { 0 };
};

View file

@ -85,10 +85,13 @@ GLTexture* GL45Backend::syncGPUObject(const TexturePointer& texturePointer) {
if (texture.getUsageType() == TextureUsageType::RESOURCE) {
auto varTex = static_cast<GL45VariableAllocationTexture*> (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;
}
}
}
}