mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:37:46 +02:00
I think it might be working.
This commit is contained in:
parent
70eaac8d6c
commit
ce12a216c0
6 changed files with 90 additions and 71 deletions
|
@ -459,10 +459,13 @@ void GLVariableAllocationSupport::updateMemoryPressure() {
|
||||||
|
|
||||||
auto newState = MemoryPressureState::Idle;
|
auto newState = MemoryPressureState::Idle;
|
||||||
if (hasTransfers) {
|
if (hasTransfers) {
|
||||||
|
qDebug() << "Transferring";
|
||||||
newState = MemoryPressureState::Transfer;
|
newState = MemoryPressureState::Transfer;
|
||||||
} else if (pressure > OVERSUBSCRIBED_PRESSURE_VALUE && canDemote) {
|
} else if (pressure > OVERSUBSCRIBED_PRESSURE_VALUE && canDemote) {
|
||||||
|
qDebug() << "Demoting";
|
||||||
newState = MemoryPressureState::Oversubscribed;
|
newState = MemoryPressureState::Oversubscribed;
|
||||||
} else if (pressure < UNDERSUBSCRIBED_PRESSURE_VALUE && unallocated != 0 && canPromote) {
|
} else if (pressure < UNDERSUBSCRIBED_PRESSURE_VALUE && unallocated != 0 && canPromote) {
|
||||||
|
qDebug() << "Promoting";
|
||||||
newState = MemoryPressureState::Undersubscribed;
|
newState = MemoryPressureState::Undersubscribed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ protected:
|
||||||
static void manageMemory();
|
static void manageMemory();
|
||||||
|
|
||||||
//bool canPromoteNoAllocate() const { return _allocatedMip < _populatedMip; }
|
//bool canPromoteNoAllocate() const { return _allocatedMip < _populatedMip; }
|
||||||
bool canPromote() const { return _allocatedMip > 0; }
|
bool canPromote() const { return _allocatedMip > 0 || _populatedMip > 0; }
|
||||||
bool canDemote() const { return _allocatedMip < _maxAllocatedMip; }
|
bool canDemote() const { return _allocatedMip < _maxAllocatedMip; }
|
||||||
bool hasPendingTransfers() const { return _populatedMip > _allocatedMip; }
|
bool hasPendingTransfers() const { return _populatedMip > _allocatedMip; }
|
||||||
void executeNextTransfer(const TexturePointer& currentTexture);
|
void executeNextTransfer(const TexturePointer& currentTexture);
|
||||||
|
|
|
@ -51,6 +51,9 @@ KtxStorage::KtxStorage(const std::string& filename) : _filename(filename) {
|
||||||
ktx::StoragePointer storage{ new storage::FileStorage(_filename.c_str()) };
|
ktx::StoragePointer storage{ new storage::FileStorage(_filename.c_str()) };
|
||||||
auto ktxPointer = ktx::KTX::create(storage);
|
auto ktxPointer = ktx::KTX::create(storage);
|
||||||
_ktxDescriptor.reset(new ktx::KTXDescriptor(ktxPointer->toDescriptor()));
|
_ktxDescriptor.reset(new ktx::KTXDescriptor(ktxPointer->toDescriptor()));
|
||||||
|
if (_ktxDescriptor->images.size() < _ktxDescriptor->header.numberOfMipmapLevels) {
|
||||||
|
qDebug() << "bad images found";
|
||||||
|
}
|
||||||
auto& keyValues = _ktxDescriptor->keyValues;
|
auto& keyValues = _ktxDescriptor->keyValues;
|
||||||
auto found = std::find_if(keyValues.begin(), keyValues.end(), [](const ktx::KeyValue& val) -> bool {
|
auto found = std::find_if(keyValues.begin(), keyValues.end(), [](const ktx::KeyValue& val) -> bool {
|
||||||
return val._key.compare(ktx::HIFI_MIN_POPULATED_MIP_KEY) == 0;
|
return val._key.compare(ktx::HIFI_MIN_POPULATED_MIP_KEY) == 0;
|
||||||
|
@ -167,7 +170,7 @@ void KtxStorage::assignMipData(uint16 level, const storage::StoragePointer& stor
|
||||||
memcpy(data, storage->data(), _ktxDescriptor->images[level]._imageSize);
|
memcpy(data, storage->data(), _ktxDescriptor->images[level]._imageSize);
|
||||||
_minMipLevelAvailable = level;
|
_minMipLevelAvailable = level;
|
||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
memcpy(file->mutableData() + ktx::KTX_HEADER_SIZE + offset, (uint8_t)_minMipLevelAvailable, 1);
|
memcpy(file->mutableData() + ktx::KTX_HEADER_SIZE + offset, (void*)&_minMipLevelAvailable, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -364,6 +364,7 @@ void Geometry::setTextures(const QVariantMap& textureMap) {
|
||||||
|
|
||||||
bool Geometry::areTexturesLoaded() const {
|
bool Geometry::areTexturesLoaded() const {
|
||||||
if (!_areTexturesLoaded) {
|
if (!_areTexturesLoaded) {
|
||||||
|
qDebug() << "Textures not loaded for " << _fbxGeometry->originalURL;
|
||||||
for (auto& material : _materials) {
|
for (auto& material : _materials) {
|
||||||
// Check if material textures are loaded
|
// Check if material textures are loaded
|
||||||
bool materialMissingTexture = std::any_of(material->_textures.cbegin(), material->_textures.cend(),
|
bool materialMissingTexture = std::any_of(material->_textures.cbegin(), material->_textures.cend(),
|
||||||
|
|
|
@ -422,7 +422,7 @@ void NetworkTexture::startMipRangeRequest(uint16_t low, uint16_t high) {
|
||||||
bool isHighMipRequest = low == NULL_MIP_LEVEL && high == NULL_MIP_LEVEL;
|
bool isHighMipRequest = low == NULL_MIP_LEVEL && high == NULL_MIP_LEVEL;
|
||||||
|
|
||||||
_ktxMipRequest = ResourceManager::createResourceRequest(this, _activeUrl);
|
_ktxMipRequest = ResourceManager::createResourceRequest(this, _activeUrl);
|
||||||
qDebug(networking) << ">>> Making request to " << _url << " for " << low << " to " << high;
|
//qDebug(networking) << ">>> Making request to " << _url << " for " << low << " to " << high;
|
||||||
|
|
||||||
_ktxMipLevelRangeInFlight = { low, high };
|
_ktxMipLevelRangeInFlight = { low, high };
|
||||||
if (isHighMipRequest) {
|
if (isHighMipRequest) {
|
||||||
|
@ -460,6 +460,7 @@ void NetworkTexture::ktxMipRequestFinished() {
|
||||||
_ktxHighMipRequestFinished = true;
|
_ktxHighMipRequestFinished = true;
|
||||||
maybeHandleFinishedInitialLoad();
|
maybeHandleFinishedInitialLoad();
|
||||||
} else if (_ktxResourceState == REQUESTING_MIP) {
|
} else if (_ktxResourceState == REQUESTING_MIP) {
|
||||||
|
Q_ASSERT(_ktxMipLevelRangeInFlight.first != NULL_MIP_LEVEL);
|
||||||
ResourceCache::requestCompleted(_self);
|
ResourceCache::requestCompleted(_self);
|
||||||
|
|
||||||
if (_ktxMipRequest->getResult() == ResourceRequest::Success) {
|
if (_ktxMipRequest->getResult() == ResourceRequest::Success) {
|
||||||
|
@ -468,20 +469,26 @@ void NetworkTexture::ktxMipRequestFinished() {
|
||||||
auto texture = _textureSource->getGPUTexture();
|
auto texture = _textureSource->getGPUTexture();
|
||||||
if (texture) {
|
if (texture) {
|
||||||
_lowestKnownPopulatedMip = _ktxMipLevelRangeInFlight.first;
|
_lowestKnownPopulatedMip = _ktxMipLevelRangeInFlight.first;
|
||||||
qDebug() << "Writing mip for " << _url;
|
//qDebug() << "Writing mip for " << _url;
|
||||||
texture->assignStoredMip(_ktxMipLevelRangeInFlight.first,
|
texture->assignStoredMip(_ktxMipLevelRangeInFlight.first,
|
||||||
_ktxMipRequest->getData().size(), reinterpret_cast<uint8_t*>(_ktxMipRequest->getData().data()));
|
_ktxMipRequest->getData().size(), reinterpret_cast<uint8_t*>(_ktxMipRequest->getData().data()));
|
||||||
} else {
|
} else {
|
||||||
qWarning(networking) << "Trying to update mips but texture is null";
|
qWarning(networking) << "Trying to update mips but texture is null";
|
||||||
}
|
}
|
||||||
|
finishedLoading(true);
|
||||||
_ktxResourceState = WAITING_FOR_MIP_REQUEST;
|
_ktxResourceState = WAITING_FOR_MIP_REQUEST;
|
||||||
} else {
|
} else {
|
||||||
_ktxResourceState = PENDING_MIP_REQUEST;
|
_ktxResourceState = PENDING_MIP_REQUEST;
|
||||||
|
finishedLoading(false);
|
||||||
handleFailedRequest(_ktxMipRequest->getResult());
|
handleFailedRequest(_ktxMipRequest->getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
_ktxMipRequest->deleteLater();
|
_ktxMipRequest->deleteLater();
|
||||||
_ktxMipRequest = nullptr;
|
_ktxMipRequest = nullptr;
|
||||||
|
|
||||||
|
if (_ktxResourceState == WAITING_FOR_MIP_REQUEST && _lowestRequestedMipLevel < _lowestKnownPopulatedMip) {
|
||||||
|
startRequestForNextMipLevel();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Mip request finished in an unexpected state: " << _ktxResourceState;
|
qWarning() << "Mip request finished in an unexpected state: " << _ktxResourceState;
|
||||||
}
|
}
|
||||||
|
@ -544,22 +551,32 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
|
||||||
return val._key.compare(gpu::SOURCE_HASH_KEY) == 0;
|
return val._key.compare(gpu::SOURCE_HASH_KEY) == 0;
|
||||||
});
|
});
|
||||||
std::string filename;
|
std::string filename;
|
||||||
if (found == keyValues.end()) {
|
std::string hash;
|
||||||
//qWarning("Source hash key not found, bailing");
|
if (found == keyValues.end() || found->_value.size() != 32) {
|
||||||
//finishedLoading(false);
|
|
||||||
//return;
|
|
||||||
filename = _url.fileName().toStdString();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (found->_value.size() < 32) {
|
|
||||||
qWarning("Invalid source hash key found, bailing");
|
qWarning("Invalid source hash key found, bailing");
|
||||||
_ktxResourceState = FAILED_TO_LOAD;
|
_ktxResourceState = FAILED_TO_LOAD;
|
||||||
finishedLoading(false);
|
finishedLoading(false);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
filename = std::string(reinterpret_cast<char*>(found->_value.data()), 32);
|
hash = filename = std::string(reinterpret_cast<char*>(found->_value.data()), 32);
|
||||||
|
//hash = filename = _url.path().replace("/", "_").toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto textureCache = DependencyManager::get<TextureCache>();
|
||||||
|
|
||||||
|
gpu::TexturePointer texture = textureCache->getTextureByHash(hash);
|
||||||
|
|
||||||
|
if (!texture) {
|
||||||
|
KTXFilePointer ktxFile = textureCache->_ktxCache.getFile(hash);
|
||||||
|
if (ktxFile) {
|
||||||
|
texture.reset(gpu::Texture::unserialize(ktxFile->getFilepath()));
|
||||||
|
if (texture) {
|
||||||
|
texture = textureCache->cacheTextureByHash(hash, texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!texture) {
|
||||||
|
|
||||||
auto memKtx = ktx::KTX::createBare(*header, keyValues);
|
auto memKtx = ktx::KTX::createBare(*header, keyValues);
|
||||||
if (!memKtx) {
|
if (!memKtx) {
|
||||||
|
@ -568,11 +585,6 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//auto d = const_cast<uint8_t*>(memKtx->getStorage()->data());
|
|
||||||
//memcpy(d + memKtx->_storage->size() - _ktxHighMipData.size(), _ktxHighMipData.data(), _ktxHighMipData.size());
|
|
||||||
|
|
||||||
auto textureCache = DependencyManager::get<TextureCache>();
|
|
||||||
|
|
||||||
// Move ktx to file
|
// Move ktx to file
|
||||||
const char* data = reinterpret_cast<const char*>(memKtx->_storage->data());
|
const char* data = reinterpret_cast<const char*>(memKtx->_storage->data());
|
||||||
size_t length = memKtx->_storage->size();
|
size_t length = memKtx->_storage->size();
|
||||||
|
@ -583,19 +595,17 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
|
||||||
_ktxResourceState = FAILED_TO_LOAD;
|
_ktxResourceState = FAILED_TO_LOAD;
|
||||||
finishedLoading(false);
|
finishedLoading(false);
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
_file = file;
|
_file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
//_ktxDescriptor.reset(new ktx::KTXDescriptor(memKtx->toDescriptor()));
|
|
||||||
auto newKtxDescriptor = memKtx->toDescriptor();
|
auto newKtxDescriptor = memKtx->toDescriptor();
|
||||||
|
|
||||||
//auto texture = gpu::Texture::serializeHeader("test.ktx", *header, keyValues);
|
//auto texture = gpu::Texture::serializeHeader("test.ktx", *header, keyValues);
|
||||||
gpu::TexturePointer texture;
|
|
||||||
texture.reset(gpu::Texture::unserialize(_file->getFilepath(), newKtxDescriptor));
|
texture.reset(gpu::Texture::unserialize(_file->getFilepath(), newKtxDescriptor));
|
||||||
texture->setKtxBacking(file->getFilepath());
|
texture->setKtxBacking(file->getFilepath());
|
||||||
texture->setSource(filename);
|
texture->setSource(filename);
|
||||||
texture->registerMipInterestListener(this);
|
|
||||||
|
|
||||||
auto& images = _originalKtxDescriptor->images;
|
auto& images = _originalKtxDescriptor->images;
|
||||||
size_t imageSizeRemaining = ktxHighMipData.size();
|
size_t imageSizeRemaining = ktxHighMipData.size();
|
||||||
|
@ -608,7 +618,7 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
|
||||||
if (image._imageSize > imageSizeRemaining) {
|
if (image._imageSize > imageSizeRemaining) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
qDebug() << "Transferring " << level;
|
//qDebug() << "Transferring " << level;
|
||||||
ktxData -= image._imageSize;
|
ktxData -= image._imageSize;
|
||||||
texture->assignStoredMip(level, image._imageSize, ktxData);
|
texture->assignStoredMip(level, image._imageSize, ktxData);
|
||||||
ktxData -= 4;
|
ktxData -= 4;
|
||||||
|
@ -618,11 +628,11 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
|
||||||
// We replace the texture with the one stored in the cache. This deals with the possible race condition of two different
|
// We replace the texture with the one stored in the cache. This deals with the possible race condition of two different
|
||||||
// images with the same hash being loaded concurrently. Only one of them will make it into the cache by hash first and will
|
// images with the same hash being loaded concurrently. Only one of them will make it into the cache by hash first and will
|
||||||
// be the winner
|
// be the winner
|
||||||
if (textureCache) {
|
|
||||||
texture = textureCache->cacheTextureByHash(filename, texture);
|
texture = textureCache->cacheTextureByHash(filename, texture);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
_lowestKnownPopulatedMip = _originalKtxDescriptor->header.numberOfMipmapLevels;
|
_lowestKnownPopulatedMip = _originalKtxDescriptor->header.numberOfMipmapLevels;
|
||||||
for (uint16_t l = 0; l < 200; l++) {
|
for (uint16_t l = 0; l < 200; l++) {
|
||||||
if (texture->isStoredMipFaceAvailable(l)) {
|
if (texture->isStoredMipFaceAvailable(l)) {
|
||||||
|
@ -631,8 +641,11 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
texture->registerMipInterestListener(this);
|
||||||
_ktxResourceState = WAITING_FOR_MIP_REQUEST;
|
_ktxResourceState = WAITING_FOR_MIP_REQUEST;
|
||||||
setImage(texture, header->getPixelWidth(), header->getPixelHeight());
|
setImage(texture, header->getPixelWidth(), header->getPixelHeight());
|
||||||
|
qDebug() << "Loaded KTX: " << QString::fromStdString(hash) << " : " << _url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ void HTTPResourceRequest::onRequestFinished() {
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
std::tie(success, size) = parseContentRangeHeader(contentRangeHeader);
|
std::tie(success, size) = parseContentRangeHeader(contentRangeHeader);
|
||||||
if (success) {
|
if (success) {
|
||||||
qWarning(networking) << "Total http resource size is: " << size;
|
//qWarning(networking) << "Total http resource size is: " << size;
|
||||||
_totalSizeOfResource = size;
|
_totalSizeOfResource = size;
|
||||||
} else {
|
} else {
|
||||||
qWarning(networking) << "Error parsing content-range header: " << contentRangeHeader;
|
qWarning(networking) << "Error parsing content-range header: " << contentRangeHeader;
|
||||||
|
@ -187,7 +187,6 @@ void HTTPResourceRequest::onRequestFinished() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPResourceRequest::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
void HTTPResourceRequest::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
||||||
qDebug() << "Progress: " << _url;
|
|
||||||
Q_ASSERT(_state == InProgress);
|
Q_ASSERT(_state == InProgress);
|
||||||
|
|
||||||
// We've received data, so reset the timer
|
// We've received data, so reset the timer
|
||||||
|
|
Loading…
Reference in a new issue