From 8d03d50d35843656264842cdb64240eb5b946fc0 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 21 Apr 2017 00:33:05 -0700 Subject: [PATCH] Cleanup progressive ktx debugging --- .../gpu/gl45/GL45BackendVariableTexture.cpp | 9 +------ libraries/gpu/src/gpu/Texture.cpp | 1 + libraries/gpu/src/gpu/Texture.h | 3 --- libraries/gpu/src/gpu/Texture_ktx.cpp | 22 +-------------- libraries/ktx/src/ktx/KTX.cpp | 3 +-- libraries/ktx/src/ktx/Reader.cpp | 2 +- .../src/model-networking/ModelCache.cpp | 1 - .../src/model-networking/TextureCache.cpp | 27 ++----------------- .../networking/src/HTTPResourceRequest.cpp | 1 - libraries/networking/src/ResourceCache.cpp | 2 -- .../render-utils/src/MeshPartPayload.cpp | 1 - libraries/shared/src/shared/Storage.cpp | 3 --- 12 files changed, 7 insertions(+), 68 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index f99209a7c2..77e42e7fdb 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -41,9 +41,6 @@ GL45VariableAllocationTexture::~GL45VariableAllocationTexture() { using GL45ResourceTexture = GL45Backend::GL45ResourceTexture; GL45ResourceTexture::GL45ResourceTexture(const std::weak_ptr& backend, const Texture& texture) : GL45VariableAllocationTexture(backend, texture) { - if (texture.source().find_first_of("box.ktx") != std::string::npos) { - qDebug() << "In box.ktx ctor"; - } auto mipLevels = texture.getNumMips(); _allocatedMip = mipLevels; @@ -53,13 +50,11 @@ GL45ResourceTexture::GL45ResourceTexture(const std::weak_ptr& backend for (uint16_t mip = 0; mip < mipLevels; ++mip) { if (glm::all(glm::lessThanEqual(texture.evalMipDimensions(mip), INITIAL_MIP_TRANSFER_DIMENSIONS)) && texture.isStoredMipFaceAvailable(mip)) { - _maxAllocatedMip = _populatedMip = mip; + _lowestRequestedMip = _maxAllocatedMip = _populatedMip = mip; break; } } - //_maxAllocatedMip = _populatedMip = mipLevels; - //glObjectLabel(GL_TEXTURE, _id, _source.length(), _source.data()); uint16_t allocatedMip = _populatedMip - std::min(_populatedMip, 2); allocateStorage(allocatedMip); _memoryPressureStateStale = true; @@ -112,7 +107,6 @@ void GL45ResourceTexture::promote() { auto oldSize = _size; // create new texture const_cast(_id) = allocate(_gpuObject); - //glObjectLabel(GL_TEXTURE, _id, _source.length(), _source.data()); uint16_t oldAllocatedMip = _allocatedMip; // allocate storage for new level allocateStorage(_allocatedMip - std::min(_allocatedMip, 2)); @@ -146,7 +140,6 @@ void GL45ResourceTexture::demote() { auto oldId = _id; auto oldSize = _size; const_cast(_id) = allocate(_gpuObject); - //glObjectLabel(GL_TEXTURE, _id, _source.length(), _source.data()); allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); uint16_t mips = _gpuObject.getNumMips(); diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index 1dbe9db2b4..bed01a805d 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -397,6 +397,7 @@ Size Texture::evalTotalSize(uint16 startingMip) const { Size size = 0; uint16 minMipLevel = std::max(getMinMip(), startingMip); uint16 maxMipLevel = getMaxMip(); + qDebug() << " min: " << minMipLevel << " " << maxMipLevel; for (uint16 level = minMipLevel; level <= maxMipLevel; level++) { size += evalMipSize(level); } diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index adf6a464f7..146615d631 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -524,9 +524,6 @@ public: ExternalUpdates getUpdates() const; - // Serialize ktx header and keyvalues directly to a file, and return a Texture representing that file - static TexturePointer serializeHeader(const std::string& ktxfile, const ktx::Header& header, const ktx::KeyValues& keyValues); - // Serialize a texture into a KTX file static ktx::KTXUniquePointer serialize(const Texture& texture); diff --git a/libraries/gpu/src/gpu/Texture_ktx.cpp b/libraries/gpu/src/gpu/Texture_ktx.cpp index 250b9ea8f3..8e30645837 100644 --- a/libraries/gpu/src/gpu/Texture_ktx.cpp +++ b/libraries/gpu/src/gpu/Texture_ktx.cpp @@ -134,21 +134,9 @@ void KtxStorage::assignMipData(uint16 level, const storage::StoragePointer& stor return; } - - //auto fileStorage = new storage::FileStorage(_filename.c_str()); - //ktx::StoragePointer file { fileStorage }; auto file = maybeOpenFile(); + auto data = file->mutableData(); - data += file->size(); - - // TODO Cache this data inside Image or ImageDescriptor? - for (int i = _ktxDescriptor->header.numberOfMipmapLevels - 1; i >= level; --i) { - data -= _ktxDescriptor->images[i]._imageSize; - data -= 4; - } - data += 4; - - data = file->mutableData(); data += ktx::KTX_HEADER_SIZE + _ktxDescriptor->header.bytesOfKeyValueData + _ktxDescriptor->images[level]._imageOffset; data += 4; @@ -173,7 +161,6 @@ void KtxStorage::assignMipFaceData(uint16 level, uint8 face, const storage::Stor throw std::runtime_error("Invalid call"); } - void Texture::setKtxBacking(const std::string& filename) { // Check the KTX file for validity before using it as backing storage { @@ -364,13 +351,6 @@ TexturePointer Texture::unserialize(const std::string& ktxfile, const ktx::KTXDe return tex; } -TexturePointer Texture::serializeHeader(const std::string& ktxfile, const ktx::Header& header, const ktx::KeyValues& keyValues) { - // Create a memory-backed KTX object - auto ktxBuffer = ktx::KTX::createBare(header, keyValues); - - return unserialize(ktxfile, ktxBuffer->toDescriptor()); -} - bool Texture::evalKTXFormat(const Element& mipFormat, const Element& texelFormat, ktx::Header& header) { if (texelFormat == Format::COLOR_RGBA_32 && mipFormat == Format::COLOR_BGRA_32) { header.setUncompressed(ktx::GLType::UNSIGNED_BYTE, 1, ktx::GLFormat::BGRA, ktx::GLInternalFormat_Uncompressed::RGBA8, ktx::GLBaseInternalFormat::RGBA); diff --git a/libraries/ktx/src/ktx/KTX.cpp b/libraries/ktx/src/ktx/KTX.cpp index e00937a67a..0dbc2e720f 100644 --- a/libraries/ktx/src/ktx/KTX.cpp +++ b/libraries/ktx/src/ktx/KTX.cpp @@ -91,9 +91,9 @@ size_t Header::evalPixelOrBlockSize() const { return 4; } } + qWarning() << "Unknown ktx format: " << glFormat << " " << glBaseInternalFormat << " " << glInternalFormat; return 0; - //throw std::runtime_error("Unknown format"); } size_t Header::evalRowSize(uint32_t level) const { @@ -284,7 +284,6 @@ Image ImageDescriptor::toImage(const ktx::StoragePointer& storage) const { FaceBytes faces; faces.resize(_faceOffsets.size()); for (size_t face = 0; face < _numFaces; ++face) { - // TODO Should we be storing pointers to unowned data? faces[face] = storage->data() + _faceOffsets[face]; } // Note, implicit cast of *this to const ImageHeader& diff --git a/libraries/ktx/src/ktx/Reader.cpp b/libraries/ktx/src/ktx/Reader.cpp index 27aee8771c..b22f262e85 100644 --- a/libraries/ktx/src/ktx/Reader.cpp +++ b/libraries/ktx/src/ktx/Reader.cpp @@ -50,7 +50,7 @@ namespace ktx { bool checkIdentifier(const Byte* identifier) { if (!(0 == memcmp(identifier, Header::IDENTIFIER.data(), Header::IDENTIFIER_LENGTH))) { - //throw ReaderException("identifier field invalid"); + throw ReaderException("identifier field invalid"); return false; } return true; diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index fc662e32a3..623832aaa8 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -364,7 +364,6 @@ void Geometry::setTextures(const QVariantMap& textureMap) { bool Geometry::areTexturesLoaded() const { if (!_areTexturesLoaded) { - //qDebug() << "Textures not loaded for " << _fbxGeometry->originalURL; for (auto& material : _materials) { // Check if material textures are loaded bool materialMissingTexture = std::any_of(material->_textures.cbegin(), material->_textures.cend(), diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index 05cfc7c06e..761f55068b 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -281,11 +281,6 @@ NetworkTexture::NetworkTexture(const QUrl& url, image::TextureUsage::Type type, _loaded = true; } - //if (_sourceIsKTX) { - //_requestByteRange.fromInclusive = 0; - //_requestByteRange.toExclusive = 1000; - //} - // if we have content, load it after we have our self pointer if (!content.isEmpty()) { _startedLoading = true; @@ -364,12 +359,9 @@ void NetworkTexture::makeRequest() { range.toExclusive = 1000; _ktxHeaderRequest->setByteRange(range); - //qCDebug(resourceLog).noquote() << "Starting request for:" << _url.toDisplayString(); emit loading(); connect(_ktxHeaderRequest, &ResourceRequest::progress, this, &NetworkTexture::ktxHeaderRequestProgress); - //connect(this, &Resource::onProgress, this, &NetworkTexture::ktxHeaderRequestFinished); - connect(_ktxHeaderRequest, &ResourceRequest::finished, this, &NetworkTexture::ktxHeaderRequestFinished); _bytesReceived = _bytesTotal = _bytes = 0; @@ -389,7 +381,6 @@ void NetworkTexture::makeRequest() { } void NetworkTexture::handleMipInterestCallback(uint16_t level) { - //qDebug(networking) << "++++ Got request for mip level: " << _url << " " << level; QMetaObject::invokeMethod(this, "handleMipInterestLevel", Qt::QueuedConnection, Q_ARG(int, level)); } @@ -426,7 +417,7 @@ void NetworkTexture::startMipRangeRequest(uint16_t low, uint16_t high) { _ktxMipRequest = ResourceManager::createResourceRequest(this, _activeUrl); if (!_ktxMipRequest) { - qCDebug(networking).noquote() << "Failed to get request for" << _url.toDisplayString(); + qCWarning(networking).noquote() << "Failed to get request for" << _url.toDisplayString(); PROFILE_ASYNC_END(resource, "Resource:" + getType(), QString::number(_requestID)); return; @@ -439,7 +430,6 @@ void NetworkTexture::startMipRangeRequest(uint16_t low, uint16_t high) { range.fromInclusive = -15000; _ktxMipRequest->setByteRange(range); } else { - qDebug(networking) << ">>> Making request to " << _url << " for " << low << " to " << high; ByteRange range; range.fromInclusive = ktx::KTX_HEADER_SIZE + _originalKtxDescriptor->header.bytesOfKeyValueData + _originalKtxDescriptor->images[low]._imageOffset + 4; @@ -478,8 +468,6 @@ void NetworkTexture::ktxMipRequestFinished() { auto texture = _textureSource->getGPUTexture(); if (texture) { - //_lowestKnownPopulatedMip = _ktxMipLevelRangeInFlight.first; - //qDebug() << "Writing mip for " << _url; texture->assignStoredMip(_ktxMipLevelRangeInFlight.first, _ktxMipRequest->getData().size(), reinterpret_cast(_ktxMipRequest->getData().data())); _lowestKnownPopulatedMip = _textureSource->getGPUTexture()->minAvailableMipLevel(); @@ -496,7 +484,7 @@ void NetworkTexture::ktxMipRequestFinished() { _ktxResourceState = PENDING_MIP_REQUEST; } else { - qWarning() << "Failed to load mip: " << _url; + qWarning(networking) << "Failed to load mip: " << _url; _ktxResourceState = FAILED_TO_LOAD; } } @@ -540,14 +528,6 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() { auto header = reinterpret_cast(ktxHeaderData.data()); - qDebug() << "Creating KTX"; - qDebug() << "Identifier:" << QString(QByteArray((char*)header->identifier, 12)); - qDebug() << "Type:" << header->glType; - qDebug() << "TypeSize:" << header->glTypeSize; - qDebug() << "numberOfArrayElements:" << header->numberOfArrayElements; - qDebug() << "numberOfFaces:" << header->numberOfFaces; - qDebug() << "numberOfMipmapLevels:" << header->numberOfMipmapLevels; - if (!ktx::checkIdentifier(header->identifier)) { qWarning() << "Cannot load " << _url << ", invalid header identifier"; _ktxResourceState = FAILED_TO_LOAD; @@ -586,7 +566,6 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() { return; } else { hash = filename = std::string(reinterpret_cast(found->_value.data()), 32); - //hash = filename = _url.path().replace("/", "_").toStdString(); } auto textureCache = DependencyManager::get(); @@ -629,7 +608,6 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() { auto newKtxDescriptor = memKtx->toDescriptor(); - //auto texture = gpu::Texture::serializeHeader("test.ktx", *header, keyValues); texture = gpu::Texture::unserialize(_file->getFilepath(), newKtxDescriptor); texture->setKtxBacking(file->getFilepath()); texture->setSource(filename); @@ -645,7 +623,6 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() { if (image._imageSize > imageSizeRemaining) { break; } - //qDebug() << "Transferring " << level; ktxData -= image._imageSize; texture->assignStoredMip(level, image._imageSize, ktxData); ktxData -= 4; diff --git a/libraries/networking/src/HTTPResourceRequest.cpp b/libraries/networking/src/HTTPResourceRequest.cpp index 7045894633..52f5ee43f5 100644 --- a/libraries/networking/src/HTTPResourceRequest.cpp +++ b/libraries/networking/src/HTTPResourceRequest.cpp @@ -132,7 +132,6 @@ void HTTPResourceRequest::onRequestFinished() { uint64_t size; std::tie(success, size) = parseContentRangeHeader(contentRangeHeader); if (success) { - //qWarning(networking) << "Total http resource size is: " << size; _totalSizeOfResource = size; } else { qWarning(networking) << "Error parsing content-range header: " << contentRangeHeader; diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index 95bfd0e24d..56897ca4cd 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -667,7 +667,6 @@ void Resource::makeRequest() { } PROFILE_ASYNC_BEGIN(resource, "Resource:" + getType(), QString::number(_requestID), { { "url", _url.toString() }, { "activeURL", _activeUrl.toString() } }); - qDebug() << "Making request to " << _url << " for byte range " << _requestByteRange.fromInclusive << "-" << _requestByteRange.toExclusive; _request = ResourceManager::createResourceRequest(this, _activeUrl); @@ -700,7 +699,6 @@ void Resource::handleDownloadProgress(uint64_t bytesReceived, uint64_t bytesTota } void Resource::handleReplyFinished() { - qDebug() << "Got response for " << _activeUrl; Q_ASSERT_X(_request, "Resource::handleReplyFinished", "Request should not be null while in handleReplyFinished"); PROFILE_ASYNC_END(resource, "Resource:" + getType(), QString::number(_requestID), { diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index e6ae6d21a1..9232564514 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -544,7 +544,6 @@ void ModelMeshPartPayload::render(RenderArgs* args) const { } if (_fadeState == FADE_WAITING_TO_START) { - //if (_model->isLoaded() && _model->getGeometry()->areTexturesLoaded()) { if (_model->isLoaded()) { if (EntityItem::getEntitiesShouldFadeFunction()()) { _fadeStartTime = usecTimestampNow(); diff --git a/libraries/shared/src/shared/Storage.cpp b/libraries/shared/src/shared/Storage.cpp index 6eb311fa60..aae1f8455f 100644 --- a/libraries/shared/src/shared/Storage.cpp +++ b/libraries/shared/src/shared/Storage.cpp @@ -67,10 +67,8 @@ StoragePointer FileStorage::create(const QString& filename, size_t size, const u return std::make_shared(filename); } -// Represents a memory mapped file FileStorage::FileStorage(const QString& filename) : _file(filename) { if (_file.open(QFile::ReadWrite)) { - //qDebug() << ">>> Opening mmapped file: " << filename; _mapped = _file.map(0, _file.size()); if (_mapped) { _valid = true; @@ -83,7 +81,6 @@ FileStorage::FileStorage(const QString& filename) : _file(filename) { } FileStorage::~FileStorage() { - //qDebug() << ">>> Closing mmapped file: " << _file.fileName(); if (_mapped) { if (!_file.unmap(_mapped)) { throw std::runtime_error("Unable to unmap file");