mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 20:22:22 +02:00
Cleanup progressive ktx debugging
This commit is contained in:
parent
bc6d476a4d
commit
8d03d50d35
12 changed files with 7 additions and 68 deletions
|
@ -41,9 +41,6 @@ GL45VariableAllocationTexture::~GL45VariableAllocationTexture() {
|
|||
using GL45ResourceTexture = GL45Backend::GL45ResourceTexture;
|
||||
|
||||
GL45ResourceTexture::GL45ResourceTexture(const std::weak_ptr<GLBackend>& 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<GLBackend>& 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<uint16_t>(_populatedMip, 2);
|
||||
allocateStorage(allocatedMip);
|
||||
_memoryPressureStateStale = true;
|
||||
|
@ -112,7 +107,6 @@ void GL45ResourceTexture::promote() {
|
|||
auto oldSize = _size;
|
||||
// create new texture
|
||||
const_cast<GLuint&>(_id) = allocate(_gpuObject);
|
||||
//glObjectLabel(GL_TEXTURE, _id, _source.length(), _source.data());
|
||||
uint16_t oldAllocatedMip = _allocatedMip;
|
||||
// allocate storage for new level
|
||||
allocateStorage(_allocatedMip - std::min<uint16_t>(_allocatedMip, 2));
|
||||
|
@ -146,7 +140,6 @@ void GL45ResourceTexture::demote() {
|
|||
auto oldId = _id;
|
||||
auto oldSize = _size;
|
||||
const_cast<GLuint&>(_id) = allocate(_gpuObject);
|
||||
//glObjectLabel(GL_TEXTURE, _id, _source.length(), _source.data());
|
||||
allocateStorage(_allocatedMip + 1);
|
||||
_populatedMip = std::max(_populatedMip, _allocatedMip);
|
||||
uint16_t mips = _gpuObject.getNumMips();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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&
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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<uint8_t*>(_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<const ktx::Header*>(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<char*>(found->_value.data()), 32);
|
||||
//hash = filename = _url.path().replace("/", "_").toStdString();
|
||||
}
|
||||
|
||||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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), {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -67,10 +67,8 @@ StoragePointer FileStorage::create(const QString& filename, size_t size, const u
|
|||
return std::make_shared<FileStorage>(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");
|
||||
|
|
Loading…
Reference in a new issue