From 70eaac8d6c5b509d3e395f2595e41011ee129f71 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 18 Apr 2017 21:16:17 -0700 Subject: [PATCH] Add persisting of ktx min mips available to ktx cache file --- libraries/gpu-gl/src/gpu/gl/GLTexture.cpp | 6 +++--- libraries/gpu/src/gpu/Texture_ktx.cpp | 4 ++++ libraries/ktx/src/ktx/KTX.cpp | 12 ++++++++++++ libraries/ktx/src/ktx/KTX.h | 1 + .../src/model-networking/TextureCache.cpp | 3 ++- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index 3853d0a9cc..c82fa4c744 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -458,12 +458,12 @@ void GLVariableAllocationSupport::updateMemoryPressure() { float pressure = (float)totalVariableMemoryAllocation / (float)allowedMemoryAllocation; auto newState = MemoryPressureState::Idle; - if (pressure > OVERSUBSCRIBED_PRESSURE_VALUE && canDemote) { + if (hasTransfers) { + newState = MemoryPressureState::Transfer; + } else if (pressure > OVERSUBSCRIBED_PRESSURE_VALUE && canDemote) { newState = MemoryPressureState::Oversubscribed; } else if (pressure < UNDERSUBSCRIBED_PRESSURE_VALUE && unallocated != 0 && canPromote) { newState = MemoryPressureState::Undersubscribed; - } else if (hasTransfers) { - newState = MemoryPressureState::Transfer; } if (newState != _memoryPressureState) { diff --git a/libraries/gpu/src/gpu/Texture_ktx.cpp b/libraries/gpu/src/gpu/Texture_ktx.cpp index e2b9b8d9ae..c0fe3f5c9c 100644 --- a/libraries/gpu/src/gpu/Texture_ktx.cpp +++ b/libraries/gpu/src/gpu/Texture_ktx.cpp @@ -155,6 +155,7 @@ void KtxStorage::assignMipData(uint16 level, const storage::StoragePointer& stor data += ktx::KTX_HEADER_SIZE + _ktxDescriptor->header.bytesOfKeyValueData + _ktxDescriptor->images[level]._imageOffset; data += 4; + auto offset = _ktxDescriptor->getValueOffsetForKey(ktx::HIFI_MIN_POPULATED_MIP_KEY); { std::lock_guard lock { _cacheFileWriteMutex }; @@ -165,6 +166,9 @@ void KtxStorage::assignMipData(uint16 level, const storage::StoragePointer& stor memcpy(data, storage->data(), _ktxDescriptor->images[level]._imageSize); _minMipLevelAvailable = level; + if (offset > 0) { + memcpy(file->mutableData() + ktx::KTX_HEADER_SIZE + offset, (uint8_t)_minMipLevelAvailable, 1); + } } } diff --git a/libraries/ktx/src/ktx/KTX.cpp b/libraries/ktx/src/ktx/KTX.cpp index c9dd18d665..68b83b1682 100644 --- a/libraries/ktx/src/ktx/KTX.cpp +++ b/libraries/ktx/src/ktx/KTX.cpp @@ -118,6 +118,18 @@ size_t Header::evalImageSize(uint32_t level) const { } } + +size_t KTXDescriptor::getValueOffsetForKey(const std::string& key) const { + size_t offset { 0 }; + for (auto& kv : keyValues) { + if (kv._key == key) { + return offset + kv._key.size() + 1; + } + offset += kv.serializedByteSize(); + } + return 0; +} + ImageDescriptors Header::generateImageDescriptors() const { ImageDescriptors descriptors; diff --git a/libraries/ktx/src/ktx/KTX.h b/libraries/ktx/src/ktx/KTX.h index 7f6f2da939..65ecc430b9 100644 --- a/libraries/ktx/src/ktx/KTX.h +++ b/libraries/ktx/src/ktx/KTX.h @@ -471,6 +471,7 @@ namespace ktx { const ImageDescriptors images; size_t getMipFaceTexelsSize(uint16_t mip = 0, uint8_t face = 0) const; size_t getMipFaceTexelsOffset(uint16_t mip = 0, uint8_t face = 0) const; + size_t getValueOffsetForKey(const std::string& key) const; }; class KTX { diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index 11121570c1..8b6530b5b9 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -377,8 +377,8 @@ void NetworkTexture::makeRequest() { startMipRangeRequest(NULL_MIP_LEVEL, NULL_MIP_LEVEL); } else if (_ktxResourceState == PENDING_MIP_REQUEST) { - _ktxResourceState = REQUESTING_MIP; if (_lowestKnownPopulatedMip > 0) { + _ktxResourceState = REQUESTING_MIP; startMipRangeRequest(_lowestKnownPopulatedMip - 1, _lowestKnownPopulatedMip - 1); } } else { @@ -393,6 +393,7 @@ void NetworkTexture::handleMipInterestCallback(uint16_t level) { } void NetworkTexture::handleMipInterestLevel(int level) { + _lowestRequestedMipLevel = std::min((uint16_t)level, _lowestRequestedMipLevel); startRequestForNextMipLevel(); }